/* ─── CSS Variables ──────────────────────────────────────────────── */
:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-success: #16a34a;
    --color-warning: #d97706;
    --color-error: #dc2626;
    --color-info: #0891b2;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ─── Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body { font-family: var(--font); background: var(--color-bg); color: var(--color-text); margin: 0; line-height: 1.5; }
h1 { font-size: 1.5rem; margin: 0 0 1.25rem; }
h2 { font-size: 1.2rem; margin: 1.5rem 0 0.75rem; color: var(--color-text); }
a { color: var(--color-primary); }

/* ─── Navigation ─────────────────────────────────────────────────── */
.nav {
    display: flex; align-items: center; background: var(--color-surface);
    padding: 0 1.5rem; height: 56px; border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow); position: sticky; top: 0; z-index: 100;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; margin-right: 2rem; white-space: nowrap; }
.nav-links { display: flex; gap: 0.25rem; flex: 1; }
.nav-links a {
    padding: 0.5rem 0.85rem; border-radius: var(--radius); text-decoration: none;
    color: var(--color-text-muted); font-size: 0.9rem; font-weight: 500; transition: background 0.15s;
}
.nav-links a:hover { background: var(--color-bg); color: var(--color-text); }
.nav-links a.active { background: var(--color-primary); color: #fff; }
.nav-logout { margin-left: auto !important; }
.nav-toggle { display: none; background: none; border: none; font-size: 1.5rem; cursor: pointer; margin-left: auto; padding: 0.25rem; }

/* ─── Container ──────────────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

/* ─── Summary Cards ──────────────────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.card {
    background: var(--color-surface); padding: 1.25rem; border-radius: var(--radius);
    box-shadow: var(--shadow); border: 1px solid var(--color-border);
}
.card-label { font-size: 0.8rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.card-value { font-size: 1.75rem; font-weight: 700; margin-top: 0.15rem; }
.card-detail { font-size: 0.85rem; color: var(--color-text-muted); }

/* ─── Table ──────────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; margin-bottom: 1rem; }
.table {
    width: 100%; border-collapse: collapse; background: var(--color-surface);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.table th, .table td { padding: 0.7rem 0.9rem; text-align: left; border-bottom: 1px solid var(--color-border); font-size: 0.9rem; }
.table th { background: var(--color-bg); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; color: var(--color-text-muted); letter-spacing: 0.03em; }
.table tbody tr:hover { background: #f1f5f9; }
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }

/* ─── Badges ─────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 0.2rem 0.55rem; border-radius: 99px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-error { background: #fef2f2; color: #991b1b; }
.badge-info { background: #cffafe; color: #155e75; }
.badge-default { background: var(--color-bg); color: var(--color-text-muted); }

/* ─── Buttons ────────────────────────────────────────────────────── */
.btn {
    display: inline-block; padding: 0.5rem 1rem; border-radius: var(--radius);
    text-decoration: none; font-size: 0.875rem; cursor: pointer; border: 1px solid transparent;
    font-weight: 500; transition: background 0.15s; line-height: 1.4;
}
.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-bg); }
.btn-link { background: none; border: none; color: var(--color-text-muted); padding: 0.5rem 0.75rem; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-full { width: 100%; text-align: center; }

/* ─── Forms & Filters ────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.35rem; font-weight: 600; font-size: 0.9rem; }
.form-group input, .form-group select {
    width: 100%; padding: 0.6rem 0.8rem; border: 1px solid var(--color-border);
    border-radius: var(--radius); font-size: 1rem; font-family: var(--font);
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; align-items: center; }
.filters input, .filters select {
    padding: 0.45rem 0.6rem; border: 1px solid var(--color-border); border-radius: var(--radius);
    font-size: 0.875rem; font-family: var(--font);
}
.inline-form { display: inline; }

/* ─── Login ──────────────────────────────────────────────────────── */
.login-body { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 1rem; }
.login-card {
    background: var(--color-surface); padding: 2.5rem; border-radius: var(--radius);
    box-shadow: 0 4px 6px rgba(0,0,0,0.07); width: 100%; max-width: 400px; text-align: center;
    border: 1px solid var(--color-border);
}
.login-card h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.login-subtitle { color: var(--color-text-muted); margin: 0 0 1.5rem; }

/* ─── Alert ──────────────────────────────────────────────────────── */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

/* ─── Voicemail Cards ────────────────────────────────────────────── */
.voicemail-card {
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 0.75rem; box-shadow: var(--shadow);
}
.voicemail-card.unhandled { border-left: 4px solid var(--color-warning); }
.voicemail-card.handled { border-left: 4px solid var(--color-success); opacity: 0.8; }
.voicemail-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.voicemail-meta { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.voicemail-body { margin: 0.5rem 0; }
.voicemail-duration { font-size: 0.85rem; color: var(--color-text-muted); margin-bottom: 0.35rem; }
.voicemail-player { width: 100%; height: 40px; }
.voicemail-actions { margin-top: 0.5rem; }

/* ─── Empty State ────────────────────────────────────────────────── */
.empty-state {
    text-align: center; padding: 3rem 1rem; background: var(--color-surface);
    border-radius: var(--radius); border: 1px solid var(--color-border);
}

/* ─── Filter Tabs ────────────────────────────────────────────────── */
.filter-tabs { display: flex; gap: 0; margin-bottom: 1.25rem; border-bottom: 2px solid var(--color-border); }
.tab {
    padding: 0.6rem 1.2rem; text-decoration: none; color: var(--color-text-muted);
    border-bottom: 2px solid transparent; margin-bottom: -2px; font-size: 0.9rem; font-weight: 500;
}
.tab:hover { color: var(--color-text); }
.tab.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }

/* ─── Chart ──────────────────────────────────────────────────────── */
.chart {
    display: flex; align-items: flex-end; gap: 2px; height: 180px; padding: 1rem 0;
    border-bottom: 2px solid var(--color-border); margin-bottom: 1.5rem; overflow-x: auto;
}
.chart-bar-wrapper {
    flex: 1; min-width: 18px; display: flex; flex-direction: column;
    align-items: center; height: 100%; justify-content: flex-end;
}
.chart-bar {
    background: var(--color-primary); border-radius: 3px 3px 0 0; min-height: 2px;
    width: 100%; max-width: 28px; position: relative; transition: height 0.3s;
}
.chart-bar:hover { background: var(--color-primary-dark); }
.chart-bar-label { position: absolute; top: -16px; left: 50%; transform: translateX(-50%); font-size: 0.65rem; color: var(--color-text-muted); white-space: nowrap; }
.chart-date { font-size: 0.6rem; color: var(--color-text-muted); margin-top: 4px; white-space: nowrap; }

/* ─── Pagination ─────────────────────────────────────────────────── */
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1.25rem; }
.pagination-info { font-size: 0.9rem; color: var(--color-text-muted); }

/* ─── Settings ───────────────────────────────────────────────────── */
.settings-form { max-width: 700px; }
.settings-section {
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius); padding: 1.25rem 1.5rem; margin-bottom: 1.25rem; box-shadow: var(--shadow);
}
.settings-section h2 { margin: 0 0 1rem; font-size: 1.1rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-help { display: block; font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.25rem; }
.checkbox-group { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 0.25rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; cursor: pointer; }
.checkbox-label input[type="checkbox"] { width: 1rem; height: 1rem; cursor: pointer; }
.form-group textarea {
    width: 100%; padding: 0.6rem 0.8rem; border: 1px solid var(--color-border);
    border-radius: var(--radius); font-size: 0.9rem; font-family: var(--font); resize: vertical;
}
.form-group textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.textarea-with-preview { position: relative; }
.textarea-with-preview textarea { padding-right: 5.5rem; }
.textarea-with-preview .btn-preview {
    position: absolute; top: 0.5rem; right: 0.5rem;
    font-size: 0.75rem; padding: 0.25rem 0.5rem; white-space: nowrap;
}
.settings-actions { margin-top: 1rem; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }

/* ─── Footer ─────────────────────────────────────────────────────── */
.footer { text-align: center; padding: 1.5rem; color: var(--color-text-muted); font-size: 0.8rem; margin-top: 2rem; }

/* ─── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .nav-links {
        display: none; position: absolute; top: 56px; left: 0; right: 0;
        background: var(--color-surface); flex-direction: column; padding: 0.75rem;
        border-bottom: 1px solid var(--color-border); box-shadow: var(--shadow); z-index: 99;
    }
    .nav.open .nav-links { display: flex; }
    .nav-toggle { display: block; }
    .nav-logout { margin-left: 0 !important; }

    .table thead { display: none; }
    .table, .table tbody, .table tr { display: block; }
    .table tr { margin-bottom: 0.75rem; border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; }
    .table td { display: flex; justify-content: space-between; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--color-bg); }
    .table td::before { content: attr(data-label); font-weight: 600; margin-right: 1rem; white-space: nowrap; }
    .table td:last-child { border-bottom: none; }

    .filters { flex-direction: column; }
    .filters input, .filters select, .filters .btn { width: 100%; }

    .voicemail-header { flex-direction: column; align-items: flex-start; }

    .form-row { grid-template-columns: 1fr; }

    h1 { font-size: 1.3rem; }
}
