:root {
  --bg: #f3f4f6; --panel: #ffffff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --brand: #1d4ed8; --brand-2: #1e40af;
  --open: #2563eb; --callback: #db2777; --pending: #d97706; --working: #7c3aed; --finished: #059669;
  --urgent: #dc2626; --high: #ea580c; --normal: #6b7280; --low: #9ca3af;
  --me: #1d4ed8; --them: #f3f4f6;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-family: "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.upper { text-transform: uppercase; }
.wide { width: 100%; }
.mt { margin-top: 6px; }

.btn { background: var(--brand); color: #fff; border: 0; padding: 8px 14px; border-radius: 6px; font-weight: 600; }
.btn:hover { background: var(--brand-2); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.dark { background: #1e293b; border: 1px solid #334155; }
.btn.dark:hover { background: #334155; }
.btn.danger { background: transparent; color: var(--urgent); border: 1px solid #fecaca; }
.btn.small { padding: 4px 10px; font-size: 12px; }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: #0f172a; }
.login-card { background: var(--panel); border-radius: 12px; padding: 28px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0 0 6px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.login-card input { border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; }
.error { color: var(--urgent); font-size: 13px; min-height: 18px; }

/* header */
header.top { background: #0f172a; color: #fff; padding: 10px 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
header.top h1 { font-size: 17px; margin: 0 8px 0 0; font-weight: 600; white-space: nowrap; }
header.top .grow { flex: 1; }
header.top input, header.top select { background: #1e293b; border: 1px solid #334155; color: #fff; padding: 7px 10px; border-radius: 6px; }
header.top input[type=search] { min-width: 200px; }
header.top input::placeholder { color: #94a3b8; }
header.top .check { display: flex; align-items: center; gap: 6px; font-size: 13px; }
header.top .who { font-size: 13px; color: #cbd5e1; }
.offline { background: var(--urgent); color: #fff; text-align: center; padding: 6px; font-size: 13px; display: none; }
.offline.show { display: block; }

/* board */
.board { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 14px; padding: 16px; overflow-x: auto; min-height: calc(100vh - 60px); }
.col { background: #e9ebef; border-radius: 10px; display: flex; flex-direction: column; min-height: 200px; }
.col.drop { outline: 2px dashed var(--brand); }
.col h2 { margin: 0; padding: 12px 14px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: 8px; }
.col h2 .dot { width: 10px; height: 10px; border-radius: 50%; }
.col h2 .count { margin-left: auto; background: #fff; color: var(--muted); border-radius: 10px; padding: 1px 8px; font-size: 12px; }
.cards { padding: 0 10px 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.empty { color: var(--muted); font-size: 12px; text-align: center; padding: 18px 0; }

.bg-open { background: var(--open); } .bg-callback { background: var(--callback); } .bg-pending { background: var(--pending); }
.bg-working { background: var(--working); } .bg-finished { background: var(--finished); }

.card { background: var(--panel); border-radius: 8px; padding: 10px 12px; border-left: 4px solid var(--normal); box-shadow: 0 1px 2px rgba(0,0,0,.06); cursor: pointer; position: relative; }
.card:hover { box-shadow: 0 3px 8px rgba(0,0,0,.1); }
.card .num { color: var(--muted); font-size: 12px; }
.card .title { font-weight: 600; margin: 2px 0 4px; padding-right: 36px; }
.card .meta { color: var(--muted); font-size: 12px; display: flex; gap: 10px; flex-wrap: wrap; }
.card .meta + .meta { margin-top: 4px; }
.card .unread { position: absolute; top: 8px; right: 10px; background: var(--urgent); color: #fff; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 7px; }
.p-urgent { border-left-color: var(--urgent); } .p-high { border-left-color: var(--high); }
.p-normal { border-left-color: var(--normal); } .p-low { border-left-color: var(--low); }
.pill { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 2px 8px; border-radius: 10px; color: #fff; }

/* modals */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: none; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.overlay.show { display: flex; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; }
.modal.wide-modal { max-width: 760px; }
.mhead { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.mhead h3 { margin: 0; font-size: 16px; flex: 1; }
.x { background: none; border: 0; font-size: 22px; color: var(--muted); line-height: 1; }
.pad { padding: 16px 20px; }
.pad h4 { margin: 20px 0 4px; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
form.f { padding: 16px 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
form.f.tight { padding: 8px 0 0; }
form.f label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
form.f .full { grid-column: 1 / -1; }
form.f input, form.f select, form.f textarea { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: #fff; }
form.f textarea { min-height: 80px; resize: vertical; }
form.f .actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }

table.staff { width: 100%; border-collapse: collapse; }
table.staff th, table.staff td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.staff th { font-size: 12px; color: var(--muted); }
table.staff td:last-child { text-align: right; white-space: nowrap; }
table.staff td .btn + .btn { margin-left: 4px; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; background: var(--bg); }
.tag.off { background: #fee2e2; color: var(--urgent); }

/* ticket detail */
.detail { max-width: 1100px; height: 88vh; display: grid; grid-template-columns: 360px 1fr; grid-template-rows: auto 1fr; overflow: hidden; }
.detail .mhead { grid-column: 1 / -1; }
.info { border-right: 1px solid var(--line); padding: 16px 20px; overflow: auto; }
.info dl { display: grid; grid-template-columns: 90px 1fr; gap: 6px 10px; margin: 0 0 16px; }
.info dt { color: var(--muted); font-size: 12px; }
.info dd { margin: 0; word-break: break-word; }
.info .desc { white-space: pre-wrap; background: var(--bg); padding: 10px; border-radius: 6px; margin-bottom: 16px; }
.info h4 { margin: 14px 0 8px; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.status-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.status-btns button { border: 2px solid transparent; border-radius: 6px; padding: 8px; font-weight: 600; color: #fff; opacity: .45; }
.status-btns button.active { opacity: 1; border-color: #0f172a; }
.status-btns button:hover { opacity: .85; }
.row { display: flex; gap: 6px; }
.row input, .row select { flex: 1; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; min-width: 0; }

.chat { display: flex; flex-direction: column; min-height: 0; }
.msgs { flex: 1; overflow: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; background: #fafafa; }
.msg { max-width: 75%; }
.msg .who { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg .bubble { background: var(--them); padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; border: 1px solid var(--line); }
.msg.mine { align-self: flex-end; text-align: right; }
.msg.mine .bubble { background: var(--me); color: #fff; border-color: var(--me); text-align: left; }
.msg.system { align-self: center; max-width: 90%; font-size: 12px; color: var(--muted); background: #eef2f7; padding: 4px 12px; border-radius: 12px; text-align: center; }
.composer { border-top: 1px solid var(--line); padding: 12px; display: flex; gap: 8px; }
.composer textarea { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; resize: none; height: 44px; }

/* photos */
.composer { align-items: flex-end; }
.attach { flex: none; width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 20px; cursor: pointer; }
.attach:hover { background: var(--bg); }
.attach:disabled { opacity: .5; cursor: wait; }
.photo-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.photo-strip:empty::before { content: "No photos yet."; grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.photo-strip button { padding: 0; border: 0; border-radius: 8px; overflow: hidden; aspect-ratio: 1; cursor: zoom-in; background: var(--line); }
.photo-strip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.msg .photo { display: block; padding: 0; border: 0; background: var(--line); border-radius: 12px; overflow: hidden; cursor: zoom-in; max-width: 260px; }
.msg.mine .photo { margin-left: auto; }
.msg .photo img { display: block; width: 100%; height: auto; max-height: 300px; object-fit: cover; }
.msg .photo + .bubble { margin-top: 4px; }
.msg .removed, .msg.mine .bubble.removed { font-style: italic; color: var(--muted); font-size: 13px; background: none; border: 1px dashed var(--line); }
.upload-bar { border-top: 1px solid var(--line); padding: 8px 14px; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 12px; }
.upload-track { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.upload-fill { height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.drop-hint { outline: 3px dashed var(--brand); outline-offset: -8px; }

.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(8,10,14,.95); display: flex; align-items: center; justify-content: center; }
.viewer[hidden] { display: none; }
.viewer img { max-width: calc(100vw - 120px); max-height: calc(100vh - 130px); border-radius: 8px; object-fit: contain; }
.viewer-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px; padding: 12px 16px; color: #cbd5e1; font-size: 14px; }
.viewer-top .grow { flex: 1; }
.vbtn { width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.08); color: #fff; font-size: 17px; cursor: pointer; display: grid; place-items: center; text-decoration: none; }
.vbtn:hover { background: rgba(255,255,255,.2); }
.vbtn.danger:hover { background: var(--urgent); }
.vnav { position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; border-radius: 50%; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.08); color: #fff; font-size: 30px; line-height: 1; cursor: pointer; }
.vnav:hover { background: rgba(255,255,255,.2); }
.vnav.prev { left: 14px; } .vnav.next { right: 14px; }
.viewer-cap { position: absolute; bottom: 16px; left: 16px; right: 16px; text-align: center; color: #e2e8f0; font-size: 14px; }
@media (max-width: 800px) {
  .viewer img { max-width: 100vw; max-height: calc(100vh - 150px); border-radius: 0; }
  .vnav { top: auto; bottom: 50px; transform: none; }
  .photo-strip { grid-template-columns: repeat(5, 1fr); }
}

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 8px; display: none; z-index: 50; max-width: 90vw; }
.toast.show { display: block; }

@media (max-width: 800px) {
  .board { grid-template-columns: 1fr; }
  .detail { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; height: 92vh; overflow: auto; }
  .info { border-right: 0; border-bottom: 1px solid var(--line); }
  .chat { min-height: 60vh; }
  form.f { grid-template-columns: 1fr; }
  header.top input[type=search] { min-width: 0; flex: 1; }
}
