:root {
  color-scheme: dark;
  --bg: #0e1116;
  --card: #161a21;
  --raised: #1c212a;
  --input: #11151b;
  --line: #262c36;
  --line-strong: #353d4a;
  --text: #e4e7ec;
  --muted: #98a1b0;
  --faint: #6b7483;
  --placeholder: #919baa;
  --accent: #6b93ff;
  --accent-strong: #4f7cf7;
  --accent-soft: rgba(107, 147, 255, 0.14);
  --danger: #ff7a7f;
  --danger-soft: rgba(255, 99, 105, 0.14);
  --ok: #5ad19a;
  --ok-soft: rgba(70, 200, 140, 0.14);
  --warn: #f2b454;
  --warn-soft: rgba(242, 170, 60, 0.14);
  --purple: #b79bff;
  --purple-soft: rgba(170, 140, 255, 0.15);
  --note: rgba(242, 190, 60, 0.08);
  --note-line: rgba(242, 190, 60, 0.35);
  --radius: 10px;
  --shadow: none;
  --font: "IBM Plex Sans Thai", -apple-system, "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 15px; line-height: 1.55;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; line-height: 1.3; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- header */
.top {
  position: sticky; top: 0; z-index: 10; background: var(--card);
  border-bottom: 1px solid var(--line);
}
.top-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 16px; height: 56px;
  display: flex; align-items: center; gap: 18px;
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; }
.brand-dot { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, #6b93ff, #9b7bff); display: inline-block; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a {
  color: var(--muted); padding: 6px 10px; border-radius: 8px; white-space: nowrap; font-size: 14px;
}
.nav a:hover { background: var(--raised); text-decoration: none; color: var(--text); }
.nav a.on { color: var(--text); background: var(--raised); font-weight: 600; }
.badge-count {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.me { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.me form { margin: 0; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--muted); cursor: pointer; font: inherit; }
.linkbtn:hover { color: var(--text); text-decoration: underline; }

main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 64px; }
.narrow { max-width: 760px; }

/* ---------- cards & forms */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card + .card { margin-top: 16px; }
.field { margin-bottom: 16px; }
.field > label, .label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.req { color: var(--danger); margin-left: 2px; }
.help { font-size: 13px; color: var(--muted); margin-top: 4px; }
.err { font-size: 13px; color: var(--danger); margin-top: 4px; }
input[type=text], input[type=email], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; font: inherit; color: inherit; background: var(--input);
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 9px 11px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.has-err input, .has-err select, .has-err textarea { border-color: var(--danger); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.checks label { font-weight: 400; display: flex; gap: 6px; align-items: center; font-size: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  border-radius: 8px; padding: 9px 16px; border: 1px solid var(--line-strong);
  background: var(--raised); color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--line); text-decoration: none; }
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-primary:hover { background: #3f6de8; }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: 0.6; cursor: wait; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--danger-soft); color: var(--danger); }

/* ---------- category picker */
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 16px; }
.cat {
  display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; color: var(--text); box-shadow: var(--shadow); transition: border-color .15s, transform .15s;
}
.cat:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.cat b { display: block; font-size: 15px; margin-bottom: 4px; }
.cat span { font-size: 13px; color: var(--muted); }

/* ---------- attachments / dropzone */
.drop {
  border: 1.5px dashed var(--line-strong); border-radius: 8px; padding: 12px; background: var(--input);
  font-size: 13px; color: var(--muted);
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-hint { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.drop-hint label { color: var(--accent); cursor: pointer; font-weight: 600; }
.attach-pick { position: relative; border-radius: 8px; }
.attach-mobile-label { display: none; }
.drop input[type=file] {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.attach-pick:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 3px; }
.previews { display: flex; flex-wrap: wrap; gap: 8px; }
.previews:not(:empty) { margin-top: 10px; }
.pv {
  position: relative; border: 1px solid var(--line); border-radius: 8px; background: var(--raised);
  width: 112px; overflow: hidden; font-size: 11px;
}
.pv img { display: block; width: 100%; height: 76px; object-fit: cover; background: var(--bg); }
.pv .pv-file { height: 76px; display: flex; align-items: center; justify-content: center; font-size: 22px; background: var(--bg); }
.pv .pv-name { padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.pv button {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 10px; border: 0;
  background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 12px; line-height: 20px; padding: 0;
}

/* ---------- lists */
.list-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a {
  padding: 6px 12px; border-radius: 999px; font-size: 13px; color: var(--muted); border: 1px solid var(--line);
  background: var(--card);
}
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.tabs .n { opacity: .7; margin-left: 4px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters select, .filters input { width: auto; min-width: 160px; padding: 7px 10px; font-size: 14px; }
.filters input[type=search] { flex: 1; min-width: 200px; }

.tlist { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.titem {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; padding: 12px 16px;
  border-top: 1px solid var(--line); color: var(--text);
}
.titem:first-child { border-top: 0; }
.titem:hover { background: var(--raised); text-decoration: none; }
.titem .t-title { font-weight: 600; }
.titem .t-id { color: var(--faint); font-weight: 400; margin-right: 6px; }
.titem .t-meta { font-size: 13px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.titem .t-right { text-align: right; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.s-new { background: var(--accent-soft); color: var(--accent); }
.s-in_progress { background: var(--warn-soft); color: var(--warn); }
.s-waiting { background: var(--purple-soft); color: var(--purple); }
.s-resolved { background: var(--ok-soft); color: var(--ok); }
.s-cancelled { background: rgba(150, 160, 175, 0.14); color: var(--muted); }
.urgent { background: var(--danger-soft); color: var(--danger); }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 6px; background: var(--bg); color: var(--muted); }

/* ---------- ticket page */
.tgrid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; align-items: start; }
.thead { margin-bottom: 16px; }
.thead .crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.thead .pills { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: minmax(120px, 34%) 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.body-text { white-space: normal; overflow-wrap: anywhere; }

.timeline { margin-top: 16px; }
.ev {
  display: flex; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line);
}
.ev:first-child { border-top: 0; }
.avatar {
  flex: 0 0 32px; height: 32px; border-radius: 16px; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.ev-main { flex: 1; min-width: 0; }
.ev-head { font-size: 13px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ev-head b { color: var(--text); }
.ev.internal .ev-main { background: var(--note); border: 1px solid var(--note-line); border-radius: 8px; padding: 10px 12px; }
.ev.draft .ev-main { background: var(--accent-soft); border: 1px dashed var(--accent); border-radius: 8px; padding: 10px 12px; }
.ev.event { padding: 8px 0; font-size: 13px; color: var(--muted); align-items: center; }
.ev.event .dot { flex: 0 0 32px; display: flex; justify-content: center; }
.ev.event .dot i { width: 8px; height: 8px; border-radius: 4px; background: var(--line-strong); display: block; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: flex-start; }
.file-img img { display: block; max-width: 220px; max-height: 160px; border-radius: 8px; border: 1px solid var(--line); }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--raised); color: var(--text);
}
.reply { margin-top: 16px; border-radius: 8px; transition: background-color .15s, box-shadow .15s; }
.reply.internal-mode { background: var(--note); box-shadow: inset 0 0 0 1px var(--note-line); padding: 12px; }
.reply.internal-mode textarea { border-color: var(--note-line); }
.reply-hint { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.reply textarea { min-height: 110px; }
.reply-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.reply-actions .left { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.reply-actions .left select { width: auto; padding: 6px 8px; font-size: 13px; }
.side .card { padding: 16px; }
.side h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 0 10px; text-transform: none; }
.side .field { margin-bottom: 12px; }
.side .field > label { font-size: 13px; }
.side select { padding: 7px 9px; font-size: 14px; }

.login-wrap { min-height: calc(100vh - 56px); display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; text-align: center; padding: 32px 24px; }
.gbtn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 11px 16px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--raised); color: var(--text);
  font-weight: 600; margin-top: 20px;
}
.gbtn:hover { background: var(--line); text-decoration: none; }

code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.codebox {
  display: flex; gap: 8px; align-items: center; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; margin: 8px 0;
}
.codebox code { flex: 1; overflow-x: auto; white-space: nowrap; }
ol.steps { padding-left: 20px; margin: 8px 0; }
ol.steps li { margin-bottom: 6px; }

@media (max-width: 820px) {
  .tgrid { grid-template-columns: 1fr; }
  .side { display: contents; }
  .side .manage-card { order: -1; }
  .side .info-card { order: 1; margin-top: 0; }
  .me .who { display: none; }
  .titem { grid-template-columns: 1fr; }
  .titem .t-right { flex-direction: row; align-items: center; justify-content: flex-start; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .file-img img { max-width: 100%; }
}

@media (max-width: 640px) {
  body { overflow-x: hidden; }
  .top-inner {
    height: auto; min-height: 56px; padding: 8px 12px;
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px;
  }
  .brand { min-width: 0; }
  .me { grid-column: 2; grid-row: 1; }
  .nav {
    grid-column: 1 / -1; grid-row: 2; width: 100%; overflow: visible;
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px;
  }
  .nav a { min-width: 0; white-space: normal; text-align: center; justify-content: center; }
  main { padding-top: 16px; }
  button, .btn, .tabs a, .nav a, .linkbtn { min-height: 44px; }
  .tabs a { display: inline-flex; align-items: center; }
  .pv button { width: 44px; height: 44px; border-radius: 22px; line-height: 44px; }
  .drop-hint { display: block; }
  .attach-desktop-copy, .attach-desktop-label { display: none; }
  .attach-mobile-label { display: inline; }
  .attach-pick {
    display: flex; width: 100%; min-height: 44px; align-items: center; justify-content: center;
    padding: 9px 14px; border: 1px solid var(--line-strong); background: var(--raised);
  }
  .drop-hint > .small { display: block; margin-top: 6px; text-align: center; }
}

@media (pointer: coarse) {
  .drop-hint { display: block; }
  .attach-desktop-copy, .attach-desktop-label { display: none; }
  .attach-mobile-label { display: inline; }
  .attach-pick {
    display: flex; width: 100%; min-height: 44px; align-items: center; justify-content: center;
    padding: 9px 14px; border: 1px solid var(--line-strong); background: var(--raised);
  }
  .drop-hint > .small { display: block; margin-top: 6px; text-align: center; }
}

/* ---------- dark tweaks */
select option { background: var(--card); color: var(--text); }
input::placeholder, textarea::placeholder { color: var(--placeholder); opacity: 1; }
input[type=date]::-webkit-calendar-picker-indicator { filter: invert(0.8); }
.pv button { background: rgba(0, 0, 0, 0.7); }
.flash.ok { border: 1px solid rgba(70, 200, 140, 0.3); }
.flash.error { border: 1px solid rgba(255, 99, 105, 0.3); }
.card, .tlist, .cat { border-color: var(--line); }
::selection { background: rgba(107, 147, 255, 0.35); }

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
