:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff4ff;
  --danger: #b91c1c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 1px 3px rgba(0,0,0,.06);
  /* status colors */
  --s-new-bg: #eef2ff; --s-new: #3730a3;
  --s-acc-bg: #e0f2fe; --s-acc: #075985;
  --s-prog-bg: #fef3c7; --s-prog: #92400e;
  --s-wait-bg: #fce7f3; --s-wait: #9d174d;
  --s-done-bg: #047857; --s-done: #ffffff;
  --s-rej-bg: #fee2e2; --s-rej: #991b1b;
  --s-other-bg: #f3f4f6; --s-other: #374151;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17; --surface: #121826; --surface-2: #0f1520; --border: #232b3b; --border-strong: #2f3a4f;
    --text: #e5e7eb; --muted: #9ca3af; --primary: #3b82f6; --primary-hover: #60a5fa; --primary-soft: #16233d;
    --danger: #f87171; --shadow: none;
    --s-new-bg: #1e1b4b; --s-new: #c7d2fe; --s-acc-bg: #0c2a3d; --s-acc: #7dd3fc; --s-prog-bg: #3a2a07; --s-prog: #fcd34d;
    --s-wait-bg: #3b0f26; --s-wait: #f9a8d4; --s-done-bg: #065f46; --s-done: #ecfdf5; --s-rej-bg: #3f1111; --s-rej: #fca5a5;
    --s-other-bg: #1f2937; --s-other: #d1d5db;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f17; --surface: #121826; --surface-2: #0f1520; --border: #232b3b; --border-strong: #2f3a4f;
  --text: #e5e7eb; --muted: #9ca3af; --primary: #3b82f6; --primary-hover: #60a5fa; --primary-soft: #16233d;
  --danger: #f87171; --shadow: none;
  --s-new-bg: #1e1b4b; --s-new: #c7d2fe; --s-acc-bg: #0c2a3d; --s-acc: #7dd3fc; --s-prog-bg: #3a2a07; --s-prog: #fcd34d;
  --s-wait-bg: #3b0f26; --s-wait: #f9a8d4; --s-done-bg: #065f46; --s-done: #ecfdf5; --s-rej-bg: #3f1111; --s-rej: #fca5a5;
  --s-other-bg: #1f2937; --s-other: #d1d5db;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; line-height: 1.45;
  background: var(--bg); color: var(--text);
  min-height: 100vh;
}
[hidden] { display: none !important; }
.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
h2 { font-size: 22px; margin: 0 0 4px; }
h3 { margin: 8px 0; }

/* logo */
.logo { width: 28px; height: 28px; border-radius: 7px; background: var(--primary); color: #fff; display: grid; place-items: center; flex: none; }
.logo svg { width: 18px; height: 18px; }
.logo-lg { width: 48px; height: 48px; border-radius: 11px; margin: 0 auto 12px; }
.logo-lg svg { width: 30px; height: 30px; }
.app-name { font-weight: 700; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ms { margin-top: 12px; padding: 10px 18px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  padding: 32px 28px; max-width: 420px; width: 100%; text-align: center;
}
.login-card h1 { font-size: 22px; margin: 0 0 8px; }

/* topbar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-row { display: flex; align-items: center; gap: 20px; min-height: 60px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 10px; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.tabs a.active { background: var(--primary-soft); color: var(--primary); }
.user { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* page */
main.container { padding-top: 28px; padding-bottom: 48px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 5px 12px; cursor: pointer; font: inherit; font-size: 13px; }
.chip .n { color: var(--muted); margin-left: 4px; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.active .n { color: inherit; opacity: .7; }
#search { min-width: 280px; flex: 0 1 340px; }

input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 9px 11px;
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }

/* table */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table td.id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); }
.table td.title { font-weight: 600; min-width: 240px; }
.table td.nowrap { white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); margin: 0; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.s-new { background: var(--s-new-bg); color: var(--s-new); }
.s-acc { background: var(--s-acc-bg); color: var(--s-acc); }
.s-prog { background: var(--s-prog-bg); color: var(--s-prog); }
.s-wait { background: var(--s-wait-bg); color: var(--s-wait); }
.s-done { background: var(--s-done-bg); color: var(--s-done); }
.s-rej { background: var(--s-rej-bg); color: var(--s-rej); }
.s-other { background: var(--s-other-bg); color: var(--s-other); }
.prio { font-size: 13px; }
.prio-High { color: #c2410c; font-weight: 600; }
.prio-Critical { color: var(--danger); font-weight: 700; }

/* form */
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
fieldset { border: none; padding: 0; margin: 0 0 22px; }
legend { font-weight: 700; display: flex; align-items: center; gap: 8px; margin-bottom: 10px; padding: 0; }
.step { width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 12px; display: inline-grid; place-items: center; }
.options { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.options-4 { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.opt { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; cursor: pointer; background: var(--surface); }
.opt:hover { border-color: var(--border-strong); }
.opt input { width: auto; margin: 3px 0 0; accent-color: var(--primary); }
.opt b { display: block; font-weight: 600; }
.opt small { color: var(--muted); display: block; margin-top: 2px; }
.opt.checked { border-color: var(--primary); background: var(--primary-soft); }
.opt-group { grid-column: 1 / -1; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-top: 4px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 18px; }
.grid label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; }
.grid .hint, .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }
.form-foot { display: flex; align-items: center; gap: 14px; border-top: 1px solid var(--border); padding-top: 16px; flex-wrap: wrap; }
.field-error { border-color: var(--danger) !important; }
fieldset.field-error { border: none !important; }
fieldset.field-error legend { color: var(--danger); }

.done { text-align: center; padding: 40px 20px; }
.done-icon { width: 52px; height: 52px; border-radius: 50%; background: #047857; color: #fff; font-size: 26px; display: grid; place-items: center; margin: 0 auto; }
.done-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: calc(100% - 32px); z-index: 10; }
.toast.err { background: var(--danger); color: #fff; }

/* Add details */
.status-cell { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.btn-add-details { padding: 2px 10px; font-size: 12px; line-height: 1.5; white-space: nowrap; }
.dialog {
  width: min(560px, calc(100% - 32px)); padding: 22px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog h3 { margin-top: 0; }
.dialog label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; margin-bottom: 14px; }
.dialog #details-ticket { font-weight: 600; color: var(--text); margin-top: -4px; }

@media (max-width: 760px) {
  .grid { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: auto; }
  .page-head { flex-direction: column; }
  #search { min-width: 0; flex: 1 1 100%; }
  .user { margin-left: 0; width: 100%; justify-content: space-between; }
}
