/* ── Custom Properties: Light Mode ──────────────────────────── */
:root {
    --bg:                #FFFFFF;
    --bg-secondary:      #f2f2f2;
    --bg-tertiary:       #e0e0e0;
    --text:              #111111;
    --text-muted:        #555555;
    --border:            #cccccc;
    --primary:           #ca0813;
    --primary-dark:      #a00610;
    --primary-contrast:  #FFFFFF;
    --accent:            #001144;
    --accent-hover:      #001f7a;
    --accent-contrast:   #FFFFFF;
    --success:           #166534;
    --success-bg:        #dcfce7;
    --warning:           #854d0e;
    --warning-bg:        #fef9c3;
    --danger:            #ca0813;
    --danger-bg:         #fee2e2;
    --shadow-sm:         0 1px 3px rgba(0,0,0,.12);
    --shadow:            0 2px 8px rgba(0,0,0,.15);
    --shadow-lg:         0 8px 32px rgba(0,0,0,.18);
    --radius:            6px;
    --radius-lg:         12px;
    --font:              -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --nav-height:        60px;
}

/* ── Custom Properties: Dark Mode ───────────────────────────── */
body.dark {
    --bg:               #000000;
    --bg-secondary:     #1a1a1a;
    --bg-tertiary:      #2a2a2a;
    --text:             #FFFFFF;
    --text-muted:       #aaaaaa;
    --border:           #333333;
    --accent:           #0132ff;
    --accent-hover:     #2a52ff;
    --success:          #22c55e;
    --success-bg:       #052e16;
    --warning:          #fcd34d;
    --warning-bg:       #2e1c00;
    --danger-bg:        #3f1010;
    --shadow-sm:        0 1px 3px rgba(0,0,0,.4);
    --shadow:           0 2px 8px rgba(0,0,0,.5);
    --shadow-lg:        0 8px 32px rgba(0,0,0,.6);
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.5;
    min-height: 100vh;
    transition: background 0.2s, color 0.2s;
}

img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: var(--font); }

/* ── App Shell ──────────────────────────────────────────────── */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Navigation ─────────────────────────────────────────────── */
.app-nav {
    background: var(--accent);
    color: var(--accent-contrast);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    height: var(--nav-height);
    gap: 0.75rem;
    flex-shrink: 0;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-logo {
    height: 44px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
}

.nav-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent-contrast);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.nav-links {
    display: flex;
    gap: 0.2rem;
    list-style: none;
    flex-shrink: 0;
}

.nav-links a {
    color: rgba(255,255,255,0.85);
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius);
    font-size: 0.88rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    min-height: 44px;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.nav-links a:hover,
.nav-links a.active {
    background: rgba(255,255,255,0.18);
    color: #fff;
    text-decoration: none;
}

.nav-user {
    font-size: 0.85rem;
    opacity: 0.85;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-theme {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.35);
    color: #fff;
    border-radius: var(--radius);
    padding: 0 0.75rem;
    min-height: 44px;
    min-width: 44px;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

.btn-theme:hover { background: rgba(255,255,255,0.15); }

/* ── Main Content ───────────────────────────────────────────── */
.app-main {
    flex: 1;
    padding: 1.5rem;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0 1.2rem;
    height: 44px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: var(--font);
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: filter 0.12s, transform 0.08s, box-shadow 0.12s;
    user-select: none;
}

.btn:active   { transform: scale(0.96); }
.btn:hover    { filter: brightness(0.9); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary  { background: var(--primary);      color: var(--primary-contrast); }
.btn-accent   { background: var(--accent);        color: var(--accent-contrast);  }
.btn-danger   { background: var(--primary);       color: var(--primary-contrast); }
.btn-ghost    { background: transparent;           color: var(--text); border: 1px solid var(--border); }
.btn-secondary{ background: var(--bg-secondary);  color: var(--text); border: 1px solid var(--border); }
.btn-nav-logout {
    background: rgba(255,255,255,0.12);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.3);
    height: 38px;
    font-size: 0.85rem;
}

.btn-lg { height: 56px; font-size: 1.1rem; padding: 0 1.6rem; }
.btn-sm { height: 36px; font-size: 0.85rem; padding: 0 0.9rem; }
.btn-xl { height: 64px; font-size: 1.2rem; padding: 0 2rem; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group   { margin-bottom: 1rem; }
.form-row     { display: flex; gap: 1rem; }
.form-row > * { flex: 1; }

label {
    display: block;
    font-weight: 600;
    font-size: 0.88rem;
    margin-bottom: 0.3rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    font-family: var(--font);
    height: 44px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

textarea { height: auto; min-height: 80px; resize: vertical; }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(1, 50, 255, 0.15);
}

body:not(.dark) input:focus,
body:not(.dark) select:focus,
body:not(.dark) textarea:focus {
    box-shadow: 0 0 0 3px rgba(0, 17, 68, 0.1);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    font-size: 0.95rem;
}

.checkbox-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    min-height: unset;
    cursor: pointer;
    accent-color: var(--primary);
}

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-weight: 500;
    border-left: 4px solid transparent;
}

.alert-error   { background: var(--danger-bg);  color: var(--danger);  border-color: var(--primary); }
.alert-success { background: var(--success-bg); color: var(--success); border-color: var(--success); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: var(--warning); }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.card-header {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
    color: var(--accent);
}

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }

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

th {
    background: var(--bg-secondary);
    padding: 0.65rem 0.85rem;
    text-align: left;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-secondary); }

.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-mono   { font-variant-numeric: tabular-nums; font-family: "Courier New", monospace; }

/* ── Modal Overlay ──────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    padding: 1rem;
}

.modal-overlay.hidden { display: none; }

.modal-box {
    background: var(--bg);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 1.25rem;
    color: var(--accent);
}

/* ── Login Screen ───────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 3rem 1.5rem 2rem;
    background: var(--bg);
}

.login-logo {
    max-width: 300px;
    max-height: 120px;
    width: auto;
    height: auto;
    object-fit: contain;
    margin-bottom: 1.5rem;
}

.login-heading {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 0.35rem;
    text-align: center;
}

.login-sub {
    color: var(--text-muted);
    margin-bottom: 2.5rem;
    font-size: 1rem;
    text-align: center;
}

.user-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    width: 100%;
    max-width: 720px;
}

.user-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-lg);
    padding: 1.1rem 0.75rem;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    word-break: break-word;
    transition: filter 0.12s, transform 0.08s, box-shadow 0.12s;
    box-shadow: var(--shadow);
    font-family: var(--font);
}

.user-btn:hover  { filter: brightness(1.12); box-shadow: var(--shadow-lg); }
.user-btn:active { transform: scale(0.95); }

/* ── PIN Keypad Modal ───────────────────────────────────────── */
.pin-modal {
    width: 320px;
    max-width: 96vw;
}

.pin-modal-name {
    text-align: center;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 1.5rem;
}

.pin-dots {
    display: flex;
    justify-content: center;
    gap: 1.1rem;
    margin-bottom: 0.5rem;
}

.pin-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: transparent;
    transition: background 0.12s, border-color 0.12s;
}

.pin-dot.filled {
    background: var(--primary);
    border-color: var(--primary);
}

.pin-error {
    min-height: 1.4em;
    color: var(--primary);
    text-align: center;
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.pin-keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.55rem;
    margin-bottom: 1.1rem;
}

.pin-key {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 62px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font);
    color: var(--text);
    transition: background 0.1s, transform 0.07s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.pin-key:hover  { background: var(--bg-tertiary); }
.pin-key:active { transform: scale(0.92); background: var(--border); }

.pin-key.key-backspace { font-size: 1.15rem; }
.pin-key.key-submit {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.pin-key.key-submit:hover  { filter: brightness(1.1); background: var(--primary); }
.pin-key.key-submit:active { filter: brightness(0.9); }

/* key-zero spans middle column */
.pin-spacer { visibility: hidden; }

.pin-cancel {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    font-size: 0.95rem;
    cursor: pointer;
    color: var(--text);
    font-family: var(--font);
    height: 44px;
    margin-top: 0.5rem;
    transition: background 0.12s;
}

.pin-cancel:hover { background: var(--bg-tertiary); }

/* ── Utility ────────────────────────────────────────────────── */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.p-0  { padding: 0; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start  { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end  { justify-content: flex-end; }
.gap-1  { gap: 0.5rem; }
.gap-2  { gap: 1rem; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--bg-secondary);
    color: var(--text-muted);
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-primary { background: var(--primary); color: #fff; }

/* ── Page Header ─────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent);
}

/* ── Section divider ────────────────────────────────────────── */
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.5rem 0;
}

/* ── Totals strip ───────────────────────────────────────────── */
.totals-strip {
    background: var(--bg-secondary);
    border-top: 2px solid var(--border);
    padding: 1rem 1.25rem;
    display: flex;
    justify-content: flex-end;
    gap: 2rem;
    font-size: 1rem;
}

.total-label  { color: var(--text-muted); margin-right: 0.5rem; }
.total-amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.total-grand  { font-size: 1.3rem; color: var(--accent); }
.total-savings { font-size: 1rem; color: var(--success); font-weight: 700; }

/* ── Print ──────────────────────────────────────────────────── */
@media print {
    .app-nav,
    .no-print,
    .btn,
    .btn-theme { display: none !important; }

    body {
        background: white !important;
        color: black !important;
        font-size: 11pt;
    }

    .app-main { padding: 0; max-width: none; }
    .card { border: 1px solid #ccc; box-shadow: none; }
    table { font-size: 10pt; }
    a { color: black; text-decoration: none; }
}
