@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --sidebar-bg: #111827;
    --sidebar-text: #94a3b8;
    --accent: #ea580c;
    --accent-dark: #c2410c;
    --accent-soft: rgba(234, 88, 12, .14);
    --line: #e5e7eb;
    --line-soft: #f1f5f9;
    --head-bg: #f8fafc;
    --text: #111827;
    --muted: #6b7280;
    --success: #15803d;  --success-soft: #dcfce7;
    --danger: #dc2626;   --danger-soft: #fee2e2;
    --warn: #b45309;     --warn-soft: #fef3c7;
    --info: #1d4ed8;     --info-soft: #dbeafe;
    --control-h: 34px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: 'Inter', -apple-system, 'Segoe UI', Arial, sans-serif; background: #fff; color: var(--text); font-size: 13.5px; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }

/* ---------- Shell: fixed sidebar + full-width main ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { width: 232px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-text); position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 30; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 16px; color: #fff; font-weight: 700; font-size: 14.5px; border-bottom: 1px solid rgba(255,255,255,.07); line-height: 1.2; }
.sidebar-brand small { display: block; font-weight: 500; font-size: 10.5px; color: var(--sidebar-text); }
.logo-icon { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #fb923c); display: flex; align-items: center; justify-content: center; color: #fff; font-size: 14px; flex-shrink: 0; }
.sidebar-section-label { padding: 16px 18px 6px; font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: #4b5563; }
.sidebar-nav { padding: 2px 10px; }
.sidebar-nav a { display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--sidebar-text); margin-bottom: 2px; }
.sidebar-nav a i { width: 16px; text-align: center; font-size: 13.5px; }
.sidebar-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-nav a.active { background: var(--accent-soft); color: #fdba74; }
.sidebar-nav a.active i { color: var(--accent); }
.sidebar-nav .nav-badge { margin-left: auto; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; border-radius: 99px; padding: 1px 7px; }
.sidebar-footer { margin-top: auto; padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.07); }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 4px 6px 8px; }
.sidebar-user .avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: #fdba74; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; }
.sidebar-user .name { font-size: 12.5px; font-weight: 700; color: #fff; }
.sidebar-user .role { font-size: 10.5px; }
.logout-link { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 7px; font-size: 12.5px; font-weight: 600; }
.logout-link:hover { background: rgba(255,255,255,.06); color: #fff; }

.main { flex: 1; margin-left: 232px; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.main-topbar { height: 56px; flex-shrink: 0; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 26px; position: sticky; top: 0; background: #fff; z-index: 20; gap: 12px; }
.main-topbar .page-title { font-size: 15.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main-content { padding: 22px 26px 50px; width: 100%; }
.main-content.flush { padding: 0; flex: 1; display: flex; min-height: 0; height: calc(100vh - 56px); }

/* ---------- Page sections (no boxes) ---------- */
.section { margin-bottom: 30px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.section-head h2 { font-size: 14.5px; font-weight: 700; }
.section-head .meta { color: var(--muted); font-size: 12.5px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.page-note { color: var(--muted); font-size: 12.5px; margin-top: 12px; }
.page-note a { color: var(--accent); font-weight: 600; }

/* ---------- Stat tiles ---------- */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 28px; }
.stat-tile { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; display: flex; align-items: center; gap: 12px; }
.stat-tile .icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.icon.orange { background: var(--accent-soft); color: var(--accent); }
.icon.green { background: var(--success-soft); color: var(--success); }
.icon.blue { background: var(--info-soft); color: var(--info); }
.icon.slate { background: var(--line-soft); color: #475569; }
.icon.red { background: var(--danger-soft); color: var(--danger); }
.stat-tile b { display: block; font-size: 20px; font-weight: 800; line-height: 1.15; }
.stat-tile span { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Tables (directly on the page) ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
table.data th { text-align: left; padding: 9px 12px; background: var(--head-bg); border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fafafa; }
table.data tr.clickable { cursor: pointer; }
table.data tr.selected td { background: #fff7ed; }
.empty-state { padding: 44px 16px; text-align: center; color: var(--muted); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.empty-state i { font-size: 24px; color: #cbd5e1; display: block; margin-bottom: 8px; }
.empty-state a { color: var(--accent); font-weight: 600; }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 2px 9px; border-radius: 99px; text-transform: capitalize; white-space: nowrap; }
.badge.ok, .badge.delivered, .badge.approved, .badge.completed, .badge.active { background: var(--success-soft); color: var(--success); }
.badge.read { background: var(--info-soft); color: var(--info); }
.badge.sent, .badge.sending, .badge.pending, .badge.in_appeal { background: var(--warn-soft); color: var(--warn); }
.badge.failed, .badge.rejected, .badge.disabled, .badge.paused { background: var(--danger-soft); color: var(--danger); }
.badge.queued, .badge.draft, .badge.opd, .badge.ipd, .badge.vip, .badge.manual, .badge.all, .badge.search, .badge.custom, .badge.plain { background: var(--line-soft); color: #475569; }

/* ---------- Controls: compact, consistent height ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--control-h); padding: 0 14px; border: 1px solid #d1d5db; background: #fff; color: var(--text); border-radius: 6px; font-size: 13px; font-weight: 600; font-family: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f9fafb; }
.btn.pri { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.pri:hover { background: var(--accent-dark); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.danger { color: var(--danger); border-color: #fecaca; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.input, select.input, textarea.input {
    height: var(--control-h); padding: 0 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px; font-family: inherit; color: var(--text); background: #fff; width: 100%;
}
textarea.input { height: auto; min-height: 96px; padding: 8px 10px; line-height: 1.45; resize: vertical; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.w-search { width: 280px; }

.form { max-width: 540px; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; }
.field .req { color: var(--danger); }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.subhead { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 0 10px; }

.btn-row { display: grid; grid-template-columns: 140px 1fr 1fr 34px; gap: 8px; margin-bottom: 8px; align-items: center; }
.icon-btn { width: var(--control-h); height: var(--control-h); border: 1px solid #d1d5db; border-radius: 6px; background: #fff; color: var(--muted); cursor: pointer; }
.icon-btn:hover { color: var(--danger); border-color: #fecaca; }

/* ---------- Alerts ---------- */
.alert { display: flex; align-items: center; gap: 9px; padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 16px; border: 1px solid transparent; }
.alert.error { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.alert.ok { background: var(--success-soft); color: #166534; border-color: #bbf7d0; }
.alert.warn { background: var(--warn-soft); color: #92400e; border-color: #fde68a; }

/* ---------- Two-column form + preview ---------- */
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 36px; align-items: start; }
.split.wide-left { grid-template-columns: minmax(0, 1fr) 340px; }
.preview-col { position: sticky; top: 78px; }
.preview-col .preview-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }

/* WhatsApp-style preview */
.wa-phone { width: 100%; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.wa-top { background: #075e54; color: #fff; padding: 10px 14px; display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; }
.wa-top .wa-av { width: 30px; height: 30px; border-radius: 50%; background: rgba(255,255,255,.25); display: flex; align-items: center; justify-content: center; font-size: 13px; }
.wa-top small { display: block; font-weight: 400; font-size: 10.5px; opacity: .8; }
.wa-screen { background: #efeae2; min-height: 380px; padding: 16px 12px; }
.wa-bubble { background: #fff; border-radius: 8px; border-top-left-radius: 0; padding: 7px 9px 5px; max-width: 92%; box-shadow: 0 1px .5px rgba(0,0,0,.13); font-size: 13px; line-height: 1.45; word-wrap: break-word; }
.wa-bubble .wa-h { font-weight: 700; margin-bottom: 3px; }
.wa-bubble .wa-f { color: #8696a0; font-size: 12px; margin-top: 4px; }
.wa-bubble .wa-t { text-align: right; color: #8696a0; font-size: 10.5px; margin-top: 2px; }
.wa-buttons { max-width: 92%; }
.wa-btn { background: #fff; border-radius: 8px; margin-top: 3px; padding: 8px; text-align: center; color: #00a5f4; font-size: 13px; font-weight: 500; box-shadow: 0 1px .5px rgba(0,0,0,.13); }
.wa-btn i { margin-right: 5px; font-size: 12px; }
.wa-empty { color: #8696a0; font-size: 12.5px; text-align: center; padding-top: 140px; }
.wa-var { background: #fef3c7; color: #92400e; border-radius: 3px; padding: 0 2px; }

/* ---------- Live chat ---------- */
.chat { display: flex; flex: 1; min-height: 0; }
.chat-list { width: 320px; flex-shrink: 0; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chat-list-head { padding: 12px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; }
.chat-items { flex: 1; overflow-y: auto; }
.chat-item { display: flex; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.chat-item:hover { background: #fafafa; }
.chat-item.active { background: #fff7ed; }
.c-av { width: 36px; height: 36px; border-radius: 50%; background: var(--line-soft); color: #475569; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.c-main { flex: 1; min-width: 0; }
.c-top { display: flex; justify-content: space-between; gap: 6px; }
.c-name { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-time { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.c-last { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.c-unread { background: var(--success); color: #fff; font-size: 10px; font-weight: 700; border-radius: 99px; padding: 1px 7px; margin-left: 6px; }
.chat-thread { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.thread-head { height: 56px; flex-shrink: 0; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 18px; gap: 10px; }
.thread-head .t-name { font-weight: 700; font-size: 14px; }
.thread-head .t-phone { font-size: 12px; color: var(--muted); }
.window-badge { font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 99px; }
.window-badge.open { background: var(--success-soft); color: var(--success); }
.window-badge.closed { background: var(--warn-soft); color: var(--warn); }
.thread-msgs { flex: 1; overflow-y: auto; background: #efeae2; padding: 18px 6%; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 64%; padding: 7px 10px 5px; border-radius: 8px; font-size: 13.5px; line-height: 1.45; box-shadow: 0 1px .5px rgba(0,0,0,.13); word-wrap: break-word; white-space: pre-wrap; }
.msg.in { background: #fff; align-self: flex-start; border-top-left-radius: 0; }
.msg.out { background: #d9fdd3; align-self: flex-end; border-top-right-radius: 0; }
.msg .m-meta { font-size: 10.5px; color: #667781; text-align: right; margin-top: 2px; white-space: normal; }
.msg .m-tpl { font-size: 10px; font-weight: 700; color: #667781; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.thread-compose { border-top: 1px solid var(--line); padding: 10px 14px; }
.compose-row { display: flex; gap: 8px; align-items: flex-end; }
.compose-row textarea.input { min-height: var(--control-h); height: var(--control-h); max-height: 120px; resize: none; padding: 7px 10px; flex: 1; }
.tpl-panel { display: none; border-bottom: 1px dashed var(--line); padding-bottom: 10px; margin-bottom: 10px; }
.tpl-panel.show { display: block; }
.tpl-panel .tpl-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tpl-panel select.input { width: 260px; }
.tpl-panel .input.var-input { width: 160px; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); flex-direction: column; gap: 8px; background: #fafafa; }
.chat-empty i { font-size: 32px; color: #cbd5e1; }
.chat-error { color: var(--danger); font-size: 12px; margin-top: 6px; }

/* ---------- Login ---------- */
body.login-body { background: linear-gradient(160deg, #111827 0%, #1f2937 55%, #111827 100%); display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: #fff; border-radius: 12px; padding: 30px 28px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-card .logo-icon { width: 44px; height: 44px; font-size: 18px; margin: 0 auto 14px; border-radius: 10px; }
.login-card h1 { text-align: center; font-size: 18px; font-weight: 800; }
.login-card .sub { text-align: center; color: var(--muted); margin: 3px 0 20px; font-size: 13px; }
.login-card .btn { width: 100%; margin-top: 6px; }

@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } .preview-col { position: static; max-width: 360px; } }
@media (max-width: 860px) { .sidebar { transform: translateX(-100%); } .main { margin-left: 0; } .chat-list { width: 260px; } }
