:root {
  --green: #57B947; --green-d: #3f9a31; --blue: #1597D6; --blue-d: #0f7bb0;
  --ink: #1b2430; --ink-2: #4a5566; --ink-3: #7b8696; --line: #e5e9ef; --bg: #f5f7fa; --card: #fff;
  --red: #d64545; --amber: #d98b0b; --purple: #7a5af8;
  --r: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 Inter, system-ui, sans-serif; color: var(--ink); background: var(--bg); }
h1, h2, h3, .brand { font-family: 'Plus Jakarta Sans', Inter, sans-serif; }
a { color: var(--blue-d); text-decoration: none; }
a:hover { text-decoration: underline; }
small { color: var(--ink-3); }

/* shell */
.shell { display: flex; min-height: 100vh; }
.side { width: 228px; flex: none; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; color: var(--ink); padding: 0 8px 18px; }
.brand:hover { text-decoration: none; }
.brand b { color: var(--green-d); }
.logo { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, var(--green), var(--blue)); color: #fff; display: grid; place-items: center; font-weight: 700; }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.side nav a svg { width: 18px; height: 18px; opacity: .7; }
.side nav a:hover { background: var(--bg); text-decoration: none; }
.side nav a.on { background: #e8f5e5; color: var(--green-d); }
.side nav a.on svg { opacity: 1; }
.me { display: flex; gap: 10px; align-items: center; border-top: 1px solid var(--line); padding: 14px 8px 0; }
.me a { color: var(--ink); font-weight: 600; }
.me small { display: block; }
.me small a { color: var(--ink-3); font-weight: 400; }
.avatar { width: 32px; height: 32px; flex: none; border-radius: 50%; background: #e3f1fa; color: var(--blue-d); display: grid; place-items: center; font-size: 12px; font-weight: 600; }
.avatar.sm { width: 24px; height: 24px; font-size: 10px; }
main { flex: 1; min-width: 0; padding: 0 28px 40px; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 22px 0 18px; }
.top h1 { margin: 0; font-size: 22px; }
.bell { position: relative; color: var(--ink-2); padding: 6px; }
.bell svg { width: 22px; height: 22px; display: block; }
.bell .count { position: absolute; top: -2px; right: -4px; background: var(--red); color: #fff; font-size: 11px; font-weight: 600; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }

/* blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; margin-bottom: 18px; }
.card h2 { font-size: 15px; margin: 0 0 12px; }
.card h2 small { font-weight: 400; font-family: Inter; margin-left: 6px; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: 1fr 1fr; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; color: var(--ink); }
.stat:hover { text-decoration: none; border-color: #cfd6df; }
.stat b { display: block; font: 700 26px/1.2 'Plus Jakarta Sans', sans-serif; }
.stat span { color: var(--ink-3); font-size: 13px; }
.stat.warn b { color: var(--red); }
.stat.good b { color: var(--green-d); }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: #e8f5e5; color: #2c6e22; border: 1px solid #cbe8c4; }
.flash.err { background: #fdecec; color: #9b2c2c; border-color: #f5c9c9; }
.muted { color: var(--ink-3); }
.empty { color: var(--ink-3); text-align: center; padding: 30px 10px; }

/* tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.unread td { background: #f4faff; }
tr.unread .subj { font-weight: 600; }
.tno { font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.subj { color: var(--ink); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--blue); margin-right: 6px; }
.num { text-align: right; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.st-open { background: #e3f1fa; color: var(--blue-d); }
.st-in_progress { background: #efeaff; color: var(--purple); }
.st-waiting_user { background: #fff4de; color: #9a6206; }
.st-resolved { background: #e8f5e5; color: var(--green-d); }
.st-reopened { background: #fdecec; color: var(--red); }
.st-closed { background: #eef0f3; color: var(--ink-2); }
.pr-low { background: #eef0f3; color: var(--ink-2); }
.pr-medium { background: #e3f1fa; color: var(--blue-d); }
.pr-high { background: #fff4de; color: #9a6206; }
.pr-urgent { background: var(--red); color: #fff; }
.overdue { background: #fdecec; color: var(--red); }
.app-chip { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.app-chip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.stars { color: #f2b01e; letter-spacing: 1px; white-space: nowrap; }
.stars .off { color: #dde2e8; }

/* tabs & filters */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--ink-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.on { color: var(--green-d); border-color: var(--green); }
.tabs a span { background: var(--bg); border-radius: 10px; padding: 0 7px; font-size: 12px; margin-left: 4px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type=search] { flex: 1; min-width: 200px; }

/* forms */
input, select, textarea { font: inherit; color: inherit; border: 1px solid #d5dbe3; border-radius: 8px; padding: 8px 10px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfe3f5; border-color: var(--blue); }
textarea { width: 100%; resize: vertical; min-height: 110px; }
label { display: block; font-weight: 500; font-size: 13px; margin-bottom: 12px; }
label > input:not([type=checkbox]):not([type=radio]), label > select, label > textarea { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 4px 0 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }
.btn { display: inline-flex; align-items: center; gap: 6px; font: 500 14px Inter, sans-serif; border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; cursor: pointer; background: var(--blue); color: #fff; }
.btn:hover { background: var(--blue-d); text-decoration: none; }
.btn.green { background: var(--green); }
.btn.green:hover { background: var(--green-d); }
.btn.ghost { background: #fff; color: var(--ink-2); border-color: #d5dbe3; }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: #fff; color: var(--red); border-color: #f0c4c4; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.key { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: var(--bg); border: 1px solid var(--line); padding: 4px 8px; border-radius: 6px; word-break: break-all; }

/* ticket page */
.ticket-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.ticket-head { margin-bottom: 16px; }
.ticket-head h2 { font-size: 20px; margin: 4px 0 8px; }
.ticket-head .actions { gap: 6px; }
.thread { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.msg { display: flex; gap: 10px; max-width: 88%; }
.msg .bubble { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; min-width: 0; }
.msg .who { font-size: 12px; color: var(--ink-3); margin-bottom: 4px; }
.msg .who b { color: var(--ink); font-weight: 600; }
.msg .body { white-space: pre-wrap; word-wrap: break-word; }
.msg.agent { align-self: flex-end; flex-direction: row-reverse; }
.msg.agent .bubble { background: #eef7fc; border-color: #d3eaf6; }
.msg.agent .avatar { background: #e8f5e5; color: var(--green-d); }
.msg.note .bubble { background: #fffaeb; border-color: #f6e3a8; }
.msg.system { align-self: center; max-width: 100%; }
.msg.system .bubble { background: transparent; border: 0; padding: 0; color: var(--ink-3); font-size: 13px; text-align: center; }
.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.files a { font-size: 12px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; }
.reply-box .opts { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.reply-box.note textarea { background: #fffaeb; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--ink-3); }
dl.kv dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.timeline li { padding: 6px 0 6px 14px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 11px; width: 8px; height: 8px; border-radius: 50%; background: #cfd6df; }
.timeline small { display: block; }
.bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--green); border-radius: 4px; }

/* public + login pages */
.solo { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.solo .card { width: 100%; max-width: 440px; padding: 28px; }
.solo .brand { justify-content: center; padding-bottom: 6px; }
.rate { display: flex; flex-direction: row-reverse; justify-content: center; gap: 4px; margin: 6px 0 16px; }
.rate input { display: none; }
.rate label { font-size: 36px; color: #dde2e8; cursor: pointer; margin: 0; line-height: 1; }
.rate input:checked ~ label, .rate label:hover, .rate label:hover ~ label { color: #f2b01e; }

/* docs */
.docs h3 { margin: 22px 0 8px; font-size: 15px; }
.docs pre { background: #1b2430; color: #e6edf3; padding: 14px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; line-height: 1.55; }
.docs code { font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
.docs p code, .docs td code, .docs li code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.method { font: 600 11px ui-monospace, monospace; padding: 2px 6px; border-radius: 4px; color: #fff; background: var(--blue); }
.method.post { background: var(--green-d); }

@media (max-width: 1000px) {
  .ticket-grid, .g2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .side { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 8px 0 0; }
  .side nav { flex-direction: row; overflow-x: auto; width: 100%; order: 3; }
  .side nav a { padding: 8px; font-size: 13px; white-space: nowrap; }
  .side nav a svg { display: none; }
  .me { border: 0; padding: 0; margin-left: auto; }
  .me div { display: none; }
  main { padding: 0 16px 30px; }
  .msg { max-width: 100%; }
  .hide-sm { display: none; }
}
