:root {
  --ink: #1f2933; --muted: #68737d; --line: #d8dcde; --bg: #f8f9f9; --panel: #fff;
  --brand: #03363d; --brand-2: #17494d; --accent: #1f73b7; --accent-dark: #144a75;
  --new: #ffb648; --open: #e34f32; --pending: #3091ec; --hold: #2f3941; --solved: #87929d; --closed: #c2c8cc;
  --note: #fff7e6; --note-line: #f5c26b; --danger: #cc3340; --ok: #038153; --warn: #c96400;
  --radius: 6px; font-size: 14px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; font-weight: 600; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .6rem; }
h4 { font-size: .9rem; margin: .8rem 0 .4rem; }
code { background: #eef0f1; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.hint { display: block; color: var(--muted); font-size: .8rem; font-weight: 400; margin-top: 2px; }
.dim td { opacity: .55; }

/* inputs */
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; background: #fff; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b4d4f0; border-color: var(--accent); }
textarea { width: 100%; resize: vertical; }
label { display: block; font-weight: 500; font-size: .9rem; }
label > input:not([type=checkbox]):not([type=radio]), label > select, label > textarea { display: block; width: 100%; margin-top: 3px; font-weight: 400; }
label.inline, .inline label { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; margin-right: 12px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px 14px; margin: 0; }
legend { font-weight: 600; padding: 0 6px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: var(--radius); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f3f4f5; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { color: var(--danger); border-color: #f0b7bd; }
.btn.wide { width: 100%; justify-content: center; padding: 9px; }
.linkbtn { border: 0; background: none; color: var(--danger); cursor: pointer; font-size: 1.1rem; padding: 0 4px; }

/* layout */
.topbar { display: flex; align-items: center; gap: 16px; background: var(--brand); color: #fff; padding: 0 16px; height: 52px; position: sticky; top: 0; z-index: 10; }
.topbar a { color: #d9e6e7; }
.brand { font-weight: 700; color: #fff !important; font-size: 1.05rem; white-space: nowrap; }
.mainnav { display: flex; gap: 2px; }
.mainnav a { padding: 15px 10px; border-bottom: 3px solid transparent; }
.mainnav a.active, .mainnav a:hover { color: #fff; border-bottom-color: #5eae91; text-decoration: none; }
.topbar .search { flex: 1; display: flex; justify-content: flex-end; }
.topbar .search input { width: 260px; border: 0; background: var(--brand-2); color: #fff; }
.topbar .search input::placeholder { color: #9fb7b9; }
.usermenu { display: flex; gap: 10px; white-space: nowrap; }
.usermenu .muted { color: #9fb7b9; }
.layout { display: flex; min-height: calc(100vh - 52px); }
.views { width: 220px; flex: none; background: #fff; border-right: 1px solid var(--line); padding: 16px 0; }
.views h3 { padding: 0 16px; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.views ul { list-style: none; margin: 0; padding: 0; }
.views a { display: flex; justify-content: space-between; padding: 7px 16px; color: var(--ink); }
.views a:hover { background: #f3f4f5; text-decoration: none; }
.views a.active { background: #e9f1f8; font-weight: 600; box-shadow: inset 3px 0 var(--accent); }
.views a.alert .count { background: var(--danger); color: #fff; }
.count { background: #e9ebed; border-radius: 10px; padding: 0 8px; font-size: .8rem; min-width: 26px; text-align: center; }
.content { flex: 1; padding: 20px 24px; min-width: 0; }

.flash { padding: 9px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid; }
.flash-success { background: #edf8f4; border-color: #aecfc2; color: #025e3c; }
.flash-error { background: #fff0f1; border-color: #f0b7bd; color: #8c232c; }
.flash-info { background: #edf7ff; border-color: #adcce4; color: #144a75; }

.pagehead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.pagehead h1 { margin: 0; flex: 1; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.crumbs { color: var(--muted); font-size: .85rem; margin-bottom: 6px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 120px; }
.narrow { max-width: 640px; }
.form-grid { display: grid; grid-template-columns: 320px 1fr; gap: 16px; }
.form-grid fieldset > * + * { margin-top: 10px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 4px 0; }

/* tables */
table.grid { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.grid th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; background: #fafbfb; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid td { padding: 8px 10px; border-bottom: 1px solid #eef0f1; vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background: #f8fafb; }
.grid.compact td, .grid.compact th { padding: 5px 6px; }
.grid.compact input { width: 100%; }
.grid .chk { width: 30px; }
.tickets .subject a { color: var(--ink); font-weight: 500; }
.tickets tr.unread .subject a { font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 30px !important; }
.bulkbar { display: flex; gap: 8px; align-items: center; background: #e9f1f8; border: 1px solid #adcce4; padding: 8px 10px; border-radius: 8px; margin-bottom: 8px; }
.pager { display: flex; gap: 14px; justify-content: center; padding: 14px; color: var(--muted); }

/* badges */
.badge { display: inline-block; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 2px 7px; border-radius: 4px; color: #fff; white-space: nowrap; }
.st-new { background: var(--new); color: #4a3000; }
.st-open { background: var(--open); }
.st-pending { background: var(--pending); }
.st-on_hold { background: var(--hold); }
.st-solved { background: var(--solved); }
.st-closed { background: var(--closed); color: #333; }
.prio { font-size: .85rem; white-space: nowrap; }
.prio-urgent { color: var(--danger); font-weight: 700; }
.prio-high { color: var(--warn); font-weight: 600; }
.prio-low { color: var(--muted); }
.sla { font-size: .78rem; padding: 2px 7px; border-radius: 10px; white-space: nowrap; font-weight: 600; }
.sla-ok { background: #edf8f4; color: var(--ok); }
.sla-warning { background: #fff4e5; color: var(--warn); }
.sla-breached { background: #fff0f1; color: var(--danger); }
.tag { display: inline-block; background: #eef0f1; color: var(--muted); border-radius: 4px; font-size: .72rem; padding: 0 6px; margin-left: 4px; }
.pill-internal { background: var(--note-line); color: #5a3a00; font-size: .72rem; border-radius: 4px; padding: 1px 6px; font-weight: 600; }
.bad { color: var(--danger); font-weight: 600; }

/* ticket page */
.ticket-head .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.ticket-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; align-items: start; }
.props .card { padding: 14px; }
.props label { margin-top: 0; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 8px; font-size: .88rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
.comment { display: flex; gap: 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin-bottom: 12px; }
.comment.by-agent { border-left: 3px solid var(--accent); }
.comment.internal { background: var(--note); border-color: var(--note-line); border-left: 3px solid var(--note-line); }
.avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; background: #d8e4ee; color: var(--accent-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; }
.by-customer .avatar { background: #e6efe9; color: #025e3c; }
.cbody { flex: 1; min-width: 0; }
.cbody header { margin-bottom: 6px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.text { overflow-wrap: anywhere; }
.attachments { list-style: none; padding: 8px 0 0; margin: 8px 0 0; border-top: 1px dashed var(--line); font-size: .88rem; }
.attachments li::before { content: "📎 "; }
.composer { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-top: 8px; }
.composer.internal-mode { background: var(--note); border-color: var(--note-line); }
.composer-tabs { display: flex; gap: 16px; align-items: center; margin-bottom: 8px; }
.composer-tabs label { display: inline-flex; gap: 6px; align-items: center; font-weight: 600; }
.composer-tabs select { margin-left: auto; }
.composer-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.activity { margin-top: 16px; font-size: .88rem; }
.activity summary { cursor: pointer; color: var(--muted); }
.activity ul { list-style: none; padding: 8px 0 0; }
.activity li { padding: 3px 0; }

/* reports */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 14px; display: flex; flex-direction: column; }
.stat .n { font-size: 1.5rem; font-weight: 700; }
.stat span:last-child { color: var(--muted); font-size: .82rem; }
.barchart { display: flex; gap: 3px; align-items: flex-end; height: 160px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar span { display: block; width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; }
.bar em { font-style: normal; font-size: .65rem; color: var(--muted); margin-top: 3px; }

/* auth */
.authpage { background: var(--brand); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.authbox { background: #fff; padding: 32px; border-radius: 10px; width: 380px; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.authbrand { text-align: center; color: var(--brand); }

/* portal */
.portalbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 32px; background: var(--brand); }
.portalbar a { color: #d9e6e7; margin-left: 16px; }
.portalbar .btn-primary { color: #fff; }
.portal-main { max-width: 980px; margin: 0 auto; padding: 28px 20px; }
.hero { text-align: center; padding: 20px 0 28px; }
.bigsearch { width: 100%; max-width: 560px; padding: 12px 16px; font-size: 1.05rem; border-radius: 30px; }
.article h1 { margin-bottom: 4px; }

@media (max-width: 1000px) {
  .ticket-grid, .two-col, .form-grid { grid-template-columns: 1fr; }
  .views { display: none; }
  .mainnav { display: none; }
}
