:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #1b2430;
  --muted: #5d6b7c;
  --line: #dfe3e8;
  --brand: #1f3a5f;
  --brand-ink: #ffffff;
  --accent: #2f6fd6;
  --good: #1f7a4d;
  --danger: #b3261e;
  --internal-bg: #fff8e6;
  --internal-line: #e8c66a;
  --mine-bg: #eef4ff;
  --radius: 10px;
  --st-new: #2f6fd6;
  --st-in_progress: #8a5a00;
  --st-waiting: #7a3fb0;
  --st-resolved: #1f7a4d;
  --st-closed: #5d6b7c;
  --pr-high: #b3261e;
  --pr-medium: #8a5a00;
  --pr-low: #5d6b7c;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b2129;
    --ink: #e6e9ee;
    --muted: #9aa6b4;
    --line: #2d3540;
    --brand: #16283f;
    --accent: #6ea2ff;
    --good: #4fbf86;
    --danger: #ff7b72;
    --internal-bg: #2b2414;
    --internal-line: #6b5520;
    --mine-bg: #1a2638;
    --st-new: #6ea2ff;
    --st-in_progress: #e0a73a;
    --st-waiting: #c38cf5;
    --st-resolved: #4fbf86;
    --st-closed: #9aa6b4;
    --pr-high: #ff7b72;
    --pr-medium: #e0a73a;
    --pr-low: #9aa6b4;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.05rem; margin: 1.75rem 0 .6rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
h3 { font-size: 1rem; margin: 0 0 .6rem; }
code { background: var(--bg); padding: .1em .35em; border-radius: 4px; }
.wrap { max-width: 1180px; margin: 0 auto; padding-inline: 16px; }
main.wrap { padding-block: 24px 48px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* header */
.top { background: var(--brand); color: var(--brand-ink); padding-top: env(safe-area-inset-top, 0px); }
.top-in { display: flex; align-items: center; gap: 20px; min-height: 56px; flex-wrap: wrap; padding-block: 6px; }
.brand { color: #fff; font-weight: 650; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.mark { background: #fff; color: var(--brand); border-radius: 6px; padding: 1px 6px; font-size: .8rem; font-weight: 800; letter-spacing: .04em; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.top nav a { color: #d6e2f2; padding: 6px 10px; border-radius: 6px; }
.top nav a:hover { background: rgba(255,255,255,.1); text-decoration: none; }
.top nav a.on { background: rgba(255,255,255,.16); color: #fff; }
.who { display: flex; gap: 10px; align-items: center; font-size: .9rem; color: #d6e2f2; margin: 0; }
.who .link { color: #fff; }

/* controls */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.google { width: 100%; padding: 11px; font-size: 1rem; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link.danger { color: var(--danger); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; max-width: 100%;
}
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 550; font-size: .92rem; }
label > input:not([type=checkbox]), label > select { width: 100%; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > label { flex: 1 1 200px; }
.row.between { justify-content: space-between; align-items: center; }
.checks { display: flex; flex-direction: column; gap: 4px; }
.files input { border-style: dashed; padding: 12px; }
.narrow-num { width: 5.5em; }

/* cards & layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card.narrow { max-width: 680px; margin: 0 auto; }
.login { max-width: 440px; margin-top: 8vh; }
.login .dev { margin-top: 16px; display: flex; gap: 6px; flex-wrap: wrap; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.page-head h1 { margin: 0; }
.flash { background: var(--mine-bg); border: 1px solid var(--line); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.flash.err { border-left-color: var(--danger); }
.empty { padding: 28px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* pills */
.pill, .tag { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; border: 1px solid currentColor; }
.tag { color: var(--muted); font-weight: 500; }
.st-new { color: var(--st-new); }
.st-in_progress { color: var(--st-in_progress); }
.st-waiting { color: var(--st-waiting); }
.st-resolved { color: var(--st-resolved); }
.st-closed { color: var(--st-closed); }
.pr-high { color: var(--pr-high); }
.pr-medium { color: var(--pr-medium); }
.pr-low { color: var(--pr-low); }

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tickets { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.tickets th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tickets td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.tickets tr:last-child td { border-bottom: 0; }
table.tickets tr:hover td { background: var(--mine-bg); }
table.tickets td.num { white-space: nowrap; font-variant-numeric: tabular-nums; }
table.tickets td.title { min-width: 240px; }
table.tickets td.title > a { color: var(--ink); font-weight: 550; }
table.tickets td.when { white-space: nowrap; color: var(--muted); font-size: .88rem; }
table.tickets tr.overdue td.num { box-shadow: inset 3px 0 0 var(--danger); }
.sub { font-size: .84rem; color: var(--muted); margin-top: 2px; }
table.plain { width: 100%; border-collapse: collapse; }
table.plain th, table.plain td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.plain thead th { font-size: .78rem; color: var(--muted); text-transform: uppercase; }
table.cats input[type=text], table.cats input:not([type]) { width: 100%; min-width: 140px; }

/* queue */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin: 8px 0 14px; }
.tab { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { text-decoration: none; color: var(--ink); }
.tab.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.count { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; font-size: .78rem; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 6px; }
.filters input[type=search] { flex: 1 1 220px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }

/* ticket */
.ticket-head { margin-bottom: 16px; }
.ticket-head h1 { margin: 4px 0 8px; }
.ticket-head .num { color: var(--muted); font-weight: 500; }
.back { font-size: .9rem; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.ticket-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
aside { display: flex; flex-direction: column; gap: 14px; }
.side select, .side input { width: 100%; }
.side dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; }
.side dt { color: var(--muted); font-size: .88rem; }
.side dd { margin: 0; }
.side details summary { cursor: pointer; color: var(--accent); font-size: .9rem; }
.side details form { margin-top: 8px; }
.timeline { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.msg.mine { background: var(--mine-bg); }
.msg.internal { background: var(--internal-bg); border-color: var(--internal-line); }
.msg.resolution { border-left: 4px solid var(--good); }
.msg .meta { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; font-size: .92rem; }
.msg time, .ev time { color: var(--muted); font-size: .84rem; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.ev { color: var(--muted); font-size: .88rem; padding: 0 16px; }
.atts { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 2px; font-size: .92rem; }
.reply.internal { background: var(--internal-bg); border-color: var(--internal-line); }
.reply .h { font-weight: 600; }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 16px; }
.stat-grid.two { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.big { font-size: 2rem; font-weight: 700; margin: 0; font-variant-numeric: tabular-nums; }
.bars { list-style: none; padding: 0; margin: 0; }
.bars li { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--line); }
.bars li:last-child { border-bottom: 0; }
.weeks { display: flex; gap: 6px; align-items: flex-end; height: 160px; overflow-x: auto; }
.wk { flex: 1 0 34px; display: flex; flex-direction: column; align-items: center; height: 100%; }
.wk .pair { flex: 1; display: flex; gap: 2px; align-items: flex-end; width: 100%; justify-content: center; }
.wk i { display: block; width: 40%; min-height: 1px; border-radius: 3px 3px 0 0; }
.wk span { font-size: .72rem; color: var(--muted); margin-top: 4px; white-space: nowrap; }
i.c { background: var(--accent); }
i.r { background: var(--good); }
.legend { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: 8px; }

@media (max-width: 860px) {
  .ticket-grid { grid-template-columns: 1fr; }
  .stat-grid.two { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .who span { display: none; }
  h1 { font-size: 1.3rem; }
  .card { padding: 14px; }
}
