/* ========== Reset & Base ========== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    color: #333;
    background: #f0f2f5;
}

/* ========== Header ========== */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: #1a1a2e;
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 20px;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    margin-right: 12px;
    padding: 4px 8px;
    border-radius: 4px;
}

.sidebar-toggle:hover {
    background: rgba(255,255,255,0.1);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo {
    font-size: 24px;
}

.header-brand h1 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 16px;
}

.system-status {
    font-size: 13px;
    padding: 4px 12px;
    border-radius: 12px;
    background: rgba(255,255,255,0.1);
}

.system-status.open {
    color: #4caf50;
}

.system-status.closed {
    color: #ff5252;
}

/* ========== Layout ========== */
.app-layout {
    display: flex;
    margin-top: 56px;
    min-height: calc(100vh - 56px);
}

/* ========== Sidebar ========== */
.sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: 240px;
    background: #16213e;
    overflow-y: auto;
    z-index: 900;
    transition: transform 0.3s ease;
}

.nav-list {
    list-style: none;
    padding: 8px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: rgba(255,255,255,0.05);
    color: #fff;
}

.nav-item.active {
    background: rgba(15, 52, 96, 0.5);
    color: #fff;
    border-left-color: #533483;
}

.nav-icon {
    font-size: 16px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

/* ========== Main Content ========== */
.main-content {
    margin-left: 240px;
    flex: 1;
    padding: 24px 32px;
    min-height: calc(100vh - 56px);
    overflow-y: auto;
}

/* ========== Loading ========== */
.loading-spinner {
    display: none;
    text-align: center;
    padding: 60px 0;
    color: #888;
}

.loading-spinner.visible {
    display: block;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e0e0e0;
    border-top-color: #0f3460;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========== Section Header ========== */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.section-header h2 {
    font-size: 22px;
    font-weight: 600;
    color: #1a1a2e;
}

/* ========== Cards ========== */
.cards-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    border-left: 4px solid #0f3460;
}

.stat-card.accent-purple {
    border-left-color: #533483;
}

.stat-card.accent-green {
    border-left-color: #4caf50;
}

.stat-card.accent-orange {
    border-left-color: #ff9800;
}

.stat-card.accent-red {
    border-left-color: #f44336;
}

.stat-card h3 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    margin-bottom: 8px;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #1a1a2e;
}

.stat-card .stat-sub {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
}

/* ========== Tables ========== */
.table-wrapper {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    overflow-x: auto;
    margin-bottom: 24px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    background: #f8f9fa;
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #666;
    border-bottom: 2px solid #e8e8e8;
    white-space: nowrap;
}

tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}

tbody tr:hover {
    background: #f8f9ff;
}

tbody tr:nth-child(even) {
    background: #fafafa;
}

tbody tr:nth-child(even):hover {
    background: #f0f2ff;
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #0f3460;
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #0a2647;
}

.btn-secondary {
    background: #e8e8e8;
    color: #333;
}

.btn-secondary:hover:not(:disabled) {
    background: #d8d8d8;
}

.btn-danger {
    background: #f44336;
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: #d32f2f;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-icon {
    padding: 5px 8px;
    font-size: 14px;
    line-height: 1;
    background: none;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    color: #666;
}

.btn-icon:hover {
    background: #f0f0f0;
    color: #333;
}

.btn-icon.danger:hover {
    background: #fee;
    color: #d32f2f;
    border-color: #fcc;
}

.btn-group {
    display: flex;
    gap: 4px;
}

/* ========== Badges ========== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-success {
    background: #e8f5e9;
    color: #2e7d32;
}

.badge-danger {
    background: #ffebee;
    color: #c62828;
}

.badge-warning {
    background: #fff3e0;
    color: #e65100;
}

.badge-info {
    background: #e3f2fd;
    color: #1565c0;
}

.badge-default {
    background: #f3e5f5;
    color: #6a1b9a;
}

.badge-neutral {
    background: #eeeeee;
    color: #616161;
}

/* ========== Forms ========== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #555;
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 9px 12px;
    font-size: 14px;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    background: #fff;
    color: #333;
    transition: border-color 0.15s;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #0f3460;
    box-shadow: 0 0 0 3px rgba(15,52,96,0.1);
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

.form-group input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-help {
    font-size: 12px;
    color: #999;
    margin-top: 4px;
}

/* ========== Audio Picker ========== */
.audio-picker {
    border: 2px dashed #d0d0d0;
    border-radius: 8px;
    padding: 8px;
    transition: border-color 0.2s, background 0.2s;
}
.audio-picker.drag-over {
    border-color: #0066cc;
    background: #f0f4ff;
}
.audio-picker audio {
    border-radius: 6px;
}

/* ========== Toggle Switch ========== */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #ccc;
    border-radius: 22px;
    transition: 0.2s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: #4caf50;
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

/* ========== Modal ========== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.visible {
    display: flex;
}

.modal-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    width: 90%;
    max-width: 640px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #eee;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a2e;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #999;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid #eee;
}

/* ========== Toast ========== */
.toast-container {
    position: fixed;
    top: 68px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    animation: toastIn 0.3s ease;
    max-width: 360px;
    word-break: break-word;
}

.toast.success {
    background: #2e7d32;
}

.toast.error {
    background: #c62828;
}

.toast.fadeout {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
    from { transform: translateX(100px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes toastOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100px); opacity: 0; }
}

/* ========== Filter Bar ========== */
.filter-bar {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 16px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.filter-bar .form-group {
    margin-bottom: 0;
    min-width: 150px;
}

.filter-bar .btn {
    align-self: flex-end;
}

/* ========== Pagination ========== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 0;
}

.pagination .btn {
    min-width: 36px;
    justify-content: center;
}

.pagination .page-info {
    font-size: 13px;
    color: #666;
    margin: 0 8px;
}

/* ========== Step List (Call Flows) ========== */
.step-list {
    list-style: none;
}

.step-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #f8f9fa;
    border: 1px solid #e8e8e8;
    border-radius: 6px;
    margin-bottom: 8px;
}

.step-item .step-number {
    width: 28px;
    height: 28px;
    background: #0f3460;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.step-item .step-body {
    flex: 1;
}

.step-item .step-type {
    font-weight: 600;
    font-size: 13px;
    color: #1a1a2e;
}

.step-item .step-config {
    font-size: 12px;
    color: #888;
    margin-top: 2px;
}

.step-item .step-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* ========== Schedule Grid ========== */
.schedule-grid {
    display: grid;
    grid-template-columns: 100px 1fr 1fr;
    gap: 1px;
    background: #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 24px;
}

.schedule-grid > div {
    background: #fff;
    padding: 10px 12px;
    font-size: 13px;
}

.schedule-grid .schedule-header {
    background: #f8f9fa;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
    color: #666;
}

.schedule-grid .day-label {
    font-weight: 600;
    display: flex;
    align-items: center;
}

.schedule-grid input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
}

/* ========== Voicemail Player ========== */
.vm-message {
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: box-shadow 0.15s;
}

.vm-message:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.vm-message.unread {
    border-left: 4px solid #0f3460;
}

.vm-message .vm-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.vm-message .vm-caller {
    font-weight: 600;
    font-size: 14px;
}

.vm-message .vm-date {
    font-size: 12px;
    color: #999;
}

.vm-message .vm-preview {
    font-size: 13px;
    color: #666;
    line-height: 1.4;
}

.vm-detail {
    display: none;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #eee;
}

.vm-detail.visible {
    display: block;
}

.vm-detail audio {
    width: 100%;
    margin: 8px 0;
}

.vm-detail .vm-transcription {
    font-size: 13px;
    line-height: 1.6;
    color: #444;
    background: #f8f9fa;
    padding: 12px;
    border-radius: 6px;
    margin-top: 8px;
}

/* ========== Empty State ========== */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: #999;
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 15px;
    margin-bottom: 16px;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .sidebar-toggle {
        display: block;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
    }

    .modal-card {
        width: 95%;
        max-height: 90vh;
    }

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

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

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-bar .form-group {
        min-width: auto;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .cards-row {
        grid-template-columns: 1fr;
    }
}

/* ========== IVR option row ========== */
.option-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.option-row input, .option-row select {
    padding: 7px 10px;
    font-size: 13px;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    font-family: inherit;
}

.option-row input[type="text"] {
    width: 60px;
}

.option-row select {
    flex: 1;
}

/* ========== Member list ========== */
.member-list {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    max-height: 200px;
    overflow-y: auto;
}

.member-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 13px;
}

.member-item:last-child {
    border-bottom: none;
}

/* ========== Misc ========== */
.text-muted {
    color: #999;
}

.text-sm {
    font-size: 12px;
}

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

.d-flex {
    display: flex;
}

.gap-8 {
    gap: 8px;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.clickable-row {
    cursor: pointer;
}

.sub-section {
    margin-top: 24px;
}

.sub-section h3 {
    font-size: 16px;
    font-weight: 600;
    color: #1a1a2e;
    margin-bottom: 12px;
}

/* ========== Dashboard Charts ========== */
.dash-section-title {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    margin: 20px 0 12px;
}

.dash-period-select {
    padding: 6px 12px;
    font-size: 13px;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-family: inherit;
}

.chart-container {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    margin-bottom: 16px;
    overflow-x: auto;
}

.chart-legend {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    font-size: 12px;
    color: #666;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    display: inline-block;
}

.bar-chart {
    display: flex;
    align-items: stretch;
    position: relative;
}

.chart-y-axis {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding-right: 8px;
    font-size: 11px;
    color: #999;
    min-width: 30px;
    text-align: right;
    padding-bottom: 20px;
}

.chart-bars {
    flex: 1;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    border-left: 1px solid #e0e0e0;
    border-bottom: 1px solid #e0e0e0;
    padding: 0 4px;
}

.chart-bar-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
}

.chart-bar-stack {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    width: 100%;
}

.chart-bar {
    width: 100%;
    min-height: 0;
    transition: height 0.3s ease;
    border-radius: 2px 2px 0 0;
}

.bar-answered {
    background: #4caf50;
}

.bar-missed {
    background: #f44336;
}

.bar-hourly {
    background: #0f3460;
}

.chart-label {
    font-size: 10px;
    color: #999;
    margin-top: 4px;
    white-space: nowrap;
    height: 16px;
    text-align: center;
}

.status-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
