/* ─────────────────────────────────────────────
   Rishs International School — Design Tokens
   All colours as CSS custom properties.
   Dark mode = one override block, zero component changes.
   ───────────────────────────────────────────── */

:root {
    /* Brand */
    --color-primary:          #1E3A8A;
    --color-primary-light:    #2563EB;
    --color-primary-dark:     #1a3d6e;
    --color-primary-bg:       #f0f4ff;
    --color-accent:           #2563EB;

    /* Semantic */
    --color-success:          #16A34A;
    --color-success-bg:       #F0FDF4;
    --color-warning:          #F59E0B;
    --color-warning-bg:       #FFFBEB;
    --color-danger:           #DC2626;
    --color-danger-bg:        #FEF2F2;
    --color-info:             #2563EB;
    --color-info-bg:          #EFF6FF;

    /* Surfaces */
    --color-bg:               #F8FAFC;
    --color-surface:          #FFFFFF;
    --color-surface-raised:   #FFFFFF;
    --color-border:           #E2E8F0;
    --color-border-light:     #F1F5F9;
    --color-border-subtle:    rgba(0,0,0,0.04);

    /* Text */
    --color-text:             #0F172A;
    --color-text-secondary:   #64748B;
    --color-text-muted:       #94A3B8;
    --color-text-inverse:     #FFFFFF;

    /* Charts — semantic mapping that should be the same in every chart on
       the dashboard. Collected = green, pending/missing = neutral grey,
       attention = amber, danger = red, trend line = sky. Kept independent
       of brand --color-primary so the dark navy doesn't dominate small
       donuts and gauges. */
    --chart-collected:        #15803d;
    --chart-pending:          #cbd5e1;
    --chart-paid:             #1d4ed8;
    --chart-unpaid:           #fbbf24;
    --chart-trend:            #0ea5e9;
    --chart-grid:             #f1f5f9;

    /* Sidebar */
    --color-sidebar-bg:       #FFFFFF;
    --color-sidebar-active:   var(--color-primary);
    --color-sidebar-active-bg: var(--color-primary-bg);
    --color-sidebar-active-text: var(--color-primary);
    --color-sidebar-hover:    #F1F5F9;

    /* Nav */
    --nav-height:             3.5rem;
    --sidebar-width:          15rem;

    /* Card */
    --card-radius:            20px;
    --card-radius-sm:         16px;
    --card-border:            var(--color-border-subtle);
    --card-shadow:            0 1px 2px rgba(15,23,42,0.04), 0 8px 24px rgba(15,23,42,0.04);
    --card-shadow-sm:         0 4px 12px rgba(0,0,0,0.03);

    /* Buttons */
    --btn-radius:             12px;
    --input-radius:           12px;

    /* Shadows */
    --shadow-dropdown:        0 4px 12px rgba(0,0,0,0.10);
    --shadow-btn-primary:     0 4px 14px rgba(30, 58, 138, 0.25);

    /* Transitions */
    --transition-fast:        150ms ease;
    --transition-base:        200ms ease;

    /* Gradient (login page) */
    --gradient-brand:         linear-gradient(160deg, #0f2b4a 0%, #1a47a8 60%, #2563eb 100%);
}

/* ── Future dark mode ── */
/* [data-theme="dark"] { ... } */

/* ── Base resets (unlayered — always applies) ── */
[x-cloak] { display: none !important; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Component styles ──
   Wrapped in @layer components so Tailwind utilities (pl-9, py-2, etc.)
   can override them. Layer priority: base < components < utilities. */
@layer components {

/* ── Card components ── */
.card {
    background: var(--color-surface);
    border-radius: var(--card-radius);
    border: 1px solid transparent;
    box-shadow: var(--card-shadow);
}

.card-sm {
    background: var(--color-surface);
    border-radius: var(--card-radius-sm);
    border: 1px solid transparent;
    box-shadow: var(--card-shadow-sm);
}

/* ── Section labels ── */
.section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
}

/* ── Status badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 500;
    padding: 2px 10px;
    border-radius: 6px;
}
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-danger  { background: var(--color-danger-bg);  color: var(--color-danger); }
.badge-info    { background: var(--color-info-bg);    color: var(--color-info); }

/* ── Status dots ── */
.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}
.dot-success { background: var(--color-success); }
.dot-warning { background: var(--color-warning); }
.dot-danger  { background: var(--color-danger); }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--btn-radius);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition-base);
    cursor: pointer;
    border: none;
    outline: none;
    min-height: 44px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary-light) 0%, var(--color-primary) 100%);
    color: var(--color-text-inverse);
    box-shadow: var(--shadow-btn-primary);
    border: none;
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
}
.btn-primary:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

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

/* ── Form inputs ── */
.form-input {
    width: 100%;
    background: #F1F5F9;
    border: 1px solid transparent;
    border-radius: var(--input-radius);
    padding: 12px 16px;
    font-size: 14px;
    transition: all var(--transition-base);
    outline: none;
}
.form-input::placeholder {
    color: var(--color-text-muted);
}
.form-input:focus {
    background: var(--color-surface);
    border-color: var(--color-primary-light);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

/* ── Checkboxes & radios ──
   Default browser-native checkboxes render with a very faint border on
   white cards, which parents with poor vision have flagged as hard to see.
   We re-style with appearance-none + a higher-contrast border + a filled
   primary state so the control is clearly visible checked or unchecked. */
input[type="checkbox"],
input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--color-surface);
    border: 1.5px solid var(--color-text-muted);   /* slate-400 — much more visible than slate-200 */
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color var(--transition-base), background-color var(--transition-base), box-shadow var(--transition-base);
    vertical-align: middle;
}
input[type="checkbox"] { border-radius: 4px; }
input[type="radio"]    { border-radius: 50%; }

input[type="checkbox"]:hover:not(:disabled),
input[type="radio"]:hover:not(:disabled) {
    border-color: var(--color-text-secondary);
}

input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
    outline: none;
    border-color: var(--color-primary-light);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.22);
}

input[type="checkbox"]:checked,
input[type="radio"]:checked {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

input[type="checkbox"]:checked {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='3.5 8.5 7 12 13 4.5'/></svg>");
    background-size: 80% 80%;
    background-position: center;
    background-repeat: no-repeat;
}

input[type="radio"]:checked {
    background-image: radial-gradient(circle, #fff 32%, transparent 36%);
}

input[type="checkbox"]:disabled,
input[type="radio"]:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

input[type="checkbox"].rounded { border-radius: 4px; }
input[type="checkbox"].rounded-full { border-radius: 50%; }

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
}
.form-label-optional {
    font-weight: 400;
    color: var(--color-text-muted);
    margin-left: 4px;
}
.form-label-required {
    color: var(--color-danger);
    margin-left: 2px;
    font-weight: 600;
}

/* ── Table styles ── */
.table-header {
    background: rgba(248, 250, 252, 0.5);
    border-bottom: 1px solid var(--color-border-light);
}
.table-header th {
    padding: 12px 20px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}
.table-row {
    border-bottom: 1px solid var(--color-border-light);
    background: var(--color-surface);
    transition: background var(--transition-fast);
}
.table-row:nth-child(even) {
    background: rgba(248, 250, 252, 0.5);
}
.table-row td.sticky,
.table-header th.sticky {
    background: #FFFFFF;
    box-shadow: 2px 0 4px rgba(0,0,0,0.04);
}
.table-header th.sticky {
    background: #F8FAFC;
}
.table-row:nth-child(even) td.sticky {
    background: rgba(248, 250, 252, 0.5);
}
.table-row:hover {
    background: #E2E8F0;
}
.table-row:hover td.sticky {
    background: #E2E8F0;
}
.table-row td {
    padding: 12px 20px;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

/* ── Sidebar ── */
.sidebar-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    padding: 0 12px;
    margin-bottom: 4px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
}
.sidebar-link:hover {
    background: var(--color-sidebar-hover);
    color: var(--color-text);
}
.sidebar-link.active {
    background: var(--color-sidebar-active-bg);
    color: var(--color-sidebar-active-text);
}
.sidebar-link i {
    font-size: 18px;
    color: var(--color-text-muted);
}
.sidebar-link.active i {
    color: var(--color-sidebar-active-text);
}

/* ── Toast notifications ── */
.toast {
    padding: 12px 20px;
    border-radius: var(--card-radius-sm);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-dropdown);
    max-width: 420px;
    width: max-content;
}
.toast-success { background: var(--color-success); color: white; }
.toast-error   { background: var(--color-danger);  color: white; }
.toast-info    { background: var(--color-info);    color: white; }

/* ── Progress bar ── */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--color-border-light);
    border-radius: 999px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    border-radius: 999px;
    background: var(--color-primary);
    transition: width 0.5s ease;
}

/* ── Spinner ── */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* ── Safe area (mobile) ── */
.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom);
}

/* ── Tom Select overrides ── */
.ts-wrapper {
    font-family: 'Inter', system-ui, sans-serif !important;
}
.ts-wrapper.single .ts-control,
.ts-wrapper.multi .ts-control {
    background: #F1F5F9 !important;
    border: 1px solid transparent !important;
    border-radius: 0.75rem !important;
    padding: 0.4375rem 0.75rem !important;
    font-size: 0.875rem !important;
    color: var(--color-text) !important;
    box-shadow: none !important;
    min-height: 0 !important;
    line-height: 1.25rem !important;
}
.ts-wrapper.single .ts-control:hover,
.ts-wrapper.multi .ts-control:hover {
    border-color: var(--color-primary-light) !important;
}
.ts-wrapper.focus .ts-control {
    background: var(--color-surface) !important;
    border-color: var(--color-primary-light) !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15) !important;
}
.ts-wrapper.single .ts-control::after {
    border-color: var(--color-text-muted) transparent transparent !important;
    margin-top: -2px !important;
}
.ts-control > input {
    color: var(--color-text) !important;
    font-size: 0.875rem !important;
    min-height: 0 !important;
    padding: 0 !important;
}
.ts-control > input::placeholder {
    color: var(--color-text-muted) !important;
}
.ts-wrapper .ts-control .item {
    color: var(--color-text) !important;
}
.ts-dropdown {
    border: 1px solid var(--color-border) !important;
    border-radius: 0.75rem !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08) !important;
    font-size: 0.875rem !important;
    margin-top: 4px !important;
    overflow: hidden;
    /* Must beat modal backdrop (z-50). Tom Select dropdowns render to
       document.body, so they're siblings of the modal, not children. */
    z-index: 60 !important;
}
.ts-dropdown .option {
    padding: 0.4375rem 0.75rem !important;
    color: var(--color-text) !important;
}
.ts-dropdown .option:hover,
.ts-dropdown .active {
    background: var(--color-primary-bg) !important;
    color: var(--color-primary) !important;
}
.ts-dropdown .option.selected {
    background: var(--color-primary) !important;
    color: white !important;
}

/* ── Flowbite Datepicker overrides ── */
.datepicker .datepicker-picker {
    background: var(--color-surface) !important;
    border: 1px solid var(--color-border) !important;
    border-radius: 0.75rem !important;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08) !important;
    font-family: 'Inter', system-ui, sans-serif !important;
    padding: 0.75rem !important;
}
.datepicker .datepicker-cell {
    border-radius: 0.5rem !important;
    color: var(--color-text) !important;
    font-size: 0.8125rem !important;
}
.datepicker .datepicker-cell:hover {
    background: var(--color-primary-bg) !important;
    color: var(--color-primary) !important;
}
.datepicker .datepicker-cell.selected,
.datepicker .datepicker-cell.range-start,
.datepicker .datepicker-cell.range-end {
    background: var(--color-primary) !important;
    color: white !important;
}
.datepicker .datepicker-cell.range {
    background: var(--color-primary-bg) !important;
    background-color: var(--color-primary-bg) !important;
    color: var(--color-primary) !important;
    border-radius: 0 !important;
}
.datepicker .datepicker-cell.range-start {
    background: var(--color-primary) !important;
    background-color: var(--color-primary) !important;
    color: white !important;
    border-radius: 0.5rem 0 0 0.5rem !important;
}
.datepicker .datepicker-cell.range-end {
    background: var(--color-primary) !important;
    background-color: var(--color-primary) !important;
    color: white !important;
    border-radius: 0 0.5rem 0.5rem 0 !important;
}
.datepicker .datepicker-cell.disabled {
    color: var(--color-text-muted) !important;
    opacity: 0.4 !important;
}
.datepicker .datepicker-header .datepicker-controls .button {
    background: transparent !important;
    border: none !important;
    color: var(--color-text) !important;
    border-radius: 0.375rem !important;
    font-weight: 600 !important;
    font-size: 0.875rem !important;
    cursor: pointer;
}
.datepicker .datepicker-header .datepicker-controls .button:hover {
    background: var(--color-primary-bg) !important;
    color: var(--color-primary) !important;
}
.datepicker .dow {
    color: var(--color-text-muted) !important;
    font-size: 0.75rem !important;
    font-weight: 500 !important;
}
.datepicker .datepicker-footer .datepicker-controls .button {
    background: var(--color-primary) !important;
    color: white !important;
    border: none !important;
    border-radius: var(--input-radius) !important;
    padding: 0.375rem 1rem !important;
    font-size: 0.8125rem !important;
    font-weight: 500 !important;
    cursor: pointer;
}
.datepicker .datepicker-footer .datepicker-controls .button:hover {
    background: var(--color-primary-light) !important;
}

} /* end @layer components */

/* ── Flowbite datepicker utility overrides (unlayered — must beat @layer utilities) ──
   The datepicker JS adds Flowbite-specific classes (bg-brand, rounded-base, etc.)
   that only exist in its bundled Tailwind v4 CSS. We remap them to our design tokens. */
.datepicker .bg-brand,
.datepicker .datepicker-cell.bg-brand {
    background-color: var(--color-primary) !important;
    color: white !important;
}
.datepicker .bg-neutral-tertiary-medium,
.datepicker .datepicker-cell.bg-neutral-tertiary-medium {
    background-color: var(--color-primary-bg) !important;
    color: var(--color-primary) !important;
}
.datepicker .bg-neutral-primary-medium {
    background-color: var(--color-surface) !important;
}
.datepicker .text-body {
    color: var(--color-text) !important;
}
.datepicker .text-heading {
    color: var(--color-text) !important;
}
.datepicker .text-fg-disabled {
    color: var(--color-text-muted) !important;
}
.datepicker .rounded-base {
    border-radius: 0.5rem !important;
}
.datepicker .rounded-s-base {
    border-start-start-radius: 0.5rem !important;
    border-end-start-radius: 0.5rem !important;
}
.datepicker .rounded-e-base {
    border-start-end-radius: 0.5rem !important;
    border-end-end-radius: 0.5rem !important;
}

/* ── Print styles (unlayered — always applies) ── */
@media print {
    nav, aside, .no-print, .toast, .btn-bar {
        display: none !important;
    }
    body {
        background: white;
        color: black;
        font-size: 12pt;
    }
    .card {
        box-shadow: none;
        border: 1px solid #ccc;
    }
    .print-only {
        display: block !important;
    }
    .page-break {
        page-break-before: always;
    }
}

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