:root {
    --sidebar-width: 260px;
    --sidebar-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #0f172a;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --accent: #facc15;
    --accent-hover: #eab308;
    --primary: #0f172a;
    --primary-dark: #020617;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body, .app-body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* App layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    flex-shrink: 0;
    padding: 1.25rem 1rem;
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .5rem .75rem 1.25rem;
    flex-shrink: 0;
}

.brand-icon {
    width: 2rem;
    height: 2rem;
    color: var(--accent);
    flex-shrink: 0;
}

.brand-icon svg { width: 100%; height: 100%; }

.brand-name {
    font-weight: 700;
    font-size: .95rem;
    color: #fff;
    line-height: 1.3;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .85rem .75rem;
    margin-bottom: .75rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius);
    flex-shrink: 0;
}

.sidebar-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: #fff;
    color: var(--sidebar-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    flex-shrink: 0;
}

.sidebar-user-info {
    min-width: 0;
}

.sidebar-user-info strong {
    display: block;
    color: #fff;
    font-size: .9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-info span {
    font-size: .75rem;
    color: var(--sidebar-text);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    margin: 0 -.25rem;
    padding: 0 .25rem;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem .85rem;
    margin-bottom: .2rem;
    border-radius: 10px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    transition: background .15s, color .15s;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.nav-item.active {
    background: var(--accent);
    color: var(--sidebar-text-active);
    font-weight: 600;
}

.nav-item.active .nav-icon { color: var(--sidebar-text-active); }

.nav-icon {
    width: 1.15rem;
    height: 1.15rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-icon svg { width: 100%; height: 100%; }

.nav-text { flex: 1; }

.nav-badge {
    background: var(--danger);
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    padding: .1rem .45rem;
    border-radius: 999px;
    min-width: 1.25rem;
    text-align: center;
}

.sidebar-footer {
    flex-shrink: 0;
    padding-top: .75rem;
    margin-top: .5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-logout:hover { color: #fca5a5; }

.main-content {
    flex: 1;
    min-width: 0;
    background: var(--bg);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.75rem 2rem 2.5rem;
}

/* Typography */
h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: .35rem;
    color: var(--text);
}

h2, .section-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text);
}

h3 {
    font-size: 1rem;
    margin-bottom: .75rem;
    color: var(--text);
}

.subtitle, .page-desc {
    color: var(--text-muted);
    font-size: .925rem;
    margin-bottom: 0;
}

.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 { margin-bottom: .35rem; }

.section-block {
    margin-bottom: 2rem;
}

.action-row, .quick-actions {
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

/* Cards */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.35rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card-danger {
    border-color: #fecaca;
    background: #fef2f2;
}

.card h3 { color: var(--text-muted); font-weight: 600; }

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stats-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stats-grid-5 { grid-template-columns: repeat(5, 1fr); }

.stats-grid-sm .stat-card { padding: 1rem; }
.stats-grid-sm .stat-value { font-size: 1.5rem; }

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.25rem 1.35rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    text-align: left;
}

.stat-card-link {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s, box-shadow .15s, transform .15s;
}

.stat-card-link:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 14px rgba(37, 99, 235, .12);
    transform: translateY(-1px);
}

.stat-card-link.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, .15);
}

.stat-card-lg {
    max-width: 420px;
    padding: 2rem;
}

.stat-card-lg .stat-value { font-size: 2rem; }

.stat-danger {
    border-color: #fecaca;
    background: #fef2f2;
}

.stat-danger .stat-value { color: var(--danger); }

.stat-label {
    font-size: .8rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: .35rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.stat-sub {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: .35rem;
}

.stat-sub a { color: var(--text-muted); }

.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }

/* Tables */
.table-scroll { overflow-x: auto; }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

.table th {
    text-align: left;
    padding: .75rem 1rem;
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}

.table td {
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table-sm td, .table-sm th { padding: .5rem .65rem; }

.table-actions {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
    align-items: center;
}

.row-danger { background: #fef2f2 !important; }
.row-muted { opacity: .55; }
.row-new-cycle { background: #fffbeb; }

.text-center { text-align: center; }

/* Badges */
.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
}

.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-muted { background: #f1f5f9; color: #64748b; }
.badge-lg { font-size: .82rem; padding: .35rem .75rem; }

input.input-readonly,
.input-readonly {
    background: var(--surface-2, #f1f5f9);
    color: var(--text-muted, #64748b);
    cursor: default;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    padding: .55rem 1.1rem;
    border: none;
    border-radius: 10px;
    font-size: .875rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: all .15s;
    font-family: inherit;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: var(--sidebar-bg);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--sidebar-bg);
    color: #fff;
}

.btn-secondary:hover { background: var(--primary-dark); }

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-outline {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--bg);
    border-color: #cbd5e1;
}

.btn-sm { padding: .35rem .7rem; font-size: .8rem; border-radius: 8px; }
.btn-block { display: flex; width: 100%; }

/* Forms */
.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    margin-bottom: .35rem;
    font-weight: 600;
    font-size: .875rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: .6rem .85rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: .9rem;
    font-family: inherit;
    background: #fff;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.25);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-actions {
    display: flex;
    gap: .75rem;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

.hint {
    color: var(--text-muted);
    font-size: .8rem;
    margin-top: .25rem;
}

.inline-form {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.inline-form select {
    padding: .45rem .65rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.admin-session-adjust {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    width: 100%;
}

.admin-session-adjust .hint {
    flex-basis: 100%;
}

.add-form .form-row {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
}

.add-form input {
    flex: 1;
    min-width: 100px;
    padding: .45rem .65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.input-sm {
    padding: .4rem .6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .85rem;
}

.filter-form {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.filter-form input,
.filter-form select {
    padding: .45rem .65rem;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: .75rem;
}

.search-form { display: flex; gap: .5rem; }

.search-form input {
    min-width: 14rem;
    padding: .45rem .75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.patient-pick-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: .35rem;
}

.patient-pick-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .55rem .75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

.patient-pick-list a {
    font-weight: 600;
    text-decoration: none;
}

.patient-pick-list a:hover {
    text-decoration: underline;
}

/* Alerts */
.alert {
    padding: .85rem 1.1rem;
    border-radius: 10px;
    margin-bottom: 1.25rem;
    font-size: .9rem;
    font-weight: 500;
}

.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

/* Login */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--sidebar-bg);
    padding: 1.5rem;
}

.login-box {
    background: var(--card);
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border);
}

.login-box h1 {
    text-align: center;
    color: var(--text);
    font-size: 1.35rem;
}

.login-box .subtitle {
    text-align: center;
    margin-bottom: 1.5rem;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .65rem;
    margin-bottom: .75rem;
}

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

/* Patient cards */
.patient-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.patient-card {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

.patient-card-link {
    text-decoration: none;
    color: inherit;
    transition: box-shadow .15s, border-color .15s;
}

.patient-card-link:hover {
    box-shadow: var(--shadow-md);
    border-color: #cbd5e1;
}

.patient-card.card-danger { border-color: #fecaca; }

.patient-card-header {
    padding: 1rem 1.1rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: .5rem;
    border-bottom: 1px solid var(--border);
}

.patient-card-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.patient-card-body { padding: 1rem 1.1rem; flex: 1; }

.info-row {
    display: flex;
    justify-content: space-between;
    font-size: .85rem;
    padding: .3rem 0;
    gap: .5rem;
}

.info-row span { color: var(--text-muted); flex-shrink: 0; }

.patient-card-action {
    padding: .85rem 1.1rem 1.1rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.passive-form {
    margin: 0;
}

.patient-card-footer {
    border-top: 1px solid var(--border);
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.25rem 0;
}

/* Responsive */
@media (max-width: 1024px) {
    .stats-grid-3,
    .stats-grid-5 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .app-layout { flex-direction: column; }

    .sidebar {
        width: 100%;
        height: auto;
        min-height: auto;
        position: relative;
        padding: 1rem;
    }

    .sidebar-nav {
        max-height: 50vh;
    }

    .container { padding: 1.25rem 1rem 2rem; }

    .form-row,
    .two-col,
    .info-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid,
    .stats-grid-3,
    .stats-grid-5 {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 480px) {
    .stats-grid,
    .stats-grid-3,
    .stats-grid-5 {
        grid-template-columns: 1fr;
    }
}

.salary-detail-row > td {
    background: var(--bg-soft, #f7f8fa);
    padding: 1rem 1.1rem !important;
}

.salary-detail-panel h4 {
    font-size: 0.95rem;
}

.salary-detail-panel .table {
    background: #fff;
}
