:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --green: #059669;
    --green-hover: #047857;
    --red: #dc2626;
    --red-light: #fef2f2;
    --orange: #ea580c;
    --orange-light: #fff7ed;
    --blue: #2563eb;
    --blue-light: #eff6ff;
    --purple: #7c3aed;
    --purple-light: #f5f3ff;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --white: #ffffff;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.6;
    min-height: 100vh;
}

/* ── Layout ── */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 16px;
}

/* ── Navbar ── */
.navbar {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
}
.navbar-brand {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}
.navbar-nav {
    display: flex;
    gap: 12px;
    align-items: center;
}
.navbar-nav a, .navbar-nav button {
    font-size: 14px;
    color: var(--gray-700);
    text-decoration: none;
    padding: 6px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    border: none;
    background: none;
}
.navbar-nav a:hover, .navbar-nav button:hover { background: var(--gray-100); }
.navbar-nav .role-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    background: var(--purple-light);
    color: var(--purple);
    font-weight: 600;
}

/* ── Cards ── */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 16px;
    border: 1px solid var(--gray-200);
}

/* ── Forms ── */
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 4px;
}
.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.form-group textarea {
    min-height: 240px;
    resize: vertical;
    font-family: "Georgia", serif;
    line-height: 1.8;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--green); color: var(--white); }
.btn-success:hover { background: var(--green-hover); }
.btn-outline {
    background: var(--white);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}
.btn-outline:hover { background: var(--gray-100); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Tables ── */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.table th {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid var(--gray-200);
    color: var(--gray-500);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
}
.table td {
    padding: 12px;
    border-bottom: 1px solid var(--gray-100);
}
.table tr:hover { background: var(--gray-50); }
.table a { color: var(--primary); text-decoration: none; font-weight: 500; }
.table a:hover { text-decoration: underline; }

/* ── Feedback categories ── */
.feedback-section { margin-bottom: 20px; }
.feedback-section h3 {
    font-size: 15px;
    padding: 8px 14px;
    border-radius: var(--radius) var(--radius) 0 0;
    margin: 0;
}
.cat-chinglish h3 { background: var(--red-light); color: var(--red); }
.cat-collocation_grammar h3 { background: var(--orange-light); color: var(--orange); }
.cat-logic h3 { background: var(--blue-light); color: var(--blue); }
.cat-optimization h3 { background: var(--purple-light); color: var(--purple); }
.feedback-item {
    padding: 12px 14px;
    border-left: 3px solid var(--gray-200);
    margin: 0;
    border-bottom: 1px solid var(--gray-100);
}
.feedback-item .issue {
    font-style: italic;
    color: var(--gray-700);
    margin-bottom: 4px;
}
.feedback-item .suggestion {
    color: var(--gray-900);
    font-size: 14px;
    white-space: pre-wrap;
}

/* ── Status badges ── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}
.badge-draft { background: #fef3c7; color: #92400e; }
.badge-published { background: #d1fae5; color: #065f46; }

/* ── Alerts ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 14px;
}
.alert-error { background: var(--red-light); color: var(--red); border: 1px solid #fecaca; }
.alert-success { background: #ecfdf5; color: var(--green); border: 1px solid #a7f3d0; }

/* ── Loading ── */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-500);
}

/* ── Utility ── */
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.text-center { text-align: center; }
.text-sm { font-size: 13px; color: var(--gray-500); }
.text-lg { font-size: 20px; font-weight: 700; }
.hidden { display: none !important; }

/* ── Auth pages ── */
.auth-card {
    max-width: 420px;
    margin: 80px auto 0;
}
.auth-card h2 { margin-bottom: 20px; text-align: center; }

/* ── Dashboard stats ── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--white);
    padding: 20px;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    text-align: center;
}
.stat-card .stat-num { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 13px; color: var(--gray-500); margin-top: 4px; }

/* ── Invite code display ── */
.invite-code {
    font-family: "Courier New", monospace;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 3px;
    background: var(--gray-100);
    padding: 8px 20px;
    border-radius: var(--radius);
    display: inline-block;
    color: var(--primary);
}

/* ── Edit mode for feedback ── */
.feedback-editable .feedback-item {
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.15s;
}
.feedback-editable .feedback-item:hover { background: var(--gray-50); }
/* ── Benchmark card ── */
.benchmark-card {
    border-left: 4px solid var(--primary);
    background: linear-gradient(135deg, #eef2ff 0%, #ffffff 100%);
}
.benchmark-card h3 { color: var(--primary); }

/* ── Exercises ── */
.exercise-item {
    padding: 16px 0;
    border-bottom: 1px solid var(--gray-100);
}
.exercise-item:last-child { border-bottom: none; }
.exercise-question {
    font-style: italic;
    color: var(--gray-700);
    font-family: Georgia, serif;
    font-size: 15px;
    padding: 10px 14px;
    background: var(--gray-50);
    border-radius: var(--radius);
    border-left: 3px solid var(--primary);
}
.exercise-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}
.option-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 14px;
}
.option-label:hover { background: var(--gray-50); border-color: var(--primary); }
.option-label input[type="radio"] { margin: 0; }
.exercise-input {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-family: Georgia, serif;
    font-size: 14px;
    margin-top: 12px;
    resize: vertical;
}
.exercise-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}
.exercise-result {
    padding: 12px 14px;
    border-radius: var(--radius);
    font-size: 14px;
}
.result-correct { background: #ecfdf5; border: 1px solid #a7f3d0; }
.result-wrong { background: var(--red-light); border: 1px solid #fecaca; }
.user-answer { color: var(--red); text-decoration: line-through; }
.correct-answer { color: var(--green); font-weight: 600; }

.feedback-edit-form textarea {
    width: 100%;
    min-height: 60px;
    padding: 8px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
}

/* ── Mobile responsive ── */
@media (max-width: 768px) {
    .container { padding: 12px; }

    .navbar { flex-wrap: wrap; padding: 8px 12px; }
    .navbar-brand { font-size: 15px; }
    .navbar-nav { flex-wrap: wrap; gap: 4px; font-size: 12px; }
    .navbar-nav a, .navbar-nav button { padding: 4px 8px; font-size: 12px; }
    .navbar-nav .role-badge { font-size: 10px; }

    .auth-card { margin-top: 24px; max-width: 100%; }

    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-card { padding: 14px; }
    .stat-card .stat-num { font-size: 22px; }

    .card { padding: 14px; }

    .table { font-size: 12px; }
    .table th, .table td { padding: 8px 6px; }

    .btn { padding: 8px 14px; font-size: 13px; }
    .btn-sm { padding: 6px 10px; font-size: 11px; }

    .form-group textarea { min-height: 160px; font-size: 16px; }
    .form-group input, .form-group select { font-size: 16px; }

    .flex-between { flex-direction: column; gap: 8px; align-items: flex-start; }

    .option-label { font-size: 13px; padding: 8px 10px; }
    .exercise-input { font-size: 16px; }

    .feedback-edit-form textarea { font-size: 16px; }
}
