/* =============================================
   Nexia Platform Admin — Clean Design
   Administrative palette · Responsive · Collapsible sidebar
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Apple-inspired neutral administrative palette */
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #f0f0f2;
    --bg-input: #f5f5f7;
    --bg-sidebar: #ffffff;
    --bg-sidebar-hover: #f0f0f2;
    --bg-sidebar-active: rgba(0, 113, 227, 0.08);
    --border: #e5e5e7;
    --border-light: #f0f0f2;
    --text-primary: #1d1d1f;
    --text-secondary: #6e6e73;
    --text-muted: #aeaeb2;
    --text-sidebar: #1d1d1f;
    --text-sidebar-muted: #86868b;
    --accent: #0071e3;
    --accent-hover: #0077ed;
    --accent-light: rgba(0, 113, 227, 0.08);
    --success: #34c759;
    --success-bg: rgba(52, 199, 89, 0.1);
    --warning: #ff9f0a;
    --warning-bg: rgba(255, 159, 10, 0.1);
    --danger: #ff3b30;
    --danger-bg: rgba(255, 59, 48, 0.1);
    --info: #5ac8fa;
    --info-bg: rgba(90, 200, 250, 0.1);
    --sidebar-w: 260px;
    --sidebar-collapsed: 0px;
    --topbar-h: 52px;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-size: 14px;
    line-height: 1.5;
}

/* ── Scrollbar (subtle) ── */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #c7c7cc;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #8e8e93;
}

/* ──────────────────────────────
   LOGIN PAGE
────────────────────────────── */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(160deg, #f5f5f7 0%, #e8e8ed 100%);
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    animation: fadeUp 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo h1 {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.login-logo p {
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 4px;
}

/* ──────────────────────────────
   LAYOUT
────────────────────────────── */
.layout {
    display: flex;
    min-height: 100vh;
}

/* ──────────────────────────────
   SIDEBAR (Apple Graphite)
────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: #ffffff;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    border-right: 1px solid var(--border);
    box-shadow: none;
}

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

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
    backdrop-filter: blur(4px);
}

.sidebar-overlay.active {
    display: block;
}

.sidebar-brand {
    padding: 24px 20px 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.3px;
}

.sidebar-brand small {
    color: var(--text-light);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    font-weight: 500;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 10px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-light);
    padding: 0 14px;
    margin-bottom: 8px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 14px;
    border-radius: 8px;
    color: #6e6e73;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
    margin-bottom: 1px;
    position: relative;
}

.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: var(--text);
}

.nav-item.active {
    background: var(--bg-sidebar-active);
    color: var(--accent);
}

.nav-item.active .nav-icon {
    stroke: var(--accent);
}

.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: all 0.2s ease;
}

.nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 9px;
    padding: 2px 7px;
    border-radius: 8px;
    font-weight: 700;
    min-width: 16px;
    text-align: center;
}

/* Sidebar footer */
.sidebar-footer {
    padding: 12px 10px 16px;
    border-top: 1px solid var(--border);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--bg);
}

.sidebar-user .avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #5856d6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 13px;
    flex-shrink: 0;
}

.sidebar-user .info .name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
}

.sidebar-user .info .role {
    font-size: 10px;
    color: var(--text-light);
}

.sidebar-footer .btn-ghost {
    color: var(--text-light);
    border-color: var(--border);
    font-size: 12px;
}

.sidebar-footer .btn-ghost:hover {
    background: var(--bg);
    color: var(--text);
    border-color: var(--accent);
}

/* Sidebar scrollbar */
.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.08);
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.15);
}

/* ── WhatsApp status dot ── */
.wa-status-indicator {
    display: flex;
    align-items: center;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

.status-dot.qr {
    background: var(--warning);
    box-shadow: 0 0 6px var(--warning);
    animation: pulse 1.5s infinite;
}

.status-dot.disconnected {
    background: var(--danger);
    box-shadow: 0 0 6px var(--danger);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

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

@media (max-width: 768px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }
}

/* ── Live chat input ── */
.chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}

.chat-input-bar input {
    flex: 1;
    border-radius: 20px;
    padding: 8px 14px;
}

.chat-input-bar .btn {
    border-radius: 20px;
    padding: 8px 18px;
}

/* ── QR container ── */
.qr-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px;
}

.qr-container img {
    border-radius: var(--radius);
    max-width: 240px;
}

.wa-status-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
}

.wa-status-banner.connected {
    background: var(--success-bg);
    color: #248a3d;
}

.wa-status-banner.disconnected {
    background: var(--danger-bg);
    color: #d70015;
}

.wa-status-banner.qr {
    background: var(--warning-bg);
    color: #8a6914;
}



/* ──────────────────────────────
   MAIN CONTENT
────────────────────────────── */
.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.main.expanded {
    margin-left: 0;
}

.topbar {
    height: var(--topbar-h);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.menu-toggle {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    transition: var(--transition);
    display: flex;
    align-items: center;
}

.menu-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.topbar-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.content {
    padding: 20px;
    max-width: 1400px;
}

/* ──────────────────────────────
   STAT CARDS
────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-card .label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 6px;
    font-weight: 600;
}

.stat-card .value {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -1px;
    margin-bottom: 2px;
}

.stat-card .sub {
    font-size: 11px;
    color: var(--text-secondary);
}

.stat-card.accent .value {
    color: var(--accent);
}

.stat-card.success .value {
    color: var(--success);
}

.stat-card.warning .value {
    color: var(--warning);
}

.stat-card.info .value {
    color: #5856d6;
}

/* ──────────────────────────────
   CARDS & TABLES
────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-light);
}

.card-header h3 {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.card-body {
    padding: 18px;
}

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

th {
    text-align: left;
    padding: 10px 14px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    background: var(--bg-primary);
}

td {
    padding: 10px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-secondary);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: var(--bg-hover);
}

/* ──────────────────────────────
   FORMS
────────────────────────────── */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    transition: var(--transition);
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
    background: var(--bg-secondary);
}

textarea {
    resize: vertical;
    min-height: 100px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
}

/* ──────────────────────────────
   BUTTONS
────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    letter-spacing: -0.1px;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 2px 8px rgba(0, 113, 227, 0.3);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #ff453a;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

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

/* ──────────────────────────────
   BADGES
────────────────────────────── */
.badge {
    display: inline-flex;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
}

.badge-info {
    background: var(--info-bg);
    color: #5856d6;
}

.badge-accent {
    background: var(--accent-light);
    color: var(--accent);
}

/* ──────────────────────────────
   MODAL
────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

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

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: fadeUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-light);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.modal-close {
    background: var(--bg-hover);
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--border);
    color: var(--text-primary);
}

.modal-body {
    padding: 22px;
}

.modal-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--border-light);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ── ALERTS ── */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-size: 13px;
    font-weight: 500;
}

.alert-success {
    background: var(--success-bg);
    border: 1px solid rgba(52, 199, 89, 0.2);
    color: #248a3d;
}

.alert-error {
    background: var(--danger-bg);
    border: 1px solid rgba(255, 59, 48, 0.2);
    color: #d70015;
}

/* ──────────────────────────────
   CHAT VIEWER
────────────────────────────── */
.chat-messages {
    max-height: 500px;
    overflow-y: auto;
    padding: 14px;
    background: var(--bg-primary);
}

.chat-msg {
    display: flex;
    margin-bottom: 10px;
}

.chat-msg.user {
    justify-content: flex-end;
}

.chat-bubble {
    max-width: 70%;
    padding: 9px 13px;
    border-radius: 18px;
    font-size: 13px;
    line-height: 1.45;
}

.chat-msg.user .chat-bubble {
    background: var(--accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-msg.assistant .chat-bubble {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-time {
    font-size: 9px;
    color: var(--text-muted);
    margin-top: 3px;
}

/* ── Department dot ── */
.dept-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

/* ── Notification bell ── */
.notif-btn {
    position: relative;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.notif-btn:hover {
    background: var(--border);
}

.notif-count {
    position: absolute;
    top: -3px;
    right: -3px;
    background: var(--danger);
    color: white;
    font-size: 8px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

/* ──────────────────────────────
   RESPONSIVE
────────────────────────────── */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .main {
        margin-left: 0 !important;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .grid-2 {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .health-grid {
        grid-template-columns: 1fr 1fr;
    }

    .bridge-grid {
        grid-template-columns: 1fr;
    }

    /* Modal improvements for tablets */
    .modal {
        width: 95%;
        max-height: 90vh;
    }

    .modal-content {
        max-width: 100% !important;
    }
}

@media (max-width: 640px) {
    .content {
        padding: 12px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .health-grid {
        grid-template-columns: 1fr;
    }

    .topbar-title {
        font-size: 14px;
    }

    .login-card {
        padding: 32px 24px;
    }

    /* Table responsive: horizontal scroll */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -12px;
        padding: 0 12px;
    }

    table {
        font-size: 12px;
        min-width: 600px;
    }

    th,
    td {
        padding: 8px 10px;
        white-space: nowrap;
    }

    .card-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }

    .chat-bubble {
        max-width: 85%;
    }

    /* Modal full-width on mobile */
    .modal {
        width: 100%;
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 92vh;
        margin-top: auto;
    }

    .modal-header {
        padding: 14px 16px;
        position: sticky;
        top: 0;
        background: var(--bg-card);
        z-index: 5;
    }

    .modal-body {
        padding: 16px;
    }

    /* Wizard responsive */
    .wizard-steps {
        gap: 8px !important;
    }

    .step-circle {
        width: 28px !important;
        height: 28px !important;
        font-size: 12px !important;
    }

    /* Bridge card buttons */
    .bridge-actions {
        flex-wrap: wrap;
    }
}

/* ── Pulse animation for health dots ── */
@keyframes pulse2 {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ── Table responsive wrapper ── */
.table-responsive {
    overflow-x: auto;
    border-radius: var(--radius);
}

/* ── Bridge grid ── */
.bridge-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

/* ── Modal stacking ── */
.modal + .modal {
    z-index: 205;
}

.modal + .modal + .modal {
    z-index: 210;
}

/* ── Smooth card entrance ── */
@keyframes cardFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.stat-card, .health-card, .bridge-card {
    animation: cardFadeIn 0.3s ease-out backwards;
}

.stat-card:nth-child(1) { animation-delay: 0.02s; }
.stat-card:nth-child(2) { animation-delay: 0.04s; }
.stat-card:nth-child(3) { animation-delay: 0.06s; }
.stat-card:nth-child(4) { animation-delay: 0.08s; }
.stat-card:nth-child(5) { animation-delay: 0.10s; }
.stat-card:nth-child(6) { animation-delay: 0.12s; }