:root {
  --bg: #f4f5f7; --panel: #fff; --border: #e3e6ea; --text: #1d2329; --muted: #67717c;
  --brand: #128c7e; --brand-dark: #0b6b60; --brand-soft: #e3f4f1;
  --in: #fff; --out: #d9fdd3; --note: #fff6d6; --danger: #c62828; --warn: #b26a00;
  --radius: 10px; --shadow: 0 1px 3px rgba(0,0,0,.08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand-dark); }
code { background: #eef0f2; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .center { text-align: center; }
.hidden { display: none !important; }

/* Buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--text); cursor: pointer; font: inherit; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #f0f2f4; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { color: var(--danger); border-color: #f0c4c4; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
label { display: block; margin: 0 0 12px; font-weight: 500; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label.check input { width: auto; margin: 0; }
.alert { background: #fdecea; color: var(--danger); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.alert.ok { background: var(--brand-soft); color: var(--brand-dark); }

/* Auth pages */
body.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--panel); border-radius: 14px; padding: 28px; box-shadow: 0 4px 24px rgba(0,0,0,.08); }
.auth-card h1 { font-size: 20px; margin: 18px 0 10px; }
.auth-card .btn { width: 100%; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; }
.btn-ms { margin-bottom: 4px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.code-input { font-size: 20px; letter-spacing: 4px; text-align: center; }
.qr { display: flex; justify-content: center; margin: 10px 0; }
.codes { columns: 2; padding-left: 18px; margin: 12px 0 18px; }
.codes li { margin-bottom: 6px; }

/* App shell */
.shell { display: grid; grid-template-rows: 52px 1fr; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 0 16px; background: var(--brand-dark); color: #fff; }
.topbar .brand { color: #fff; }
.topbar nav { display: flex; gap: 4px; margin-left: 12px; }
.topbar nav a { color: #d6efeb; text-decoration: none; padding: 6px 12px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.14); color: #fff; }
.topbar .spacer { flex: 1; }
.topbar .me { position: relative; }
.topbar .me button { background: transparent; border: 0; color: #fff; cursor: pointer; font: inherit; display: flex; align-items: center; gap: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #2fae9f; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; flex: none; }
.menu { position: absolute; right: 0; top: 40px; background: #fff; color: var(--text); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.15); min-width: 220px; padding: 6px; z-index: 30; }
.menu button, .menu a { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; font: inherit; color: inherit; text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--bg); }
.menu .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; font-size: 12.5px; color: var(--muted); }

.inbox { display: grid; grid-template-columns: 340px 1fr 300px; min-height: 0; }
.inbox.no-side { grid-template-columns: 340px 1fr; }
.col { background: var(--panel); border-right: 1px solid var(--border); min-height: 0; display: flex; flex-direction: column; }
.list-head { padding: 12px; border-bottom: 1px solid var(--border); display: grid; gap: 10px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border: 0; background: var(--bg); padding: 5px 10px; border-radius: 99px; cursor: pointer; font: inherit; font-size: 12.5px; color: var(--muted); }
.tabs button.active { background: var(--brand); color: #fff; }
.tabs .count { font-weight: 600; margin-left: 3px; }
.conv-list { overflow-y: auto; flex: 1; }
.conv { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; padding: 11px 12px; border-bottom: 1px solid #f0f1f3; cursor: pointer; }
.conv:hover { background: #f8f9fa; }
.conv.active { background: var(--brand-soft); }
.conv .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .preview { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.conv .meta { text-align: right; font-size: 11.5px; color: var(--muted); display: grid; gap: 4px; justify-items: end; }
.badge { background: var(--brand); color: #fff; border-radius: 99px; padding: 1px 7px; font-size: 11px; font-weight: 600; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: #eef0f2; color: var(--muted); }
.tag.pending { background: #fff1d6; color: var(--warn); }
.tag.closed { background: #eceff1; }
.tag.unassigned { background: #fde7e7; color: var(--danger); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.chat { display: flex; flex-direction: column; min-height: 0; background: #efeae2; border-right: 1px solid var(--border); }
.chat-head { background: var(--panel); padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-head .title { flex: 1; min-width: 160px; }
.chat-head .title b { display: block; }
.chat-head select { width: auto; margin: 0; padding: 5px 8px; }
.messages { flex: 1; overflow-y: auto; padding: 16px 6%; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 68%; padding: 7px 10px 5px; border-radius: 8px; box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.in { background: var(--in); align-self: flex-start; }
.msg.out { background: var(--out); align-self: flex-end; }
.msg.note { background: var(--note); align-self: center; max-width: 80%; border: 1px dashed #e6c86e; }
.msg.system { background: rgba(255,255,255,.7); align-self: center; font-size: 12px; color: var(--muted); box-shadow: none; padding: 3px 10px; }
.msg .foot { font-size: 11px; color: var(--muted); text-align: right; margin-top: 3px; display: flex; gap: 6px; justify-content: flex-end; }
.msg .who { font-size: 11.5px; font-weight: 600; color: var(--brand-dark); margin-bottom: 2px; }
.msg.note .who { color: var(--warn); }
.msg .err { color: var(--danger); font-size: 12px; margin-top: 4px; }
.msg img, .msg video { max-width: 100%; max-height: 320px; border-radius: 6px; display: block; margin-bottom: 4px; }
.msg audio { max-width: 260px; }
.tick.read { color: #34b7f1; }
.day { align-self: center; background: #e1f2fb; font-size: 11.5px; padding: 3px 10px; border-radius: 6px; color: #3b5563; margin: 8px 0; }
.composer { background: var(--panel); border-top: 1px solid var(--border); padding: 10px 12px; }
.composer .mode { display: flex; gap: 4px; margin-bottom: 8px; }
.composer .row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { margin: 0; resize: none; min-height: 40px; max-height: 160px; }
.composer.note-mode textarea { background: var(--note); }
.window-warn { background: #fff4e0; color: var(--warn); padding: 8px 12px; font-size: 13px; border-radius: 8px; margin-bottom: 8px; }
.attach { position: relative; overflow: hidden; }
.attach input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.side { padding: 16px; overflow-y: auto; }
.side h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }
.side h3:first-child { margin-top: 0; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); flex-direction: column; gap: 6px; }

/* Admin */
.page { overflow-y: auto; padding: 24px; }
.page-inner { max-width: 1100px; margin: 0 auto; }
.page h2 { margin: 0 0 14px; font-size: 20px; }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.subnav { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
td .btn { margin-right: 4px; }
.table-wrap { overflow-x: auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.stat { background: var(--bg); border-radius: 8px; padding: 12px; }
.stat b { display: block; font-size: 22px; }
.ok-dot, .bad-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.ok-dot { background: #2e9e5b; } .bad-dot { background: #d9822b; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 12px; }
.kv div:nth-child(odd) { color: var(--muted); }
pre.log { background: #1d2329; color: #d5dde4; padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 12px; max-height: 240px; }

/* Modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(20,25,30,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 12px; padding: 22px; width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin: 0 0 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1d2329; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: 90vw; }
.toast.error { background: var(--danger); }

@media (max-width: 1100px) { .inbox { grid-template-columns: 300px 1fr; } .inbox .side { display: none; } }
@media (max-width: 760px) {
  .inbox, .inbox.no-side { grid-template-columns: 1fr; }
  .inbox.has-active .col.list { display: none; }
  .inbox:not(.has-active) .chat { display: none; }
  .msg { max-width: 88%; }
  .topbar nav a { padding: 6px 8px; }
  .topbar .brand span { display: none; }
  .kv { grid-template-columns: 1fr; }
}
.back-btn { display: none; }
@media (max-width: 760px) { .back-btn { display: inline-flex; } }
.btn.attach.disabled { opacity: .5; }
.clip-icon { display: inline-block; width: 18px; height: 18px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21.4 11.1l-9.2 9.2a6 6 0 0 1-8.5-8.5l9.2-9.2a4 4 0 0 1 5.7 5.7l-9.2 9.2a2 2 0 0 1-2.8-2.8l8.5-8.5'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21.4 11.1l-9.2 9.2a6 6 0 0 1-8.5-8.5l9.2-9.2a4 4 0 0 1 5.7 5.7l-9.2 9.2a2 2 0 0 1-2.8-2.8l8.5-8.5'/%3E%3C/svg%3E") center / contain no-repeat; }
.info-btn { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); background: transparent; color: #fff; font: 700 15px/1 Georgia, serif; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.info-btn:hover { background: rgba(255,255,255,.15); }
.info-head { display: flex; gap: 14px; align-items: center; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.info h4 { margin: 16px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.release { padding: 10px 0; border-bottom: 1px solid #f0f1f3; }
.release:last-child { border-bottom: 0; }
.release-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.release.current .release-head b { color: var(--brand-dark); }
.cl-section { margin-top: 6px; }
.cl-section ul { margin: 4px 0 0; padding-left: 20px; }
.cl-section li { margin-bottom: 3px; }
.cl-tag { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; }
.cl-tag.new { background: var(--brand-soft); color: var(--brand-dark); }
.cl-tag.changed { background: #e6eefc; color: #2f5bb7; }
.cl-tag.fixed { background: #fff1d6; color: var(--warn); }
.modal:has(.info) { max-width: 560px; }
.setting { margin-bottom: 14px; }
.setting label { margin-bottom: 2px; }
.input-row { display: flex; gap: 6px; align-items: center; }
.input-row input { flex: 1; }
.input-row .btn { margin-top: 4px; }
