:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --surface-3: #e4e9ef;
  --border: #dbe1e8;
  --text: #16191d;
  --text-dim: #667080;
  --text-faint: #97a1ae;
  --accent: #2f6df6;
  --accent-soft: #e8f0ff;
  --accent-text: #ffffff;
  --new: #2f6df6;
  --progress: #d98324;
  --waiting: #8b5cf6;
  --done: #2e9e5b;
  --danger: #d64545;
  --note: #fff6d9;
  --note-border: #e8d08a;
  --radius: 9px;
  --head-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101317;
    --surface: #181c21;
    --surface-2: #1f242a;
    --surface-3: #272d34;
    --border: #2b323a;
    --text: #e7eaee;
    --text-dim: #9aa4b1;
    --text-faint: #6d7885;
    --accent: #5b8dff;
    --accent-soft: #1d2b45;
    --note: #322a12;
    --note-border: #5c4c1c;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 12px;
  transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
button.ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
button.danger { color: var(--danger); border-color: transparent; background: transparent; }
button.danger:hover:not(:disabled) { background: #fdecec; }
button.small { padding: 3px 9px; font-size: 13px; }
button:disabled { opacity: .45; cursor: not-allowed; }

input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 9px;
  width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

.hidden { display: none !important; }

/* ================= вход ================= */
.login-wrap { height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 30px; width: 100%; max-width: 350px;
  box-shadow: 0 8px 28px rgba(0,0,0,.08);
}
.login-card h1 { margin: 0 0 3px; font-size: 20px; }
.login-card p.sub { margin: 0 0 22px; color: var(--text-dim); font-size: 13px; }
.login-card label { display: block; margin-bottom: 13px; font-size: 13px; color: var(--text-dim); }
.login-card label input { margin-top: 5px; }
.login-card button { width: 100%; margin-top: 8px; }

/* ================= шапка ================= */
header.top {
  height: var(--head-h);
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  flex: 0 0 auto;
}
header.top .brand {
  font-weight: 650; display: flex; align-items: center; gap: 8px;
  padding-right: 6px; white-space: nowrap;
}
header.top .brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--done); }
#project-select { width: auto; max-width: 230px; font-weight: 550; }
header.top .search { flex: 1; max-width: 420px; }
header.top .spacer { flex: 1; }
.counters { display: flex; gap: 12px; font-size: 13px; color: var(--text-dim); white-space: nowrap; }
.counters b { color: var(--text); }
.counters .accent b { color: var(--accent); }

.menu { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.14);
  min-width: 210px; padding: 5px; z-index: 40;
}
.menu-panel button {
  display: block; width: 100%; text-align: left;
  border: none; background: none; border-radius: 6px; padding: 7px 10px;
}
.menu-panel button:hover { background: var(--surface-2); }
.menu-panel .sep { height: 1px; background: var(--border); margin: 5px 0; }
.menu-panel .who { padding: 7px 10px 9px; font-size: 12px; color: var(--text-dim); }

/* ================= рабочая область ================= */
.workspace { flex: 1; display: flex; min-height: 0; }

.pane-list {
  flex: 0 0 390px; min-width: 0;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.filters-bar {
  flex: 0 0 auto; padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.filters-bar select { width: auto; max-width: 125px; font-size: 13px; padding: 4px 7px; }
.chip {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 3px 11px; font-size: 13px; color: var(--text-dim);
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.list-scroll { flex: 1; overflow-y: auto; }

.ticket {
  display: block; width: 100%; text-align: left;
  border: none; border-bottom: 1px solid var(--border);
  background: none; border-radius: 0;
  padding: 10px 12px 10px 14px;
  position: relative;
}
.ticket:hover { background: var(--surface-2); }
.ticket.active { background: var(--accent-soft); }
.ticket::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
}
.ticket[data-status="new"]::before         { background: var(--new); }
.ticket[data-status="in_progress"]::before { background: var(--progress); }
.ticket[data-status="waiting"]::before     { background: var(--waiting); }
.ticket[data-status="done"]::before        { background: var(--done); }

.ticket .row1 { display: flex; align-items: baseline; gap: 8px; }
.ticket .subject {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ticket.unread .subject { font-weight: 650; }
.ticket .when { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.ticket .row2 { display: flex; gap: 5px; align-items: center; margin-top: 5px; flex-wrap: wrap; }
.ticket .icons { margin-left: auto; display: flex; gap: 7px; color: var(--text-faint); font-size: 12px; }
.ticket .unread-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: 0 0 auto;
}

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-2); border: 1px solid transparent;
  border-radius: 5px; padding: 1px 7px; font-size: 12px; color: var(--text-dim);
  white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.badge .k { color: var(--text-faint); }
.badge.clickable { cursor: pointer; }
.badge.clickable:hover { border-color: var(--accent); color: var(--accent); }
.badge.kind { background: transparent; border-color: var(--border); }
.badge.kind-complaint { color: var(--danger); border-color: var(--danger); }
.badge.kind-suggestion { color: var(--accent); border-color: var(--accent); }

.pager {
  flex: 0 0 auto; display: flex; gap: 8px; align-items: center; justify-content: center;
  padding: 8px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--text-dim);
}

/* ================= правая панель ================= */
.pane-detail { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

.detail-head {
  flex: 0 0 auto; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: 10px 16px;
}
.detail-head .line1 { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.detail-head .title { font-weight: 600; font-size: 15px; }
.detail-head .line2 { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.detail-head select { width: auto; font-size: 13px; padding: 4px 8px; }
.detail-head .back { display: none; }

.thread { flex: 1; overflow-y: auto; padding: 16px; }
.bubble-row { display: flex; margin-bottom: 12px; }
.bubble-row.own { justify-content: flex-end; }
.bubble {
  max-width: min(660px, 78%);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 9px 13px;
}
.bubble-row.own .bubble { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.bubble-row.own .bubble .meta, .bubble-row.own .bubble .lbl { color: rgba(255,255,255,.75); }
.bubble-row.note { justify-content: center; }
.bubble-row.note .bubble {
  background: var(--note); border-color: var(--note-border); max-width: 92%;
}
.bubble .meta { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; display: flex; gap: 8px; }
.bubble .body { white-space: pre-wrap; word-wrap: break-word; }
.bubble .translation {
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border);
  white-space: pre-wrap; word-wrap: break-word;
}
.bubble-row.own .translation { border-top-color: rgba(255,255,255,.35); }
.bubble .lbl {
  font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--text-faint); margin-bottom: 3px;
}
.bubble .shots { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.bubble .shots img {
  max-width: 190px; max-height: 150px; border-radius: 7px; cursor: zoom-in;
  border: 1px solid var(--border); display: block; background: var(--surface-2);
}
.bubble .tools { margin-top: 6px; }
/* На синем пузыре оператора обычная кнопка сливается с фоном. */
.bubble-row.own .tools button {
  color: rgba(255,255,255,.85);
  border-color: rgba(255,255,255,.35);
  background: rgba(255,255,255,.08);
}
.bubble-row.own .tools button:hover:not(:disabled) {
  background: rgba(255,255,255,.2); color: #fff;
}
.bubble-row.own mark { background: #ffe79a; color: #3a2f0a; }

.composer {
  flex: 0 0 auto; background: var(--surface);
  border-top: 1px solid var(--border); padding: 10px 16px 12px;
}
.composer .tabs { display: flex; gap: 6px; margin-bottom: 8px; align-items: center; }
.composer textarea { min-height: 62px; }
.composer.note-mode textarea { background: var(--note); border-color: var(--note-border); }
.composer .actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.composer .actions .hint { font-size: 12px; color: var(--text-faint); margin-left: auto; }
.attach-preview { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 8px; }
.attach-preview .item {
  display: flex; align-items: center; gap: 6px; font-size: 12px;
  background: var(--surface-2); border-radius: 6px; padding: 4px 8px;
}

.empty { display: grid; place-items: center; height: 100%; color: var(--text-faint); padding: 40px; text-align: center; }

mark { background: #ffe79a; color: #3a2f0a; border-radius: 3px; padding: 0 2px; }

/* ================= модальные окна ================= */
.modal-back {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.45);
  display: grid; place-items: center; padding: 16px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; width: 100%; max-width: 680px;
  max-height: 88vh; overflow: auto; box-shadow: 0 16px 48px rgba(0,0,0,.25);
}
.modal.wide { max-width: 900px; }
.modal h2 { margin: 0; font-size: 17px; }
.modal h3 { font-size: 14px; margin: 20px 0 9px; color: var(--text-dim); }
.modal .head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.modal .head button { margin-left: auto; }
.modal table { width: 100%; border-collapse: collapse; font-size: 13px; }
.modal th, .modal td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.modal th { color: var(--text-dim); font-weight: 500; }
.modal .field { margin-bottom: 11px; }
.modal .field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.modal .row { display: flex; gap: 8px; align-items: flex-start; }
.modal .row > * { flex: 1; }
.tabs-nav { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs-nav button { border: none; background: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 14px; color: var(--text-dim); }
.tabs-nav button.on { color: var(--accent); border-bottom-color: var(--accent); }

code.key {
  display: block; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 7px; padding: 11px; margin: 10px 0; word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
}
.note-box {
  background: var(--note); border: 1px solid var(--note-border);
  border-radius: 7px; padding: 9px 12px; font-size: 13px; margin: 10px 0;
}

.lightbox {
  position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.85);
  display: grid; place-items: center; padding: 24px; cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px;
  border-radius: 8px; z-index: 100; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 14px;
}
.toast.err { background: var(--danger); color: #fff; }

/* ================= узкий экран ================= */
@media (max-width: 900px) {
  .pane-list { flex: 1 1 100%; }
  .workspace.detail-open .pane-list { display: none; }
  .workspace:not(.detail-open) .pane-detail { display: none; }
  .detail-head .back { display: inline-flex; }
  header.top .counters { display: none; }
  .bubble { max-width: 88%; }
}
