/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --bg: #000000; --surface: #0c0c10; --border: #1e1e2a;
    --card-bg: var(--surface);
    --text: #e8e8f0; --text-muted: #7878a0; --text-xs: #48487a;
    --primary: #0088ff; --primary-hover: #0070d4; --primary-light: #071828;
    --green: #10b981; --green-bg: #001a10; --green-border: #0d4a28;
    --red: #f87171; --red-bg: #1a0505; --red-border: #4a1010;
    --yellow: #fbbf24; --yellow-bg: #181000; --yellow-border: #4a3500;
    --blue: #60a5fa; --blue-bg: #071828; --blue-border: #1a3a6a;
    --sidebar-bg: #000000; --sidebar-text: #7890a8; --sidebar-active: #0088ff;
    --radius: 8px; --shadow: 0 1px 4px rgba(0,0,0,0.5);
}
html { font-size: 15px; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 240px; background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; }
.content { flex: 1; margin-left: 240px; padding: 28px 32px; }

/* ── Sidebar ── */
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.brand-icon { width: 36px; height: 36px; background: var(--sidebar-active); color: #fff; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }
.brand-icon-lg { width: 56px; height: 56px; font-size: 20px; border-radius: 12px; }
.sidebar-brand span { font-size: 16px; font-weight: 600; color: #fff; }
.sidebar-nav { list-style: none; padding: 12px 8px; flex: 1; }
.sidebar-nav li { margin-bottom: 2px; }
.sidebar-nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 6px; color: var(--sidebar-text); font-size: 14px; transition: all 0.15s; }
.sidebar-nav a:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.sidebar-nav a.active { background: var(--sidebar-active); color: #fff; }
.sidebar-nav a svg { flex-shrink: 0; opacity: 0.7; }
.sidebar-nav a.active svg, .sidebar-nav a:hover svg { opacity: 1; }
.nav-divider { margin-top: 10px !important; padding-top: 10px; border-top: 1px solid rgba(255,255,255,0.08); }
.nav-heading { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: rgba(255,255,255,0.35); padding: 4px 12px 2px; font-weight: 600; }
.sidebar-footer { padding: 16px 18px; border-top: 1px solid rgba(255,255,255,0.08); }
.user-info { margin-bottom: 8px; }
.user-name { display: block; font-weight: 500; color: #fff; font-size: 13px; }
.user-client { display: block; font-size: 11px; color: var(--sidebar-text); }
.logout-link { font-size: 12px; color: var(--text-xs); }
.logout-link:hover { color: var(--red); }

/* ── Mobile ── */
.mobile-toggle { display: none; background: none; border: none; cursor: pointer; color: var(--text); padding: 8px; }
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.2s; }
    .sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.3); }
    .content { margin-left: 0; padding: 16px; }
    .mobile-toggle { display: block; margin-bottom: 12px; }
    .grid-2 { grid-template-columns: 1fr !important; }
    .filter-bar { flex-direction: column; }
    .form-row { flex-direction: column; }
    .stat-cards { grid-template-columns: 1fr 1fr !important; }
}

/* ── Typography ── */
.page-title { font-size: 22px; font-weight: 600; margin-bottom: 20px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.text-center { text-align: center; }
.mono { font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace; font-size: 13px; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; color: var(--text); }

/* ── Stat Cards ── */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 16px; box-shadow: var(--shadow); }
.stat-card-warning { border-color: var(--yellow-border); background: var(--yellow-bg); }
.stat-card-purple { border-color: #2d1a5a; background: #120a20; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.stat-card-warning .stat-value { color: var(--yellow); }
.stat-value-purple { color: #a78bfa; }
.card-title-purple { color: #a78bfa; }
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }

/* ── Tables ── */
.table-responsive { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; padding: 8px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); border-bottom: 2px solid var(--border); font-weight: 600; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover { background: rgba(255,255,255,0.03); }

/* ── Badges ── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 500; }
.badge-green { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.badge-red { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); border: 1px solid var(--yellow-border); }
.badge-gray { background: #141420; color: #8888a8; border: 1px solid #2a2a3a; }
.badge-blue { background: var(--blue-bg); color: var(--blue); border: 1px solid var(--blue-border); }

/* ── Buttons ── */
.btn { display: inline-block; padding: 8px 16px; border-radius: 6px; font-size: 14px; font-weight: 500; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; transition: all 0.15s; line-height: 1.4; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-danger:hover { background: #b91c1c; }
.btn-outline { background: transparent; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Forms ── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 4px; color: var(--text); }
.form-group input, .form-group select { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; background: var(--surface); color: var(--text); transition: border 0.15s; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.input-lg { font-size: 18px !important; padding: 12px 14px !important; letter-spacing: 0.02em; }
.form-help { display: block; margin-top: 4px; font-size: 12px; color: var(--text-muted); }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.filter-bar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.filter-bar .form-group { margin-bottom: 0; }

/* ── Alerts ── */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; }
.alert-error { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-border); }
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }

/* ── Forwarding ── */
.fwd-status { margin-bottom: 20px; }
.fwd-indicator { display: flex; align-items: center; gap: 14px; padding: 18px; border-radius: var(--radius); }
.fwd-on { background: var(--yellow-bg); border: 1px solid var(--yellow-border); color: var(--yellow); }
.fwd-off { background: var(--green-bg); border: 1px solid var(--green-border); color: var(--green); }
.fwd-label { display: block; font-weight: 600; font-size: 15px; }
.fwd-number { display: block; font-size: 20px; font-weight: 700; font-family: 'SF Mono', Monaco, monospace; }
.fwd-sublabel { display: block; font-size: 13px; opacity: 0.8; }
.fwd-form { margin-top: 16px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── Settings ── */
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: none; }
.setting-info { flex: 1; margin-right: 16px; }
.setting-info strong { font-size: 14px; }
.toggle-btn { padding: 6px 16px; border-radius: 20px; font-size: 12px; font-weight: 600; border: none; cursor: pointer; min-width: 56px; transition: all 0.15s; }
.toggle-on { background: var(--green); color: #fff; }
.toggle-off { background: #1e1e2a; color: #7878a0; }
.toggle-btn:hover { opacity: 0.85; }
.password-form { max-width: 500px; }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding-top: 16px; border-top: 1px solid var(--border); margin-top: 12px; }
.page-info { font-size: 13px; color: var(--text-muted); }

/* ── Misc ── */
.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.link-more { display: block; margin-top: 12px; font-size: 13px; font-weight: 500; }
.info-list { list-style: disc; padding-left: 20px; font-size: 14px; color: var(--text-muted); }
.info-list li { margin-bottom: 6px; }
.info-list strong { color: var(--text); }
code { background: #0e0e18; border: 1px solid #2a2a3a; padding: 2px 6px; border-radius: 4px; font-size: 13px; font-family: 'SF Mono', Monaco, monospace; }
.inline { display: inline; }
.vm-audio { height: 32px; max-width: 200px; }

/* ── AI Nav Highlight ── */
.sidebar-nav a.nav-ai { color: #a78bfa; }
.sidebar-nav a.nav-ai:hover { background: rgba(139,92,246,0.15); color: #c4b5fd; }
.sidebar-nav a.nav-ai.active { background: #7c3aed; color: #fff; }
.sidebar-nav a.nav-ai svg { opacity: 1; }

/* ── Chart Container ── */
.chart-container { position: relative; height: 200px; }

/* ── AI Call Cards ── */
.ai-calls-list { list-style: none; }
.ai-call-card { padding: 12px 0; border-bottom: 1px solid var(--border); }
.ai-call-card:last-child { border-bottom: none; }
.ai-call-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.ai-call-caller { font-weight: 500; font-size: 14px; }
.ai-call-time { font-size: 11px; color: var(--text-muted); }
.ai-call-summary { font-size: 13px; color: var(--text-muted); line-height: 1.4; }
.badge-purple { background: #120a20; color: #a78bfa; border: 1px solid #2d1a5a; }

/* ── Login Page ── */
.login-page { background: var(--sidebar-bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-container { width: 100%; max-width: 380px; padding: 20px; }
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand h1 { color: #fff; font-size: 24px; margin-top: 14px; }
.login-brand p { color: var(--sidebar-text); font-size: 14px; }
.login-form { background: var(--surface); padding: 28px 24px; border-radius: 12px; box-shadow: 0 4px 24px rgba(0,0,0,0.2); }
.login-form .form-group label { color: var(--text); }
.login-form .btn-block { margin-top: 6px; padding: 11px; font-size: 15px; }

/* ── Admin views ── */
.badge-orange { background: #181005; color: #fb923c; border: 1px solid #4a2800; }
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 24px; max-width: 700px; box-shadow: var(--shadow); margin-bottom: 16px; }
.form-card label { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 500; }
.form-card input, .form-card textarea, .form-card select { display: block; width: 100%; padding: 8px 12px; margin-top: 4px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-size: 14px; }
.form-card input:focus, .form-card textarea:focus, .form-card select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.form-card textarea { resize: vertical; min-height: 60px; }
.form-card .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-card input[type="checkbox"] { display: inline; width: auto; margin-right: 6px; }
.back-link { display: inline-block; margin-bottom: 16px; font-size: 13px; font-weight: 500; }
.admin-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); font-size: 13px; }
.admin-table th { background: var(--bg); text-align: left; padding: 8px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); border-bottom: 2px solid var(--border); font-weight: 600; white-space: nowrap; }
.admin-table td { padding: 8px 12px; border-top: 1px solid var(--border); white-space: nowrap; }
.admin-table tbody tr:first-child td { border-top: none; }
.admin-table tbody tr:hover { background: rgba(255,255,255,0.03); }
pre.code-block { white-space: pre-wrap; font-size: 12px; background: var(--bg); padding: 12px; border-radius: 6px; border: 1px solid var(--border); max-height: 500px; overflow: auto; }

/* ── Breadcrumbs ── */
.breadcrumbs { display: flex; align-items: center; gap: 6px; margin-bottom: 16px; font-size: 13px; }
.breadcrumbs a { color: var(--primary); font-weight: 500; }
.breadcrumbs a:hover { text-decoration: underline; }
.bc-sep { color: var(--text-xs); }
.bc-current { color: var(--text-muted); font-weight: 500; }

/* ── Back link in sidebar ── */
.sidebar-nav a.nav-back { color: var(--sidebar-text); font-size: 13px; opacity: 0.7; }
.sidebar-nav a.nav-back:hover { opacity: 1; }

/* ── Tree Nav ── */
.nav-tree-toggle { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border-radius: 6px; color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.15s; user-select: none; text-transform: uppercase; letter-spacing: 0.08em; }
.nav-tree-toggle:hover { background: rgba(255,255,255,0.08); }
.nav-tree-toggle svg { transition: transform 0.2s; flex-shrink: 0; }
.nav-tree-toggle.open svg { transform: rotate(90deg); }
.nav-tree-children { overflow: hidden; max-height: 0; transition: max-height 0.25s ease; }
.nav-tree-children.open { max-height: 800px; }
.nav-tree-children .sidebar-nav { padding: 0 0 0 8px; }
.nav-tree-children .sidebar-nav a { font-size: 13px; padding: 7px 12px; }

/* ── User brand link ── */
.sidebar-brand a { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.sidebar-brand a:hover { text-decoration: none; }
.sidebar-brand a:hover span { color: var(--sidebar-active); }

/* ── Client list in nav ── */
.nav-client-list { max-height: 300px; overflow-y: auto; }
.nav-client-list::-webkit-scrollbar { width: 4px; }
.nav-client-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }
.nav-client-item { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 6px; color: var(--sidebar-text); font-size: 12px; transition: all 0.15s; text-decoration: none; }
.nav-client-item:hover { background: rgba(255,255,255,0.08); color: #fff; text-decoration: none; }
.nav-client-item .client-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); flex-shrink: 0; }
.nav-client-item .client-dot.inactive { background: var(--text-xs); }
.nav-client-item .client-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-client-item .client-code { font-family: 'SF Mono', Monaco, monospace; font-size: 10px; color: var(--text-xs); text-transform: uppercase; }

/* ── Section title ── */
.section-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; color: var(--text); }

/* ── Client Cards ── */
.client-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.client-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); transition: all 0.15s; text-decoration: none; color: var(--text); }
.client-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(0,136,255,0.12); text-decoration: none; transform: translateY(-1px); }
.client-card-header { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.client-card-icon { width: 40px; height: 40px; background: var(--primary); color: #fff; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.client-card-name { font-weight: 600; font-size: 15px; }
.client-card-code { font-size: 11px; color: var(--text-muted); font-family: 'SF Mono', Monaco, monospace; text-transform: uppercase; }
.client-card-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.client-card-stat { text-align: center; }
.client-stat-val { display: block; font-weight: 700; font-size: 16px; color: var(--text); }
.client-stat-lbl { display: block; font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* ── Location Cards ── */
.location-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.location-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow); transition: all 0.15s; text-decoration: none; color: var(--text); }
.location-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(0,136,255,0.12); text-decoration: none; transform: translateY(-1px); }
.location-card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.location-card-num { width: 32px; height: 32px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; color: var(--primary); }
.location-card-name { font-weight: 600; font-size: 14px; flex: 1; }
.location-card-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; }

/* ── Dialplan Flow Diagram ── */
.flow-card { display: flex; gap: 16px; align-items: flex-start; }
.flow-step { flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; font-size: 14px; display: flex; align-items: center; justify-content: center; margin-top: 2px; }
.flow-content { flex: 1; min-width: 0; }
.flow-title { font-size: 0.95rem; font-weight: 600; margin-bottom: 4px; }
.flow-desc { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; }
.flow-desc code { background: rgba(255,255,255,0.06); border: none; padding: 1px 5px; border-radius: 3px; font-size: 0.8rem; }
.flow-status { margin-top: 8px; display: flex; align-items: center; gap: 8px; }
.flow-ctx-link { font-family: 'SF Mono', 'Consolas', monospace; font-size: 0.8rem; color: var(--primary); text-decoration: none; margin-right: 6px; }
.flow-ctx-link:hover { text-decoration: underline; }

@media (max-width: 768px) {
    .client-grid { grid-template-columns: 1fr; }
    .location-grid { grid-template-columns: 1fr; }
    .client-card-stats { grid-template-columns: repeat(2, 1fr); }
    .flow-card { flex-direction: column; gap: 8px; }
}
