/* P1 Dialer admin panel */
:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e3e8ef;
    --text: #1b2433;
    --muted: #6b7789;
    --primary: #2f6fed;
    --primary-dark: #1f56c7;
    --primary-soft: #e8f0fe;
    --success: #13a26b;
    --success-soft: #e3f6ee;
    --warning: #c98a04;
    --warning-soft: #fdf3dc;
    --danger: #d64545;
    --danger-soft: #fdeaea;
    --sidebar: #111827;
    --sidebar-2: #1f2937;
    --sidebar-text: #c7cfdc;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
    --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------------------------------------------------------------- layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 232px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
    display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; font-weight: 700; font-size: 17px; color: #fff; }
.brand-mark { background: var(--primary); color: #fff; border-radius: 8px; padding: 4px 8px; font-size: 14px; letter-spacing: .02em; }
.brand-lg { font-size: 22px; justify-content: center; color: var(--text); padding: 0 0 6px; }
#nav { flex: 1; overflow-y: auto; padding: 4px 10px; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7d8799; padding: 14px 10px 6px; }
.nav-link {
    display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
    color: var(--sidebar-text); font-weight: 500; margin-bottom: 1px;
}
.nav-link:hover { background: var(--sidebar-2); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-icon { width: 18px; text-align: center; opacity: .9; }
.sidebar-footer { padding: 14px; border-top: 1px solid #253042; }
.user-chip { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; font-size: 13px; color: #fff; }
.user-chip .dot { width: 8px; height: 8px; background: var(--success); border-radius: 50%; }
.sidebar .btn-ghost { color: var(--sidebar-text); border-color: #334155; }
.sidebar .btn-ghost:hover { background: var(--sidebar-2); color: #fff; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; gap: 12px; padding: 16px 28px; background: var(--surface);
    border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 19px; flex: 1; }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.topbar .menu-toggle { display: none; }
.main { padding: 24px 28px 48px; max-width: 1400px; width: 100%; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

/* ----------------------------------------------------------------- cards */
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-header h2 { flex: 1; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }
.stack > * + * { margin-top: 16px; }

.stat { padding: 16px 18px; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.stat-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stat.accent { border-left: 3px solid var(--primary); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody tr:hover { background: #fafbfd; }
tbody tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------------------------------------------------------------- badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef1f5; color: #4a5568; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.blue { background: var(--primary-soft); color: var(--primary); }
.badge.yellow { background: var(--warning-soft); color: var(--warning); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.plain::before { display: none; }

/* --------------------------------------------------------------- buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px;
    border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
    font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.95); background: var(--success); }
.btn-warning { background: var(--warning-soft); border-color: #f3dfa8; color: #8a5d00; }
.btn-danger { background: var(--danger-soft); border-color: #f5c6c6; color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* ----------------------------------------------------------------- forms */
.form { display: grid; gap: 14px; }
.form-row { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { display: grid; gap: 6px; font-weight: 600; font-size: 13px; }
label .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input, select, textarea {
    font: inherit; padding: 8px 11px; border: 1px solid #cfd7e3; border-radius: 8px; background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type=checkbox] { width: auto; }
.checks { display: flex; gap: 6px; flex-wrap: wrap; }
.check-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid #cfd7e3; border-radius: 8px; font-weight: 500; cursor: pointer; }
.check-pill input { margin: 0; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .grow { flex: 1; }
.toolbar input, .toolbar select { width: auto; min-width: 200px; }

/* ---------------------------------------------------------------- alerts */
.alert { padding: 11px 14px; border-radius: 8px; border: 1px solid; font-size: 13.5px; }
.alert-error { background: var(--danger-soft); border-color: #f5c6c6; color: #9b2c2c; }
.alert-warning { background: var(--warning-soft); border-color: #f3dfa8; color: #7a5200; }
.alert-info { background: var(--primary-soft); border-color: #c9d9fb; color: #1d4ea8; }
.alert-success { background: var(--success-soft); border-color: #b7e6d1; color: #0d6e48; }
.alert ul { margin: 6px 0 0 18px; padding: 0; }

/* ----------------------------------------------------------------- modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-wide { max-width: 860px; }
.modal-header { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h2 { flex: 1; }
.modal-body { padding: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 12px 12px; }
.close-x { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }

/* ---------------------------------------------------------------- toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 60; }
.toast { background: #1b2433; color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 420px; animation: slide .18s ease-out; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------------------------------------------------------- charts */
.chart { width: 100%; height: 190px; }
.chart .bar { fill: #c9d9fb; }
.chart .bar-answered { fill: var(--primary); }
.chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.progress { height: 8px; background: #edf0f5; border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab { padding: 9px 14px; border: none; background: none; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 14px; border-top: 1px solid var(--border); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); display: inline-block; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ----------------------------------------------------------------- login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #111827 0%, #1e3a8a 100%); }
.login-card { background: #fff; padding: 34px 32px; border-radius: 14px; width: 100%; max-width: 380px; box-shadow: 0 25px 60px rgba(0,0,0,.35); }
.login-card .muted { text-align: center; margin: 0 0 20px; }
.login-card .alert { margin-bottom: 14px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
    .sidebar { position: fixed; left: -240px; z-index: 40; transition: left .2s; }
    .sidebar.open { left: 0; }
    .topbar .menu-toggle { display: inline-flex; }
    .main { padding: 16px; }
    .topbar { padding: 12px 16px; }
    .grid-4, .grid-3, .grid-2, .form-row { grid-template-columns: minmax(0, 1fr); }
    .span-2 { grid-column: auto; }
    .toolbar input, .toolbar select { min-width: 0; width: 100%; }
}
