/* === Stat cards === */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--sp-md);
    margin-bottom: var(--sp-md);
}

.stat-card {
    text-align: center;
    padding: var(--sp-lg) var(--sp-md);
}

.stat-label {
    font-size: var(--fs-xs);
    color: var(--c-text-muted);
    font-weight: 600;
    margin-bottom: var(--sp-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: var(--fs-2xl);
    font-weight: 700;
    color: var(--c-primary);
}

/* === Tables (Excel-style grid) === */
/* Restyled to match the Excel-style report grid: hairline gridlines on
   every cell, green header row, sticky header, row hover highlight.
   Applies to every .data-table across all modules (patients, doctors,
   catalogue, quotes, orders, invoices, results). */

.data-table-wrap {
    /* Do NOT set overflow or max-height here - that creates a competing
       scroll container. .main-area (overflow:auto) is the sole scroll
       container, so position:sticky; top:0 on th sticks to the top of
       .main-area and stays frozen when scrolling. Horizontal overflow
       of wide tables is handled by .main-area's overflow-x:auto. */
    border: 1px solid #d4d4d4;
    border-radius: var(--radius);
}

.data-table {
    width: 100%;
    /* border-collapse: separate + border-spacing: 0 gives the same
       seamless gridline look as collapse, but is more reliable with
       position:sticky on th cells (collapse can break sticky borders
       in some browsers). */
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--fs-sm);
    min-width: 400px;
}

/* Header row - Excel green */
.data-table thead {
    background: #217346;
    color: #fff;
}

.data-table th {
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid #1a5c38;
    /* Sticky header - stays visible when scrolling, like Excel freeze top row */
    position: sticky;
    top: 0;
    z-index: 2;
}

/* Body cells - hairline gridlines on every side (the Excel look) */
.data-table td {
    padding: 6px 12px;
    border: 1px solid #e0e0e0;
    white-space: nowrap;
}

/* Numeric / money / count cells - right-aligned tabular figures */
.data-table td.num,
.data-table th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Row hover - light green like Excel cell selection */
.data-table tbody tr {
    transition: background var(--t-fast);
}

.data-table tbody tr:hover {
    background: #eaf3ee;
}

/* Row-number gutter (injected by JS) - grey, like Excel row headers */
.data-table .xl-rownum {
    background: #f3f3f3;
    color: #595959;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    width: 40px;
    min-width: 40px;
    border: 1px solid #d4d4d4;
    /* Sticky so row numbers stay visible on horizontal scroll */
    position: sticky;
    left: 0;
    z-index: 1;
}

/* Header cell for the row-number column.
   This cell sits at the intersection of the sticky top row (z-index: 2)
   and the sticky left column (z-index: 1), so it needs z-index: 3 to
   stay visible above both when scrolling in either direction. */
.data-table th.xl-rownum-head {
    background: #f3f3f3;
    color: #595959;
    border: 1px solid #d4d4d4;
    width: 40px;
    min-width: 40px;
    text-align: center;
    text-transform: none;
    letter-spacing: 0;
    font-size: 11px;
    position: sticky;
    top: 0;
    left: 0;
    z-index: 3;
}

/* Action buttons inside cells - keep compact */
.data-table td:last-child {
    white-space: nowrap;
}

@media print {
    .data-table-wrap {
        border: none;
    }
    .data-table th {
        position: static;
    }
    .data-table .xl-rownum,
    .data-table th.xl-rownum-head {
        display: none;
    }
    .pagination-bar { display: none; }
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-xs);
    padding: var(--sp-sm) var(--sp-lg);
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
    font-weight: 600;
    cursor: pointer;
    transition: background var(--t-fast), opacity var(--t-fast);
    text-decoration: none;
    min-height: 40px; /* touch target */
}

.btn-primary {
    background: var(--c-primary);
    color: #fff;
}
.btn-primary:hover { background: var(--c-primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    background: var(--c-secondary);
    color: #fff;
}
.btn-secondary:hover { background: #4a5a6a; }

.btn-danger {
    background: var(--c-danger);
    color: #fff;
}

.btn-sm {
    padding: var(--sp-xs) var(--sp-sm);
    font-size: var(--fs-xs);
    min-height: 32px;
}

.btn-block { width: 100%; }

/* === -orms === */
.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--sp-xs);
    margin-bottom: var(--sp-md);
}

.form-label {
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--c-text);
}

.form-input, .form-select, .form-textarea {
    padding: var(--sp-sm) var(--sp-md);
    border: 2px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-size: var(--fs-base);
    transition: border-color var(--t-fast);
    min-height: 40px; /* touch target */
    width: 100%;
    background: var(--c-surface);
    color: var(--c-text);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    border-color: var(--c-focus);
    outline: none;
}

.form-input[aria-invalid="true"] {
    border-color: var(--c-danger);
}

.form-error {
    color: var(--c-danger);
    font-size: var(--fs-xs);
    min-height: 1em;
}

.form-error-general {
    color: var(--c-danger);
    font-size: var(--fs-sm);
    text-align: center;
    padding: var(--sp-sm);
    background: #fdf2f2;
    border-radius: var(--radius-sm);
    margin-bottom: var(--sp-md);
    display: none;
}

.form-error-general.visible { display: block; }

/* === Login page === */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    background: linear-gradient(135deg, var(--c-primary), var(--c-primary-hover));
    padding: var(--sp-md);
}

.login-card {
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: var(--sp-xl);
    width: 100%;
    max-width: 400px;
}

.login-title {
    font-size: var(--fs-xl);
    color: var(--c-primary);
    text-align: center;
    margin-bottom: var(--sp-xs);
}

.login-subtitle {
    text-align: center;
    color: var(--c-text-muted);
    font-size: var(--fs-sm);
    margin-bottom: var(--sp-xl);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: var(--sp-md);
}

.login-footer {
    margin-top: var(--sp-lg);
    text-align: center;
}

/* === Permission tags === */
.perm-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-xs);
    margin-top: var(--sp-sm);
}

.perm-tag {
    display: inline-block;
    padding: 2px var(--sp-sm);
    background: var(--c-surface-alt);
    border: 1px solid var(--c-border);
    border-radius: 12px;
    font-size: var(--fs-xs);
    color: var(--c-text-muted);
    white-space: nowrap;
}

/* === Role cards === */
.role-card {
    margin-bottom: var(--sp-md);
}

.role-name {
    font-size: var(--fs-md);
    color: var(--c-primary);
    margin-bottom: var(--sp-xs);
    font-weight: 600;
}

.role-desc {
    font-size: var(--fs-sm);
    color: var(--c-text-muted);
    margin-bottom: var(--sp-sm);
}

/* === Status badges === */
.badge {
    display: inline-block;
    padding: 2px var(--sp-sm);
    border-radius: 12px;
    font-size: var(--fs-xs);
    font-weight: 600;
    white-space: nowrap;
}

.badge-success { background: #d4efdf; color: #1d8348; }
.badge-danger { background: #fadbd8; color: #922b21; }
.badge-info { background: #d6eaf8; color: #1a5276; }
.badge-muted { background: var(--c-surface-alt); color: var(--c-text-muted); }

/* === Coming soon === */
.coming-soon {
    text-align: center;
    padding: var(--sp-xl);
}

.coming-soon-icon {
    font-size: 48px;
    margin-bottom: var(--sp-md);
    opacity: 0.3;
}

.coming-soon-title {
    font-size: var(--fs-lg);
    color: var(--c-text-muted);
    margin-bottom: var(--sp-sm);
}

.coming-soon-text {
    font-size: var(--fs-sm);
    color: var(--c-text-muted);
}

/* === Loading / empty / error states === */
.state-loading, .state-empty, .state-error {
    padding: var(--sp-xl);
    text-align: center;
    font-size: var(--fs-sm);
}

.state-loading { color: var(--c-text-muted); }
.state-empty { color: var(--c-text-muted); }
.state-error { color: var(--c-danger); }

/* === Sections === */
.section {
    margin-bottom: var(--sp-lg);
}

.section-title {
    font-size: var(--fs-md);
    color: var(--c-primary);
    margin-bottom: var(--sp-sm);
    padding-bottom: var(--sp-xs);
    border-bottom: 2px solid var(--c-border);
    font-weight: 600;
}

/* === Utility === */
.text-muted { color: var(--c-text-muted); }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.mt-md { margin-top: var(--sp-md); }
.mb-md { margin-bottom: var(--sp-md); }
.hidden { display: none !important; }

/* ============================================
   Responsive breakpoints
   Mobile-first: base = phone (<640px)
   ============================================ */

/* - - Phone: <640px - compact topbar - - */
@media (max-width: 639px) {
    .topbar {
        padding: 0 var(--sp-xs);
    }

    .topbar-logo {
        font-size: var(--fs-md);
    }

    /* Hide "Online" text, keep just the dot */
    .conn-text {
        display: none;
    }

    .conn-indicator {
        gap: 0;
    }

    /* Hide username on very small screens */
    .topbar-user {
        display: none;
    }

    /* Compact sign-out button - icon only */
    .topbar-right .btn {
        padding: var(--sp-xs) var(--sp-sm);
        font-size: var(--fs-xs);
        min-height: 32px;
        white-space: nowrap;
    }
}
/* - - Tablet: - -640px - - */
@media (min-width: 640px) {
    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Restore username and Online text on tablet+ */
    .topbar-user {
        display: block;
        max-width: 150px;
    }

    .conn-text {
        display: inline;
    }
}

/* - - Desktop: - -1024px - - */
@media (min-width: 1024px) {
    .stat-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .topbar-user {
        max-width: 200px;
    }

    /* Sidebar is visible on desktop - can be collapsed/expanded */
    .sidebar {
        position: static;
        transform: none;
    }

    /* Show hamburger toggle on desktop too - for collapse/expand */
    .sidebar-toggle {
        display: flex;
    }

    .sidebar-overlay {
        display: none !important;
    }

    .main-area {
        padding: var(--sp-lg);
    }
}

/* - - Wide desktop: - -1280px - - */
@media (min-width: 1280px) {
    .stat-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ============================================
   Mobile sidebar behavior (<1024px)
   Sidebar is off-canvas, toggled by hamburger
   ============================================ */
@media (max-width: 1023px) {
    .sidebar {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        bottom: 0;
        width: var(--sidebar-w);
        transform: translateX(-100%);
        z-index: 95;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }
}

/* === Print === */
@media print {
    .topbar, .sidebar, .statusbar, .sidebar-toggle, .sidebar-overlay {
        display: none !important;
    }
    .main-area {
        padding: 0;
        overflow: visible;
    }
    .app-shell {
        height: auto;
        overflow: visible;
    }
}
