:root {
  --bg: #0f172a; --surface: #1e293b; --surface-2: #273449; --line: #334155;
  --text: #e2e8f0; --muted: #94a3b8; --brand: #6366f1; --brand-2: #4f46e5;
  --ok: #22c55e; --warn: #f59e0b; --danger: #ef4444; --info: #38bdf8;
  --radius: 12px; --shadow: 0 6px 24px rgba(0,0,0,.28);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f1f5f9; --surface: #ffffff; --surface-2: #f8fafc; --line: #e2e8f0;
    --text: #0f172a; --muted: #64748b; --shadow: 0 6px 20px rgba(15,23,42,.08);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Tajawal", -apple-system, "Segoe UI", Tahoma, "Noto Naskh Arabic", sans-serif;
  background: var(--bg); color: var(--text); direction: rtl;
}
a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* Layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-inline-start: 1px solid var(--line);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 6px;
}
.brand { font-weight: 800; font-size: 18px; padding: 8px 10px 16px; letter-spacing: .3px; }
.brand span { color: var(--brand); }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 10px; color: var(--muted); background: none; border: 0;
  width: 100%; text-align: start; font-size: 14.5px;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--brand); color: #fff; }
.nav-spacer { flex: 1; }
.main { padding: 22px 26px; overflow: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.topbar h1 { font-size: 20px; margin: 0; }
.who { color: var(--muted); font-size: 13px; }
.who b { color: var(--text); }

/* Cards / stat tiles */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .n { font-size: 26px; font-weight: 800; }
.stat .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stat.warn .n { color: var(--warn); } .stat.danger .n { color: var(--danger); }

/* Toolbar / filters */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
/* Base input look for the desk's own controls. The login screen is styled
   entirely with Tailwind utilities, so its inputs opt out via .sd-tw — an
   element[type] selector here would otherwise out-specify Tailwind's classes. */
select, input:not([type]):not(.sd-tw), input[type=text]:not(.sd-tw), input[type=password]:not(.sd-tw), input[type=email]:not(.sd-tw), textarea {
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: 9px 11px; font-size: 14px; outline: none;
}
select:focus, input:not(.sd-tw):focus, textarea:focus { border-color: var(--brand); }
textarea { width: 100%; resize: vertical; min-height: 90px; }
.grow { flex: 1; min-width: 160px; }

/* Buttons */
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 9px; padding: 9px 14px; font-size: 14px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 6px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Table / list */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 110px 1fr 120px 110px 130px; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line); align-items: center; cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row .subj { font-weight: 600; }
.row .sub { color: var(--muted); font-size: 12.5px; }
.row .ref { font-family: ui-monospace, monospace; font-size: 12.5px; color: var(--muted); }
.head-row { color: var(--muted); font-size: 12px; text-transform: uppercase; cursor: default; background: var(--surface-2); }
.head-row:hover { background: var(--surface-2); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.s-open { background: rgba(56,189,248,.16); color: var(--info); }
.s-pending { background: rgba(245,158,11,.16); color: var(--warn); }
.s-resolved { background: rgba(34,197,94,.16); color: var(--ok); }
.s-closed { background: rgba(148,163,184,.18); color: var(--muted); }
.p-low { background: rgba(148,163,184,.18); color: var(--muted); }
.p-normal { background: rgba(56,189,248,.14); color: var(--info); }
.p-high { background: rgba(245,158,11,.18); color: var(--warn); }
.p-urgent { background: rgba(239,68,68,.18); color: var(--danger); }
.overdue { color: var(--danger); font-weight: 700; font-size: 11.5px; }

/* Ticket detail */
.detail { display: grid; grid-template-columns: 1fr 300px; gap: 18px; }
.thread { display: flex; flex-direction: column; gap: 12px; }
.msg { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.msg.staff { border-inline-start: 3px solid var(--brand); }
.msg.requester { border-inline-start: 3px solid var(--info); }
.msg.internal { border-inline-start: 3px solid var(--warn); background: rgba(245,158,11,.06); }
.msg .meta { color: var(--muted); font-size: 12px; margin-bottom: 6px; display: flex; gap: 8px; }
.msg .body { white-space: pre-wrap; line-height: 1.5; }
.aside .box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.aside .box h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.field select, .field input { width: 100%; }
.kv { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; }
.kv span { color: var(--muted); }

/* Animated login brand badge (Tailwind-built login screen). A gentle float +
   pulsing glow around the Lucide headset icon. */
.sd-badge {
  animation: sd-badge-float 3.4s ease-in-out infinite;
  box-shadow: 0 12px 26px rgba(79, 70, 229, .40);
}
.sd-badge svg { width: 30px; height: 30px; animation: sd-badge-icon 3.4s ease-in-out infinite; }
@keyframes sd-badge-float {
  0%, 100% { transform: translateY(0); box-shadow: 0 12px 26px rgba(79, 70, 229, .40); }
  50%      { transform: translateY(-5px); box-shadow: 0 20px 38px rgba(79, 70, 229, .55); }
}
@keyframes sd-badge-icon {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}
@media (prefers-reduced-motion: reduce) {
  .sd-badge, .sd-badge svg { animation: none; }
}

/* Login */
.login-wrap {
  display: grid; place-items: center; min-height: 100vh; padding: 24px;
  background:
    radial-gradient(1100px 560px at 50% -12%, rgba(99, 102, 241, .20), transparent 62%),
    radial-gradient(760px 460px at 100% 112%, rgba(79, 70, 229, .16), transparent 60%),
    var(--bg);
}
.login-card {
  position: relative; background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 34px 30px 30px; width: 100%; max-width: 400px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, .16), 0 2px 8px rgba(15, 23, 42, .05);
}
.login-brand { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 26px; }
.login-badge {
  width: 62px; height: 62px; border-radius: 18px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
  box-shadow: 0 12px 26px rgba(79, 70, 229, .38); margin-bottom: 14px;
}
.login-badge svg { width: 30px; height: 30px; }
.login-card h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.login-card .sub { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.login-field { margin-bottom: 15px; }
.login-field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 7px; }
.login-input { position: relative; display: flex; align-items: center; }
.login-input > svg {
  position: absolute; inset-inline-start: 13px; width: 17px; height: 17px;
  color: var(--muted); pointer-events: none;
}
.login-input input {
  width: 100%; padding: 12px 14px; padding-inline-start: 40px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font-size: 14.5px; outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
.login-input input::placeholder { color: var(--muted); opacity: .7; }
.login-input input:focus {
  border-color: var(--brand); background: var(--surface);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, .16);
}
.login-input input:focus + svg, .login-input:focus-within > svg { color: var(--brand); }
.login-btn {
  width: 100%; margin-top: 8px; padding: 13px; border: 0; border-radius: 12px; cursor: pointer;
  font-size: 15px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  box-shadow: 0 10px 22px rgba(79, 70, 229, .30);
  transition: transform .12s ease, box-shadow .15s, opacity .15s;
}
.login-btn:hover { transform: translateY(-1px); box-shadow: 0 14px 30px rgba(79, 70, 229, .38); }
.login-btn:active { transform: translateY(0); }
.login-btn:disabled { opacity: .6; cursor: not-allowed; transform: none; box-shadow: none; }
.login-err {
  background: rgba(239, 68, 68, .10); color: var(--danger);
  border: 1px solid rgba(239, 68, 68, .28); border-radius: 11px;
  padding: 10px 12px; font-size: 12.5px; line-height: 1.5; margin-bottom: 16px; text-align: center;
}

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(2,6,23,.6); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: 100%; max-width: 480px; box-shadow: var(--shadow); max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.priv-grid { display: grid; gap: 6px; }
.priv-group { border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.priv-group > label { font-weight: 700; font-size: 13px; }
.priv-actions { display: grid; gap: 4px; padding: 8px 4px 0; }
.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }

/* Toast */
.toast { position: fixed; inset-block-end: 22px; inset-inline-start: 22px; z-index: 100;
  background: var(--surface); border: 1px solid var(--line); border-inline-start: 3px solid var(--brand);
  border-radius: 10px; padding: 12px 16px; box-shadow: var(--shadow); font-size: 14px; max-width: 340px; }
.toast.err { border-inline-start-color: var(--danger); }
.toast.ok { border-inline-start-color: var(--ok); }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; overflow-x: auto; border: 0; border-bottom: 1px solid var(--line); }
  .brand { display: none; }
  .detail { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr auto; }
  .row .ref, .row .col-hide { display: none; }
}
