/* ==========================================================================
   Student Complaint System — App Shell Stylesheet
   Tokens and components per /design.md. Do not introduce one-off colors —
   derive everything from the tokens below.
   ========================================================================== */

:root {
    /* Cairo University brand foundation */
    --cu-parchment: #EFEACC;
    --cu-burgundy: #8A0000;
    --cu-navy: #313168;
    --cu-sky: #9FDCEF;
    --cu-deep: #1A1A40;

    /* Application semantic tokens */
    --accent: #8A0000;
    --sidebar: #313168;
    --bg: #F3F4F6;
    --white: #FFFFFF;
    --border: #E5E7EB;
    --text: #111827;
    --text-muted: #6B7280;

    /* Status colors */
    --status-green-bg: #DCFCE7;
    --status-green-text: #166534;
    --status-amber-bg: #FEF3C7;
    --status-amber-text: #92400E;
    --status-red-bg: #FEE2E2;
    --status-red-text: #991B1B;
    --status-blue-bg: #DBEAFE;
    --status-blue-text: #1E40AF;
    --status-grey-bg: #E5E7EB;
    --status-grey-text: #374151;

    /* Spacing (4px base) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-14: 56px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Plus Jakarta Sans', 'Segoe UI', Tahoma, sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

[lang="ar"] {
    font-size: 1.06em; /* Arabic display/body text runs 5-10% larger */
}

[lang="ar"] body,
.app-root[lang="ar"] {
    line-height: 1.8;
}

a { color: var(--accent); }

h1, h2, h3 { font-family: 'Plus Jakarta Sans', 'Segoe UI', Tahoma, sans-serif; color: var(--text); margin: 0 0 var(--space-4); }
h1 { font-size: 24px; font-weight: 600; }
h2 { font-size: 20px; font-weight: 600; }
h3 { font-size: 18px; font-weight: 600; }

.text-muted { color: var(--text-muted); }

.eyebrow {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--text-muted);
}

/* Direction-aware helpers: default LTR, overridden under [dir="rtl"] */
[dir="ltr"] { direction: ltr; }
[dir="rtl"] { direction: rtl; text-align: right; }

/* Always-LTR exceptions inside RTL content (tracking IDs, emails, dates) */
[dir="ltr-inline"], .ltr-inline {
    direction: ltr;
    display: inline-block;
    unicode-bidi: embed;
}

/* ==========================================================================
   Topbar
   ========================================================================== */

.topbar {
    height: 60px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-6);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-brand {
    font-weight: 700;
    color: var(--cu-navy);
    font-size: 16px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.topbar-user {
    font-size: 13px;
    color: var(--text-muted);
}

.lang-toggle {
    font-size: 12px;
    font-weight: 600;
    color: var(--cu-burgundy);
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
}
.lang-toggle:hover { text-decoration: underline; }
.lang-toggle:focus-visible { box-shadow: 0 0 0 3px rgba(139,0,0,0.15); outline: none; border-radius: 4px; }

.inline-form { display: inline; }

.sidebar-toggle-btn { display: none; font-size: 18px; }
@media (max-width: 1024px) {
    .sidebar-toggle-btn { display: inline-flex; }
}

/* ==========================================================================
   Sidebar (used from Phase 3 onward once role dashboards exist)
   ========================================================================== */

.app-root { display: flex; flex-direction: column; min-height: 100vh; }
.app-body { display: flex; flex: 1; }

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: #cbd5e1;
    padding: var(--space-4) 0;
}

.sidebar .nav-section-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.45);
    padding: var(--space-4) var(--space-4) var(--space-2);
}

.nav-link {
    display: block;
    padding: var(--space-2) var(--space-4);
    color: #cbd5e1;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background 0.2s;
}
[dir="rtl"] .nav-link { border-left: none; border-right: 3px solid transparent; }

.nav-link:hover { background: rgba(255,255,255,0.06); }

.nav-link.active {
    background: rgba(139,0,0,0.15);
    color: #fff;
    border-left-color: var(--cu-burgundy);
}
[dir="rtl"] .nav-link.active { border-left-color: transparent; border-right-color: var(--cu-burgundy); }

/* ==========================================================================
   Content
   ========================================================================== */

.content {
    flex: 1;
    padding: var(--space-6);
}

.app-footer {
    padding: var(--space-4) var(--space-6);
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    border-top: 1px solid var(--border);
    background: var(--white);
}

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: var(--space-5);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-4);
}

.stat-card .stat-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
}
.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    margin-top: var(--space-1);
}
.stat-card .stat-delta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: var(--space-1);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 13px;
    border-radius: 6px;
    padding: 9px 16px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.14s, transform 0.08s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(139,0,0,0.2); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn:disabled, .btn.disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary { background: var(--cu-burgundy); color: #fff; }
.btn-primary:hover { background: #740000; }

.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #F9FAFB; }

.btn-danger { background: #DC2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-success { background: #16A34A; color: #fff; }
.btn-success:hover { background: #128038; }

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
}
.icon-btn:hover { background: #F1F5F9; color: var(--text); }

/* ==========================================================================
   Forms — App shell
   ========================================================================== */

.form-group { margin-bottom: var(--space-4); }
.form-group label { display: block; font-weight: 600; font-size: 13px; margin-bottom: var(--space-2); }
.req { color: var(--cu-burgundy); margin-inline-start: 2px; }

.form-control {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}
.form-control:focus {
    outline: none;
    border-color: var(--cu-burgundy);
    box-shadow: 0 0 0 3px rgba(139,0,0,0.2);
}

.form-hint { font-size: 12px; color: var(--text-muted); margin-top: var(--space-1); }
.field-error { font-size: 12px; color: var(--status-red-text); margin-top: var(--space-1); }

.label-alt {
    display: block;
    font-weight: 400;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.badge-green { background: var(--status-green-bg); color: var(--status-green-text); }
.badge-amber { background: var(--status-amber-bg); color: var(--status-amber-text); }
.badge-red   { background: var(--status-red-bg);   color: var(--status-red-text); }
.badge-blue  { background: var(--status-blue-bg);  color: var(--status-blue-text); }
.badge-grey  { background: var(--status-grey-bg);  color: var(--status-grey-text); }

/* ==========================================================================
   Alerts
   ========================================================================== */

.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: var(--space-4);
    border-left: 3px solid transparent;
}
[dir="rtl"] .alert { border-left: none; border-right: 3px solid transparent; }

.alert-success { background: var(--status-green-bg); color: var(--status-green-text); border-left-color: #16A34A; }
.alert-warning { background: var(--status-amber-bg); color: var(--status-amber-text); border-left-color: #92400E; }
.alert-error   { background: var(--status-red-bg);   color: var(--status-red-text);   border-left-color: #991B1B; }
.alert-info    { background: var(--status-blue-bg);  color: var(--status-blue-text);  border-left-color: #1E40AF; }
[dir="rtl"] .alert-success { border-right-color: #16A34A; }
[dir="rtl"] .alert-warning { border-right-color: #92400E; }
[dir="rtl"] .alert-error   { border-right-color: #991B1B; }
[dir="rtl"] .alert-info    { border-right-color: #1E40AF; }

.alert-floating { margin: var(--space-4) var(--space-6) 0; }

/* ==========================================================================
   Tables
   ========================================================================== */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: var(--white);
}
.data-table th {
    background: #F9FAFB;
    text-transform: uppercase;
    font-size: 11px;
    color: var(--text-muted);
    text-align: left;
    padding: var(--space-3);
    border-bottom: 1px solid var(--border);
}
[dir="rtl"] .data-table th { text-align: right; }
.data-table td {
    padding: var(--space-3);
    border-bottom: 1px solid var(--border);
}
.data-table tbody tr:nth-child(odd) { background: #FAFAFB; }
.data-table tbody tr:hover { background: #F1F5F9; }
.table-actions { display: flex; gap: var(--space-2); }

@media (max-width: 768px) {
    .data-table { display: none; }
}

/* ==========================================================================
   Status Timeline
   ========================================================================== */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline-item {
    display: flex;
    gap: var(--space-4);
    padding-bottom: var(--space-5);
    position: relative;
}
.timeline-rail {
    width: 10px;
    display: flex;
    justify-content: center;
    position: relative;
}
.timeline-rail::before {
    content: '';
    position: absolute;
    top: 12px;
    bottom: -20px;
    width: 2px;
    background: var(--border);
}
.timeline-item:last-child .timeline-rail::before { display: none; }
.timeline-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--cu-burgundy);
    margin-top: 4px;
    z-index: 1;
}
.timeline-dot.pending {
    background: transparent;
    border: 2px solid var(--border);
}
.timeline-dot.current {
    box-shadow: 0 0 0 3px rgba(139,0,0,0.15);
}
.timeline-title { font-size: 13px; font-weight: 600; }
.timeline-meta { font-size: 11px; color: var(--text-muted); }
.timeline-note { font-size: 12px; color: var(--text-muted); }

@media (max-width: 640px) {
    .timeline-rail { width: 8px; }
}

/* ==========================================================================
   Routing Preview
   ========================================================================== */

.routing-preview {
    background: var(--status-blue-bg);
    border-left: 3px solid var(--status-blue-text);
    border-radius: 6px;
    padding: var(--space-4);
}
[dir="rtl"] .routing-preview { border-left: none; border-right: 3px solid var(--status-blue-text); }
.routing-preview .eyebrow { color: var(--cu-navy); }

/* ==========================================================================
   Progress bars
   ========================================================================== */

.progress-bar-track { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--cu-burgundy); }
.progress-bar-fill.complete { background: #16A34A; }
.progress-bar-fill.warning { background: #92400E; }

/* ==========================================================================
   Searchable select (type-ahead combobox — e.g. HoD forward-to-any-department)
   ========================================================================== */

.search-results {
    position: relative;
    z-index: 10;
    margin-top: 4px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    max-height: 220px;
    overflow-y: auto;
}
.search-result-item {
    padding: var(--space-2) var(--space-3);
    font-size: 13px;
    cursor: pointer;
}
.search-result-item:hover,
.search-result-item:focus {
    background: var(--bg);
    outline: none;
}
.search-result-item + .search-result-item {
    border-top: 1px solid var(--border);
}
.search-selected {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    padding: 6px 10px;
    background: var(--status-blue-bg);
    color: var(--status-blue-text);
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}

/* ==========================================================================
   Action disclosures (Respond/Forward/Close/Escalate on complaint detail)
   ========================================================================== */

.action-disclosure {
    margin-bottom: var(--space-3);
}
.action-disclosure summary {
    cursor: pointer;
    list-style: none;
    display: inline-flex;
}
.action-disclosure summary::-webkit-details-marker { display: none; }
.action-disclosure[open] summary {
    margin-bottom: var(--space-1);
}

/* ==========================================================================
   Empty states
   ========================================================================== */

.empty-state {
    text-align: center;
    max-width: 400px;
    margin: var(--space-10) auto;
}

/* ==========================================================================
   Responsive shell
   ========================================================================== */

@media (max-width: 1024px) {
    .sidebar { position: fixed; inset-inline-start: -240px; top: 60px; bottom: 0; transition: inset-inline-start 0.2s ease; z-index: 15; }
    .sidebar.open { inset-inline-start: 0; }
}

/* ==========================================================================
   Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .btn, .nav-link, .sidebar, .modal, .auth-input { transition: none; }
}
