/* NTP — shared shell for the three branded pages (chat, documents, users).
 *
 * Owns the design tokens, the base rules, the sign-in / forbidden panes, the
 * sidebar + drawer layout and the profile dialog, so the pages share one
 * identity from one file. Each page's own stylesheet loads after this one
 * and only styles what is specific to that page. Logical properties handle
 * RTL; an inline <head> script sets data-theme before first paint. */

/* ===== Design tokens ===== */
:root {
  --brand: #0b6e4f;            /* Vision-2030 green */
  --brand-strong: #0a5f44;
  --brand-soft: #e6f3ee;
  --brand-contrast: #ffffff;
  --accent: #c9a227;           /* heritage gold */

  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-hover: #f1f5f3;
  --border: #e3e8e6;
  --border-strong: #d1d9d6;

  --text: #16201d;
  --text-muted: #5d6b66;
  --text-faint: #93a09b;

  --amber: #b45309; --amber-soft: #fef3c7;
  --green: #15803d; --green-soft: #dcfce7;
  --danger: #b91c1c; --danger-soft: #fee2e2;
  --slate: #475569; --slate-soft: #e8edf2;

  --shadow-sm: 0 1px 2px rgba(16, 32, 29, 0.06);
  --shadow-md: 0 4px 16px rgba(16, 32, 29, 0.10);
  --shadow-lg: 0 12px 40px rgba(16, 32, 29, 0.18);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;

  --font-ui: "Inter", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  --font-ar: "Tajawal", "Segoe UI", "Noto Sans Arabic", sans-serif;

  --sidebar-w: 272px;
}

:root[data-theme="dark"] {
  --brand: #1f9d6f;
  --brand-strong: #16a34a;
  --brand-soft: #14241e;
  --brand-contrast: #ffffff;
  --accent: #d4af37;

  --bg: #0d1411;
  --surface: #131c18;
  --surface-2: #18231e;
  --surface-hover: #1c2823;
  --border: #243029;
  --border-strong: #2f3d35;

  --text: #e8efeb;
  --text-muted: #9fb0a8;
  --text-faint: #6b7c74;

  --amber: #fbbf24; --amber-soft: #3a2e11;
  --green: #4ade80; --green-soft: #14301f;
  --danger: #f87171; --danger-soft: #3a1717;
  --slate: #94a3b8; --slate-soft: #232c33;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
}

/* ===== Base ===== */
* { box-sizing: border-box; }
/* Let [hidden] beat the ID-level display rules below. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[dir="rtl"] body { font-family: var(--font-ar); }
button, input, select, textarea { font-family: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ===== Brand lockup ===== */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { display: inline-flex; line-height: 0; }
.brand-mark svg { border-radius: 9px; box-shadow: var(--shadow-sm); }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.brand--lg { justify-content: center; }
.brand--lg .brand-name { font-size: 20px; }
.brand-sub { margin: 2px 0 14px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ===== Sign-in / forbidden panes ===== */
#login-pane, #forbidden {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: radial-gradient(900px 500px at 50% -10%, var(--brand-soft), transparent 70%), var(--bg);
}
#login-form, .forbidden-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 36px 32px; width: 380px; max-width: 100%;
  display: flex; flex-direction: column; gap: 14px;
}
.forbidden-card { text-align: center; }
.forbidden-card h1 { margin: 0; font-size: 20px; }
.forbidden-card p { margin: 0; color: var(--text-muted); }
#login-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
#login-form input {
  padding: 11px 12px; font-size: 14.5px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
}
#login-form input:focus { border-color: var(--brand); background: var(--surface); outline: none; }
#login-form button, .forbidden-card button {
  margin-top: 6px; padding: 11px 12px; font-size: 14.5px; font-weight: 600;
  background: var(--brand); color: var(--brand-contrast);
  border: 0; border-radius: var(--radius-sm); cursor: pointer; transition: background .15s;
}
#login-form button:hover, .forbidden-card button:hover { background: var(--brand-strong); }
.error { color: var(--danger); font-size: 12.5px; margin: 0; }

/* ===== App layout: sidebar + page ===== */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  height: 100dvh;
}
#app > main {
  min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  overflow: hidden; position: relative;
}

/* ===== Sidebar ===== */
#sidebar {
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0;
}
#sidebar > header { padding: 16px; border-block-end: 1px solid var(--border); }

.app-nav { display: flex; flex-direction: column; gap: 2px; padding: 10px 8px; border-block-end: 1px solid var(--border); }
.app-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; text-decoration: none;
  color: var(--text-muted); transition: background .12s, color .12s;
}
.app-nav a:hover { background: var(--surface-hover); color: var(--text); }
.app-nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; }
.app-nav svg { flex: none; }

.sidebar-fill { flex: 1; min-height: 0; }

#sidebar > footer {
  padding: 12px;
  border-block-start: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px;
}

#profile-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; text-align: start; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
}
#profile-btn:hover { background: var(--surface-hover); }
.avatar-initials {
  flex: none; width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff; letter-spacing: .02em;
  background: linear-gradient(135deg, var(--brand-strong), var(--brand));
  box-shadow: var(--shadow-sm);
}
.avatar-initials--lg { width: 48px; height: 48px; border-radius: 13px; font-size: 16px; }
.profile-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.profile-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-email { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-controls { display: flex; gap: 8px; align-items: center; }
.sidebar-controls select, #logout, #theme-toggle {
  padding: 7px 10px; font-size: 12.5px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text); cursor: pointer;
}
.sidebar-controls select:hover, #logout:hover, #theme-toggle:hover { background: var(--surface-hover); }
.sidebar-controls .lang-switch { flex: 1; margin: 0; }
.sidebar-controls select { width: 100%; }
#theme-toggle { display: inline-flex; align-items: center; line-height: 0; }
#theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] #theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] #theme-toggle .icon-moon { display: inline; }

/* ===== Small-screen header + drawer ===== */
#topbar {
  display: none;
  align-items: center; gap: 12px;
  padding: 10px 14px; border-block-end: 1px solid var(--border); background: var(--surface);
}
#menu-toggle { border: 0; background: transparent; color: var(--text); cursor: pointer; padding: 4px; line-height: 0; }
#scrim { display: none; }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  #topbar { display: flex; }
  #sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0;
    width: min(86vw, var(--sidebar-w)); z-index: 30;
    transform: translateX(-104%); transition: transform .25s ease;
    box-shadow: var(--shadow-lg);
  }
  [dir="rtl"] #sidebar { transform: translateX(104%); }
  #app.sidebar-open #sidebar { transform: none; }
  #app.sidebar-open #scrim {
    display: block; position: fixed; inset: 0; z-index: 20;
    background: rgba(0, 0, 0, 0.4);
  }
}
@media (prefers-reduced-motion: reduce) { #sidebar { transition: none; } }

/* ===== Profile dialog ===== */
.shell-modal {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: rgba(0, 0, 0, 0.45);
}
.pm-card {
  width: min(480px, 100%); max-height: 90vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden;
}
.pm-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-block-end: 1px solid var(--border);
}
.pm-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.pm-close { background: transparent; border: 0; font-size: 24px; line-height: 1; cursor: pointer; color: var(--text-muted); }
.pm-close:hover { color: var(--text); }
.pm-body { padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.pm-identity { display: flex; align-items: center; gap: 12px; }
.pm-identity-text { min-width: 0; }
.pm-name { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.pm-email { color: var(--text-muted); font-size: 13px; overflow-wrap: anywhere; }
.pm-grid {
  margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px;
  padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius-sm); font-size: 13.5px;
}
.pm-grid dt { color: var(--text-muted); font-size: 12.5px; }
.pm-grid dd { margin: 0; font-weight: 500; }
.pm-badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pm-badge.role-superuser { background: #fbe7c2; color: #92660a; }
:root[data-theme="dark"] .pm-badge.role-superuser { background: #3a2e11; color: #fbbf24; }
.pm-badge.role-staff { background: var(--green-soft); color: var(--green); }
.pm-badge.role-user { background: var(--slate-soft); color: var(--slate); }
.pm-badge.yes { background: var(--green-soft); color: var(--green); }
.pm-badge.no { background: var(--amber-soft); color: var(--amber); }
.pm-form { display: flex; flex-direction: column; gap: 12px; padding-block-start: 4px; border-block-start: 1px solid var(--border); }
.pm-form h4 { margin: 10px 0 0; font-size: 13px; font-weight: 700; }
.pm-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
.pm-form input {
  padding: 10px 12px; font-size: 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
}
.pm-form input:focus { border-color: var(--brand); background: var(--surface); outline: none; }
.pm-form input[aria-invalid="true"] { border-color: var(--danger); background: var(--surface); }
.pm-form input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.pm-form .field-error { display: block; color: var(--danger); font-size: 12px; font-weight: 500; line-height: 1.4; }
.pm-msg { margin: 0; font-size: 13px; padding: 8px 12px; border-radius: var(--radius-sm); }
.pm-msg.ok { background: var(--green-soft); color: var(--green); }
.pm-msg.err { background: var(--danger-soft); color: var(--danger); }
.pm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.pm-btn { padding: 9px 14px; font-size: 13px; border-radius: var(--radius-sm); cursor: pointer; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); }
.pm-btn.primary { background: var(--brand); color: var(--brand-contrast); border-color: transparent; font-weight: 600; }
.pm-btn.primary:hover { background: var(--brand-strong); }
.pm-btn:disabled { opacity: .5; cursor: not-allowed; }
@media (max-width: 480px) { .pm-grid { grid-template-columns: 1fr; gap: 2px 0; } .pm-grid dd { margin-block-end: 6px; } }
