:root {
    --ink: #10212b;
    --muted: #647681;
    --line: #dce6e9;
    --canvas: #f3f7f7;
    --surface: #ffffff;
    --brand: #0b5f72;
    --brand-deep: #073d50;
    --brand-soft: #dff3f2;
    --accent: #e5a93d;
    --safe: #137c64;
    --danger: #b64045;
    --warning: #9b6715;
    --shadow: 0 18px 45px rgba(15, 42, 52, 0.1);
    --radius: 20px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--canvas);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 92% 8%, rgba(25, 142, 150, 0.08), transparent 34rem),
        var(--canvas);
    color: var(--ink);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.skip-link {
    position: fixed;
    z-index: 100;
    top: 10px;
    left: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--ink);
    color: white;
    transform: translateY(-140%);
}
.skip-link:focus { transform: translateY(0); }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.login-view {
    position: relative;
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 20px;
    overflow: hidden;
    background: linear-gradient(145deg, #062f40 0%, #0a5364 48%, #0f7180 100%);
}

.login-backdrop,
.login-backdrop::before,
.login-backdrop::after {
    position: absolute;
    content: "";
    border-radius: 50%;
    pointer-events: none;
}
.login-backdrop {
    width: 38rem;
    height: 38rem;
    right: -14rem;
    top: -18rem;
    border: 1px solid rgba(255, 255, 255, 0.18);
}
.login-backdrop::before {
    width: 25rem;
    height: 25rem;
    left: -47rem;
    top: 34rem;
    background: rgba(229, 169, 61, 0.12);
}
.login-backdrop::after {
    width: 12rem;
    height: 12rem;
    left: -8rem;
    top: 30rem;
    border: 1px solid rgba(255, 255, 255, 0.16);
}

.login-card {
    position: relative;
    width: min(100%, 470px);
    padding: 34px;
    border: 1px solid rgba(255, 255, 255, 0.68);
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 30px 80px rgba(0, 24, 35, 0.32);
}

.brand-lockup,
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 13px;
}
.brand-lockup { margin-bottom: 42px; }
.brand-lockup div,
.sidebar-brand div,
.sidebar-status div { display: grid; gap: 2px; }
.brand-lockup strong,
.sidebar-brand strong { font-size: 15px; letter-spacing: 0.01em; }
.brand-lockup span:not(.brand-mark),
.sidebar-brand span:not(.brand-mark) { color: var(--muted); font-size: 12px; }

.brand-mark {
    display: grid;
    place-items: center;
    width: 50px;
    height: 50px;
    border-radius: 16px;
    background: linear-gradient(145deg, var(--brand), var(--brand-deep));
    color: white;
    font-weight: 800;
    letter-spacing: -0.04em;
    box-shadow: 0 10px 24px rgba(7, 61, 80, 0.24);
}
.brand-mark-small { width: 42px; height: 42px; border-radius: 13px; }

.eyebrow {
    display: block;
    margin-bottom: 7px;
    color: var(--brand);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
.eyebrow-light { color: #9cdedb; }

.login-copy h1 {
    margin: 0;
    font-size: clamp(27px, 6vw, 38px);
    line-height: 1.08;
    letter-spacing: -0.045em;
}
.login-copy p {
    margin: 17px 0 28px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.65;
}

.stack { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: #334851; font-size: 13px; font-weight: 700; }
label small { color: var(--muted); font-weight: 500; }

input, select {
    width: 100%;
    min-height: 46px;
    padding: 10px 13px;
    border: 1px solid #cbdadc;
    border-radius: 12px;
    outline: none;
    background: white;
    color: var(--ink);
    transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
input:focus, select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 4px rgba(11, 95, 114, 0.12);
}
input:disabled, select:disabled { background: #eef3f3; color: #8b999e; cursor: not-allowed; }

.button {
    min-height: 42px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: white;
    color: var(--ink);
    font-weight: 750;
    transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:focus-visible, .nav-item:focus-visible, .quick-action:focus-visible, .icon-button:focus-visible {
    outline: 3px solid rgba(229, 169, 61, 0.7);
    outline-offset: 2px;
}
.button:disabled { opacity: 0.52; cursor: not-allowed; }
.button-wide { width: 100%; min-height: 49px; }
.button-primary {
    color: white;
    background: linear-gradient(135deg, var(--brand), #087887);
    box-shadow: 0 10px 24px rgba(11, 95, 114, 0.2);
}
.button-quiet { border-color: var(--line); background: rgba(255, 255, 255, 0.74); }
.button-danger { color: white; background: var(--danger); }

.form-message { min-height: 20px; margin: 0; color: var(--danger); font-size: 13px; }
.login-footnote { margin: 26px 0 0; color: #87969c; text-align: center; font-size: 11px; }

.portal-view { min-height: 100vh; }

.sidebar {
    position: fixed;
    z-index: 30;
    inset: 0 auto 0 0;
    display: flex;
    width: 264px;
    padding: 25px 18px;
    flex-direction: column;
    background: #fff;
    border-right: 1px solid var(--line);
}
.sidebar-brand { padding: 0 7px 27px; border-bottom: 1px solid #edf1f2; }
.nav-list { display: grid; gap: 7px; margin-top: 25px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    padding: 12px 13px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: #53666f;
    text-align: left;
    font-size: 14px;
    font-weight: 700;
}
.nav-item:hover { background: #f1f7f7; color: var(--brand-deep); }
.nav-item.is-active { background: var(--brand-soft); color: var(--brand-deep); }
.nav-icon { display: grid; place-items: center; width: 23px; font-size: 18px; }

.sidebar-status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: auto;
    padding: 14px;
    border-radius: 14px;
    background: #f3f8f8;
}
.sidebar-status strong { font-size: 12px; }
.sidebar-status span:not(.status-dot) { color: var(--muted); font-size: 10px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: #c19540; box-shadow: 0 0 0 4px rgba(193, 149, 64, 0.15); }
.status-dot.is-ready { background: var(--safe); box-shadow: 0 0 0 4px rgba(19, 124, 100, 0.15); }

.app-column { min-height: 100vh; margin-left: 264px; }
.topbar {
    position: sticky;
    z-index: 20;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 82px;
    padding: 14px clamp(20px, 4vw, 44px);
    border-bottom: 1px solid rgba(210, 225, 228, 0.9);
    background: rgba(243, 247, 247, 0.9);
    backdrop-filter: blur(16px);
}
.topbar h2 { margin: 0; font-size: 20px; letter-spacing: -0.025em; }
.topbar .eyebrow { margin-bottom: 3px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 29px;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
}
.badge-safe { background: #ddf3ec; color: #0d6d57; }
.badge-danger { background: #f7e0e1; color: #993238; }

.content { width: min(100%, 1540px); margin: 0 auto; padding: 32px clamp(20px, 4vw, 44px) 60px; }
.page-section { display: none; }
.page-section.is-visible { display: block; animation: reveal 220ms ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.hero-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 28px;
    min-height: 235px;
    padding: clamp(28px, 5vw, 52px);
    border-radius: 26px;
    overflow: hidden;
    background:
        radial-gradient(circle at 84% 20%, rgba(255, 255, 255, 0.13), transparent 14rem),
        linear-gradient(135deg, #073d50, #0b6673);
    color: white;
    box-shadow: var(--shadow);
}
.hero-panel h1 { max-width: 800px; margin: 0; font-size: clamp(29px, 4vw, 49px); line-height: 1.04; letter-spacing: -0.05em; }
.hero-panel p { max-width: 780px; margin: 18px 0 0; color: #d7eeee; line-height: 1.65; }
.hero-shield {
    display: grid;
    place-items: center;
    min-width: 150px;
    padding: 22px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.09);
    text-align: center;
}
.hero-shield > span { display: grid; place-items: center; width: 49px; height: 49px; margin-bottom: 11px; border-radius: 50%; background: #9bded8; color: var(--brand-deep); font-size: 25px; font-weight: 900; }
.hero-shield strong { font-size: 13px; }
.hero-shield small { margin-top: 3px; color: #b8d9db; }

.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 20px 0; }
.metric-grid-compact { margin-top: 0; }
.metric-card {
    display: grid;
    gap: 7px;
    min-height: 124px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(15, 42, 52, 0.04);
}
.metric-grid-compact .metric-card { min-height: 100px; }
.metric-card strong { align-self: end; font-size: 25px; letter-spacing: -0.04em; }
.metric-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.metric-card small { color: #809097; font-size: 11px; }

.panel-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 0.8fr); gap: 18px; }
.panel {
    padding: 23px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 9px 28px rgba(15, 42, 52, 0.045);
}
.panel-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.panel h3 { margin: 0; font-size: 19px; letter-spacing: -0.025em; }
.safety-panel { background: linear-gradient(160deg, #f7fbfb, #e9f5f4); }
.check-list { display: grid; gap: 12px; padding: 0; margin: 21px 0 0; list-style: none; color: #466069; font-size: 13px; }
.check-list li::before { content: "✓"; display: inline-grid; place-items: center; width: 21px; height: 21px; margin-right: 8px; border-radius: 50%; background: #cdebe5; color: var(--safe); font-weight: 900; }

.quick-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; }
.quick-action {
    display: grid;
    gap: 5px;
    min-height: 150px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fbfdfd;
    color: var(--ink);
    text-align: left;
}
.quick-action:hover { border-color: #9bc6c9; transform: translateY(-2px); }
.quick-icon { display: grid; place-items: center; width: 36px; height: 36px; margin-bottom: 12px; border-radius: 11px; background: var(--brand-soft); color: var(--brand); font-size: 18px; }
.quick-action small { color: var(--muted); line-height: 1.45; }

.section-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 25px;
}
.section-heading h1 { margin: 0; font-size: clamp(28px, 4vw, 42px); letter-spacing: -0.045em; }
.section-heading p { max-width: 720px; margin: 9px 0 0; color: var(--muted); line-height: 1.55; }

.alert { margin: 18px 0; padding: 17px 19px; border: 1px solid; border-radius: 15px; }
.alert strong { display: block; margin-bottom: 4px; }
.alert p { margin: 0; font-size: 13px; line-height: 1.5; }
.alert-warning { border-color: #ead8ad; background: #fff8e8; color: #78500f; }
.alert-safe { border-color: #b9ded5; background: #eaf7f3; color: #0e6653; }

.query-form { display: grid; grid-template-columns: 1.35fr 1fr 1fr 1fr auto; align-items: end; gap: 13px; }
.query-form-ledger { grid-template-columns: 1.2fr 1fr 1fr 0.65fr 0.7fr auto; }
.query-form .button { min-height: 46px; }

.table-tools { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 14px; }
.search-field { width: min(100%, 390px); }
.muted { color: var(--muted); font-size: 12px; }
.table-shell { width: 100%; overflow: auto; border: 1px solid var(--line); border-radius: 15px; }
.table-shell.empty-state { display: grid; min-height: 220px; place-items: center; padding: 30px; border-style: dashed; color: var(--muted); text-align: center; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th { position: sticky; top: 0; z-index: 1; padding: 12px 14px; border-bottom: 1px solid var(--line); background: #f3f8f8; color: #526871; text-align: left; white-space: nowrap; }
.data-table td { max-width: 340px; padding: 13px 14px; border-bottom: 1px solid #edf2f3; vertical-align: top; line-height: 1.45; }
.data-table tbody tr:hover { background: #f8fbfb; }
.data-table tbody tr:last-child td { border-bottom: 0; }

.counter-panel { max-width: 930px; }
.counter-form { display: grid; gap: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.span-two { grid-column: 1 / -1; }
.danger-zone { padding: 20px; border: 1px solid #e8bfc1; border-radius: 16px; background: #fff7f7; }
.danger-zone > p { margin: 5px 0 18px; color: #74565a; font-size: 13px; }
.check-control { display: flex; align-items: flex-start; gap: 9px; margin: 18px 0; font-weight: 600; }
.check-control input { width: 18px; min-height: 18px; margin: 1px 0 0; }

.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.mobile-only { display: none; }

.toast {
    position: fixed;
    z-index: 80;
    right: 22px;
    bottom: 22px;
    max-width: min(420px, calc(100vw - 44px));
    padding: 14px 17px;
    border-radius: 14px;
    background: #123d49;
    color: white;
    box-shadow: var(--shadow);
    font-size: 13px;
}
.toast.is-error { background: #8f3137; }

.loading-overlay {
    position: fixed;
    z-index: 70;
    inset: 0;
    display: grid;
    place-items: center;
    gap: 12px;
    align-content: center;
    background: rgba(5, 35, 45, 0.43);
    color: white;
    backdrop-filter: blur(3px);
}
.spinner { width: 38px; height: 38px; border: 4px solid rgba(255, 255, 255, 0.3); border-top-color: white; border-radius: 50%; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1120px) {
    .panel-grid { grid-template-columns: 1fr; }
    .query-form, .query-form-ledger { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .query-form .button { align-self: end; }
}

@media (max-width: 820px) {
    .mobile-only { display: inline-grid; place-items: center; }
    .sidebar { transform: translateX(-102%); transition: transform 180ms ease; box-shadow: var(--shadow); }
    .sidebar.is-open { transform: translateX(0); }
    .app-column { margin-left: 0; }
    .topbar { padding: 12px 18px; }
    .topbar > div:nth-child(2) { flex: 1; }
    .topbar .eyebrow, #mode-badge { display: none; }
    .content { padding: 24px 17px 48px; }
    .hero-panel { grid-template-columns: 1fr; }
    .hero-shield { display: none; }
    .metric-grid { grid-template-columns: 1fr; }
    .metric-card { min-height: 94px; }
    .quick-grid { grid-template-columns: 1fr; }
    .quick-action { min-height: 112px; }
    .section-heading { align-items: flex-start; flex-direction: column; }
    .query-form, .query-form-ledger, .form-grid { grid-template-columns: 1fr; }
    .span-two { grid-column: auto; }
    .table-tools { align-items: stretch; flex-direction: column; }
    .search-field { width: 100%; }
}

@media (max-width: 520px) {
    .login-card { padding: 26px 21px; border-radius: 22px; }
    .brand-lockup { margin-bottom: 31px; }
    .topbar-actions .button { padding-inline: 11px; }
    .hero-panel { min-height: 0; padding: 28px 22px; border-radius: 20px; }
    .panel, .metric-card { padding: 18px; border-radius: 17px; }
    .section-heading h1 { font-size: 31px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

