:root {
  --navy: #14213d; --gold: #fca311; --bg: #f3f4f6; --card: #fff; --line: #e5e7eb;
  --text: #111827; --muted: #6b7280; --red: #b91c1c; --green: #15803d; --blue: #1d4ed8;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--blue); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.pad { padding: 16px; }
.error { color: var(--red); }
.boot { text-align: center; padding: 80px 16px; color: var(--muted); }
[hidden] { display: none !important; }

/* header */
.top { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 24px; padding: 10px 20px; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; display: flex; flex-direction: column; line-height: 1.15; }
.brand b { font-size: 20px; letter-spacing: .5px; color: var(--gold); }
.brand span { font-size: 11px; opacity: .8; text-transform: uppercase; letter-spacing: 1px; }
.brand.big { color: var(--navy); align-items: center; margin-bottom: 20px; }
.brand.big b { font-size: 32px; color: var(--navy); }
.top nav { display: flex; gap: 4px; flex: 1; }
.top nav a { color: #d1d5db; text-decoration: none; padding: 6px 12px; border-radius: 6px; }
.top nav a.on, .top nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.who { display: flex; align-items: center; gap: 12px; font-size: 13px; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 20px; margin-bottom: 16px; }
.card.narrow { max-width: 400px; margin: 8vh auto; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.back { display: inline-block; margin-bottom: 12px; text-decoration: none; }

/* forms */
label { display: block; font-size: 13px; font-weight: 600; color: #374151; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border: 1px solid #d1d5db; border-radius: 6px; font: inherit; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
input[type=file] { padding: 6px; }
input[type=checkbox] { display: inline; width: auto; margin: 0 6px 0 0; }
.hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.check { font-weight: 400; display: flex; align-items: center; }
.auth form label { margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid .wide { grid-column: 1 / -1; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn { display: inline-block; border: 1px solid #d1d5db; background: #fff; color: var(--text); padding: 9px 16px; border-radius: 6px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.btn.primary:hover { filter: brightness(.95); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: wait; }
.top .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stats:empty { display: none; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; text-align: left; cursor: pointer; font: inherit; }
.stat:hover { border-color: var(--gold); }
.stat b { display: block; font-size: 26px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.hot b { color: var(--red); }
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 200px; margin: 0; }
.toolbar select { width: auto; margin: 0; }

table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafafa; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
table.tickets tbody tr { cursor: pointer; }
table.tickets tbody tr:hover { background: #fffbeb; }
tr.off { opacity: .55; }
.num { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; font-weight: 600; }
.actions { white-space: nowrap; text-align: right; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #e5e7eb; color: #374151; }
.s-new { background: #dbeafe; color: #1e40af; }
.s-assigned { background: #e0e7ff; color: #3730a3; }
.s-in_progress { background: #fef3c7; color: #92400e; }
.s-waiting_customer { background: #fce7f3; color: #9d174d; }
.s-resolved { background: #dcfce7; color: #166534; }
.prio { font-size: 13px; white-space: nowrap; }
.p-high { color: #b45309; font-weight: 600; }
.p-urgent { color: var(--red); font-weight: 700; }
.p-low { color: var(--muted); }

/* ticket */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 24px; margin: 0 0 16px; }
.facts dt { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.facts dd { margin: 0; }
.desc { white-space: pre-wrap; margin: 0; padding-top: 14px; border-top: 1px solid var(--line); }
.controls { display: flex; gap: 16px; align-items: end; flex-wrap: wrap; }
.controls label { flex: 1; min-width: 160px; }
.update { border-left: 3px solid var(--line); padding: 4px 0 4px 14px; margin-bottom: 16px; }
.update p { margin: 4px 0 0; white-space: pre-wrap; }
.update.system { color: var(--muted); font-size: 13px; }
.update.internal { border-left-color: var(--gold); background: #fffbeb; padding: 8px 14px; border-radius: 0 6px 6px 0; }
.meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.tag { font-size: 11px; background: #eef0f3; padding: 1px 7px; border-radius: 999px; color: #374151; }
.tag:empty { display: none; }
.tag.warn { background: var(--gold); color: var(--navy); font-weight: 600; }
.atts { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.att { font-size: 13px; max-width: 100%; }
.att img { display: block; height: 140px; max-width: 100%; border-radius: 6px; border: 1px solid var(--line); object-fit: cover; }
.att video { display: block; max-width: min(360px, 100%); max-height: 240px; border-radius: 6px; background: #000; }
#reply { border-top: 1px solid var(--line); padding-top: 16px; display: grid; gap: 10px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: .2s; max-width: 90vw; z-index: 10; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--red); }

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
  .top { gap: 10px; }
  .who span { display: none; }
  table.tickets thead { display: none; }
  table.tickets, table.tickets tbody, table.tickets tr, table.tickets td { display: block; }
  table.tickets tr { padding: 10px 12px; border-bottom: 1px solid var(--line); }
  table.tickets td { padding: 2px 0; border: 0; display: inline-block; margin-right: 10px; }
  table.tickets td:nth-child(2) { display: block; }
  table:not(.tickets) { display: block; overflow-x: auto; }
}
