/*
 * SIMAS design system. Mobile first: the base rules target phones, wider screens are added with
 * min-width queries. Kemenkes teal is the brand colour; text-bearing teal uses the darker
 * --primary so white text on it meets WCAG AA contrast.
 */

:root {
    --brand: #00a19a;
    --primary: #00807a;
    --primary-dark: #00665f;
    --primary-soft: #e5f4f3;
    --primary-ring: rgb(0 128 122 / 0.25);
    --navy: #16324f;
    --lime: #8cc63f;

    --bg: #f3f6f8;
    --surface: #ffffff;
    --surface-muted: #f8fafb;
    --border: #e2e8ed;
    --border-strong: #cfd8df;
    --text: #17242f;
    --muted: #586876;
    --subtle: #8a98a5;

    --success: #15803d;
    --success-soft: #e8f6ee;
    --warning: #a35a06;
    --warning-soft: #fff4e0;
    --danger: #c62828;
    --danger-soft: #fdecec;
    --info: #0b6e8a;
    --info-soft: #e4f3f8;

    /* Names used by the page stylesheets (login, print, unduh-dokumen) and app.css. */
    --dark: var(--text);
    --light: var(--surface-muted);
    --gray-100: #f1f4f6;
    --gray-200: var(--border);
    --gray-300: var(--border-strong);
    --gray-400: var(--subtle);
    --gray-500: #6b7b88;
    --gray-600: var(--muted);
    --gray-700: #34444f;
    --gray-800: #1f2d38;

    --font: 'Plus Jakarta Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --radius-sm: 8px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --shadow-sm: 0 1px 2px rgb(16 40 60 / 0.06);
    --shadow: 0 1px 3px rgb(16 40 60 / 0.08), 0 1px 2px rgb(16 40 60 / 0.04);
    --shadow-md: 0 6px 16px -4px rgb(16 40 60 / 0.12);
    --shadow-lg: 0 16px 40px -12px rgb(16 40 60 / 0.25);
    --transition: 0.18s ease;

    --sidebar-width: 268px;
    --header-height: 60px;

    /* Colours that change with the theme; the dark values are below. */
    --on-primary: #fff;
    --on-solid: #fff;
    --navy-text: var(--navy);
    --navy-soft: #e8eef5;
    --success-border: #bfe5cd;
    --success-text: #12632f;
    --success-hover: #116632;
    --success-soft-hover: #d5f0df;
    --warning-border: #f5d9a8;
    --warning-text: #7a4304;
    --warning-soft-hover: #ffe9c2;
    --danger-border: #f6c9c9;
    --danger-text: #9b1c1c;
    --danger-hover: #a51f1f;
    --danger-soft-hover: #fad7d7;
    --info-border: #bfe1ec;
    --info-text: #0a5a70;
    --header-bg: rgb(255 255 255 / 0.92);
    --overlay: rgb(15 30 45 / 0.45);
    --chart-teal: #00a19a;
    --chart-navy: #1e3a5f;
    --chart-gold: #d99a1e;
    --chart-amber: #f7b32b;
    --chart-grid: rgb(0 0 0 / 0.08);
}

/*
 * Dark theme: chosen with the header button (stored per browser) or, until then, following the device
 * setting. The two selectors carry the same values; keep them in sync.
 */
:root[data-theme="dark"] {
    color-scheme: dark;

    --brand: #22b8b0;
    /* Bright teal with dark text on it: white on a dark-mode teal would be too faint. */
    --primary: #2bb3ab;
    --primary-dark: #5fd0c8;
    --primary-soft: rgb(43 179 171 / 0.16);
    --primary-ring: rgb(43 179 171 / 0.35);
    --on-primary: #04211f;
    --navy-text: #9db8d9;
    --navy-soft: rgb(157 184 217 / 0.14);

    --bg: #0f171e;
    --surface: #16212b;
    --surface-muted: #1b2833;
    --border: #26343f;
    --border-strong: #344552;
    --text: #e6edf3;
    --muted: #a3b1bd;
    --subtle: #7d8c98;

    --success: #3fb96b;
    --success-soft: rgb(63 185 107 / 0.15);
    --success-border: rgb(63 185 107 / 0.4);
    --success-text: #9de3b5;
    --success-hover: #5fcf86;
    --success-soft-hover: rgb(63 185 107 / 0.25);
    --warning: #f0b44c;
    --warning-soft: rgb(240 180 76 / 0.14);
    --warning-border: rgb(240 180 76 / 0.4);
    --warning-text: #f6cf8a;
    --warning-soft-hover: rgb(240 180 76 / 0.24);
    --danger: #f26b6b;
    --danger-soft: rgb(242 107 107 / 0.14);
    --danger-border: rgb(242 107 107 / 0.4);
    --danger-text: #ffb3b3;
    --danger-hover: #f58b8b;
    --danger-soft-hover: rgb(242 107 107 / 0.24);
    --info: #4fb8d8;
    --info-soft: rgb(79 184 216 / 0.14);
    --info-border: rgb(79 184 216 / 0.4);
    --info-text: #a5dcef;
    --on-solid: #0b1410;

    --gray-100: #1d2a35;
    --gray-500: #8494a1;
    --gray-700: #c5d0d9;
    --gray-800: #dde5ec;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.35);
    --shadow: 0 1px 3px rgb(0 0 0 / 0.4), 0 1px 2px rgb(0 0 0 / 0.3);
    --shadow-md: 0 6px 16px -4px rgb(0 0 0 / 0.5);
    --shadow-lg: 0 16px 40px -12px rgb(0 0 0 / 0.6);
    --header-bg: rgb(22 33 43 / 0.92);
    --overlay: rgb(0 0 0 / 0.6);

    --chart-teal: #2ec4bb;
    --chart-navy: #8fb3e0;
    --chart-gold: #e6ac3a;
    --chart-amber: #f7c35b;
    --chart-grid: rgb(255 255 255 / 0.08);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --brand: #22b8b0;
        /* Bright teal with dark text on it: white on a dark-mode teal would be too faint. */
        --primary: #2bb3ab;
        --primary-dark: #5fd0c8;
        --primary-soft: rgb(43 179 171 / 0.16);
        --primary-ring: rgb(43 179 171 / 0.35);
        --on-primary: #04211f;
        --navy-text: #9db8d9;
        --navy-soft: rgb(157 184 217 / 0.14);

        --bg: #0f171e;
        --surface: #16212b;
        --surface-muted: #1b2833;
        --border: #26343f;
        --border-strong: #344552;
        --text: #e6edf3;
        --muted: #a3b1bd;
        --subtle: #7d8c98;

        --success: #3fb96b;
        --success-soft: rgb(63 185 107 / 0.15);
        --success-border: rgb(63 185 107 / 0.4);
        --success-text: #9de3b5;
        --success-hover: #5fcf86;
        --success-soft-hover: rgb(63 185 107 / 0.25);
        --warning: #f0b44c;
        --warning-soft: rgb(240 180 76 / 0.14);
        --warning-border: rgb(240 180 76 / 0.4);
        --warning-text: #f6cf8a;
        --warning-soft-hover: rgb(240 180 76 / 0.24);
        --danger: #f26b6b;
        --danger-soft: rgb(242 107 107 / 0.14);
        --danger-border: rgb(242 107 107 / 0.4);
        --danger-text: #ffb3b3;
        --danger-hover: #f58b8b;
        --danger-soft-hover: rgb(242 107 107 / 0.24);
        --info: #4fb8d8;
        --info-soft: rgb(79 184 216 / 0.14);
        --info-border: rgb(79 184 216 / 0.4);
        --info-text: #a5dcef;
        --on-solid: #0b1410;

        --gray-100: #1d2a35;
        --gray-500: #8494a1;
        --gray-700: #c5d0d9;
        --gray-800: #dde5ec;

        --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.35);
        --shadow: 0 1px 3px rgb(0 0 0 / 0.4), 0 1px 2px rgb(0 0 0 / 0.3);
        --shadow-md: 0 6px 16px -4px rgb(0 0 0 / 0.5);
        --shadow-lg: 0 16px 40px -12px rgb(0 0 0 / 0.6);
        --header-bg: rgb(22 33 43 / 0.92);
        --overlay: rgb(0 0 0 / 0.6);

        --chart-teal: #2ec4bb;
        --chart-navy: #8fb3e0;
        --chart-gold: #e6ac3a;
        --chart-amber: #f7c35b;
        --chart-grid: rgb(255 255 255 / 0.08);
    }
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    font-size: 0.9375rem;
    line-height: 1.55;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

body.nav-open {
    overflow: hidden;
}

img {
    max-width: 100%;
}

a {
    color: var(--primary);
}

h1,
h2,
h3,
h4 {
    line-height: 1.3;
    letter-spacing: -0.01em;
}

hr {
    border: 0;
    border-top: 1px solid var(--border);
}

small {
    font-size: 0.8125rem;
}

/* ------------------------------------------------------------------ App shell */

.app-container {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1000;
    width: min(var(--sidebar-width), 85vw);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.25s ease, visibility 0.25s;
    visibility: hidden;
}

.sidebar.show {
    transform: translateX(0);
    visibility: visible;
    box-shadow: var(--shadow-lg);
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 999;
    background: var(--overlay);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.sidebar.show + .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1rem 0.875rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand {
    flex: 1;
    min-width: 0;
}

.sidebar-logo-link {
    display: block;
    border-radius: var(--radius-sm);
}

.sidebar-logo {
    display: block;
    width: 100%;
    max-width: 190px;
    height: auto;
}

.sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.sidebar-close:hover {
    background: var(--gray-100);
    color: var(--text);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-label {
    padding: 0.5rem 0.75rem 0.375rem;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--subtle);
}

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    color: var(--gray-700);
    font-weight: 500;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}

.nav-item .icon {
    color: var(--gray-500);
    transition: color var(--transition);
}

.nav-item:hover {
    background: var(--gray-100);
    color: var(--text);
}

.nav-item.active {
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 600;
}

.nav-item.active .icon {
    color: var(--primary);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: -0.75rem;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--primary);
}

.sidebar-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    border-radius: var(--radius);
    color: inherit;
    text-decoration: none;
}

a.user-info:hover {
    background: var(--gray-100);
}

.user-avatar {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--navy));
    color: #fff;
    font-weight: 700;
    font-size: 0.8125rem;
}

.user-details {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.75rem;
    color: var(--muted);
}

.main-content {
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.content-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: var(--header-height);
    padding: 0.5rem 1rem;
    background: var(--header-bg);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--border);
}

.content-header-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.content-header h2 {
    font-size: 1.0625rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.year-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    flex-shrink: 0;
    padding: 0.375rem 0.75rem;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
}

.content-body {
    flex: 1;
    width: 100%;
    max-width: 1320px;
    margin: 0 auto;
    padding: 1rem;
}

.content-footer {
    padding: 1rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.8125rem;
}

/* ------------------------------------------------------------------ Cards */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    min-width: 0;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border);
}

.card-header h3 {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-size: 0.975rem;
    font-weight: 700;
}

.card-header h3 .icon {
    width: 32px;
    height: 32px;
    padding: 7px;
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--primary);
}

.card-body {
    padding: 1rem;
}

.card-body > h4 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9375rem;
}

.card-footer {
    padding: 0.875rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--surface-muted);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ------------------------------------------------------------------ Stat cards */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.stats-grid > .card {
    grid-column: 1 / -1;
}

.stat-card {
    --tone: var(--primary);
    --tone-soft: var(--primary-soft);
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas:
        'icon value'
        'label label';
    align-items: center;
    gap: 0.5rem 0.75rem;
    padding: 0.875rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    right: -24px;
    top: -24px;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--tone-soft);
    opacity: 0.7;
}

.stat-card.success {
    --tone: var(--success);
    --tone-soft: var(--success-soft);
}

.stat-card.warning {
    --tone: var(--warning);
    --tone-soft: var(--warning-soft);
}

.stat-card.danger {
    --tone: var(--danger);
    --tone-soft: var(--danger-soft);
}

.stat-card.info {
    --tone: var(--navy-text);
    --tone-soft: var(--navy-soft);
}

.stat-icon {
    grid-area: icon;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    background: var(--tone-soft, var(--primary-soft));
    color: var(--tone, var(--primary));
}

.stat-icon .icon {
    width: 20px;
    height: 20px;
}

.stat-value {
    grid-area: value;
    position: relative;
    z-index: 1;
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    grid-area: label;
    color: var(--muted);
    font-size: 0.8125rem;
    line-height: 1.35;
}

/* ------------------------------------------------------------------ Forms */

.form-group {
    margin-bottom: 1rem;
    min-width: 0;
}

.form-label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-700);
}

.form-control {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 1rem;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:hover {
    border-color: var(--gray-500);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
}

.form-control::placeholder {
    color: var(--subtle);
}

.form-control[readonly],
.form-control:disabled {
    background: var(--gray-100);
    color: var(--gray-700);
}

textarea.form-control {
    min-height: 96px;
    resize: vertical;
}

.form-select {
    appearance: none;
    padding-right: 2.5rem;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23586876' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.75rem center;
    background-repeat: no-repeat;
    background-size: 1.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0 1rem;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.625rem;
    margin-top: 0.5rem;
}

.form-actions .btn {
    flex: 1 1 140px;
}

/* ------------------------------------------------------------------ Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0.625rem 1.125rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition),
        box-shadow var(--transition);
}

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

.btn-primary {
    background: var(--primary);
    color: var(--on-primary);
    box-shadow: 0 1px 2px rgb(0 80 76 / 0.25);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: var(--on-solid);
}

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

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

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

.btn-warning {
    background: var(--warning-soft);
    border-color: var(--warning-border);
    color: var(--warning-text);
}

.btn-warning:hover {
    background: var(--warning-soft-hover);
}

.btn-secondary {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-100);
}

.btn-outline {
    background: var(--surface);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary-soft);
}

.btn-sm {
    min-height: 38px;
    padding: 0.4375rem 0.75rem;
    font-size: 0.8125rem;
}

/* Row actions in tables are icon-only buttons: a square target. */
.table .btn-sm,
.dokumen-actions .btn-sm {
    width: 38px;
    padding: 0;
}

.btn-sm.btn-danger {
    background: var(--danger-soft);
    border-color: var(--danger-border);
    color: var(--danger);
}

.btn-sm.btn-danger:hover {
    background: var(--danger-soft-hover);
}

.btn-sm.btn-success {
    background: var(--success-soft);
    border-color: var(--success-border);
    color: var(--success);
}

.btn-sm.btn-success:hover {
    background: var(--success-soft-hover);
}

.btn-lg {
    min-height: 50px;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

/* ------------------------------------------------------------------ Alerts & badges */

.alert {
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
}

.alert {
    overflow-wrap: anywhere;
}

.alert > .icon:first-child {
    margin-right: 0.25rem;
}

.alert .copy-btn {
    vertical-align: middle;
    margin-left: 0.25rem;
}

.alert-danger {
    background: var(--danger-soft);
    border-color: var(--danger-border);
    color: var(--danger-text);
}

.alert-success {
    background: var(--success-soft);
    border-color: var(--success-border);
    color: var(--success-text);
}

.alert-warning {
    background: var(--warning-soft);
    border-color: var(--warning-border);
    color: var(--warning-text);
}

.alert-info {
    background: var(--info-soft);
    border-color: var(--info-border);
    color: var(--info-text);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.1875rem 0.625rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
}

.badge-primary {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

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

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

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

/* ------------------------------------------------------------------ Tables */

.table-responsive {
    /* Positioned so absolutely placed children (visually-hidden labels) are clipped with the table. */
    position: relative;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -1rem;
    padding: 0 1rem;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table th,
.table td {
    padding: 0.75rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: var(--surface-muted);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.table thead th:first-child {
    border-top-left-radius: var(--radius-sm);
}

.table thead th:last-child {
    border-top-right-radius: var(--radius-sm);
}

.table tbody tr {
    transition: background var(--transition);
}

.table tbody tr:hover {
    background: var(--surface-muted);
}

.table tbody tr:last-child td {
    border-bottom: 0;
}

/*
 * Phones: app.js labels every cell with its column header and adds .is-stacked, so each row
 * becomes a small card. Without JavaScript the table simply scrolls sideways.
 */
@media (max-width: 767.98px) {
    .table.is-stacked thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
    }

    .table.is-stacked,
    .table.is-stacked tbody,
    .table.is-stacked tr,
    .table.is-stacked td {
        display: block;
    }

    .table.is-stacked tr {
        padding: 0.375rem 0;
        margin-bottom: 0.75rem;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: var(--surface);
    }

    .table.is-stacked tbody tr:hover {
        background: var(--surface);
    }

    .table.is-stacked td {
        position: relative;
        min-height: 2rem;
        padding: 0.375rem 0.875rem 0.375rem 7.75rem;
        border: 0;
        overflow-wrap: anywhere;
    }

    .table.is-stacked td::before {
        content: attr(data-label);
        position: absolute;
        left: 0.875rem;
        top: 0.375rem;
        width: 6.25rem;
        color: var(--muted);
        font-size: 0.75rem;
        font-weight: 600;
        line-height: 1.75;
    }

    .table.is-stacked td.cell-no {
        display: none;
    }

    .table.is-stacked td.cell-actions {
        display: flex;
        justify-content: flex-end;
        margin-top: 0.375rem;
        padding: 0.625rem 0.875rem 0.25rem;
        border-top: 1px solid var(--border);
    }

    .table.is-stacked td.cell-actions::before,
    .table.is-stacked td[colspan]::before {
        display: none;
    }

    .table.is-stacked td[colspan] {
        display: block;
        padding: 1rem;
    }

    .table.is-stacked tr:has(td[colspan]) {
        border-style: dashed;
    }
}

/* ------------------------------------------------------------------ Tabs */

.tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    padding: 0.25rem;
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab {
    flex: 1 0 auto;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.tab:hover {
    background: var(--gray-100);
    color: var(--text);
}

.tab.active {
    background: var(--primary);
    color: var(--on-primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ------------------------------------------------------------------ Modal */

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    align-items: flex-end;
    justify-content: center;
    background: var(--overlay);
}

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

.modal {
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--surface);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-lg);
}

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

.modal-header h3 {
    font-size: 1.0625rem;
}

.modal-close {
    border: 0;
    background: none;
    color: var(--muted);
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-body {
    padding: 1.25rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
}

/* ------------------------------------------------------------------ Search, pagination, misc */

.search-box {
    display: flex;
    flex-wrap: wrap;
    gap: 0.625rem;
    margin-bottom: 1rem;
}

/* Phones: keyword on its own row, dates and buttons in pairs; a lone button takes the full row. */
.search-box .search-input {
    flex: 1 1 100%;
}

.search-box input[type='date'],
.search-box .btn {
    flex: 1 1 40%;
}

.card-body > form:last-child .search-box,
.card-body > form:only-child .search-box {
    margin-bottom: 0;
}

.filter-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.copy-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.copy-btn.copied {
    background: var(--success);
    border-color: var(--success);
    color: var(--on-solid);
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.375rem;
    margin-top: 1rem;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--gray-700);
    font-weight: 600;
    font-size: 0.875rem;
    text-decoration: none;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

a.page-link:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.page-link.active {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--on-primary);
}

.autocomplete-wrapper {
    position: relative;
}

.autocomplete-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 100;
    display: none;
    max-height: 240px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.autocomplete-list.show {
    display: block;
}

.autocomplete-item {
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    cursor: pointer;
}

.autocomplete-item:hover {
    background: var(--gray-100);
}

.autocomplete-item.selected {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.file-upload {
    padding: 1.5rem 1rem;
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-muted);
    text-align: center;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}

.file-upload:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.file-upload input {
    display: none;
}

.file-upload p {
    color: var(--muted);
    font-size: 0.875rem;
}

.file-preview {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius);
    background: var(--gray-100);
}

.file-preview .file-name {
    flex: 1;
    min-width: 0;
    font-size: 0.875rem;
    overflow-wrap: anywhere;
}

.file-preview .remove-file {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--danger);
    cursor: pointer;
}

.result-box {
    padding: 1.25rem;
    margin-top: 1rem;
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, var(--primary) 0%, var(--navy) 100%);
    color: #fff;
    text-align: center;
}

.result-box h4 {
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    opacity: 0.9;
}

.result-box .result-value {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.chart-box {
    position: relative;
    height: 240px;
}

/* ------------------------------------------------------------------ Utilities */

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--muted); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.d-flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 0.75rem; }
.gap-3 { gap: 1.25rem; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.625rem;
}

.toolbar .btn {
    flex: 1 1 200px;
}

/* ------------------------------------------------------------------ Login & error pages */

.auth-container {
    min-height: 100vh;
    display: flex;
    background: var(--bg);
}

.auth-left {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 1rem;
}

.auth-right {
    display: none;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 1.75rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}

.login-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-logo {
    display: block;
    width: 100%;
    max-width: 280px;
    height: auto;
    margin: 0 auto;
}

.login-header h1 {
    margin-bottom: 0.25rem;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
}

.login-header p {
    color: var(--muted);
    font-size: 0.875rem;
}

.auth-brand {
    max-width: 520px;
    color: #fff;
}

.auth-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.875rem;
    margin-bottom: 1.25rem;
    border: 1px solid rgb(255 255 255 / 0.25);
    border-radius: 999px;
    background: rgb(255 255 255 / 0.1);
    font-size: 0.8125rem;
    font-weight: 600;
}

.auth-brand h2 {
    margin-bottom: 0.75rem;
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.2;
}

.auth-brand > p {
    margin-bottom: 2rem;
    color: rgb(255 255 255 / 0.82);
    font-size: 1rem;
}

.chart-container {
    width: 100%;
    padding: 1.25rem;
    border: 1px solid rgb(255 255 255 / 0.2);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}

.chart-header {
    margin-bottom: 0.75rem;
    color: var(--text);
}

.chart-header h2 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    font-weight: 700;
}

.chart-header p {
    color: var(--muted);
    font-size: 0.8125rem;
}

/* ------------------------------------------------------------------ Wider screens */

@media (min-width: 576px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stat-card {
        grid-template-areas:
            'icon value'
            'icon label';
        gap: 0.125rem 0.875rem;
        padding: 1rem 1.125rem;
    }

    .stat-icon {
        width: 46px;
        height: 46px;
    }

    .stat-value {
        align-self: end;
        font-size: 1.625rem;
    }

    .stat-label {
        align-self: start;
    }

    .search-box .btn {
        flex: 0 0 auto;
    }

    .search-box .search-input {
        flex: 1 1 260px;
    }

    .search-box input[type='date'] {
        flex: 0 1 170px;
    }

    .search-box .search-jenis {
        flex: 0 1 210px;
    }

    .form-actions .btn,
    .toolbar .btn {
        flex: 0 0 auto;
    }

    .login-card {
        padding: 2.25rem 2rem;
    }

    .modal-overlay {
        align-items: center;
        padding: 1rem;
    }

    .modal {
        border-radius: var(--radius-xl);
    }

    .chart-box {
        height: 300px;
    }
}

@media (min-width: 768px) {
    .form-row {
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }

    .content-header {
        padding: 0.5rem 1.5rem;
    }

    .content-header h2 {
        font-size: 1.25rem;
    }

    .content-body {
        padding: 1.5rem;
    }

    .card-header {
        padding: 1rem 1.25rem;
    }

    .card-body {
        padding: 1.25rem;
    }

    .table-responsive {
        margin: 0 -1.25rem;
        padding: 0 1.25rem;
    }

    .stats-grid {
        gap: 1rem;
        margin-bottom: 1rem;
    }

    .stats-grid > .card {
        grid-column: auto;
    }

    .mb-3 { margin-bottom: 1.5rem; }
    .mt-3 { margin-top: 1.5rem; }
}

@media (min-width: 992px) {
    .stats-grid:has(> .card) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    /* An odd chart out (e.g. the third of three) takes the full row. */
    .stats-grid > .card:last-child:nth-child(odd) {
        grid-column: 1 / -1;
    }

    .auth-right {
        flex: 1.1;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 3rem;
        background:
            radial-gradient(circle at 15% 20%, rgb(140 198 63 / 0.25), transparent 40%),
            radial-gradient(circle at 85% 85%, rgb(0 161 154 / 0.45), transparent 45%),
            linear-gradient(150deg, #007c76 0%, var(--navy) 100%);
    }

    .auth-left {
        padding: 2rem;
    }
}

@media (min-width: 1024px) {
    .sidebar {
        width: var(--sidebar-width);
        transform: none;
        visibility: visible;
        box-shadow: none;
    }

    .sidebar.show {
        box-shadow: none;
    }

    .sidebar-backdrop,
    .sidebar-close {
        display: none;
    }

    .main-content {
        margin-left: var(--sidebar-width);
    }

    .content-body {
        padding: 1.75rem 2rem;
    }

    .content-header {
        padding: 0.5rem 2rem;
    }
}

@media (min-width: 1200px) {
    /* Four cards per row; a row with fewer cards stretches them to fill it. */
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(calc(25% - 0.75rem), 1fr));
    }
}

/* ------------------------------------------------------------------ Print */

@media print {
    .sidebar,
    .sidebar-backdrop,
    .content-header,
    .btn,
    .search-box,
    .no-print {
        display: none !important;
    }

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

    .content-body {
        padding: 0;
    }
}
