:root {
  --bg:#f5f6f9; --panel:#ffffff; --fg:#1f2633; --muted:#6b7280;
  --accent:#5b5bf0;           /* indigo — links, active nav, secondary actions */
  --accent-ink:#4a46d6;
  --green:#12b886;            /* emerald — primary call-to-action */
  --green-ink:#0e9d74;
  --line:#e6e8ee; --line-soft:#eef0f4;
  --note:#fff8e6; --note-line:#f1e2b6;
  --danger:#e11d48; --sidebar:#171a2b; --brand:#E30613;
}
* { box-sizing:border-box; }
body { margin:0; font:15px/1.5 system-ui,Segoe UI,Roboto,sans-serif; background:var(--bg); color:var(--fg); }
a { color:var(--accent); text-decoration:none; } a:hover { text-decoration:underline; }

header.top { background:var(--sidebar); color:#eceefb; padding:11px 20px; display:flex; align-items:center; gap:16px; }
header.top a.brand { display:inline-flex; align-items:center; gap:9px; font-weight:700; text-decoration:none; }
header.top a.brand:hover { text-decoration:none; }
header.top a.brand:hover .logo-img { filter:brightness(1.12); }
.logo-img { height:19px; width:auto; display:block; }
header.top .brand .sub { font-weight:400; color:#c7cbe6; font-size:14px; }
.login .brandhead { display:flex; align-items:center; gap:9px; }
.login .brandhead .logo-img { height:24px; }
header.top nav { display:flex; gap:16px; margin-left:auto; align-items:center; font-size:14px; }
header.top nav a { color:#c7cbe6; }
header.top nav a:hover { color:#fff; text-decoration:none; }
.langswitch { display:inline-flex; gap:4px; align-items:center; }
.langswitch a { font-size:12px; font-weight:600; padding:2px 7px; border-radius:6px; opacity:.65; }
.langswitch a.on { opacity:1; background:rgba(255,255,255,.14); }
header.top .langswitch a { color:#c7cbe6; }
header.top .langswitch a.on { color:#fff; }
.authbar { display:flex; justify-content:flex-end; padding:10px 18px; }
.authbar .langswitch a { color:var(--muted); }
.authbar .langswitch a.on { background:#e7e9fb; color:var(--accent-ink); }

.wrap { max-width:1120px; margin:0 auto; padding:20px 22px 60px; }
/* The inbox list has 7 columns and benefits from more width on large screens;
   reading pages (ticket detail, settings) keep the narrower 1120 for legibility. */
.wrap.wide { max-width:1500px; }
.flash { background:#eef2ff; border:1px solid #d9defb; color:#3a3f8f; padding:9px 13px; border-radius:9px; margin:10px 0; }

/* preset view chips */
.presets { display:flex; flex-wrap:wrap; gap:6px; margin:16px 0 12px; }
.presets.savedrow { margin:-4px 0 12px; padding-top:10px; border-top:1px solid var(--line); }
.presets.savedrow .chip { font-weight:600; }
.presets.savedrow .chip.on { background:var(--sidebar); border-color:var(--sidebar); }
.chip { display:inline-flex; align-items:center; gap:6px; padding:6px 13px; border-radius:20px;
  border:1px solid var(--line); background:#fff; color:var(--fg); font-size:13px; font-weight:600; text-decoration:none; }
.chip:hover { border-color:var(--accent); color:var(--accent); text-decoration:none; }
.chip.on { background:var(--accent); color:#fff; border-color:var(--accent); }
.chip-count { font-size:11.5px; font-weight:700; background:var(--line-soft); color:var(--muted);
  border-radius:10px; padding:1px 7px; min-width:18px; text-align:center; }
.chip:hover .chip-count { background:#e7e9fb; color:var(--accent-ink); }
.chip.on .chip-count { background:rgba(255,255,255,.22); color:#fff; }

/* filters + search */
.toolbar { display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin:14px 0; }
.toolbar input[type=search], .toolbar select { padding:9px 11px; border:1px solid var(--line); border-radius:9px; background:#fff; font:inherit; color:var(--fg); }
.toolbar input[type=search] { flex:1; min-width:220px; }
.search-spin { color:var(--accent); font-size:13px; font-weight:600; }
.toolbar input:focus, .toolbar select:focus { outline:none; border-color:var(--accent); box-shadow:0 0 0 3px rgba(91,91,240,.15); }

/* ticket list */
table.tickets { width:100%; border-collapse:separate; border-spacing:0; background:var(--panel); border:1px solid var(--line); border-radius:12px; overflow:hidden; box-shadow:0 1px 2px rgba(20,23,40,.04); }
table.tickets th, table.tickets td { text-align:left; padding:11px 14px; border-bottom:1px solid var(--line-soft); vertical-align:top; }
table.tickets th { font-size:11.5px; text-transform:uppercase; letter-spacing:.5px; color:var(--muted); background:#fafbfc; font-weight:600; }
table.tickets tr:last-child td { border-bottom:0; }
table.tickets tbody tr:hover td { background:#fafbff; }
table.tickets tr.unread td { font-weight:600; }
table.tickets tr.unread td:first-child { box-shadow:inset 3px 0 0 var(--accent); }
/* Column sizing: Subject stays the flexible column; the short columns shrink to
   their content (width:1% + nowrap) so the date never wraps, and Customer is
   capped with an ellipsis instead of sprawling across the freed space. */
table.tickets .col-customer { max-width:200px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
table.tickets .col-channel, table.tickets .col-status, table.tickets .col-updated { width:1%; white-space:nowrap; }
.tm { color:var(--muted); font-size:.85em; white-space:nowrap; }
.subject { display:block; color:var(--fg); }
.snippet { color:var(--muted); font-weight:400; font-size:13px; }

/* badges / tags / status pills */
.badge { display:inline-block; padding:2px 10px; border-radius:20px; font-size:12px; font-weight:600; border:1px solid transparent; }
.badge.channel { background:var(--line-soft); color:#4b5563; }
.badge.status-new { background:#e1effe; color:#1e63c9; }
.badge.status-open { background:#e7e5fd; color:#5145cd; }
.badge.status-pending { background:#fef3c7; color:#96650c; }
.badge.status-waiting_customer { background:#eceff3; color:#556072; }
.badge.status-closed { background:#d8f3e3; color:#0f7a56; }
.tag { display:inline-block; padding:1px 8px; border-radius:6px; font-size:12px; background:var(--line-soft); color:#5b6472; margin-right:4px; }
/* stable per-tag color palette (see tag_color filter) */
.tag.c0 { background:#e1effe; color:#1e63c9; }
.tag.c1 { background:#d8f3e3; color:#0f7a56; }
.tag.c2 { background:#fef3c7; color:#96650c; }
.tag.c3 { background:#ede9fd; color:#6d43c9; }
.tag.c4 { background:#fde7f0; color:#b83280; }
.tag.c5 { background:#d5f2ee; color:#0e7c86; }
.tag.c6 { background:#ffe8d6; color:#b5591b; }
.tag.c7 { background:#e5e3fd; color:#5145cd; }
.tag.c8 { background:#fde3e3; color:#c22; }
.tag.c9 { background:#eaf5cf; color:#5a7a12; }
.tag.c10 { background:#d9f0fb; color:#1076a8; }
.tag.c11 { background:#eceff3; color:#556072; }
/* editable tag chips on the ticket page */
.tagchips { display:flex; flex-wrap:wrap; gap:6px; margin-bottom:8px; }
.tagchips .tag { display:inline-flex; align-items:center; gap:4px; padding:3px 6px 3px 9px; margin:0; font-weight:600; }
.tagx { background:none; border:0; color:inherit; opacity:.6; cursor:pointer; font-size:14px; line-height:1; padding:0; }
.tagx:hover { opacity:1; }
.tag-input { width:100%; padding:7px 10px; border:1px solid var(--line); border-radius:8px; font:inherit; }
.tag-input:focus { outline:none; border-color:var(--accent); box-shadow:0 0 0 3px rgba(91,91,240,.15); }

/* ticket detail */
.tnav { display:flex; align-items:center; gap:8px; margin-bottom:6px;
  position:sticky; top:0; z-index:5; background:var(--bg);
  padding:8px 0; border-bottom:1px solid var(--line); }
.tnav-spacer { flex:1; }
.tnav-pos { font-size:13px; color:var(--muted); margin-right:2px; }
.tnav-btn { display:inline-flex; align-items:center; justify-content:center; width:30px; height:30px;
  border:1px solid var(--line); border-radius:8px; background:#fff; color:var(--fg); font-size:15px; text-decoration:none; }
.tnav-btn:hover { border-color:var(--accent); color:var(--accent); text-decoration:none; }
.tnav-btn.disabled { opacity:.4; cursor:default; }
.grid { display:grid; grid-template-columns:1fr 340px; gap:20px; align-items:start; }
.side { position:sticky; top:54px; align-self:start; }
@media (max-width:900px){ .grid { grid-template-columns:1fr; } .side { position:static; } }
.thread { display:flex; flex-direction:column; gap:12px; }
.msg { background:var(--panel); border:1px solid var(--line); border-radius:12px; padding:12px 14px; box-shadow:0 1px 2px rgba(20,23,40,.04); }
.msg.outbound { background:#f2f7ff; border-color:#d8e6fb; }
.msg .meta { font-size:12px; color:var(--muted); margin-bottom:6px; display:flex; gap:10px; flex-wrap:wrap; align-items:center; }
.msg .body { white-space:pre-wrap; }
.msg .htmlbody { width:100%; min-height:60px; border:0; background:#fff; border-radius:8px; display:block; }
.msg .meta .viewtoggle { margin-left:auto; cursor:pointer; color:var(--accent); font-size:12px; }
.msg .atts { margin-top:10px; display:flex; flex-wrap:wrap; gap:10px; align-items:flex-start; }
.att-img img { max-width:170px; max-height:170px; border:1px solid var(--line); border-radius:8px;
  display:block; object-fit:cover; background:#f3f4f8; }
.att-img:hover img { border-color:var(--accent); }
.att-file { display:inline-flex; align-items:center; gap:8px; border:1px solid var(--line);
  border-radius:8px; padding:6px 10px; background:#fff; }
.att-ico { font-size:18px; }
.att-name { color:var(--fg); font-size:13px; max-width:240px; overflow:hidden;
  text-overflow:ellipsis; white-space:nowrap; }
.att-dl { color:var(--muted); font-size:15px; text-decoration:none; }
.att-dl:hover { color:var(--accent); }
.filter-hint { font-size:12px; color:var(--muted); margin:-4px 0 10px 2px; }
.filter-form { display:flex; gap:12px; align-items:flex-end; flex-wrap:wrap; }
.filter-form > div { flex:1; min-width:180px; }
.filter-form label { display:block; font-size:12px; font-weight:600; color:var(--muted); margin-bottom:4px; }
.filter-form input { width:100%; padding:8px 10px; border:1px solid var(--line); border-radius:8px; font:inherit; }
.filter-form input:focus { outline:none; border-color:var(--accent); box-shadow:0 0 0 3px rgba(91,91,240,.15); }
.cbcell { width:34px; text-align:center; }
.cbcell input { width:16px; height:16px; cursor:pointer; }
.bulk-bar { display:flex; align-items:center; gap:12px; margin:0 0 12px; padding:9px 14px;
  background:#eef0fb; border:1px solid #d9defb; border-radius:10px; font-size:14px; }
.bulk-bar #bulk-count { font-weight:600; color:var(--accent-ink); }
.bulk-bar select { padding:6px 8px; border:1px solid var(--line); border-radius:7px; background:#fff; font:inherit; }
.bulk-bar .btn { padding:7px 13px; }
.imgbar { background:#f3f4f8; border:1px solid var(--line); border-radius:8px; padding:6px 11px; font-size:12.5px; color:#4b5563; margin-bottom:8px; display:flex; align-items:center; gap:6px; }
.linklike { background:none; border:0; color:var(--accent); cursor:pointer; font:inherit; font-weight:600; padding:0; }
.linklike:hover { text-decoration:underline; }

/* private internal notes */
.notes-card { background:var(--note); border:1px solid var(--note-line); border-radius:12px; padding:14px; }
.notes-card h3 { margin:0 0 8px; font-size:12px; text-transform:uppercase; letter-spacing:.5px; color:#8a6d1f; }
.pnote { border-top:1px solid var(--note-line); padding:8px 0; }
.pnote:first-child { border-top:0; padding-top:0; }
.pnote-meta { font-size:12px; color:#8a6d1f; margin-bottom:3px; }
.pnote-body { white-space:pre-wrap; font-size:14px; color:#5b4a1a; }
.pnote-del { float:right; background:none; border:0; color:#8a6d1f; opacity:.6; cursor:pointer; font-size:14px; line-height:1; padding:0; }
.pnote-del:hover { opacity:1; }
.note-input { width:100%; padding:9px 11px; border:1px solid var(--note-line); border-radius:8px; font:14px/1.5 system-ui; background:#fff; resize:vertical; }
.note-input:focus { outline:none; border-color:#d9b94a; box-shadow:0 0 0 3px rgba(217,185,74,.2); }

.side .card { background:var(--panel); border:1px solid var(--line); border-radius:12px; padding:14px; margin-bottom:14px; box-shadow:0 1px 2px rgba(20,23,40,.04); }
.side .card h3 { margin:0 0 8px; font-size:12px; text-transform:uppercase; letter-spacing:.5px; color:var(--muted); }
.kv { font-size:14px; margin:3px 0; } .kv b { color:var(--muted); font-weight:600; }

/* reply box */
.replybox textarea { width:100%; min-height:160px; padding:12px; border:1px solid var(--line); border-radius:9px; font:14px/1.5 system-ui; background:#fff; resize:vertical; color:var(--fg); overflow:hidden; }
.replybox textarea:focus { outline:none; border-color:var(--accent); box-shadow:0 0 0 3px rgba(91,91,240,.15); }
.tpl-menu { position:fixed; z-index:50; display:none; background:#fff; border:1px solid var(--line);
  border-radius:10px; box-shadow:0 8px 24px rgba(20,23,40,.16); max-height:230px; overflow-y:auto;
  min-width:250px; padding:4px; }
.tpl-item { display:flex; align-items:center; gap:8px; padding:7px 10px; border-radius:7px; cursor:pointer; font-size:14px; }
.tpl-item.on { background:#eef0fb; }
.tpl-title { font-weight:600; }
.tpl-sc { font-size:12px; color:var(--accent); }
.tpl-lang { margin-left:auto; font-size:11px; color:var(--muted); background:var(--line-soft); padding:1px 6px; border-radius:6px; }
.reply-tabs { display:flex; gap:4px; align-items:center; margin-bottom:-1px; }
.rtab { border:1px solid var(--line); border-bottom:0; background:#f1f2f6; color:var(--muted);
  padding:6px 13px; border-radius:9px 9px 0 0; font:inherit; font-size:13px; font-weight:600; cursor:pointer; }
.rtab.on { background:#fff; color:var(--fg); }
.rtab .muted { font-weight:400; opacity:.7; }
.rtab-hint { font-size:12px; color:var(--accent); margin-left:8px; }
.reply-tabs + textarea { border-top-left-radius:0; }
.replybox .notes { background:var(--note); border:1px solid var(--note-line); border-radius:9px; padding:10px 12px; font-size:13px; color:#7a5c1a; margin:8px 0; }
.replybox .notes ul { margin:4px 0 0 18px; padding:0; }

.btn { padding:9px 16px; border:0; border-radius:9px; font:inherit; font-weight:600; cursor:pointer; background:var(--green); color:#fff; }
.btn:hover { background:var(--green-ink); }
.btn.secondary { background:var(--accent); } .btn.secondary:hover { background:var(--accent-ink); }
.btn.ghost { background:var(--line-soft); color:var(--fg); } .btn.ghost:hover { background:#e2e5ec; }
.btn.danger { background:var(--danger); } .btn.danger:hover { filter:brightness(.93); }
.btn:disabled { opacity:.5; cursor:wait; }
.actions { display:flex; gap:8px; margin-top:10px; flex-wrap:wrap; align-items:center; }
.marketplace-cta { display:block; text-align:center; background:var(--accent); color:#fff; padding:11px; border-radius:9px; font-weight:600; margin:8px 0; }
.marketplace-cta:hover { background:var(--accent-ink); text-decoration:none; }
.canned { display:flex; gap:6px; flex-wrap:wrap; margin:8px 0; }
.canned button { font-size:12px; padding:4px 10px; border:1px solid var(--line); border-radius:20px; background:#fff; cursor:pointer; color:var(--fg); }
.canned button:hover { border-color:var(--accent); color:var(--accent); }
.spinner { color:var(--muted); font-size:13px; display:none; }
.htmx-request .spinner { display:inline; }

/* login / register */
.login { max-width:360px; margin:7vh auto; background:var(--panel); border:1px solid var(--line); border-radius:14px; padding:28px; box-shadow:0 6px 24px rgba(20,23,40,.07); }
.login h1 { font-size:20px; margin:0 0 16px; }
.login .brandhead .logo { font-family:'Syncopate', system-ui, sans-serif; font-weight:700; letter-spacing:0; color:var(--brand); }
.login label { display:block; font-size:13px; font-weight:600; margin:12px 0 5px; }
.login input { width:100%; padding:10px 12px; border:1px solid var(--line); border-radius:9px; font:inherit; }
.login input:focus { outline:none; border-color:var(--accent); box-shadow:0 0 0 3px rgba(91,91,240,.15); }
.login .btn { width:100%; margin-top:18px; }

/* stats */
table.stats { border-collapse:collapse; background:#fff; border:1px solid var(--line); border-radius:10px; overflow:hidden; }
table.stats th, table.stats td { padding:9px 15px; border-bottom:1px solid var(--line-soft); text-align:left; }
table.stats th { background:#fafbfc; font-size:12px; color:var(--muted); text-transform:uppercase; letter-spacing:.4px; }

.err { color:var(--danger); background:#fff; border:1px solid var(--line); border-radius:9px; padding:16px; margin-top:20px; white-space:pre-wrap; }

/* ------- mobile ------- */
@media (max-width:640px) {
  html, body { overflow-x:hidden; }
  .wrap { padding:12px 12px 48px; }
  header.top { flex-wrap:wrap; gap:6px 12px; padding:9px 12px; }
  header.top nav { gap:12px; row-gap:4px; flex-wrap:wrap; font-size:13px; }

  .presets { gap:5px; margin:12px 0 10px; }
  .chip { padding:5px 11px; }
  .toolbar { gap:8px; }
  .toolbar input[type=search] { flex:1 1 100%; }
  .toolbar .btn { flex:0 0 auto; }
  .toolbar select { flex:1 1 42%; min-width:0; }

  /* ticket list -> stacked cards */
  table.tickets { border:0; box-shadow:none; background:transparent; border-radius:0; }
  table.tickets thead { display:none; }
  table.tickets, table.tickets tbody { display:block; }
  table.tickets tr { display:block; position:relative; background:var(--panel);
    border:1px solid var(--line); border-radius:11px; margin-bottom:8px; padding:12px 14px;
    box-shadow:0 1px 2px rgba(20,23,40,.05); }
  table.tickets tbody tr:hover td { background:transparent; }
  table.tickets td { display:inline; border:0; padding:0; }
  table.tickets td.cbcell { position:absolute; top:12px; right:12px; width:auto; }
  table.tickets .col-subject { display:block; padding-right:28px; }
  table.tickets .col-subject .subject { font-size:15px; }
  table.tickets .col-customer { display:block; color:var(--muted); font-size:13px; margin-top:3px;
    max-width:none; white-space:normal; overflow:visible; }
  table.tickets .col-channel, table.tickets .col-tags,
  table.tickets .col-status, table.tickets .col-updated {
    display:inline-flex; align-items:center; flex-wrap:wrap; gap:4px; margin:8px 8px 0 0; width:auto; }
  table.tickets .col-updated { color:var(--muted); font-size:12px; }
  table.tickets tr.unread { border-left:3px solid var(--accent); }
  table.tickets tr.unread td:first-child { box-shadow:none; }

  /* ticket detail already stacks (<=900); keep the reply usable */
  .grid { gap:14px; }
}
