/* ==========================================================================
   Aloqa Markazi — web panel uslublari
   ========================================================================== */
:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-2: #f7f9fc;
  --border: #e2e8f1;
  --border-soft: #edf1f6;
  --text: #16202f;
  --muted: #6b7789;
  --accent: #2b6ee7;
  --accent-soft: #e8f0ff;
  --accent-text: #1c4fa8;
  --success: #1f9d68;
  --warning: #d98324;
  --danger: #d64545;
  --bubble-user: #ffffff;
  --bubble-admin: #dceaff;
  --bubble-note: #fff5d9;
  --bubble-system: #eceff4;
  --shadow: 0 14px 40px rgba(28, 44, 74, .10);
  --shadow-sm: 0 2px 8px rgba(28, 44, 74, .07);
  --radius: 14px;
}

[data-theme="dark"] {
  --bg: #0f1621;
  --panel: #161f2c;
  --panel-2: #1b2634;
  --border: #263244;
  --border-soft: #202b3b;
  --text: #e6edf6;
  --muted: #93a1b5;
  --accent: #4d8dfd;
  --accent-soft: #1c2e4d;
  --accent-text: #a9c8ff;
  --bubble-user: #1c2735;
  --bubble-admin: #1e3a63;
  --bubble-note: #3d3418;
  --bubble-system: #1a2331;
  --shadow: 0 14px 40px rgba(0, 0, 0, .45);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Inter, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: .9em; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------------------------------------------- LOGIN */
.login-body {
  display: grid; place-items: center; padding: 24px;
  background: linear-gradient(135deg, #e9f1ff, #f6f9fc 45%, #eaf7f3);
}
.login-card {
  width: min(420px, 100%); background: var(--panel); border: 1px solid var(--border);
  border-radius: 24px; padding: 34px; box-shadow: var(--shadow);
}
.brand-mark {
  width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center;
  background: var(--accent-soft); font-size: 28px;
}
.login-card h1 { margin: 18px 0 6px; font-size: 24px; }
.login-card p { margin: 0 0 24px; }
.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 7px; font-weight: 600; font-size: 14px; }
.login-form input {
  width: 100%; padding: 13px 14px; border: 1px solid var(--border);
  border-radius: 12px; outline: none; background: var(--panel);
}
.login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(43,110,231,.14); }
.login-foot { margin-top: 20px; font-size: 12px; text-align: center; }
.error-box {
  background: #fff0f0; color: #a33; border: 1px solid #ffd3d3;
  padding: 10px 12px; border-radius: 10px; margin-bottom: 16px; font-size: 14px;
}
.primary-btn, .send-btn {
  border: 0; background: var(--accent); color: #fff; border-radius: 12px;
  padding: 12px 16px; font-weight: 700;
}
.primary-btn:hover, .send-btn:hover { filter: brightness(1.06); }
.primary-btn:disabled, .send-btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------------------------------------------------------------- SHELL */
.app-shell { height: 100vh; display: grid; grid-template-columns: 380px 1fr; overflow: hidden; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-width: 0;
}
.sidebar-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px 10px; gap: 10px; border-bottom: 1px solid var(--border-soft);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-badge {
  width: 38px; height: 38px; border-radius: 12px; background: var(--accent-soft);
  display: grid; place-items: center; font-size: 19px;
}
.sidebar-head h1 { font-size: 17px; margin: 2px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eyebrow { font-size: 9px; letter-spacing: .16em; color: var(--muted); font-weight: 800; }
.head-actions { display: flex; gap: 6px; align-items: center; }
.head-actions form { display: contents; }
.icon-btn {
  border: 1px solid var(--border); background: var(--panel); width: 34px; height: 34px;
  border-radius: 10px; display: inline-grid; place-items: center; font-size: 15px;
  text-decoration: none; color: var(--text); flex: none;
}
.icon-btn:hover { background: var(--panel-2); border-color: var(--accent); }
.ghost-btn {
  border: 1px solid var(--border); background: var(--panel); border-radius: 10px;
  padding: 8px 12px; font-size: 13px; font-weight: 600; color: var(--text); text-decoration: none;
  display: inline-block;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
.ghost-btn.wide { width: 100%; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding: 10px 14px; }
.stat-card {
  border: 1px solid var(--border); background: var(--panel); border-radius: 12px;
  padding: 9px 11px; text-align: left; display: flex; justify-content: space-between;
  gap: 6px; align-items: center;
}
.stat-card strong { font-size: 17px; }
.stat-card span { font-size: 10.5px; color: var(--muted); text-align: right; line-height: 1.2; }
.stat-card.active { border-color: var(--accent); background: var(--accent-soft); }
.stat-card.active span { color: var(--accent-text); }

.search-wrap { padding: 2px 14px 10px; display: flex; gap: 7px; }
.search-wrap input {
  flex: 1; min-width: 0; border: 1px solid var(--border); background: var(--panel-2);
  border-radius: 11px; padding: 10px 12px; outline: none;
}
.search-wrap input:focus { border-color: var(--accent); background: var(--panel); }
.filter-toggle {
  border: 1px solid var(--border); background: var(--panel); border-radius: 11px;
  width: 40px; flex: none;
}
.filters {
  padding: 0 14px 12px; display: grid; gap: 9px; grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border-soft);
}
.filters label { display: grid; gap: 4px; font-size: 11px; font-weight: 700; color: var(--muted); }
.filters select, .filters input[type="text"] {
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 9px;
  padding: 7px 9px; outline: none; font-size: 13px;
}
.filters .check { grid-column: 1 / -1; display: flex; align-items: center; gap: 7px; font-size: 12px; }

.list-meta {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 16px; font-size: 12px; font-weight: 700; color: var(--muted);
  border-top: 1px solid var(--border-soft); border-bottom: 1px solid var(--border-soft);
}
.pill { background: var(--accent-soft); color: var(--accent-text); border-radius: 999px; padding: 2px 9px; }
.conversation-list { overflow: auto; flex: 1; }
.list-more { padding: 10px 14px; }

.conv-item {
  width: 100%; border: 0; border-bottom: 1px solid var(--border-soft); background: var(--panel);
  padding: 12px 14px; text-align: left; display: grid;
  grid-template-columns: 42px 1fr auto; gap: 10px; align-items: center;
}
.conv-item:hover { background: var(--panel-2); }
.conv-item.selected { background: var(--accent-soft); }
.conv-item.prio-urgent { border-left: 3px solid var(--danger); }
.conv-item.prio-high { border-left: 3px solid var(--warning); }
.avatar {
  width: 42px; height: 42px; border-radius: 13px; background: var(--accent-soft);
  color: var(--accent-text); display: grid; place-items: center; font-weight: 800; font-size: 14px;
}
.conv-main { min-width: 0; display: grid; gap: 3px; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conv-time { font-size: 10.5px; color: var(--muted); flex: none; }
.conv-preview {
  font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis;
}
.conv-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag-chip {
  font-size: 10px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 7px; color: var(--muted);
}
.conv-right { display: grid; gap: 5px; justify-items: end; }
.unread {
  background: var(--accent); color: #fff; border-radius: 999px; min-width: 21px; height: 21px;
  padding: 0 6px; display: grid; place-items: center; font-size: 11px; font-weight: 800;
}
.status-dot { font-size: 11px; }
.empty-note { padding: 26px 18px; color: var(--muted); text-align: center; font-size: 14px; }

/* ---------------------------------------------------------------- CHAT */
.chat-pane { min-width: 0; position: relative; background: var(--bg); }
.empty-state { height: 100%; display: grid; place-content: center; text-align: center; color: var(--muted); padding: 20px; }
.empty-state h2 { color: var(--text); margin: 12px 0 6px; }
.empty-state p { margin: 0; line-height: 1.6; }
.empty-icon { font-size: 50px; }

.chat-view { height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.chat-ident { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-head h2 { margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.chat-actions { display: flex; gap: 7px; align-items: center; flex: none; }
.chat-actions select {
  border: 1px solid var(--border); background: var(--panel); padding: 8px 9px;
  border-radius: 10px; max-width: 170px; font-size: 13px;
}
.only-mobile { display: none; }

.chat-body { display: grid; grid-template-columns: 1fr auto; min-height: 0; }
.message-area {
  overflow-y: auto; padding: 18px 6% 22px; min-height: 0;
  background-image: radial-gradient(rgba(120,140,170,.18) .7px, transparent .7px);
  background-size: 17px 17px;
}
.load-older { text-align: center; padding-bottom: 14px; }
#messageList { display: flex; flex-direction: column; gap: 9px; }

.day-sep { text-align: center; margin: 12px 0 4px; }
.day-sep span {
  background: var(--panel); border: 1px solid var(--border); color: var(--muted);
  font-size: 11px; font-weight: 700; padding: 3px 12px; border-radius: 999px;
}

.message {
  max-width: min(660px, 84%); padding: 9px 12px 7px; border-radius: var(--radius);
  box-shadow: var(--shadow-sm); position: relative;
}
.message.user { align-self: flex-start; background: var(--bubble-user); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.message.admin { align-self: flex-end; background: var(--bubble-admin); border-bottom-right-radius: 5px; }
.message.system { align-self: center; background: var(--bubble-system); font-size: 12px; color: var(--muted); }
.message.note { align-self: flex-end; background: var(--bubble-note); border: 1px dashed rgba(180,140,20,.5); }
.message.failed { outline: 1.5px solid var(--danger); }
.msg-sender { font-size: 11px; font-weight: 800; color: var(--accent-text); margin-bottom: 3px; }
.msg-text { white-space: pre-wrap; word-break: break-word; line-height: 1.45; font-size: 14.5px; }
.msg-text a { word-break: break-all; }
.msg-meta { font-size: 10px; color: var(--muted); margin-top: 5px; display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.msg-badge { font-size: 9.5px; border: 1px solid var(--border); border-radius: 5px; padding: 0 4px; }

/* --- media --- */
.media-box { margin: 0 0 6px; max-width: min(520px, 70vw); }
.chat-image {
  display: block; max-width: 100%; max-height: 380px; border-radius: 11px;
  object-fit: cover; background: #0d141d; cursor: zoom-in;
}
.chat-video {
  display: block; width: min(480px, 68vw); max-width: 100%; max-height: 400px;
  border-radius: 11px; background: #0d141d;
}
.chat-video.round { border-radius: 50%; width: 230px; height: 230px; object-fit: cover; }
.chat-audio { display: block; width: min(340px, 66vw); max-width: 100%; margin: 3px 0; }
.chat-sticker { display: block; max-width: 160px; max-height: 160px; object-fit: contain; }
.media-meta { font-size: 10.5px; opacity: .7; margin-top: 4px; overflow-wrap: anywhere; }
.media-load {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border);
  background: var(--panel-2); border-radius: 11px; padding: 10px 13px; cursor: pointer;
  font-size: 13px; font-weight: 600; max-width: 100%;
}
.media-load:hover { border-color: var(--accent); }
.media-error { font-size: 12px; color: var(--danger); background: rgba(214,69,69,.08); padding: 7px 10px; border-radius: 9px; }
.file-chip {
  display: flex; align-items: center; gap: 9px; border: 1px solid var(--border);
  background: var(--panel-2); border-radius: 11px; padding: 9px 12px; text-decoration: none;
  color: inherit; max-width: 340px;
}
.file-chip:hover { border-color: var(--accent); }
.file-chip .fi { font-size: 20px; }
.file-chip .fn { font-weight: 650; font-size: 13px; word-break: break-all; }
.file-chip .fs { font-size: 11px; color: var(--muted); }

/* --- info panel --- */
.info-panel {
  width: 320px; border-left: 1px solid var(--border); background: var(--panel);
  overflow-y: auto; display: flex; flex-direction: column;
}
.info-tabs { display: flex; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.info-tabs .tab {
  flex: 1; border: 0; background: transparent; padding: 11px 6px; font-size: 12.5px;
  font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent;
}
.info-tabs .tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-body { padding: 14px; font-size: 13.5px; }
.info-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border-soft); }
.info-row span:first-child { color: var(--muted); font-size: 12px; }
.info-row span:last-child { font-weight: 600; text-align: right; word-break: break-word; }
.info-actions { display: grid; gap: 8px; margin-top: 14px; }
.info-actions textarea, .info-actions input {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px;
  background: var(--panel-2); outline: none; resize: vertical;
}
.media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.media-grid button { border: 0; padding: 0; background: var(--panel-2); border-radius: 9px; overflow: hidden; aspect-ratio: 1; }
.media-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-grid .ph { display: grid; place-items: center; height: 100%; font-size: 20px; }
.note-item { background: var(--bubble-note); border-radius: 10px; padding: 9px 11px; margin-bottom: 8px; font-size: 13px; }
.note-item .nm { font-size: 10.5px; color: var(--muted); margin-top: 5px; display: flex; justify-content: space-between; }
.note-item button { border: 0; background: none; color: var(--danger); font-size: 11px; }

/* --- composer --- */
.composer-wrap { background: var(--panel); border-top: 1px solid var(--border); }
.composer {
  display: grid; grid-template-columns: auto auto auto 1fr auto; gap: 8px;
  align-items: end; padding: 10px 14px;
}
.composer textarea {
  resize: none; max-height: 150px; min-height: 42px; border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; outline: none; background: var(--panel-2);
  line-height: 1.4;
}
.composer textarea:focus { border-color: var(--accent); background: var(--panel); }
.composer.note-mode textarea { background: var(--bubble-note); border-color: #d9b64a; }
.send-btn { height: 42px; white-space: nowrap; }
.composer-hint { padding: 0 16px 8px; font-size: 11.5px; color: var(--muted); min-height: 0; }
.attach-preview { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 14px 0; }
.attach-item {
  display: flex; align-items: center; gap: 7px; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; font-size: 12px;
}
.attach-item button { border: 0; background: none; color: var(--danger); font-size: 14px; }

/* ---------------------------------------------------------------- MODAL */
.modal {
  position: fixed; inset: 0; background: rgba(10, 18, 30, .55);
  display: grid; place-items: center; z-index: 60; padding: 18px;
}
.modal-card {
  background: var(--panel); border-radius: 18px; width: min(540px, 100%);
  max-height: 84vh; overflow: auto; box-shadow: var(--shadow); padding: 18px;
}
.modal-card header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-card h3 { margin: 0; font-size: 17px; }
.quick-list { display: grid; gap: 8px; }
.quick-item {
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  background: var(--panel-2); cursor: pointer; text-align: left; width: 100%;
}
.quick-item:hover { border-color: var(--accent); }
.quick-item strong { display: block; font-size: 13.5px; margin-bottom: 3px; }
.quick-item span { font-size: 12px; color: var(--muted); }
.quick-item .del { float: right; color: var(--danger); font-size: 12px; }
.quick-add { margin-top: 14px; }
.quick-add summary { cursor: pointer; font-weight: 700; font-size: 13px; margin-bottom: 8px; }
.quick-add input, .quick-add textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 11px; margin-bottom: 8px; background: var(--panel-2); outline: none;
}

/* --- lightbox --- */
.lightbox {
  position: fixed; inset: 0; background: rgba(6, 10, 16, .93); z-index: 80;
  display: grid; place-items: center; padding: 30px;
}
.lightbox-body { max-width: 94vw; max-height: 86vh; display: grid; place-items: center; }
.lightbox-body img, .lightbox-body video { max-width: 94vw; max-height: 86vh; border-radius: 10px; }
.lightbox-close, .lightbox-download {
  position: absolute; top: 18px; border: 0; border-radius: 10px; padding: 9px 14px;
  background: rgba(255,255,255,.14); color: #fff; font-size: 15px; text-decoration: none;
}
.lightbox-close { right: 18px; }
.lightbox-download { right: 76px; font-size: 13px; }

.toast {
  position: fixed; right: 18px; bottom: 18px; background: #172033; color: #fff;
  padding: 11px 15px; border-radius: 12px; box-shadow: var(--shadow); z-index: 90;
  max-width: 340px; font-size: 13.5px;
}
.toast.error { background: #9c3232; }
.toast.success { background: #1c7a52; }

/* ---------------------------------------------------------------- REPORTS */
.reports-body { overflow-y: auto; }
.reports-shell { max-width: 1280px; margin: 0 auto; padding: 18px 20px 50px; }
.reports-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; margin-bottom: 14px;
}
.reports-head h1 { font-size: 18px; margin: 2px 0 0; }
.period-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 12px 14px; margin-bottom: 12px;
}
.period-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.period-buttons button {
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 9px;
  padding: 7px 12px; font-size: 13px; font-weight: 600;
}
.period-buttons button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.period-custom { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.period-custom input {
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 9px; padding: 6px 9px;
}
.export-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.report-meta { font-size: 12.5px; color: var(--muted); margin: 0 4px 12px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 13px 15px;
}
.kpi .k-label { font-size: 11.5px; color: var(--muted); font-weight: 700; }
.kpi .k-value { font-size: 24px; font-weight: 800; margin-top: 5px; }
.kpi .k-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.kpi.good .k-value { color: var(--success); }
.kpi.warn .k-value { color: var(--warning); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 15px 17px;
}
.card.wide { grid-column: 1 / -1; }
.card h3 { margin: 0 0 12px; font-size: 14.5px; }
.chart { width: 100%; overflow: hidden; }
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; }
.dot.c1 { background: #2b6ee7; } .dot.c2 { background: #1f9d68; }
.dot.c3 { background: #d98324; } .dot.c4 { background: #8b5cf6; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border-soft); }
th { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; }

.bar-row { display: grid; grid-template-columns: 110px 1fr 52px; gap: 9px; align-items: center; margin-bottom: 7px; font-size: 12.5px; }
.bar-track { background: var(--panel-2); border-radius: 6px; height: 15px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; }
.bar-row .bv { text-align: right; font-weight: 700; font-size: 12px; }

@media print {
  .reports-head, .period-bar, .toast { display: none !important; }
  body { background: #fff; }
  .card, .kpi { break-inside: avoid; box-shadow: none; }
}

/* ---------------------------------------------------------------- RESPONSIVE */
@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 330px 1fr; }
  .info-panel { width: 280px; }
}
@media (max-width: 900px) {
  .info-panel { position: absolute; right: 0; top: 0; bottom: 0; width: 300px; z-index: 20; box-shadow: var(--shadow); }
  .message-area { padding: 16px 4%; }
}
@media (max-width: 720px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { height: 100vh; }
  .app-shell.chat-open .sidebar { display: none; }
  .app-shell:not(.chat-open) .chat-pane { display: none; }
  .only-mobile { display: inline-grid; }
  .chat-actions select { max-width: 120px; font-size: 12px; }
  .composer { grid-template-columns: auto auto 1fr auto; }
  #noteBtn { display: none; }
  .message { max-width: 92%; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .reports-shell { padding: 12px 12px 40px; }
}

/* ==========================================================================
   v3 POLISH — zamonaviy, zich va ishchi interfeys
   ========================================================================== */
:root {
  --bg: #f2f5fa;
  --panel: rgba(255,255,255,.96);
  --panel-2: #f7f9fd;
  --border: #dfe6f1;
  --border-soft: #edf1f7;
  --text: #111b2b;
  --muted: #66748a;
  --accent: #2563eb;
  --accent-2: #0ea5e9;
  --accent-soft: #eaf1ff;
  --accent-text: #1849a9;
  --shadow: 0 24px 70px rgba(29, 48, 83, .12);
  --shadow-sm: 0 5px 18px rgba(32, 51, 85, .08);
  --radius: 16px;
}
[data-theme="dark"] {
  --bg: #0b1220;
  --panel: rgba(18,27,42,.97);
  --panel-2: #152033;
  --border: #26364d;
  --border-soft: #1d2a3d;
  --text: #edf4ff;
  --muted: #94a3b8;
  --accent: #4f8cff;
  --accent-2: #38bdf8;
  --accent-soft: #172f57;
  --accent-text: #bad3ff;
}

body { background: var(--bg); }
button, input, textarea, select { transition: border-color .16s ease, box-shadow .16s ease, background .16s ease, transform .12s ease; }
button:active { transform: translateY(1px); }

.login-body {
  position: relative; overflow: hidden;
  background:
    radial-gradient(circle at 12% 18%, rgba(37,99,235,.18), transparent 30%),
    radial-gradient(circle at 88% 78%, rgba(14,165,233,.16), transparent 33%),
    linear-gradient(145deg, #edf4ff 0%, #f8fbff 45%, #eefaf8 100%);
}
.login-body::before,
.login-body::after {
  content: ""; position: fixed; border-radius: 999px; pointer-events: none; filter: blur(2px);
}
.login-body::before { width: 330px; height: 330px; left: -120px; bottom: -150px; background: rgba(37,99,235,.09); }
.login-body::after { width: 280px; height: 280px; right: -100px; top: -120px; background: rgba(14,165,233,.08); }
.login-card {
  position: relative; z-index: 1; width: min(430px, 100%); padding: 38px;
  border: 1px solid rgba(255,255,255,.88);
  box-shadow: 0 30px 90px rgba(30,57,96,.16), inset 0 1px rgba(255,255,255,.9);
  backdrop-filter: blur(16px);
}
.brand-mark {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 14px 28px rgba(37,99,235,.24);
}
.login-form input { background: #fbfdff; min-height: 48px; }
.login-form input:focus { box-shadow: 0 0 0 4px rgba(37,99,235,.12); }
.login-form .primary-btn {
  min-height: 48px; font-size: 14px; letter-spacing: .01em;
  background: linear-gradient(135deg, var(--accent), #3978f6 60%, var(--accent-2));
  box-shadow: 0 12px 26px rgba(37,99,235,.2);
}
.login-foot { padding-top: 15px; border-top: 1px solid var(--border-soft); }

.sidebar { box-shadow: 8px 0 34px rgba(33,48,75,.035); z-index: 3; }
.sidebar-head { padding: 16px 16px 13px; background: linear-gradient(180deg, var(--panel), var(--panel-2)); }
.brand-badge {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  box-shadow: 0 8px 18px rgba(37,99,235,.20);
}
.stat-card { min-height: 48px; box-shadow: 0 1px 0 rgba(255,255,255,.5) inset; }
.stat-card:hover { border-color: #b9c7dc; box-shadow: var(--shadow-sm); }
.stat-card.active { box-shadow: 0 8px 20px rgba(37,99,235,.09); }
.search-wrap input:focus,
.filters select:focus,
.filters input:focus,
.composer textarea:focus,
.info-actions textarea:focus,
.info-actions input:focus { box-shadow: 0 0 0 3px rgba(37,99,235,.09); }
.conv-item { min-height: 72px; }
.conv-item:hover { transform: translateX(1px); }
.conv-item.selected { box-shadow: inset 3px 0 var(--accent); }
.avatar { background: linear-gradient(135deg, var(--accent-soft), #e6f7ff); border: 1px solid rgba(37,99,235,.08); }

.chat-pane {
  background:
    radial-gradient(circle at 80% 10%, rgba(37,99,235,.045), transparent 25%),
    var(--bg);
}
.chat-head { min-height: 66px; backdrop-filter: blur(12px); box-shadow: 0 1px 0 rgba(255,255,255,.45); }
.message-area {
  background-image:
    radial-gradient(rgba(95,115,145,.15) .7px, transparent .7px),
    linear-gradient(180deg, rgba(255,255,255,.13), transparent 25%);
}
.message { box-shadow: 0 7px 22px rgba(31,47,75,.075); }
.message.admin { background: linear-gradient(145deg, var(--bubble-admin), color-mix(in srgb, var(--bubble-admin) 84%, white)); }
.composer-wrap { box-shadow: 0 -10px 36px rgba(28,44,74,.045); }
.composer textarea { min-height: 46px; border-radius: 14px; }
.send-btn {
  min-height: 46px; background: linear-gradient(135deg, var(--accent), #3478f6);
  box-shadow: 0 8px 18px rgba(37,99,235,.18);
}
.info-panel { box-shadow: -10px 0 30px rgba(30,45,70,.035); }

.modal { backdrop-filter: blur(5px); }
.modal-card { border: 1px solid var(--border); }
.toast { box-shadow: 0 18px 46px rgba(12,25,45,.25); }

.reports-head, .period-bar, .card, .kpi { box-shadow: 0 8px 28px rgba(31,48,78,.045); }
.kpi { position: relative; overflow: hidden; }
.kpi::after { content: ""; position: absolute; right: -20px; top: -30px; width: 78px; height: 78px; border-radius: 50%; background: rgba(37,99,235,.045); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}


/* v4 qulayliklar */
.quick-filter-bar { display:flex; gap:6px; flex-wrap:wrap; padding:0 14px 10px; }
.mini-chip { border:1px solid var(--border); background:var(--panel-2); color:var(--muted); border-radius:999px; padding:6px 9px; font-size:12px; }
.mini-chip:hover { color:var(--accent); border-color:var(--accent); background:var(--accent-soft); }
.filters input[type="date"] { width:100%; }
.report-tools { display:flex; gap:8px; align-items:center; flex:1 1 320px; }
.report-tools input { min-width:260px; flex:1; border:1px solid var(--border); background:var(--panel); border-radius:10px; padding:9px 11px; }
@media (max-width: 720px) { .report-tools { flex-basis:100%; } .report-tools input { min-width:0; } }

.list-meta-right { display:flex; align-items:center; gap:6px; }
.queue-pill { font-size:11px; color:var(--muted); background:var(--panel-2); border:1px solid var(--border); padding:4px 7px; border-radius:999px; }
.finish-chat-btn { border:1px solid color-mix(in srgb, var(--success) 45%, var(--border)); background:color-mix(in srgb, var(--success) 10%, var(--panel)); color:var(--success); border-radius:10px; padding:8px 10px; font-weight:700; }
.finish-chat-btn:hover:not(:disabled) { background:color-mix(in srgb, var(--success) 18%, var(--panel)); }
.finish-chat-btn:disabled { opacity:.55; cursor:default; }

/* ---------------------------------------------------------- 2FA sahifasi */
.code-input {
  text-align: center;
  font-size: 30px !important;
  letter-spacing: .38em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  padding: 14px 10px !important;
}
.login-alt { margin-top: 14px; text-align: center; }
.link-btn {
  border: 0; background: none; color: var(--muted);
  font-size: 13px; text-decoration: underline; padding: 4px;
}
.link-btn:hover { color: var(--accent); }

/* ------------------------------------------------------- E'lonlar oynasi */
.wide-modal { width: min(680px, 100%); }
.ann-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.ann-tabs .tab {
  border: 0; background: none; padding: 10px 14px; font-size: 13px; font-weight: 700;
  color: var(--muted); border-bottom: 2px solid transparent;
}
.ann-tabs .tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.ann-pane { display: grid; gap: 12px; }
.ann-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ann-grid label, .ann-field {
  display: grid; gap: 5px; font-size: 12px; font-weight: 700; color: var(--muted);
}
.ann-grid select, .ann-grid input, .ann-field input, .ann-field textarea {
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 10px;
  padding: 9px 11px; outline: none; font-weight: 400; color: var(--text); width: 100%;
}
.ann-field textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
.ann-grid select:focus, .ann-field textarea:focus, .ann-field input:focus { border-color: var(--accent); }
.ann-estimate {
  background: var(--accent-soft); color: var(--accent-text); border-radius: 10px;
  padding: 9px 12px; font-size: 13px; font-weight: 700;
}
.ann-hint { font-size: 11.5px; color: var(--muted); margin-top: -6px; }
.ann-preview:not(:empty) {
  border: 1px dashed var(--border); border-radius: 12px; padding: 11px 13px;
  background: var(--bubble-admin); font-size: 14px; line-height: 1.5; white-space: pre-wrap;
  word-break: break-word;
}
.ann-actions { display: flex; gap: 8px; justify-content: flex-end; }
.ann-warning {
  font-size: 12px; color: var(--muted); background: var(--panel-2);
  border-radius: 10px; padding: 9px 12px;
}
.ann-list { display: grid; gap: 9px; max-height: 60vh; overflow: auto; }
.ann-item {
  border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px; background: var(--panel-2);
}
.ann-item-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.ann-item-head strong { font-size: 13.5px; }
.ann-item-body { font-size: 12.5px; color: var(--muted); margin: 5px 0 8px; word-break: break-word; }
.ann-bar { background: var(--border-soft); border-radius: 6px; height: 8px; overflow: hidden; }
.ann-bar span { display: block; height: 100%; background: var(--accent); border-radius: 6px; transition: width .3s; }
.ann-meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.ann-item-actions { display: flex; gap: 6px; margin-top: 9px; }
.ann-badge { font-size: 10.5px; border-radius: 999px; padding: 2px 9px; font-weight: 700; }
.ann-badge.done { background: rgba(31,157,104,.14); color: var(--success); }
.ann-badge.running { background: rgba(43,110,231,.14); color: var(--accent); }
.ann-badge.pending { background: rgba(217,131,36,.14); color: var(--warning); }
.ann-badge.cancelled { background: rgba(214,69,69,.14); color: var(--danger); }
@media (max-width: 640px) { .ann-grid { grid-template-columns: 1fr; } }

/* ------------------------------------------------- v5: navigatsiya va chat */
.scope-tabs {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  padding: 8px 12px; border-top: 1px solid var(--border-soft);
}
.scope {
  border: 1px solid var(--border); background: var(--panel); border-radius: 10px;
  padding: 7px 4px; font-size: 11.5px; font-weight: 700; color: var(--muted);
  display: flex; align-items: center; justify-content: center; gap: 4px;
}
.scope.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.scope-badge {
  background: rgba(0,0,0,.12); border-radius: 999px; padding: 0 5px;
  font-size: 10px; min-width: 16px;
}
.scope.active .scope-badge { background: rgba(255,255,255,.25); }

.chat-banner {
  padding: 9px 16px; font-size: 12.5px; font-weight: 600;
  background: var(--bubble-note); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.chat-banner.closed { background: var(--bubble-system); color: var(--muted); }
.chat-banner.warn { background: rgba(217,131,36,.16); }
.chat-banner button {
  border: 1px solid var(--border); background: var(--panel); border-radius: 9px;
  padding: 5px 10px; font-size: 12px; font-weight: 700; white-space: nowrap;
}

.chat-search {
  display: flex; gap: 6px; align-items: center; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.chat-search input {
  flex: 1; min-width: 0; border: 1px solid var(--border); background: var(--panel-2);
  border-radius: 10px; padding: 8px 11px; outline: none;
}
.chat-search input:focus { border-color: var(--accent); }
.search-count { font-size: 12px; color: var(--muted); white-space: nowrap; }
mark.hit { background: #ffe08a; color: #3a2d00; border-radius: 3px; padding: 0 2px; }
mark.hit.current { background: var(--accent); color: #fff; }

.jump-latest {
  position: absolute; right: 22px; bottom: 92px; z-index: 5;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  border-radius: 999px; padding: 9px 15px; font-size: 12.5px; font-weight: 700;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 7px;
}
.jump-latest span:not(:empty) {
  background: var(--accent); color: #fff; border-radius: 999px;
  padding: 0 7px; font-size: 11px;
}
.unread-divider { text-align: center; margin: 8px 0; }
.unread-divider span {
  background: var(--accent); color: #fff; font-size: 10.5px; font-weight: 800;
  padding: 3px 12px; border-radius: 999px;
}
.composer.locked { opacity: .55; pointer-events: none; }
.lang-chip {
  font-size: 10px; border: 1px solid var(--border); border-radius: 999px;
  padding: 1px 7px; color: var(--muted); margin-left: 6px;
}

/* ------------------------------------------- Foydalanuvchiga xabar oynasi */
.out-results { display: grid; gap: 6px; max-height: 320px; overflow: auto; }
.out-item {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center;
  border: 1px solid var(--border); border-radius: 11px; padding: 9px 11px;
  background: var(--panel-2); text-align: left; width: 100%;
}
.out-item:hover:not(:disabled) { border-color: var(--accent); }
.out-item:disabled { opacity: .55; cursor: not-allowed; }
.out-item .oi-name { font-weight: 700; font-size: 13.5px; }
.out-item .oi-sub { font-size: 11.5px; color: var(--muted); }
.out-item .oi-flag { font-size: 11px; color: var(--muted); }
.out-target {
  background: var(--accent-soft); color: var(--accent-text); border-radius: 10px;
  padding: 10px 12px; font-size: 13.5px; font-weight: 700; margin-bottom: 12px;
}

/* ---------------------------------------------- Tez filtrlar va banner */
.quick-scopes {
  display: flex; gap: 6px; padding: 0 14px 10px; flex-wrap: wrap;
}
.quick-scopes .scope {
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 999px;
  padding: 6px 12px; font-size: 12px; font-weight: 700; color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
}
.quick-scopes .scope em {
  font-style: normal; background: var(--border-soft); color: var(--text);
  border-radius: 999px; padding: 0 6px; font-size: 11px; min-width: 18px; text-align: center;
}
.quick-scopes .scope.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.quick-scopes .scope.active em { background: rgba(255,255,255,.24); color: #fff; }

.closed-banner {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  flex-wrap: wrap; padding: 11px 16px; background: var(--panel-2);
  border-top: 1px solid var(--border); font-size: 13px;
}
.closed-banner span { color: var(--muted); margin-left: 8px; }
.closed-actions { display: flex; gap: 7px; }
.composer-wrap.locked { opacity: .45; pointer-events: none; filter: grayscale(.4); }

/* ==========================================================================
   V6 — LAYOUT TUZATISHLARI
   Muammo: sahifa cheksiz pastga cho'zilardi, chat qismi ekrandan chiqib
   ketardi. Yechim: butun ilova viewport balandligiga qat'iy qamaladi,
   scroll faqat ichki bloklarda bo'ladi.
   ========================================================================== */

html, body { height: 100%; }
body:has(.app-shell) { overflow: hidden; }

.app-shell {
  height: 100vh;
  height: 100dvh;          /* mobil brauzer manzil paneli hisobga olinadi */
  max-height: 100dvh;
  overflow: hidden;
  align-items: stretch;
}

.sidebar { min-height: 0; overflow: hidden; }
.conversation-list { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }

.chat-pane {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-view {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;  /* head · body · banner · composer */
  overflow: hidden;
}

.chat-body { min-height: 0; overflow: hidden; }

.message-area {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  position: relative;
}

.info-panel { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.composer-wrap { flex: none; }
.empty-state { flex: 1; min-height: 0; }

/* "Eng pastga" tugmasi */
.jump-latest {
  position: sticky;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 12.5px;
  font-weight: 700;
  box-shadow: var(--shadow);
  z-index: 5;
  display: block;
}
.jump-latest:hover { border-color: var(--accent); color: var(--accent); }

/* --- Suhbatlar ro'yxati: aniq ajratilgan preview kartochkalar ------------ */
.conv-item {
  border-bottom: 1px solid var(--border-soft);
  border-left: 3px solid transparent;
  align-items: flex-start;
  padding: 11px 14px;
  transition: background .12s ease;
}
.conv-item + .conv-item { margin-top: 0; }
.conv-item.selected { border-left-color: var(--accent); }
.conv-name { display: flex; align-items: center; gap: 6px; }
.conv-preview {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
  overflow: hidden;
  line-height: 1.35;
  max-height: 2.7em;
}
.conv-item .avatar { width: 40px; height: 40px; font-size: 13px; }

/* --- Mobil: ustma-ust emas, ekran bo'yicha almashadi --------------------- */
@media (max-width: 720px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr); }
  .sidebar, .chat-pane { height: 100dvh; max-height: 100dvh; }
  .app-shell.chat-open .sidebar { display: none; }
  .app-shell:not(.chat-open) .chat-pane { display: none; }
  .message-area { padding: 14px 12px 18px; }
  .message { max-width: 94%; }
  .info-panel {
    position: absolute; inset: 0; width: 100%; z-index: 30;
  }
  .quick-scopes { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 8px; }
  .quick-scopes .scope { flex: none; }
}

/* --- Tor ekranlarda ma'lumot paneli chatni siqib qo'ymasin --------------- */
@media (max-width: 1080px) {
  .info-panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(320px, 86vw); z-index: 25; }
  .chat-body { position: relative; }
}
