/* ===== TaskCraft — design system ===== */
:root {
  --bg: #eef1f6;
  --bg-tint: #e7ebf3;
  --surface: #ffffff;
  --surface-2: #f4f6fa;
  --ink: #151a23;
  --muted: #5f6b7e;
  --faint: #98a2b3;
  --line: #e3e7ef;
  --line-strong: #d3dae4;
  --accent: #4b5bf5;
  --accent-strong: #3b49d6;
  --accent-tint: #eef0ff;
  --todo: #64748b;
  --doing: #f59e0b;
  --done: #22c55e;
  --danger: #e5484d;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(20, 30, 60, .06), 0 1px 3px rgba(20, 30, 60, .05);
  --shadow-md: 0 6px 18px rgba(20, 30, 60, .10);
  --shadow-lg: 0 18px 50px rgba(20, 30, 60, .22);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #0e131d;
  --bg-tint: #151c29;
  --surface: #1a2231;
  --surface-2: #131a26;
  --ink: #e7ebf3;
  --muted: #9aa6bc;
  --faint: #6b7689;
  --line: #283143;
  --line-strong: #38445b;
  --accent: #6f7cff;
  --accent-strong: #8b95ff;
  --accent-tint: #1f2740;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-md: 0 8px 22px rgba(0, 0, 0, .45);
  --shadow-lg: 0 20px 55px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:root[data-theme="light"] body,
:root:not([data-theme="dark"]) body {
  background: radial-gradient(1200px 600px at 80% -10%, #f3f0ff 0%, transparent 60%), var(--bg);
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
::selection { background: var(--accent-tint); }

/* ===== buttons ===== */
.btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 4px 14px rgba(75, 91, 245, .32);
}
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(127, 137, 170, .14); }
.btn.danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn.danger:hover { background: rgba(229, 72, 77, .12); }
.btn.sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.icon { padding: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-svg { width: 18px; height: 18px; display: block; }

/* ===== topbar ===== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 11px 18px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; font-size: 18px; }
.brand img { width: 28px; height: 28px; }
.brand .accent { color: var(--accent); }
.topbar .grow { flex: 1; }
.userchip { font-size: 13px; color: var(--muted); font-weight: 600; padding: 0 2px; }
.langtoggle { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 999px; overflow: hidden; }
.langtoggle button { border: 0; background: var(--surface); padding: 7px 12px; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.langtoggle button.active { background: var(--accent); color: #fff; }

/* ===== layout ===== */
.wrap { max-width: 1280px; margin: 0 auto; padding: 18px; }
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.searchbox {
  position: relative; display: flex; align-items: center; margin-left: auto;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 999px; padding: 0 14px; min-width: 200px; max-width: 380px; flex: 1;
}
.searchbox input { border: 0; outline: 0; background: transparent; padding: 10px 8px; width: 100%; font-size: 14px; color: var(--ink); }
.searchbox svg { color: var(--faint); flex: none; }
.btn.newticket { padding: 10px 16px; font-size: 14.5px; }

/* ===== stats ===== */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(116px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; box-shadow: var(--shadow-sm); }
.stat .num { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.stat .lbl { font-size: 11.5px; color: var(--muted); margin-top: 2px; text-transform: uppercase; letter-spacing: .04em; }
.stat .num .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: middle; }

/* ===== filters ===== */
.filters { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; align-items: flex-start; }
.filtergroup { display: flex; flex-direction: column; gap: 6px; }
.filtergroup .glabel { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; max-width: 540px; }
.chip { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 5px 11px; font-size: 13px; font-weight: 600; transition: all .12s; }
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.empty { color: var(--faint); border-style: dashed; cursor: default; }
.filters .clear { margin-left: auto; align-self: center; }

/* ===== board ===== */
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: start; }
.column { background: var(--bg-tint); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.column > .col-head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 10px; font-weight: 700; }
.col-head .dot { width: 10px; height: 10px; border-radius: 50%; }
.col-head .count { margin-left: auto; font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; font-weight: 700; }
.col-todo .dot { background: var(--todo); }
.col-doing .dot { background: var(--doing); }
.col-done .dot { background: var(--done); }
.cards { display: flex; flex-direction: column; gap: 9px; min-height: 44px; }
.col-empty { color: var(--faint); font-size: 13px; text-align: center; padding: 16px 6px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); }

/* ===== card (slim, uniform) ===== */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; box-shadow: var(--shadow-sm); position: relative;
  transition: box-shadow .15s, border-color .15s; cursor: pointer;
}
.card:hover { box-shadow: var(--shadow-md); border-color: var(--line-strong); }
.card .title {
  font-weight: 700; font-size: 14.5px; letter-spacing: -.01em; padding-right: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card .preview {
  color: var(--muted); font-size: 13px; line-height: 1.45; margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card .tags { display: flex; gap: 5px; margin-top: 9px; overflow: hidden; max-height: 23px; flex-wrap: wrap; }
.tag { font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.tag.person { background: color-mix(in srgb, #2f6df6 14%, var(--surface)); color: #2f6df6; }
.tag.project { background: var(--accent-tint); color: var(--accent-strong); }
:root[data-theme="dark"] .tag.person { color: #8fb4ff; }
.card .cardbar { display: flex; align-items: center; gap: 2px; margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--line); opacity: 0; transition: opacity .12s; }
.card:hover .cardbar, .card:focus-within .cardbar { opacity: 1; }
.cardbar .grow { flex: 1; }
.mini { border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 3px 8px; font-size: 12px; color: var(--muted); font-weight: 700; }
.mini:hover { background: var(--surface-2); color: var(--ink); }
.mini:disabled { opacity: .4; }

/* drag: the clone must follow the cursor — never set `transform` here (Sortable
   uses transform:translate on the fallback clone to track the pointer). */
.sortable-ghost { opacity: .35; }
.sortable-drag { box-shadow: var(--shadow-lg); opacity: .98; cursor: grabbing; }

/* ===== auth / pending ===== */
.center-screen { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-md); padding: 26px; }
.auth-card .brand { justify-content: center; font-size: 22px; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--muted); font-size: 13.5px; margin-bottom: 18px; }
.tabs { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px; margin-bottom: 18px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 999px; font-weight: 700; color: var(--muted); font-size: 14px; }
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 11px 12px; font-size: 14.5px; background: var(--surface-2); color: var(--ink);
}
.field textarea { resize: vertical; line-height: 1.5; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--accent); background: var(--surface); }
.auth-card .btn.primary { width: 100%; justify-content: center; margin-top: 6px; padding: 12px; }
.form-msg { font-size: 13px; margin-top: 10px; min-height: 18px; text-align: center; }
.form-msg.err { color: var(--danger); }
.form-msg.ok { color: #1a8a4f; }
.pending-icon { font-size: 40px; text-align: center; }

/* ===== modal ===== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 24, .5); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: 100%; max-width: 560px; max-height: 90dvh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 22px; }
.modal.wide { max-width: 680px; }
.modal h2 { margin: 0 0 4px; font-size: 19px; letter-spacing: -.01em; }
.modal .sub, .admin-panel .sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-head { display: flex; align-items: flex-start; gap: 10px; }
.modal-head .grow { flex: 1; }
.detail-title {
  flex: 1; width: 100%; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 7px 10px; font-size: 20px; font-weight: 800; letter-spacing: -.01em;
  background: transparent; color: var(--ink); font-family: inherit;
}
.detail-title:hover { background: var(--surface-2); }
.detail-title:focus { outline: 2px solid var(--accent); background: var(--surface); }
.section-title { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin: 18px 0 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* status pills */
.statuspills { display: inline-flex; gap: 6px; }
.statuspills button { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 12.5px; font-weight: 700; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.statuspills button .dot { width: 8px; height: 8px; border-radius: 50%; }
.statuspills button.active { color: var(--ink); border-color: var(--ink); background: var(--surface-2); }

/* re-prompt box */
.reprompt { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.reprompt textarea { width: 100%; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 10px; font-size: 14px; background: var(--surface); color: var(--ink); resize: vertical; min-height: 56px; line-height: 1.45; }
.reprompt .hint { font-size: 12px; color: var(--faint); margin: 4px 2px 8px; }

/* compose modal mic */
.mic.recording { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, .5); } 50% { box-shadow: 0 0 0 8px rgba(229, 72, 77, 0); } }

/* token editor */
.token-input { display: flex; flex-wrap: wrap; gap: 6px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 7px; background: var(--surface-2); }
.token-input input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 90px; padding: 4px; font-size: 14px; color: var(--ink); }
.token { background: var(--accent-tint); color: var(--accent-strong); border-radius: 999px; padding: 3px 6px 3px 10px; font-size: 12.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.token button { border: 0; background: transparent; color: inherit; font-size: 14px; line-height: 1; cursor: pointer; padding: 0 2px; }

/* user mgmt rows */
.userrow { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.userrow .uname { font-weight: 700; font-size: 14px; }
.userrow .umail { color: var(--muted); font-size: 12px; }
.userrow .badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.badge.pending { background: #fff4e0; color: #b06f00; }
.badge.approved { background: #e7f8ee; color: #1a8a4f; }
.badge.admin { background: var(--accent-tint); color: var(--accent-strong); }
.userrow .grow { flex: 1; }

/* user edit (inline) */
.useredit { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; align-items: center; }
.useredit input { flex: 1; min-width: 140px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13.5px; background: var(--surface-2); color: var(--ink); }
.useredit input:focus { outline: 2px solid var(--accent); background: var(--surface); }

/* ===== admin view ===== */
.admin-layout { display: grid; grid-template-columns: 220px 1fr; gap: 18px; align-items: start; }
.admin-nav { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 78px; }
.admin-nav button {
  text-align: left; border: 1px solid transparent; background: transparent; color: var(--muted);
  border-radius: var(--radius-sm); padding: 10px 12px; font-weight: 700; font-size: 14px;
}
.admin-nav button:hover { background: var(--surface-2); color: var(--ink); }
.admin-nav button.active { background: var(--accent-tint); color: var(--accent-strong); border-color: var(--line); }
.admin-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 20px; min-height: 320px;
}
.admin-panel #sysprompt {
  width: 100%; min-height: 320px; font-family: var(--mono); font-size: 13px; line-height: 1.5;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 12px;
  background: var(--surface-2); color: var(--ink); resize: vertical;
}
.admin-panel #sysprompt:focus { outline: 2px solid var(--accent); background: var(--surface); }
@media (max-width: 860px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-nav { flex-direction: row; flex-wrap: wrap; position: static; }
}

/* ===== markdown ===== */
.md { font-size: 14.5px; line-height: 1.6; color: var(--ink); word-break: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { margin: .7em 0 .3em; line-height: 1.25; }
.md h1 { font-size: 1.25em; } .md h2 { font-size: 1.15em; } .md h3 { font-size: 1.04em; }
.md p { margin: .5em 0; }
.md ul, .md ol { margin: .4em 0; padding-left: 1.4em; }
.md li { margin: .2em 0; }
.md code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-size: .9em; font-family: var(--mono); }
.md pre { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; overflow: auto; }
.md pre code { background: none; border: 0; padding: 0; }
.md blockquote { border-left: 3px solid var(--line-strong); margin: .5em 0; padding: .1em .9em; color: var(--muted); }
.md a { color: var(--accent); }
.md strong { font-weight: 700; }

/* ===== mobile tabs ===== */
.col-tabs { display: none; gap: 6px; margin-bottom: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 5px; box-shadow: var(--shadow-sm); }
.col-tabs button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 999px; font-weight: 700; font-size: 13.5px; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.col-tabs button .dot { width: 9px; height: 9px; border-radius: 50%; }
.col-tabs button.active { background: var(--surface-2); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ===== toast ===== */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); z-index: 100; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast .toast-inner { background: var(--ink); color: var(--surface); padding: 11px 18px; border-radius: 999px; font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-lg); }
#toast.err .toast-inner { background: var(--danger); color: #fff; }

.spinner { width: 16px; height: 16px; border: 2px solid rgba(127, 137, 170, .35); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
.btn.primary .spinner { border-color: rgba(255, 255, 255, .4); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== responsive ===== */
@media (max-width: 860px) {
  .wrap { padding: 12px; }
  .col-tabs { display: flex; }
  .board { grid-template-columns: 1fr; gap: 0; }
  .column { display: none; background: transparent; border: 0; padding: 0; }
  .column.active { display: block; }
  .topbar { gap: 8px; padding: 9px 12px; flex-wrap: wrap; }
  .toolbar { flex-wrap: wrap; }
  .searchbox { min-width: 140px; }
  .stats { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 460px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .userchip { display: none; }
  .btn.newticket { flex: 1; justify-content: center; }
}
