:root {
    --steel: #2c3e50;
    --accent: #0b6;
    --err: #c0392b;
    --ok: #1e7a46;

    /* Theming surfaces (light defaults) */
    --bg: #f5f6f8;
    --text: #1f2733;
    --heading: #2c3e50;
    --card: #fff;
    --line: #d9dde2;
    --muted: #6b7785;
    --thead: #eef1f4;
    --topbar-bg: #2c3e50;
    --topbar-text: #fff;
    --shadow: rgba(0, 0, 0, .08);
}

/* Dark palette: when the user explicitly picks Dark, or for System/default when
   the OS prefers dark (but never when the user has forced Light). */
:root[data-theme="dark"] {
    --bg: #10151b;
    --text: #e6e9ee;
    --heading: #eaf2ff;
    --card: #1a212a;
    --line: #33404e;
    --muted: #9aa7b4;
    --thead: #222c37;
    --topbar-bg: #0c1116;
    --topbar-text: #f0f3f7;
    --shadow: rgba(0, 0, 0, .5);
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #10151b;
        --text: #e6e9ee;
        --heading: #eaf2ff;
        --card: #1a212a;
        --line: #33404e;
        --muted: #9aa7b4;
        --thead: #222c37;
        --topbar-bg: #0c1116;
        --topbar-text: #f0f3f7;
        --shadow: rgba(0, 0, 0, .5);
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
}

/* Login / error pages */
body.centered { display: flex; flex-direction: column; min-height: 100vh; }
.card {
    background: var(--card); padding: 2rem; border-radius: 10px; width: 100%; max-width: 26rem;
    box-shadow: 0 2px 18px var(--shadow); margin: auto;
}

/* Branding */
.brand { display: inline-flex; align-items: center; gap: .55rem; }
.logo { height: 30px; width: auto; display: block; background: #fff; border-radius: 4px; padding: 2px; }
.logo-card { display: block; width: 100%; max-width: 230px; height: auto; margin: 0 auto 1.25rem; }

/* Footer */
.site-footer {
    display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; justify-content: center; align-items: center;
    color: var(--muted); font-size: .85rem; padding: 1.5rem 1rem;
    border-top: 1px solid var(--line); margin-top: 2rem;
}
body.centered .site-footer { border-top: 0; margin-top: 0; }
.theme-switch { display: inline-flex; align-items: center; gap: .3rem; }
.theme-switch button {
    background: transparent; color: var(--muted); border: 1px solid var(--line);
    padding: .2rem .65rem; border-radius: 999px; font-size: .8rem;
}
.theme-switch button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

/* App chrome */
.topbar {
    background: var(--topbar-bg); color: var(--topbar-text); padding: .8rem 1.2rem;
    display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem;
}
.topbar .who { font-size: .9rem; opacity: .92; }
.topbar a { color: #cfe8ff; }
.container { max-width: 60rem; margin: 1.5rem auto; padding: 0 1rem 3rem; }

h1 { color: var(--heading); }

.profile {
    background: var(--card); border: 1px solid var(--line); border-radius: 8px;
    padding: 1rem; margin-bottom: 1.25rem; display: grid; gap: .35rem;
}
.profile .lbl { display: inline-block; width: 7rem; color: var(--muted); font-size: .85rem; }

/* Table */
table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); }
th, td { padding: .5rem; border-bottom: 1px solid var(--line); text-align: left; }
thead th { background: var(--thead); font-size: .85rem; }
tfoot td { font-weight: 600; }
td input, td select {
    width: 100%; padding: .45rem; border: 1px solid var(--line); border-radius: 6px;
    background: var(--card); color: var(--text);
}

/* Buttons */
button {
    font: inherit; cursor: pointer; border: 0; border-radius: 6px;
    padding: .6rem 1.1rem; background: var(--accent); color: #fff;
}
button.secondary { background: var(--card); color: var(--text); border: 1px solid var(--line); margin: .8rem 0; }
button.removeRow { background: var(--card); color: var(--err); border: 1px solid var(--line); padding: .25rem .55rem; }
#submitBtn { display: block; margin-top: 1.25rem; font-size: 1.05rem; padding: .75rem 1.5rem; }

/* Form fields (login) */
label { display: block; margin: .75rem 0 .25rem; font-weight: 600; }
input[type=email] {
    width: 100%; padding: .6rem; border: 1px solid var(--line); border-radius: 6px;
    background: var(--card); color: var(--text);
}
.card button { width: 100%; margin-top: 1rem; }

.receipts { margin-top: 1.25rem; border: 1px solid var(--line); border-radius: 8px; }
.receipts legend { padding: 0 .4rem; color: var(--heading); font-weight: 600; }
.hint { color: var(--muted); font-size: .85rem; margin: .25rem 0 .6rem; }

.notice { padding: .7rem .9rem; border-radius: 6px; margin: .75rem 0; }
.notice.success { background: #e6f6ec; color: var(--ok); border: 1px solid #b6e3c6; }
.notice.error { background: #fdecea; color: var(--err); border: 1px solid #f3c2bc; }

/* Decision page */
textarea {
    width: 100%; padding: .6rem; border: 1px solid var(--line); border-radius: 6px; font: inherit;
    background: var(--card); color: var(--text);
}
.actions { display: flex; gap: .75rem; margin-top: 1.25rem; flex-wrap: wrap; }
.actions button { font-size: 1.05rem; padding: .7rem 1.6rem; }
button.approve { background: var(--ok); }
button.reject { background: var(--err); }
.status-badge { display: inline-block; vertical-align: middle; margin-left: .5rem;
    padding: .15rem .65rem; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.status-Submitted { background: #eef1f4; color: #2c3e50; }
.status-Info-Requested { background: #fff4e5; color: #9a6700; }
.status-Approved  { background: #e6f6ec; color: var(--ok); }
.status-Rejected  { background: #fdecea; color: var(--err); }

/* Conversation thread */
.thread { margin: 1.5rem 0; }
.thread h2 { color: var(--heading); font-size: 1.1rem; margin-bottom: .5rem; }
.msg { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; margin: .5rem 0; background: var(--card); }
.msg-approver { border-left: 3px solid var(--steel); }
.msg-employee { border-left: 3px solid var(--accent); }
.msg-meta { font-size: .85rem; margin-bottom: .25rem; }
.msg-meta .hint { margin-left: .4rem; }
.msg-body { white-space: pre-wrap; }
.remove-receipt { font-size: .85rem; color: var(--err); }

/* Admin: report summary cards */
.report { display: flex; flex-wrap: wrap; gap: .75rem; margin: 1rem 0 1.25rem; }
.report .stat {
    flex: 1 1 8rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px;
    padding: .7rem .9rem; display: grid; gap: .15rem;
}
.report .stat.total { background: var(--steel); color: #fff; border-color: var(--steel); }
.report .stat-label { font-size: .8rem; color: var(--muted); }
.report .stat.total .stat-label { color: #cfe8ff; }
.report .stat-n { font-size: 1.5rem; font-weight: 700; line-height: 1; }
.report .stat-amt { font-size: .9rem; }

/* Admin: filter bar */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filters select, .filters input {
    padding: .45rem; border: 1px solid var(--line); border-radius: 6px;
    background: var(--card); color: var(--text);
}
.filters label { display: inline-flex; align-items: center; gap: .35rem; margin: 0; font-weight: 400; font-size: .9rem; }
.btnlink {
    display: inline-block; text-decoration: none; padding: .55rem 1rem; border-radius: 6px;
    background: var(--card); color: var(--text); border: 1px solid var(--line);
}

/* Reviewer toolbar (print / export) */
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 1.25rem 0; }

/* Sortable headers + per-column filters (approver dashboard) */
th a.sort { color: inherit; text-decoration: none; display: inline-block; }
th a.sort:hover { text-decoration: underline; }
.col-filters th { background: var(--card); padding: .35rem .4rem; vertical-align: top; }
.col-filters input, .col-filters select {
    width: 100%; padding: .3rem; border: 1px solid var(--line); border-radius: 5px;
    background: var(--card); color: var(--text); font-size: .85rem; margin: 0 0 .2rem;
}
.col-filters .col-filter-actions { white-space: nowrap; }
.col-filters .col-filter-actions button { padding: .35rem .7rem; }
.col-filters .btnlink { padding: .3rem .6rem; font-size: .85rem; }

/* Pager + receipt list */
.pager { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; }
.receipt-list { margin: .25rem 0 .5rem; padding-left: 1.2rem; }
.receipt-list li { margin: .15rem 0; }

/* Receipt gallery (submission detail) */
.receipt-gallery { display: flex; flex-wrap: wrap; gap: .6rem; margin: .35rem 0 .5rem; }
.receipt-thumb { display: block; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--card); }
.receipt-thumb img { display: block; height: 120px; width: auto; max-width: 200px; object-fit: cover; }
.receipt-file {
    display: inline-flex; align-items: center; gap: .5rem; text-decoration: none;
    border: 1px solid var(--line); border-radius: 6px; padding: .5rem .75rem;
    background: var(--card); color: var(--text);
}
.receipt-ico { font-size: 1.4rem; line-height: 1; }

/* Print: force a light, chrome-free layout regardless of theme */
@media print {
    :root {
        --bg: #fff; --text: #000; --heading: #000; --card: #fff;
        --line: #ccc; --muted: #555; --thead: #eee;
    }
    .topbar, .site-footer, .toolbar, #decisionForm, .actions { display: none !important; }
    body { background: #fff; }
    .container { margin: 0; max-width: none; padding: 0; }
    .profile, table, .msg { break-inside: avoid; }
}
