/* Wayfs Desk. One neutral surface; each service brings only its own colour (P2P green, Storage violet),
   so a glance at a row or a header tells which service a ticket belongs to. */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --line: #e4e7ec;
  --text: #15181e;
  --muted: #667085;
  --faint: #98a2b3;
  --accent: #2f6bff;
  --accent-soft: #e8efff;
  --red: #e5484d;
  --amber: #c98a00;
  --amber-soft: #fff6dc;
  --green: #1fae7a;
  --p2p: #1fae7a;
  --storage: #6c63ff;
  --bubble-in: #ffffff;
  --bubble-out: #2f6bff;
  --bubble-out-text: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1015; --panel: #161920; --panel-2: #1b1f27; --line: #262b35; --text: #e8eaef; --muted: #98a0ad; --faint: #6b7380;
    --accent: #5b8cff; --accent-soft: #1d2a47; --amber-soft: #3a2f10; --bubble-in: #1f2430; --bubble-out: #3b6cf0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1015; --panel: #161920; --panel-2: #1b1f27; --line: #262b35; --text: #e8eaef; --muted: #98a0ad; --faint: #6b7380;
  --accent: #5b8cff; --accent-soft: #1d2a47; --amber-soft: #3a2f10; --bubble-in: #1f2430; --bubble-out: #3b6cf0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }

/* --- layout ---------------------------------------------------------------- */
.app { display: grid; grid-template-columns: 236px 380px minmax(0, 1fr) 300px; height: 100vh; }

.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 12px; gap: 4px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--p2p), var(--storage)); font-size: 15px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.nav-title { margin: 14px 8px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 600; }
.nav { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; border: 0; background: none; text-align: left; width: 100%; color: var(--text); }
.nav:hover { background: var(--panel-2); }
.nav.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .ico { width: 18px; text-align: center; opacity: .8; }
.nav .count { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav.active .count { color: var(--accent); }
.nav .count.hot { background: var(--red); color: #fff; border-radius: 10px; padding: 0 7px; font-weight: 600; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--c, var(--faint)); }
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.side-foot .who { min-width: 0; flex: 1; }
.side-foot .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .who span { font-size: 12px; color: var(--muted); }

/* --- ticket list ------------------------------------------------------------- */
.list { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.list-head h1 { margin: 0; font-size: 18px; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; }
.search input { border: 0; background: none; outline: none; padding: 8px 0; width: 100%; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 20px; padding: 3px 10px; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.chip.active { border-color: var(--c, var(--accent)); color: var(--text); background: color-mix(in srgb, var(--c, var(--accent)) 12%, transparent); }
.rows { overflow-y: auto; flex: 1; }
.row { display: grid; grid-template-columns: 4px 1fr; border-bottom: 1px solid var(--line); cursor: pointer; background: var(--panel); }
.row:hover { background: var(--panel-2); }
.row.active { background: var(--accent-soft); }
.row .bar { background: var(--c); }
.row-body { padding: 10px 12px 11px; min-width: 0; }
.row-top { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.row-top .time { margin-left: auto; }
.tag { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 6px; color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent); }
.row-name { font-weight: 600; margin-top: 3px; display: flex; align-items: center; gap: 6px; }
.row-name .unread { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.row-text { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

.pill { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 20px; white-space: nowrap; }
.pill.new { background: var(--red); color: #fff; }
.pill.open { background: var(--accent-soft); color: var(--accent); }
.pill.waiting { background: var(--amber-soft); color: var(--amber); }
.pill.closed { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }

/* --- conversation ------------------------------------------------------------ */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.conv-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 12px 18px; display: flex; align-items: center; gap: 12px;
  box-shadow: inset 0 3px 0 var(--c, transparent); }
.svc-badge { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; font-size: 12px; padding: 5px 10px; border-radius: 8px;
  color: #fff; background: var(--c); white-space: nowrap; }
.conv-title { min-width: 0; flex: 1; }
.conv-title h2 { margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-title div { font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 7px 12px; font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.icon { padding: 7px 9px; }
select.btn { appearance: none; padding-right: 26px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 52%, calc(100% - 8px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }

.timeline { flex: 1; overflow-y: auto; padding: 20px 18px 8px; display: flex; flex-direction: column; gap: 8px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 2px 10px; border-radius: 20px; margin: 6px 0; }
.msg { max-width: min(560px, 78%); display: flex; flex-direction: column; gap: 3px; }
.msg .bubble { padding: 9px 12px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--shadow); }
.msg .meta { font-size: 11px; color: var(--faint); padding: 0 4px; }
.msg.in { align-self: flex-start; }
.msg.in .bubble { background: var(--bubble-in); border-top-left-radius: 4px; }
.msg.out { align-self: flex-end; }
.msg.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); border-top-right-radius: 4px; }
.msg.out .meta { text-align: right; }
.msg.note { align-self: center; max-width: 70%; }
.msg.note .bubble { background: var(--amber-soft); color: var(--text); border: 1px dashed color-mix(in srgb, var(--amber) 50%, transparent); box-shadow: none; }
.event { align-self: center; font-size: 12px; color: var(--muted); }
.attach { display: block; margin: -3px -6px 6px; }
.attach img, .attach video { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; }
.attach a.file { display: inline-flex; gap: 6px; align-items: center; padding: 6px 10px; border-radius: 8px; background: color-mix(in srgb, currentColor 10%, transparent); color: inherit; }

.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 14px 12px; }
.composer.note-mode { background: var(--amber-soft); }
.comp-tabs { display: flex; gap: 4px; margin-bottom: 8px; align-items: center; }
.comp-tab { border: 0; background: none; padding: 4px 10px; border-radius: 7px; font-weight: 600; color: var(--muted); font-size: 13px; }
.comp-tab.active { background: var(--panel-2); color: var(--text); }
.composer.note-mode .comp-tab.active { background: rgba(255, 255, 255, .5); }
.comp-tabs .hint { margin-left: auto; font-size: 12px; color: var(--faint); }
.comp-box { display: flex; gap: 8px; align-items: flex-end; }
.comp-box textarea { flex: 1; resize: none; min-height: 44px; max-height: 220px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--panel); outline: none; }
.comp-box textarea:focus { border-color: var(--accent); }
.macros { position: relative; }
.menu { position: absolute; bottom: calc(100% + 6px); left: 0; width: 320px; max-height: 340px; overflow-y: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .18); padding: 6px; z-index: 5; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 8px; }
.menu button:hover { background: var(--panel-2); }
.menu button span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 24px; }
.placeholder .big { font-size: 40px; margin-bottom: 8px; }
.placeholder b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

/* --- info panel -------------------------------------------------------------- */
.info { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 16px; }
.person { display: flex; gap: 12px; align-items: center; }
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--c, var(--accent)); flex: none; }
.person b { display: block; font-size: 15px; }
.person span { color: var(--muted); font-size: 12px; }
.card { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.card h3 { margin: 0; padding: 9px 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--panel-2); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.kv b { font-weight: 600; text-align: right; }
.kv b.ok { color: var(--green); } .kv b.bad { color: var(--red); }
.hist { padding: 7px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; font-size: 13px; cursor: pointer; }
.hist:hover { background: var(--panel-2); }
.hist:last-child { border-bottom: 0; }
.hist .t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- pages: team, macros ----------------------------------------------------- */
.page { flex: 1; overflow-y: auto; padding: 24px; }
.page h2 { margin: 0 0 4px; font-size: 20px; }
.page .lead { color: var(--muted); margin: 0 0 18px; max-width: 640px; }
.table { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; max-width: 820px; }
.trow { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.trow:last-child { border-bottom: 0; }
.trow .grow { flex: 1; min-width: 0; }
.trow .grow b { display: block; }
.trow .grow span { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; }
.invite { margin: 14px 0; max-width: 820px; background: var(--accent-soft); border-radius: var(--radius); padding: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.invite code { background: var(--panel); padding: 6px 10px; border-radius: 8px; flex: 1; min-width: 240px; overflow-wrap: anywhere; }
.form { display: grid; gap: 8px; max-width: 820px; margin-bottom: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.form input, .form textarea, .form select { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: var(--panel); }
.form .line { display: flex; gap: 8px; }
.form .line input { flex: 1; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #15181e; color: #fff; padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); z-index: 50; font-weight: 500; }

/* --- sign-in pages ------------------------------------------------------------ */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.gate-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); }
.gate-card h1 { margin: 16px 0 6px; font-size: 22px; letter-spacing: -.01em; }
.gate-card p { color: var(--muted); margin: 0 0 18px; }
.gate-card ol { padding-left: 20px; margin: 0 0 20px; color: var(--text); }
.gate-card li { margin-bottom: 6px; }
.gate-card .btn { width: 100%; justify-content: center; padding: 11px; font-size: 15px; }
.services-row { display: flex; gap: 8px; margin-top: 18px; justify-content: center; }

/* --- added: urgency, waiting clock, tags, viewers, stats ---------------------- */
.prio { font-size: 11px; font-weight: 700; color: var(--red); }
.sla { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--amber); white-space: nowrap; }
.sla.late { color: var(--red); }
.assignee { font-weight: 400; color: var(--muted); font-size: 12px; }
.row-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.row-tags span, .tagx { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.tags-edit { padding: 10px 12px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tagx:hover { border-color: var(--red); color: var(--red); }
.tags-edit input { border: 1px dashed var(--line); background: none; border-radius: 6px; padding: 2px 8px; font-size: 12px; width: 110px; outline: none; }
.info-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.info-actions .btn { flex: 1; justify-content: center; }
.viewers { background: var(--amber-soft); color: var(--amber); font-size: 12px; font-weight: 600; padding: 6px 18px; border-bottom: 1px solid var(--line); }
.failed { color: var(--red); font-weight: 600; }
.msg.out .meta .failed { color: var(--red); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; max-width: 980px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi span { display: block; color: var(--muted); font-size: 12px; }
.kpi b { display: block; font-size: 24px; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--faint); font-size: 12px; }
.chart-card { max-width: 980px; margin-bottom: 16px; background: var(--panel); }
.legend { display: inline-flex; align-items: center; gap: 5px; text-transform: none; letter-spacing: 0; font-weight: 500; margin-left: 10px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding: 14px 12px 10px; }
.bar-col { flex: 1; height: 100%; display: flex; flex-direction: column-reverse; gap: 1px; min-width: 3px; }
.bar-col i { display: block; background: var(--c); border-radius: 3px 3px 0 0; min-height: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; max-width: 980px; }
.grid2 .card { background: var(--panel); }
.page .lead select.btn { padding-top: 3px; padding-bottom: 3px; }

.linkbtn { border: 0; background: none; padding: 0 2px; color: var(--accent); font-size: 11px; font-weight: 600; }
.linkbtn.subtle { color: var(--faint); font-weight: 500; opacity: 0; transition: opacity .15s; }
.msg:hover .linkbtn.subtle { opacity: 1; }
.msg.gone .bubble { opacity: .55; text-decoration: line-through; }
.svc-select { border: 0; cursor: pointer; appearance: none; padding-right: 22px; font-family: inherit;
  background-image: linear-gradient(45deg, transparent 50%, #fff 50%), linear-gradient(135deg, #fff 50%, transparent 50%);
  background-position: calc(100% - 12px) 52%, calc(100% - 7px) 52%; background-size: 5px 5px; background-repeat: no-repeat; background-color: var(--c); }
.svc-select option { color: var(--text); background: var(--panel); }
.wait-toggle { margin-left: 10px; font-size: 12px; }
.person-note { width: 100%; border: 0; resize: vertical; min-height: 64px; padding: 10px 12px; background: var(--panel); outline: none; font-size: 13px; }
.person-note:focus { background: var(--panel-2); }
.invites-list { margin-bottom: 12px; }

.info > * { flex-shrink: 0; }
.conv-head { flex-wrap: wrap; row-gap: 8px; }
.conv-title { min-width: 240px; }
.actions { flex-wrap: wrap; }
.comp-tabs { flex-wrap: wrap; row-gap: 4px; }
@container (max-width: 640px) { .comp-tabs .hint { display: none; } }
.main { container-type: inline-size; }

/* --- narrower screens: these come last so they win over the base rules above ---------- */
@media (max-width: 1440px) {
  .app { grid-template-columns: 220px 340px minmax(0, 1fr); }
  .info { display: none; }
  .app.show-info { grid-template-columns: 220px 340px minmax(0, 1fr) 300px; }
  .app.show-info .info { display: flex; }
}
@media (max-width: 1100px) {
  .app, .app.show-info { grid-template-columns: 300px minmax(0, 1fr); }
  .side { display: none; }
  .app.show-info .info { display: flex; position: fixed; right: 0; top: 0; bottom: 0; width: min(340px, 92vw); z-index: 20; box-shadow: -12px 0 32px rgba(0,0,0,.2); }
}
/* --- phone: one column at a time ---------------------------------------------- */
.mobile-only { display: none; }
@media (max-width: 760px) {
  .app, .app.show-info { grid-template-columns: 1fr; }
  .app .main { display: none; }
  .app.conv-open .list { display: none; }
  .app.conv-open .main { display: flex; }
  .mobile-only { display: inline-flex; }
  .conv-head { padding: 10px 12px; flex-wrap: wrap; }
  .actions { width: 100%; }
  .actions .btn { flex: 0 0 auto; justify-content: center; white-space: nowrap; }
  .actions #statusSel { flex: 1 1 auto; min-width: 0; }
  .comp-box { flex-wrap: wrap; }
  .comp-box textarea { order: -1; flex-basis: 100%; }
  .comp-box #send { margin-left: auto; }
  .msg { max-width: 88%; }
  .page { padding: 16px; }
}

