/*
 * Finance (LinfraFin) - the Vaultex look (LINFRA_VAULTEX/DESIGN.md) as plain CSS: no CDN, nothing fetched. The
 * values are Vaultex's; where a rule stands in for a Tailwind class the class is named in the comment, so the two
 * can be compared. Started from the shell mockup's stylesheet.
 */

/* ── Theme tokens - DESIGN.md §1, copied from Vaultex wwwroot/css/app.css ─────────────────────────────── */
:root {
    --bg:               #f4f6f8;
    --surface:          #ffffff;
    --surface-2:        #eef2f6;
    --border:           #e2e8f0;
    --primary:          #0c6b7b;
    --text:             #1a202c;
    --text-2:           #4a5568;
    --text-3:           #718096;
    --hover:            #f7fafc;
    --sidebar:          #ffffff;
    --sidebar-hover:    #f0f4f8;
    --sidebar-active:   #0c6b7b;
    --sidebar-active-bg:#e6f3f5;
    --sidebar-text:     #4a5568;
    --sidebar-section:  #a0aec0;
    --header:           #ffffff;
    --input-bg:         #ffffff;
    --table-head:       #f7fafc;
}

[data-theme="dark"] {
    --bg:               #0d0d0d;
    --surface:          #1a1a1a;
    --surface-2:        #242424;
    --border:           #252525;
    --text:             #e2e8f0;
    --text-2:           #a0aec0;
    --text-3:           #718096;
    --hover:            #222222;
    --sidebar:          #111111;
    --sidebar-hover:    #1e1e1e;
    --sidebar-active:   #ffffff;
    --sidebar-active-bg:#0c6b7b;
    --sidebar-text:     rgba(255,255,255,0.6);
    --sidebar-section:  rgba(255,255,255,0.25);
    --header:           #1a1a1a;
    --input-bg:         #1a1a1a;
    --table-head:       #161616;
}

/* ── Environment banner - DESIGN.md §15 ───────────────────────────────────────────────────────────────────
   28px while it shows, 0 in Prod. Anything sized to the viewport subtracts --env-banner-h, never a raw 100vh,
   or the page gains a scrollbar the height of the banner. */
:root { --env-banner-h: 0px; }
html.has-env-banner { --env-banner-h: 28px; }

.env-banner {
    height: var(--env-banner-h);
    line-height: var(--env-banner-h);
    background: #b91c1c;
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.env-banner-dev { background: #c2410c; }

/* ── Base ─────────────────────────────────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

p, h1 { margin: 0; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
svg { display: block; flex-shrink: 0; }

.i-3-5 { width: 14px; height: 14px; }
.i-4   { width: 16px; height: 16px; }
.i-5   { width: 20px; height: 20px; }
.i-8   { width: 32px; height: 32px; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Theme toggle icons: the sun shows in dark (switch to light), the moon in light. */
.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* Scrollbar - thin, themed thumb (Vaultex app.css). */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #4a5568; }

/* Page enter - DESIGN.md §12. */
.fade { animation: fade-in .15s ease; }
@keyframes fade-in {
    from { opacity: 0; transform: translateY(3px); }
    to   { opacity: 1; transform: none; }
}

.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Brand ────────────────────────────────────────────────────────────────────────────────────────────── */
.brand-tile {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.brand-tile-lg { width: 36px; height: 36px; }

.brand-name {
    font-weight: 700;
    font-size: 18px;
    line-height: 1;
    color: var(--text);
    white-space: nowrap;
}
.brand-sub {
    font-size: 12px;
    line-height: 1;
    margin-top: 4px;
    color: var(--text-3);
}

/* ── Cards, labels, inputs, buttons - DESIGN.md §5–§7 ─────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.card-pad { padding: 16px; }
@media (min-width: 640px) { .card-pad { padding: 24px; } }

.stack > * + * { margin-top: 16px; }

.label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-3);
}
.required { color: #ef4444; }

/* px-3 py-1.5 text-sm, focus:ring-1 focus:ring-[#0c6b7b] */
.input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 14px;
    line-height: 20px;
    background: var(--input-bg);
    color: var(--text);
    outline: none;
}
.input::placeholder { color: var(--text-3); opacity: 1; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.input[readonly] { opacity: .6; cursor: not-allowed; }
.input-upper { text-transform: uppercase; }

/* Show / hide password: the eye sits inside the field, the text keeps clear of it. */
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 36px; }
.eye {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    padding: 2px;
    border: 0;
    background: none;
    color: var(--text-3);
    cursor: pointer;
}
.eye .icon-eye-off { display: none; }
.eye[aria-pressed="true"] .icon-eye { display: none; }
.eye[aria-pressed="true"] .icon-eye-off { display: block; }

.help { font-size: 12px; margin-top: 4px; color: var(--text-3); }

/* px-3.5 py-1.5 text-sm font-medium rounded, hover:opacity-90, disabled:opacity-50 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    border: 1px solid transparent;
    border-radius: 4px;
    color: #ffffff;
    text-decoration: none;
    cursor: pointer;
    transition: opacity .15s, background-color .15s;
}
.btn:hover { opacity: .9; }
.btn:disabled, .btn.is-busy { opacity: .5; cursor: default; pointer-events: none; }
.btn-primary   { background: #0c6b7b; }
.btn-secondary { background: #4a5568; }
.btn-block { width: 100%; padding-top: 8px; padding-bottom: 8px; }

/* The LinfraERP / LinfraHR Google button: white, a thin border and the four-colour G, in both themes. */
.btn-google { background: #ffffff; color: #1f1f1f; border-color: #ced4da; gap: 8px; }
.btn-google:hover { background: #f1f3f4; border-color: #adb5bd; opacity: 1; }
.btn-google svg { width: 18px; height: 18px; }

/* Soft badge - DESIGN.md §3. Only the five colours exist. */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 16px;
}
.badge-success { background: rgba(16,185,129,.15); color: #10b981; }

/* ── Login ────────────────────────────────────────────────────────────────────────────────────────────── */
.login {
    min-height: calc(100vh - var(--env-banner-h));
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--bg);
}
.login-wrap { width: 100%; max-width: 384px; }

.login-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 32px;
}

.login-card { padding: 24px; }
@media (min-width: 640px) { .login-card { padding: 32px; } }

.login-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text);
}

.or {
    text-align: center;
    font-size: 12px;
    margin: 12px 0 8px;
    color: var(--text-3);
}
.caption {
    text-align: center;
    font-size: 11px;
    line-height: 1.3;
    margin-top: 8px;
    color: var(--text-3);
}

/* GoogleCallback's refusal - a danger-tinted box under the buttons. */
.notice-danger {
    margin-top: 16px;
    padding: 10px 14px;
    border: 1px solid rgba(239,68,68,.5);
    border-radius: 6px;
    background: rgba(239,68,68,.08);
}
.notice-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 700;
    color: #ef4444;
}
.notice-text { font-size: 12px; margin-top: 2px; color: var(--text-2); }

.login-foot { text-align: center; font-size: 12px; margin-top: 16px; color: var(--text-3); }
.login-foot span { color: var(--primary); }

/* Fixed top-right, below the environment banner when there is one. */
.theme-fab {
    position: fixed;
    right: 16px;
    top: calc(16px + var(--env-banner-h));
    z-index: 50;
    display: flex;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-2);
    cursor: pointer;
}

/* ── App shell - DESIGN.md §15 ────────────────────────────────────────────────────────────────────────── */
.app {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--env-banner-h));
    overflow: hidden;
    background: var(--bg);
}
.app-body { display: flex; flex: 1; min-height: 0; overflow: hidden; }
.app-main { display: flex; flex-direction: column; flex: 1; min-width: 0; overflow: hidden; }

/* Mobile backdrop behind the open drawer. */
.backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0,0,0,.4);
}
.app.sidebar-open .backdrop { display: block; }

/* Sidebar: a 260px drawer under 768px; 210px (60px collapsed) in the flow from 768px. */
.sidebar {
    position: fixed;
    top: var(--env-banner-h);
    bottom: 0;
    left: 0;
    z-index: 50;
    width: 260px;
    display: flex;
    flex-direction: column;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform .2s ease-in-out, width .2s ease-in-out, min-width .2s ease-in-out;
}
.app.sidebar-open .sidebar { transform: none; }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand .brand-name { font-size: 14px; }
.sidebar-sub {
    font-size: 12px;
    line-height: 1;
    margin-top: 2px;
    white-space: nowrap;
    color: var(--sidebar-text);
}
.sidebar-brand-text { overflow: hidden; }

.sidebar-nav { flex: 1; padding: 8px; overflow-y: auto; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background-color .15s;
}
.nav-link + .nav-link { margin-top: 2px; }
.nav-link:hover { background: var(--sidebar-hover); }
.nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active);
    font-weight: 600;
}

.nav-section {
    padding: 16px 8px 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--sidebar-section);
}
.nav-divider { margin: 8px 0; border-top: 1px solid var(--border); }

.sidebar-foot { flex-shrink: 0; border-top: 1px solid var(--border); }

.account-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px;
    border: 0;
    background: none;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: opacity .15s;
}
.account-btn:hover { opacity: .8; }
.account-text { flex: 1; min-width: 0; }
.account-name, .account-sub {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.account-name { font-size: 14px; font-weight: 600; line-height: 1.25; color: var(--text); }
.account-sub  { font-size: 12px; line-height: 1.25; color: var(--sidebar-text); }
.account-btn .chevrons { color: var(--sidebar-text); }

.collapse-btn {
    display: none;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-top: 1px solid var(--border);
    background: none;
    font-size: 14px;
    color: var(--sidebar-text);
    cursor: pointer;
    transition: opacity .15s;
}
.collapse-btn:hover { opacity: .8; }
.collapse-btn svg { transition: transform .2s; }

/* Only the desktop sidebar collapses; the drawer always shows its labels. */
.when-collapsed { display: none; }

@media (min-width: 768px) {
    .backdrop, .app.sidebar-open .backdrop { display: none; }

    .sidebar {
        position: relative;
        top: auto;
        bottom: auto;
        z-index: auto;
        width: 210px;
        min-width: 210px;
        transform: none;
    }
    .collapse-btn { display: flex; }

    .app.sidebar-collapsed .sidebar { width: 60px; min-width: 60px; }
    .app.sidebar-collapsed .when-expanded { display: none; }
    .app.sidebar-collapsed .when-collapsed { display: block; }
    .app.sidebar-collapsed .nav-link,
    .app.sidebar-collapsed .account-btn,
    .app.sidebar-collapsed .collapse-btn { justify-content: center; }
    .app.sidebar-collapsed .sidebar-brand { padding-left: 14px; padding-right: 14px; }
    .app.sidebar-collapsed .collapse-btn svg { transform: rotate(180deg); }
    .app.sidebar-collapsed .menu-up { left: 56px; right: auto; bottom: 0; min-width: 200px; }
}

/* Header - 56px, hamburger on mobile, theme toggle and account on the right. */
.header {
    height: 56px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--header);
    border-bottom: 1px solid var(--border);
}
@media (min-width: 640px) { .header { padding: 0 24px; } }

.header-title {
    display: none;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-2);
}
@media (min-width: 640px) { .header-title { display: block; } }

.header-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }

.icon-btn {
    display: flex;
    padding: 6px;
    border: 0;
    border-radius: 4px;
    background: none;
    color: var(--text-2);
    cursor: pointer;
    transition: background-color .15s;
}
.icon-btn:hover { background: var(--hover); }
.hamburger { padding: 8px; margin-left: -8px; }
@media (min-width: 768px) { .hamburger { display: none; } }

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 9999px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
}
.avatar-btn { border: 0; padding: 0; cursor: pointer; }

/* The profile photo, laid over the initials - if it fails to load it removes itself and the initials show. */
.avatar { position: relative; overflow: hidden; }
.avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* My Profile: the photo is the upload button. */
.avatar-upload { cursor: pointer; }
.avatar-upload::after {
    content: "Change";
    position: absolute;
    inset: auto 0 0 0;
    padding: 2px 0 4px;
    font-size: 10px;
    font-weight: 600;
    text-align: center;
    color: #ffffff;
    background: rgba(0,0,0,.45);
    opacity: 0;
    transition: opacity .15s;
}
.avatar-upload:hover::after, .avatar-upload.is-busy::after { opacity: 1; }
.avatar-upload.is-busy { pointer-events: none; }
.avatar-upload.is-busy::after { content: "Saving…"; }
.avatar-lg { width: 56px; height: 56px; font-size: 20px; }

/* Dropdown menus (header avatar, sidebar account row). */
.menu-anchor { position: relative; }
.menu {
    position: absolute;
    z-index: 50;
    padding: 6px 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 20px 25px -5px rgba(0,0,0,.15), 0 8px 10px -6px rgba(0,0,0,.1);
}
.menu-down { right: 0; top: 40px; width: 208px; }
.menu-up { left: 8px; right: 8px; bottom: 100%; margin-bottom: 4px; }

.menu-head { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.menu-name, .menu-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-name { font-size: 14px; font-weight: 600; color: var(--text); }
.menu-sub  { font-size: 12px; margin-top: 2px; color: var(--sidebar-text); }

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    font-size: 14px;
    color: var(--text-2);
    text-decoration: none;
    transition: background-color .15s;
}
.menu-item:hover { background: var(--hover); }
.menu-item-danger { color: #ef4444; }

/* Content - <main> owns the page padding; pages start with their own vertical stack. */
.content { flex: 1; overflow-y: auto; padding: 16px; }
@media (min-width: 640px) { .content { padding: 24px; } }

.page > * + * { margin-top: 24px; }
.page-narrow { max-width: 576px; }

.page-title { font-size: 20px; line-height: 28px; font-weight: 700; color: var(--text); }
.page-sub   { font-size: 14px; margin-top: 2px; color: var(--text-3); }

.section-title { font-size: 14px; font-weight: 600; color: var(--text); }
.section-sub   { font-size: 12px; margin-top: 2px; color: var(--text-3); }

/* Empty state - the dashboard has nothing to show yet. */
.empty { padding: 48px 20px; text-align: center; }
.empty svg { margin: 0 auto 8px; color: var(--text-3); }
.empty-title { font-size: 14px; font-weight: 500; color: var(--text); }
.empty-text  { font-size: 14px; margin-top: 2px; color: var(--text-3); }

/* My Profile */
.profile-id { display: flex; align-items: center; gap: 16px; }
.profile-id-text { min-width: 0; }
.profile-name { font-weight: 600; color: var(--text); }
.profile-sub  { font-size: 14px; color: var(--text-3); }
.profile-id .badge { margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 640px) {
    .grid-2 { grid-template-columns: 1fr 1fr; }
    .span-2 { grid-column: 1 / -1; }
}

/* ── Modal - DESIGN.md §10. The forced change-password modal is the first user. ──────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0,0,0,.4);
}
.modal-panel {
    width: 100%;
    max-width: 512px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 20px 25px -5px rgba(0,0,0,.2), 0 8px 10px -6px rgba(0,0,0,.15);
}
.modal-sm { max-width: 400px; }
.modal-head { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-head-warning { background: rgba(245,158,11,.15); }
.modal-title { font-size: 14px; font-weight: 600; color: var(--text); }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-text { font-size: 14px; color: var(--text-2); }
/* Footer: secondary left, action right (DESIGN.md §19). */
.modal-foot { display: flex; align-items: center; justify-content: space-between; }

.btn-warning { background: #d97706; }

/* Password rules checklist - ticked as each is met. */
.rules { list-style: none; margin: 8px 0 0; padding: 0; font-size: 12px; color: var(--text-3); }
.rules li { display: flex; align-items: center; gap: 6px; line-height: 20px; }
.rules li::before { content: "\25CB"; width: 12px; text-align: center; }
.rules li.met { color: #10b981; }
.rules li.met::before { content: "\2713"; }

/* ── Status pages (403 / 404 / 405 / 500) ─────────────────────────────────────────────────────────────── */
.status-card { padding: 32px 24px; text-align: center; }
.status-code { font-size: 40px; font-weight: 700; line-height: 1; color: var(--primary); }
.status-title { font-size: 16px; font-weight: 600; margin-top: 12px; color: var(--text); }
.status-text { font-size: 14px; margin: 4px 0 20px; color: var(--text-3); }

/* ── Toast - DESIGN.md §11: centred overlay, 3 s (errors 5 s). The one place fixed colours are used. ── */
/* Above the modal, so a refusal on the forced change-password modal is visible. */
.toast-host {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 80;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: calc(100% - 32px);
    max-width: 360px;
    pointer-events: none;
}
@media (min-width: 640px) { .toast-host { width: auto; } }

.toast {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 20px;
    pointer-events: auto;
    animation: fade-in .15s ease;
}
@media (min-width: 640px) { .toast { padding: 16px 24px; } }

.toast-icon { width: 20px; height: 20px; margin-right: 12px; }
.toast-text { flex: 1; font-weight: 500; }
.toast-close {
    display: flex;
    margin-left: 12px;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    opacity: .5;
    cursor: pointer;
    transition: opacity .15s;
}
.toast-close:hover { opacity: 1; }

.toast-success { background: #bbf7d0; color: #166534; }
.toast-success .toast-icon { color: #16a34a; }
.toast-error   { background: #fecaca; color: #991b1b; }
.toast-error .toast-icon { color: #dc2626; }
.toast-warning { background: #fed7aa; color: #854d0e; }
.toast-warning .toast-icon { color: #ea580c; }
.toast-info    { background: #bfdbfe; color: #1e40af; }
.toast-info .toast-icon { color: #2563eb; }
