:root {
  --bg-0: #0a0f1c; --bg-1: #0e1626;
  --surface: #131d31; --surface-2: #1b2740; --surface-3: #243150;
  --text: #eaf0fb; --muted: #93a1bd; --faint: #6b7790;
  --accent: #3b82f6; --accent-2: #2563eb;
  --grad: linear-gradient(135deg, #3b82f6, #2563eb);
  --border: rgba(255,255,255,.09); --border-2: rgba(255,255,255,.06);
  --ring: rgba(59,130,246,.45);
  --in: #1b2740; --out: #2563eb;
  --green: #34d399; --amber: #fbbf24; --red: #fb7185; --blue: #60a5fa; --slate: #94a3b8;
  --shadow: 0 24px 70px rgba(0,0,0,.5);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg-0: #eef1f8; --bg-1: #e9edf6; --surface: #ffffff; --surface-2: #f3f6fb; --surface-3: #e9eef7;
    --text: #16203a; --muted: #5a6782; --faint: #8a96ad;
    --border: rgba(20,30,60,.12); --border-2: rgba(20,30,60,.07);
    --in: #eef2f9; --out: #2563eb; --shadow: 0 24px 60px rgba(40,50,90,.16);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: radial-gradient(1100px 560px at 50% -12%, rgba(59,130,246,.28), transparent 60%),
              linear-gradient(180deg, var(--bg-0), var(--bg-1)); background-attachment: fixed;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; margin-top: 2rem; }
.error { color: var(--red); font-size: .9rem; }

/* ---------- Login ---------- */
.screen { display: flex; flex-direction: column; min-height: 100dvh; }
#login { align-items: center; justify-content: center; padding: 1.5rem; position: relative; overflow: hidden; background: #060a14; }
/* epic animated aurora */
#login::before, #login::after { content: ""; position: absolute; border-radius: 50%; filter: blur(90px); opacity: .55; z-index: 0; pointer-events: none; }
#login::before { width: 540px; height: 540px; background: radial-gradient(circle, #3b82f6, transparent 70%); top: -140px; left: -120px; animation: drift1 19s ease-in-out infinite alternate; }
#login::after { width: 580px; height: 580px; background: radial-gradient(circle, #2563eb, transparent 70%); bottom: -180px; right: -140px; animation: drift2 23s ease-in-out infinite alternate; }
@keyframes drift1 { to { transform: translate(140px, 90px) scale(1.25); } }
@keyframes drift2 { to { transform: translate(-110px, -70px) scale(1.18); } }
#login .login-card, #login #daily-quote { position: relative; z-index: 1; }
#daily-quote { max-width: 440px; margin: 1.4rem auto 0; text-align: center; }
.q-text { display: block; font-style: italic; font-size: 1.05rem; line-height: 1.55; color: #eaf0fb; opacity: .94; text-shadow: 0 1px 12px rgba(0,0,0,.35); }
.q-author { display: block; margin-top: .55rem; font-size: .85rem; color: #aeb8d0; }
@media (prefers-reduced-motion: reduce) { #login::before, #login::after { animation: none; } }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 2.1rem 1.9rem 1.9rem; display: flex; flex-direction: column; gap: .85rem; box-shadow: var(--shadow);
}
.login-card::before { content: ""; display: block; width: 64px; height: 64px; margin: 0 auto .4rem;
  background: url('icon.svg') center/cover no-repeat; border-radius: 18px; box-shadow: 0 10px 30px rgba(59,130,246,.45); }
.login-card h1 { margin: 0; text-align: center; font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-card > p { text-align: center; margin: 0 0 .3rem; }

input, textarea, select {
  width: 100%; background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: .6rem .7rem; font-size: .95rem; transition: border-color .15s, box-shadow .15s;
}
.login-card input { padding: .85rem .9rem; border-radius: 12px; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
button { font-family: inherit; }
.btn-primary, button[type=submit] {
  background: var(--grad); color: #fff; border: 0; border-radius: 10px; padding: .6rem 1rem; font-size: .95rem;
  font-weight: 600; cursor: pointer; box-shadow: 0 8px 22px rgba(59,130,246,.35); transition: transform .12s, filter .12s;
}
.login-card button[type=submit] { padding: .9rem; border-radius: 12px; }
.btn-primary:hover, button[type=submit]:hover { filter: brightness(1.06); transform: translateY(-1px); }
button:disabled { opacity: .6; cursor: default; transform: none; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: .55rem .9rem; font-weight: 500; cursor: pointer; }
.btn-ghost:hover { background: var(--surface-2); }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: .95rem; font-weight: 500; }

/* ---------- Helpdesk shell ---------- */
.hd { display: flex; height: 100dvh; }
.side {
  width: 232px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 1rem .7rem; gap: .25rem;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; padding: .4rem .5rem 1rem; letter-spacing: -.01em; }
.brand i { width: 30px; height: 30px; border-radius: 9px; background: url('icon.svg') center/cover; box-shadow: 0 6px 16px rgba(59,130,246,.4); }
.nav, .pnav { display: flex; align-items: center; gap: .6rem; width: 100%; text-align: left; background: none; border: 0;
  color: var(--muted); font-size: .95rem; font-weight: 500; padding: .6rem .7rem; border-radius: 10px; cursor: pointer; }
.nav:hover, .pnav:hover { background: var(--surface-2); color: var(--text); }
.nav.active, .pnav.active { background: var(--surface-3); color: var(--text); }
.nav .count { margin-left: auto; background: var(--grad); color: #fff; font-size: .7rem; font-weight: 700; border-radius: 999px; padding: .05rem .4rem; }
.side-foot { margin-top: auto; padding-top: .6rem; border-top: 1px solid var(--border-2); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.3rem; border-bottom: 1px solid var(--border); }
.topbar h2 { margin: 0; font-size: 1.2rem; font-weight: 600; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.filters { display: flex; gap: .3rem; }
.filters button { background: none; border: 1px solid transparent; color: var(--muted); padding: .35rem .7rem; border-radius: 8px; cursor: pointer; font-size: .88rem; font-weight: 500; }
.filters button:hover { color: var(--text); }
.filters button.on { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ---------- Ticket table ---------- */
.table-wrap { overflow: auto; flex: 1; }
table.tickets { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.tickets thead th { position: sticky; top: 0; background: var(--bg-1); text-align: left; color: var(--faint);
  font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; padding: .6rem .8rem; border-bottom: 1px solid var(--border); }
table.tickets td { padding: .7rem .8rem; border-bottom: 1px solid var(--border-2); vertical-align: middle; }
table.tickets tbody tr { cursor: pointer; }
table.tickets tbody tr:hover { background: var(--surface); }
table.tickets tr.unread td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.t-no { color: var(--faint); font-variant-numeric: tabular-nums; }
.t-subj { font-weight: 600; }
.t-subj .preview { display: block; font-weight: 400; color: var(--muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 38ch; }
.t-time { color: var(--muted); white-space: nowrap; font-size: .82rem; }
.empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }

/* chips */
.chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .73rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-open { color: var(--blue); background: color-mix(in srgb, var(--blue) 16%, transparent); }
.st-in_progress { color: var(--amber); background: color-mix(in srgb, var(--amber) 16%, transparent); }
.st-waiting { color: var(--slate); background: color-mix(in srgb, var(--slate) 16%, transparent); }
.st-closed { color: var(--faint); background: color-mix(in srgb, var(--faint) 16%, transparent); }
.pr-urgent { color: var(--red); background: color-mix(in srgb, var(--red) 16%, transparent); }
.pr-high { color: #fb923c; background: color-mix(in srgb, #fb923c 16%, transparent); }
.pr-normal { color: var(--slate); background: color-mix(in srgb, var(--slate) 14%, transparent); }
.pr-low { color: var(--faint); background: color-mix(in srgb, var(--faint) 14%, transparent); }
.chan { font-size: .72rem; color: var(--faint); text-transform: uppercase; letter-spacing: .03em; }
.clip { color: var(--faint); font-size: .8rem; }
.due-over { color: var(--red); font-weight: 600; }

/* ---------- Ticket detail ---------- */
.detail { flex: 1; display: flex; overflow: hidden; }
.thread-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.messages { flex: 1; overflow-y: auto; padding: 1.1rem; display: flex; flex-direction: column; gap: .5rem; }
.msg { max-width: 76%; padding: .6rem .85rem; border-radius: 16px; font-size: .92rem; white-space: pre-wrap; word-wrap: break-word; line-height: 1.45; }
.msg.inbound { align-self: flex-start; background: var(--in); border-bottom-left-radius: 5px; }
.msg.outbound { align-self: flex-end; background: var(--grad); color: #fff; border-bottom-right-radius: 5px; }
.msg.auto { align-self: flex-end; background: var(--surface-2); color: var(--muted); font-style: italic; }
.msg.note { align-self: stretch; max-width: 100%; background: color-mix(in srgb, var(--amber) 12%, var(--surface)); border: 1px dashed color-mix(in srgb, var(--amber) 50%, transparent); color: var(--text); font-size: .88rem; }
.msg.emergency { box-shadow: 0 0 0 1px var(--red); }
.msg .meta { display: block; font-size: .66rem; opacity: .75; margin-top: .25rem; }
.msg .att { display: inline-flex; align-items: center; gap: .3rem; margin-top: .35rem; margin-right: .35rem; font-size: .8rem;
  background: rgba(0,0,0,.18); padding: .2rem .5rem; border-radius: 8px; color: inherit; text-decoration: none; }
.msg .att:hover { background: rgba(0,0,0,.3); }

.reply { border-top: 1px solid var(--border); padding: .7rem 1rem calc(.7rem + var(--safe-b)); background: var(--surface); display: flex; flex-direction: column; gap: .5rem; }
.reply textarea { resize: none; max-height: 140px; min-height: 44px; border-radius: 12px; }
.reply.note-mode textarea { background: color-mix(in srgb, var(--amber) 12%, var(--surface-2)); }
.reply-row { display: flex; align-items: center; gap: .8rem; }
.reply-row .spacer { flex: 1; }
.attach-lbl, .note-lbl { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .85rem; cursor: pointer; }
.attach-lbl input, .note-lbl input { display: none; }
.note-lbl input { display: inline-block; width: auto; }
.note-lbl { gap: .4rem; }
#t-filenames { color: var(--faint); font-size: .8rem; }

/* properties panel */
.props { width: 290px; flex-shrink: 0; border-left: 1px solid var(--border); background: var(--surface); padding: 1.1rem; overflow-y: auto; }
.prop { margin-bottom: 1rem; }
.prop > label { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); margin-bottom: .35rem; font-weight: 600; }
.prop .val { font-size: .9rem; }
.est-box { background: var(--surface-2); border-radius: 12px; padding: .8rem; }
.est-box .big { font-size: 1.15rem; font-weight: 700; }

/* lists reused (approvals, plans) */
.list { list-style: none; margin: 0; padding: .6rem; overflow-y: auto; flex: 1; }
.list li { background: var(--surface); border: 1px solid var(--border-2); border-radius: 12px; padding: .85rem 1rem; margin-bottom: .5rem; }
.list .row { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.list .name { font-weight: 600; }
.list .sub { color: var(--muted); font-size: .85rem; }
.pad { padding: 1.1rem 1.3rem; overflow-y: auto; }
.formcard { max-width: 460px; display: flex; flex-direction: column; gap: .6rem; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 1.2rem; }
.formcard h3 { margin: 0 0 .3rem; font-weight: 600; }
.ok-msg { color: var(--green); }

/* profile chip + avatar */
.profile-chip { display: flex; align-items: center; gap: .6rem; width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: .5rem .6rem; cursor: pointer; color: var(--text); }
.profile-chip:hover { background: var(--surface-3); }
.ava { width: 30px; height: 30px; border-radius: 50%; background: var(--grad) center/cover; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; flex-shrink: 0; }

/* report metric cards */
.report-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.report-cards .card { background: var(--surface-2); border-radius: 12px; padding: 1rem; }
.report-cards .card .k { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); }
.report-cards .card .v { font-size: 1.5rem; font-weight: 700; margin-top: .25rem; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50; }
.modal-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 1.3rem; display: flex; flex-direction: column; gap: .6rem; box-shadow: var(--shadow); }
.modal-card h3 { margin: 0 0 .3rem; font-weight: 600; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .3rem; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .hd { flex-direction: column; height: auto; min-height: 100dvh; }
  .side { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; padding: .6rem; border-right: 0; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
  .brand { padding: .2rem .4rem; }
  .nav { width: auto; padding: .45rem .6rem; }
  .side-foot { margin: 0 0 0 auto; padding: 0; border: 0; }
  .main { overflow: visible; }
  .detail { flex-direction: column; }
  .props { width: 100%; border-left: 0; border-top: 1px solid var(--border); order: -1; }
  .t-subj .preview { max-width: 60vw; }
  .hide-sm { display: none !important; }
}
