/* ============================================
   VOICE AGENT — DESIGN SYSTEM v2
   ============================================
   Configurable brand:
     --primary   → main accent (buttons, links, active)
     --secondary → dark tones (topbar, sidebar)
   ============================================ */

:root {
    --primary: #5046e5;
    --primary-hover: #4338ca;
    --primary-light: #f0efff;
    --primary-subtle: #a5b4fc;
    --secondary: #1e293b;
    --secondary-light: #334155;

    --success: #16a34a;
    --success-light: #f0fdf4;
    --warning: #ca8a04;
    --warning-light: #fefce8;
    --danger: #e53e3e;
    --danger-light: #fff5f5;
    --info: #2563eb;
    --info-light: #eff6ff;

    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-hover: #fafbfc;
    --text: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --border: #e2e8f0;
    --border-light: #edf2f7;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.05);
    --transition: 150ms cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif; background: #eef0f4; color: var(--text); line-height: 1.6; font-size: 14px; -webkit-font-smoothing: antialiased; }

/* ============================================
   LAYOUT — No fixed sidebar, topbar based
   ============================================ */
.app-container { display: flex; flex-direction: column; min-height: 100vh; }
.main-content {
    padding: 28px 32px;
    flex: 1;
    margin: 68px 10px 10px 10px;
    width: calc(100% - 20px);
    background: #ffffff;
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 6px rgba(0,0,0,.05);
    border: 1px solid var(--border-light);
    min-height: calc(100vh - 78px);
}

/* ============================================
   TOP BAR — Always visible
   ============================================ */
.app-topbar {
    position: fixed; top: 0; left: 0; right: 0; height: 60px; z-index: 90;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px;
    box-shadow: var(--shadow-sm);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 16px; }

.topbar-menu-btn, .topbar-back-btn {
    width: 36px; height: 36px; border-radius: var(--radius-sm); border: none;
    background: var(--bg); cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary); transition: all var(--transition);
}
.topbar-menu-btn:hover, .topbar-back-btn:hover { background: var(--primary-light); color: var(--primary); }

.topbar-title { font-size: 16px; font-weight: 700; color: var(--text); letter-spacing: -.01em; margin: 0; }

.topbar-user { display: flex; align-items: center; gap: 10px; }
.user-avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--primary);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
}
.user-name { font-size: 13px; font-weight: 600; color: var(--text-secondary); }

/* ============================================
   SIDEBAR — Collapsible overlay (hidden by default)
   ============================================ */
.app-sidebar {
    position: fixed; top: 0; left: 0; width: 280px; height: 100vh; z-index: 200;
    background: var(--secondary); color: #fff;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
    display: flex; flex-direction: column;
    box-shadow: var(--shadow-lg);
}
.app-sidebar.open { transform: translateX(0); }

.sidebar-overlay {
    position: fixed; inset: 0; z-index: 190;
    background: rgba(15,23,42,.4); backdrop-filter: blur(2px);
    opacity: 0; pointer-events: none; transition: opacity .25s;
}
.sidebar-overlay.open { opacity: 1; pointer-events: auto; }

.sidebar-brand {
    padding: 20px; display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand-icon { font-size: 22px; }
.brand-text { font-size: 16px; font-weight: 700; letter-spacing: -.01em; }

.sidebar-nav { list-style: none; padding: 12px 10px; flex: 1; overflow-y: auto; }
.sidebar-nav li { margin-bottom: 2px; }
.sidebar-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px; border-radius: var(--radius-sm);
    color: rgba(255,255,255,.6); text-decoration: none;
    font-size: 14px; font-weight: 500; transition: all var(--transition);
}
.sidebar-link:hover { background: rgba(255,255,255,.08); color: rgba(255,255,255,.9); }
.sidebar-link.active { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(99,102,241,.4); }
.sidebar-icon { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-icon svg { opacity: .75; }
.sidebar-link:hover .sidebar-icon svg, .sidebar-link.active .sidebar-icon svg { opacity: 1; }
.sidebar-label { white-space: nowrap; }

.sidebar-foot { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.06); }
.sidebar-foot .sidebar-label { font-size: 11px; color: rgba(255,255,255,.3); }

/* ============================================
   NAVIGATION CARDS — Dashboard home grid
   ============================================ */
.nav-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.nav-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    text-decoration: none;
    color: var(--text);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow);
    transition: all .2s cubic-bezier(.4,0,.2,1);
    cursor: pointer;
}

.nav-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-subtle);
}

.nav-card-icon {
    width: 48px; height: 48px; border-radius: var(--radius);
    background: var(--primary-light); color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.nav-card-body h3 { font-size: 15px; font-weight: 700; margin-bottom: 4px; color: var(--text); }
.nav-card-body p { font-size: 13px; color: var(--text-muted); line-height: 1.4; }

/* ============================================
   PAGE HEADER — moved to topbar by sidebar.js
   ============================================ */
.page-header {
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px;
}
.page-header h2 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }

/* ============================================
   CARDS
   ============================================ */
.card {
    background: var(--bg); border-radius: var(--radius-lg);
    margin-bottom: 20px;
    border: 1px solid var(--border-light); overflow: hidden;
    transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-sm); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border-light); display: flex; justify-content: space-between; align-items: center; }
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* ============================================
   STAT CARDS
   ============================================ */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); padding: 20px; border-radius: var(--radius-lg); box-shadow: var(--shadow); border: 1px solid var(--border-light); transition: transform var(--transition), box-shadow var(--transition); }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-card .label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.stat-card .value.success { color: var(--success); }
.stat-card .value.warning { color: var(--warning); }
.stat-card .value.danger { color: var(--danger); }
.stat-card .value.primary { color: var(--primary); }

/* ============================================
   BUTTONS
   ============================================ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 18px; border-radius: var(--radius); font-size: 14px; font-weight: 500; border: none; cursor: pointer; transition: all var(--transition); text-decoration: none; white-space: nowrap; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 3px rgba(99,102,241,.3); }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 3px 8px rgba(99,102,241,.35); transform: translateY(-1px); }
.btn-secondary { background: var(--surface); color: var(--text-secondary); border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--surface-hover); border-color: var(--primary-subtle); color: var(--primary); }
.btn-success { background: var(--success); color: #fff; box-shadow: 0 1px 3px rgba(16,185,129,.3); }
.btn-success:hover { background: #059669; transform: translateY(-1px); }
.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 1px 3px rgba(239,68,68,.3); }
.btn-danger:hover { background: #dc2626; transform: translateY(-1px); }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: var(--radius-sm); }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* ============================================
   TABLES
   ============================================ */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { padding: 12px 16px; text-align: left; font-size: 12px; font-weight: 700; letter-spacing: .03em; color: var(--primary); background: #eef0fb; border-bottom: 2px solid var(--primary-subtle); }
tbody td { padding: 14px 16px; border-bottom: 1px solid var(--border-light); color: var(--text-secondary); vertical-align: middle; }
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--primary-light); }
tbody tr:last-child td { border-bottom: none; }

.table-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--border-light); }
.table-toolbar .info { font-size: 12px; color: var(--text-muted); }
.pagination { display: flex; gap: 4px; align-items: center; }
.pagination button { width: 32px; height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-secondary); transition: all var(--transition); }
.pagination button:hover { border-color: var(--primary); color: var(--primary); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ============================================
   BADGES
   ============================================ */
.badge { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.badge-success { background: #f0fdf4; color: #16a34a; }
.badge-warning { background: #fefce8; color: #a16207; }
.badge-danger { background: #fff5f5; color: #e53e3e; }
.badge-info { background: #eff6ff; color: #2563eb; }
.badge-secondary { background: #f7f8fa; color: #4a5568; }

/* ============================================
   FORMS
   ============================================ */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--text-secondary); }
.form-control { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; color: var(--text); background: var(--surface); transition: border-color var(--transition), box-shadow var(--transition); }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control {
    min-height: 96px;
    resize: vertical;
    line-height: 1.6;
    padding: 12px 14px;
    font-family: inherit;
    tab-size: 2;
}
/* Comfortable sizing for long-form prompt / knowledge-base editors. */
textarea.form-control.textarea-lg { min-height: 160px; }
textarea.form-control.textarea-xl { min-height: 260px; }
/* Structured, line-based content (KB facts, triggers) reads better in mono. */
textarea.form-control.textarea-mono {
    font-family: 'SF Mono', 'Menlo', 'Consolas', ui-monospace, monospace;
    font-size: 13px;
}
/* Auto-grow textareas never show a scrollbar mid-typing, and their height is
   driven by content — so the fixed min-heights above (96/160/260px) must not
   force a tall box. Keep only a small ~2-line floor; the JS grows from there.
   Placed AFTER textarea-lg/xl so it wins the min-height for autogrow fields. */
textarea.form-control.autogrow { overflow: hidden; resize: none; min-height: 44px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

/* ============================================
   CHIPS & PILLS
   ============================================ */
.chip-select { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-hover); min-height: 42px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; cursor: pointer; transition: all var(--transition); border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary); user-select: none; }
.chip:hover { border-color: var(--primary-subtle); color: var(--primary); }
.chip.selected { background: var(--primary); color: #fff; border-color: var(--primary); box-shadow: 0 1px 4px rgba(99,102,241,.25); }

.lang-bar { display: flex; gap: 6px; }
.lang-pill { padding: 5px 14px; border-radius: 20px; font-size: 12px; font-weight: 600; cursor: pointer; background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border); transition: all var(--transition); }
.lang-pill:hover { border-color: var(--primary-subtle); color: var(--primary); }
.lang-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ============================================
   MODALS
   ============================================ */
.modal-backdrop { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15,23,42,.5); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; z-index: 1000; }
.modal-backdrop.active { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius-lg); width: 90%; max-width: 560px; max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-lg); animation: modalIn .2s ease-out; }
@keyframes modalIn { from { opacity:0; transform: translateY(10px) scale(.98); } to { opacity:1; transform: translateY(0) scale(1); } }
.modal-header { padding: 18px 24px; border-bottom: 1px solid var(--border-light); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 24px; }
.modal-footer { padding: 14px 24px; border-top: 1px solid var(--border-light); display: flex; justify-content: flex-end; gap: 10px; }
.close-btn { width: 28px; height: 28px; border-radius: 50%; border: none; background: var(--bg); font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--text-muted); transition: all var(--transition); }
.close-btn:hover { background: var(--danger-light); color: var(--danger); }

/* ============================================
   GRID & PAGE HELPERS
   ============================================ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.page-section { display: none; }
.page-section.active { display: block; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; margin-bottom: 16px; }

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .main-content { padding: 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .nav-cards { grid-template-columns: 1fr; }
}
