/* Subcontractor Bill Tracker: light theme, styles for every view. */

/* ===== Tokens ===== */
:root {
    --bg: #f2f4f7;
    --card: #ffffff;
    --line: #d8dde4;
    --text: #1f2933;
    --mut: #6b7683;
    --ac: #1a7cf0;
    --acd: #1466c8;
    --head: #eef1f5;
    --g0: #e2e9f3;
    --g1: #d3deec;
    --lock: #f4f5f7;
    --hv: #eef5fe;
    --er: #c0392b;
    --erb: #fdecea;
    --ok: #12794a;
    --warn: #fff8e6;
    --row-h: 28px;
    --head-h: 26px;
    --idx-w: 52px;
    --rec-w: 84px;
}

/* ===== Base ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body,
#app {
    height: 100%;
    margin: 0;
}

body {
    background: #f5f6fa;
    color: #0f172a;
    font: 14px/1.4 "Inter", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
    overflow-x: hidden;
}

button,
input,
select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.grid-scroller:focus-visible {
    outline: 2px solid var(--ac);
    outline-offset: 1px;
}

input,
select {
    height: 36px;
    padding: 0 10px;
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--card);
}

input:disabled,
select:disabled {
    background: var(--lock);
    color: var(--mut);
}

[aria-invalid="true"] {
    border-color: var(--er);
}

/* ===== Layout roots ===== */
.app,
.app-view {
    height: 100%;
}

.shell { display: flex; height: 100%; position: relative; }
.shell-main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; margin-left: 64px; padding-top: 0 !important; margin-top: 0 !important; }

.content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-top: 0 !important;
    margin-top: 0 !important;
}

.toast-host {
    display: none;
}

/* ===== Shared controls ===== */
.btn-primary,
.btn-secondary {
    height: 34px;
    padding: 0 16px;
    border-radius: 6px;
    font-weight: 600;
}

.btn-primary {
    border: 0;
    background: var(--ac);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--acd);
}

.btn-primary:disabled {
    opacity: 0.6;
}

.btn-secondary {
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--head);
}

.btn-secondary:disabled {
    opacity: 0.6;
}

.icon-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--card);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover:not(:disabled) {
    background: var(--head);
    color: var(--ac);
}

.icon-btn:disabled {
    opacity: 0.45;
}

.text-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 24px;
    padding: 0 6px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #334155;
    font-size: 13px;
    font-weight: 500;
}

.text-btn:hover:not(:disabled) {
    background: #f1f5f9;
    color: #3157f5;
}

.text-btn:disabled {
    opacity: 0.45;
}

/* ===== Brand ===== */
.brand {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-weight: 700;
    font-size: 19px;
    letter-spacing: 0.01em;
}

.brand::before {
    content: "";
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #2f7be0;
}

.brand-logo {
    display: block;
    height: auto;
}

/* ===== Icons ===== */
.icon {
    display: inline-block;
    position: relative;
    flex: none;
    width: 16px;
    height: 16px;
}

.icon-grid {
    width: 18px;
    height: 15px;
    border: 2px solid currentColor;
    border-radius: 2px;
    background:
        linear-gradient(currentColor, currentColor) 0 4px / 100% 1.5px no-repeat,
        linear-gradient(currentColor, currentColor) 5px 0 / 1.5px 100% no-repeat;
}

.icon-clock {
    width: 18px;
    height: 18px;
    border: 2px solid currentColor;
    border-radius: 50%;
}

.icon-clock::before {
    content: "";
    position: absolute;
    left: 6px;
    top: 2px;
    width: 1.5px;
    height: 6px;
    background: currentColor;
}

.icon-clock::after {
    content: "";
    position: absolute;
    left: 6px;
    top: 7px;
    width: 5px;
    height: 1.5px;
    background: currentColor;
}

/* Lucide icons (ISC licence) drawn with a mask so they take the text colour */
.icon-refresh,
.icon-pencil,
.icon-lock,
.icon-download {
    width: 16px;
    height: 16px;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: currentColor;
    -webkit-mask: var(--ic) center / contain no-repeat;
    mask: var(--ic) center / contain no-repeat;
}

.icon-refresh {
    --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8'/%3E%3Cpath d='M21 3v5h-5'/%3E%3Cpath d='M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16'/%3E%3Cpath d='M8 16H3v5'/%3E%3C/svg%3E");
}

.icon-pencil {
    --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z'/%3E%3Cpath d='m15 5 4 4'/%3E%3C/svg%3E");
}

.icon-lock {
    --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='18' height='11' x='3' y='11' rx='2' ry='2'/%3E%3Cpath d='M7 11V7a5 5 0 0 1 10 0v4'/%3E%3C/svg%3E");
}

.icon-download {
    --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3Cpath d='M12 15V3'/%3E%3C/svg%3E");
}

.refresh-btn.is-busy .icon {
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ===== Login ===== */
.login {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 32px 8%;
    background: linear-gradient(135deg, #17c3ff, #0b66ee);
}

.login-card {
    width: 100%;
    max-width: 380px;
    padding: 32px 30px;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 6px 24px rgba(0, 40, 120, 0.25);
}

.login-card .brand {
    display: flex;
    justify-content: center;
}

.login-card .brand-logo {
    margin: 0 auto;
}

.login-card h1 {
    margin: 22px 0 18px;
    font-size: 22px;
    font-weight: 400;
    text-align: center;
}

.login-card label {
    display: block;
    margin: 12px 0 4px;
    font-size: 12px;
    color: var(--mut);
}

.login-error {
    min-height: 18px;
    margin: 8px 0;
    font-size: 12px;
    color: var(--er);
}

.login-card button[type="submit"] {
    width: 100%;
    height: 36px;
    border: 0;
    border-radius: 6px;
    background: var(--ac);
    color: #fff;
    font-weight: 600;
}

.login-card button[type="submit"]:hover:not(:disabled) {
    background: var(--acd);
}

.login-card button[type="submit"]:disabled {
    opacity: 0.6;
}

.login-card .login-microsoft {
    width: 100%;
    height: 36px;
    margin: 4px 0 8px;
    border: 0;
    border-radius: 6px;
    background: var(--ac);
    color: #fff;
    font-weight: 600;
}

.login-card .login-microsoft:hover:not(:disabled) {
    background: var(--acd);
}

.login-card .login-microsoft:disabled {
    opacity: 0.6;
}

/* ===== Loading and error ===== */
.app-loading,
.app-error {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--mut);
}

.app-error-text {
    margin: 0;
    color: var(--er);
    font-size: 14px;
}

/* ===== Shell ===== */
.sidebar { position: absolute; top: 0; left: 0; bottom: 0; z-index: 50; width: 64px; overflow: hidden; display: flex; flex-direction: column; align-items: stretch; padding-top: 10px; gap: 4px; background: linear-gradient(180deg, #1b3250, #1d242c); transition: width .35s cubic-bezier(.22, 1, .36, 1), box-shadow .35s; }
.sidebar.is-expanded { width: 220px; box-shadow: 8px 0 24px rgba(0, 0, 0, .25); }
.nav-btn { position: relative; z-index: 1; width: 100%; height: 48px; flex: none; display: flex; align-items: center; justify-content: flex-start; gap: 14px; padding: 0 0 0 23px; border: 0; background: transparent !important; color: #cfd8e3; white-space: nowrap; }
.nav-btn .icon { flex: none; }
.nav-btn:hover { color: #fff; }
.nav-btn.is-active { color: #fff; }
.nav-btn.is-active .icon-grid { width: 18px; height: 13px; border: 0; border-radius: 0; background: currentColor; -webkit-mask: var(--icon-fill) 0 0 / 18px 13px no-repeat; mask: var(--icon-fill) 0 0 / 18px 13px no-repeat; --icon-fill: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 13'%3E%3Crect x='0' y='0' width='6.5' height='4.5'/%3E%3Crect x='8.5' y='0' width='9.5' height='4.5'/%3E%3Crect x='0' y='6.5' width='6.5' height='6.5'/%3E%3Crect x='8.5' y='6.5' width='9.5' height='6.5'/%3E%3C/svg%3E"); }
.nav-btn.is-active .icon-clock { width: 18px; height: 18px; border: 0; border-radius: 0; background: currentColor; -webkit-mask: var(--icon-fill) 0 0 / 18px 18px no-repeat; mask: var(--icon-fill) 0 0 / 18px 18px no-repeat; --icon-fill: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Cpath fill-rule='evenodd' d='M9 0A9 9 0 1 0 9 18A9 9 0 1 0 9 0ZM8 4H9.5V9H13V10.5H8Z'/%3E%3C/svg%3E"); }
.nav-btn.is-active .icon-grid::before { display: none; }
.nav-btn.is-active .icon-grid::after { display: none; }
.nav-btn.is-active .icon-clock::before { display: none; }
.nav-btn.is-active .icon-clock::after { display: none; }
.nav-label { max-width: 0; opacity: 0; overflow: hidden; font-size: 14px; font-weight: 600; color: inherit; transition: max-width .35s cubic-bezier(.22, 1, .36, 1), opacity .2s; }
.sidebar.is-expanded .nav-label { max-width: 160px; opacity: 1; transition-delay: .05s; }

.badge {
    position: absolute;
    top: 6px;
    right: 10px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--ac);
    color: #fff;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
}
.nav-btn .badge { top: 3px; left: 37px; right: auto; }
.nav-glow { position: absolute; left: 8px; right: 8px; top: 0; height: 48px; z-index: 0; border-radius: 999px; background: rgba(255, 255, 255, .14); border: 0; box-shadow: none; pointer-events: none; transition: transform .28s cubic-bezier(.34, 1.2, .64, 1), height .28s cubic-bezier(.34, 1.2, .64, 1); }
.nav-glow.glow-move-a { animation: glow-stretch-a .32s cubic-bezier(.2, 0, 0, 1); }
.nav-glow.glow-move-b { animation: glow-stretch-b .32s cubic-bezier(.2, 0, 0, 1); }
@keyframes glow-stretch-a { 0% { scale: 1 1; } 40% { scale: .97 1.12; } 75% { scale: 1.02 .98; } 100% { scale: 1 1; } }
@keyframes glow-stretch-b { 0% { scale: 1 1; } 40% { scale: .97 1.12; } 75% { scale: 1.02 .98; } 100% { scale: 1 1; } }
.sidebar-toggle { position: absolute; bottom: 16px; left: 16px; width: 32px; height: 32px; padding: 0; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .08); color: #cbd5e1; cursor: pointer; transition: left .35s cubic-bezier(.22, 1, .36, 1), background .2s; }
.sidebar-toggle:hover { background: rgba(255, 255, 255, .16); color: #fff; }
.sidebar.is-expanded .sidebar-toggle { left: 172px; }
.icon-chevron { display: block; width: 8px; height: 8px; margin-left: -3px; border: 0; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; background: none; transform: rotate(-45deg); transition: transform .35s; }
.sidebar.is-expanded .icon-chevron { margin-left: 3px; transform: rotate(135deg); }
.page-enter { animation: page-ripple .5s cubic-bezier(.22, 1, .36, 1); }
@keyframes page-ripple { from { opacity: 0; transform: translateY(10px) scale(.995); filter: blur(2px); } to { opacity: 1; transform: none; filter: none; } }

.topbar {
    height: 52px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
}

.avatar {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: #c9d6e6;
    color: #1d3552;
    font-weight: 700;
}

.shell-account {
    position: absolute;
    top: 10px;
    right: 24px;
    z-index: 25;
}

.shell-account .avatar {
    width: 36px;
    height: 36px;
    background: #e7ecff;
    color: #3157f5;
    font-weight: 700;
}

.menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 19;
    background: transparent;
}

.account-menu {
    position: absolute;
    right: 12px;
    top: 48px;
    z-index: 20;
    width: 230px;
    padding: 14px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

.shell-account .account-menu {
    top: 48px;
    right: 0;
}

.account-name {
    font-weight: 600;
    color: var(--ac);
}

.account-id {
    color: var(--mut);
    font-size: 12px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
}

.logout-btn {
    display: block;
    width: 100%;
    padding: 4px 0;
    border: 0;
    background: transparent;
    text-align: left;
}

.logout-btn:hover {
    color: var(--ac);
}

/* ===== Data page: header ===== */
.data-page {
    flex: 1;
    min-height: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 0 24px 12px;
    box-sizing: border-box;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin: 0 -24px;
    padding: 8px 80px 8px 24px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
}

.page-brand {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.page-brand .brand-logo {
    width: 72px;
    height: 36px;
    flex: none;
}

.page-title h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.page-sub {
    margin-top: 2px;
    font-size: 13px;
    color: #64748b;
}

.new-record {
    height: 34px;
    padding: 0 16px;
    border: 0;
    border-radius: 10px;
    background: #3157f5;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
}

.new-record:hover:not(:disabled) {
    background: #2748d4;
}

/* ===== Data page: toolbar ===== */
.page-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.project-filter {
    width: 250px;
    min-width: 230px;
    height: 32px;
    padding: 0 10px;
    border: 0;
    border-radius: 10px;
    background: #fff;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
}

.search-input {
    flex: 1;
    max-width: 460px;
    width: auto;
    height: 32px;
    padding: 0 10px 0 42px;
    border: 0;
    border-radius: 10px;
    font-size: 14px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat 14px center / 16px;
}

.toolbar-columns {
    margin-left: auto;
}

.page-toolbar .refresh-btn {
    margin-left: 0;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 10px;
    background: transparent;
}

.page-toolbar .refresh-btn:hover {
    background: #f1f5f9;
}

.toolbar-columns[hidden]+.refresh-btn {
    margin-left: auto;
}

/* ===== Section tabs (pending page) ===== */
.section-tabs {
    position: relative;
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    border-radius: 999px;
}

.section-tab {
    position: relative;
    z-index: 1;
    overflow: visible;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-width: 34px;
    height: 24px;
    padding: 0 8px;
    border: 0;
    border-radius: 999px;
    background: transparent !important;
    color: #64748b;
    font-size: 12px;
    font-weight: 600;
    transition: color .25s;
}

.section-tab:hover {
    color: #0f172a;
}

.section-tab.is-active {
    color: #3157f5 !important;
}

.tab-pill {
    position: absolute;
    top: 2px;
    left: 0;
    z-index: 0;
    height: 24px;
    border-radius: 999px;
    background: rgba(49, 87, 245, .14);
    transition: transform .7s cubic-bezier(.22, 1.25, .36, 1), width .7s cubic-bezier(.22, 1.25, .36, 1);
}

.tab-count {
    align-self: flex-start;
    margin: 3px 0 0 1px;
    font-size: 8px;
    font-weight: 600;
    line-height: 1;
    color: #94a3b8;
}

.section-tab.is-active .tab-count {
    color: #3157f5;
}

/* ===== Columns menu ===== */
.columns-menu {
    position: relative;
}

.columns-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 32px;
    padding: 0 16px;
    border: 0;
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
}

.columns-btn:hover {
    background: var(--head);
}

.columns-count {
    padding: 0 7px;
    border-radius: 10px;
    background: #e7ecff;
    color: #3157f5;
    font-size: 11.5px;
    font-weight: 600;
}

.columns-backdrop {
    position: fixed;
    inset: 0;
    z-index: 29;
    background: transparent;
}

.columns-panel {
    position: absolute;
    top: 44px;
    left: auto;
    right: 0;
    z-index: 30;
    width: 400px;
    max-width: calc(100vw - 32px);
    max-height: 60vh;
    overflow: auto;
    padding: 12px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

.columns-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.columns-actions button {
    height: 30px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--card);
}

.columns-actions button:hover {
    background: var(--head);
}

.columns-group {
    padding: 8px 0;
    border-top: 1px solid var(--line);
}

.columns-panel .columns-group:first-child {
    border-top: 0;
    padding-top: 0;
}

.columns-group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
    font-weight: 600;
}

.columns-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
}

.check {
    display: flex;
    align-items: center;
    gap: 6px;
}

.check input {
    width: auto;
    height: auto;
}

/* ===== Grid card and footer ===== */
.grid-card {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    overflow: hidden;
}

.grid-host {
    flex: 1;
    min-height: 0;
}

.empty-state {
    padding: 20px;
    text-align: center;
    color: var(--mut);
}

.page-footer {
    flex: none;
    height: 32px;
    padding: 0 12px;
    border-top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.record-count {
    margin-left: 0;
    font-size: 13px;
    font-weight: 400;
    color: #64748b;
    letter-spacing: 0;
}

.record-count strong {
    font-weight: 600;
    color: #334155;
}

/* ===== Grid ===== */
.grid {
    position: relative;
    height: 100%;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.grid-card .grid {
    border: 0;
    border-radius: 0;
}

.grid-scroller {
    height: 100%;
    overflow: auto;
    scrollbar-width: none;
}

.grid-scroller::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.grid-table {
    table-layout: fixed !important;
    border-collapse: separate;
    border-spacing: 0;
    width: 1px !important;
    min-width: 0 !important;
    font-size: 14px;
}

.grid-table col:nth-child(1) {
    width: var(--idx-w) !important;
}

.grid-table col:nth-child(2) {
    width: var(--rec-w) !important;
}

.grid-table th,
.grid-table td {
    height: var(--row-h);
    min-width: 0;
    padding: 0 8px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    background: var(--card);
    border-right: 1px solid #d5dbe5;
    border-bottom: 1px solid #d5dbe5;
}

.grid-table td {
    padding: 2px 8px;
    line-height: 1.2;
}

.grid-table thead th {
    position: sticky;
    z-index: 3;
    height: var(--head-h);
    padding: 0 8px;
    line-height: 1.15;
    background: var(--head);
    font-weight: 600;
    text-align: left;
}

.grid-table thead tr:first-child th {
    top: 0;
}

.grid-table thead tr:nth-child(2) th {
    top: var(--head-h);
    font-weight: 600;
    color: #111827;
    background: #e3e8ef;
}

.grid-table thead th.group {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #0f2a4a;
    background: #cfe0f5;
    border-left: 0;
}

.grid-table thead th.group:nth-of-type(even) {
    background: #bcd3ef;
}

.grid-table thead th.col-head {
    padding-right: 10px;
}

.col-resizer {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 7px;
    cursor: col-resize;
    touch-action: none;
}

.col-resizer:hover {
    background: rgba(26, 124, 240, 0.35);
}

/* # and Record columns: fixed width, sticky */
.grid-table th.col-index,
.grid-table th.col-record {
    z-index: 5;
    text-align: center;
}

.grid-table th.col-index,
.grid-table td.cell-index {
    position: sticky;
    left: 0;
    width: var(--idx-w);
    min-width: var(--idx-w);
    max-width: var(--idx-w);
    color: var(--mut);
}

.grid-table th.col-index {
    padding: 0;
}

.grid-table td.cell-index {
    text-align: left;
    padding-left: 12px;
    color: #64748b;
}

.grid-table th.col-record,
.grid-table td.cell-record {
    position: sticky;
    left: var(--idx-w);
    width: var(--rec-w);
    min-width: var(--rec-w);
    max-width: var(--rec-w);
}

.cell-index,
.cell-record {
    z-index: 2;
}

.index-label {
    font-weight: 600;
    color: #111827;
}

.align-right {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.align-center {
    text-align: center;
}

/* Edit cells */
.col-edit,
.cell-edit {
    padding: 0 !important;
    text-align: center;
    border-left: 2px solid var(--line);
}

.edit-btn {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--ac);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.edit-btn:hover:not(:disabled) {
    background: rgba(26, 124, 240, 0.14);
}

.edit-btn:disabled {
    color: var(--mut);
    opacity: 0.5;
}

/* Cell content */
.record-link {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ac);
    font-size: 14px;
    font-weight: 600;
}

.record-link:hover {
    text-decoration: underline;
}

.grid-table td.cell-amount {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.grid-table td.cell-merged {
    white-space: nowrap;
    padding: 2px 8px;
}

.cell-merged .cell-main {
    display: inline;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
    line-height: 1.3;
}

.cell-merged .cell-sub {
    display: inline;
    margin-left: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12.5px;
    color: #64748b;
    line-height: 1.3;
}

/* Row states */
.grid-table tbody tr:hover td {
    background: #eef3ff;
}

.grid-table td.is-locked {
    background: var(--lock);
    color: var(--mut);
}

.grid-table td.is-pending,
.grid-table tbody tr:hover td.is-pending {
    background: #ffff80;
}

.grid-table td.cleared-yes,
.grid-table tbody tr:hover td.cleared-yes {
    background: #80ff80;
    color: #14532d;
}

.grid-table td.cleared-no,
.grid-table tbody tr:hover td.cleared-no {
    background: #ff8080;
    color: #7f1d1d;
}

/* Section dividers: one dark 2px line at the end of Record and of every section */
.grid-table .sec-start {
    border-left: 0 !important;
    border-bottom: 1px solid #d5dbe5 !important;
    box-shadow: none !important;
}

.grid-table th.col-record,
.grid-table td.cell-record,
.grid-table th:has(+ .sec-start),
.grid-table td:has(+ .sec-start) {
    border-right: 2px solid #475569 !important;
    border-bottom: 0 !important;
    box-shadow: inset 0 -1px 0 #d5dbe5 !important;
}

/* Virtual scroll spacer rows */
.grid-spacer td {
    padding: 0;
    border: 0;
    background: transparent;
}

/* Add button in the # header cell */
.add-row-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px dashed var(--ac);
    border-radius: 6px;
    background: transparent;
    color: var(--ac);
    font-size: 18px;
    line-height: 1;
}

.add-row-btn:hover {
    background: var(--hv);
}

.grid-table thead th.col-index .add-row-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--ac);
    font-size: 22px;
    font-weight: 400;
    line-height: 1;
}

.grid-table thead th.col-index .add-row-btn:hover {
    background: rgba(26, 124, 240, 0.12);
}

.grid-add-row td {
    height: 44px;
    border-right: 0;
}

.grid-add-row td.cell-add {
    position: sticky;
    left: 0;
    z-index: 2;
    padding: 0;
    text-align: center;
    background: var(--card);
}

.grid-add-row td.cell-add-fill {
    border-right: 0;
}

/* ===== Overlay scroll bars ===== */
.vscroll,
.hscroll {
    position: absolute;
    z-index: 6;
    pointer-events: auto;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
}

.hscroll {
    bottom: 0 !important;
}

.vscroll-thumb,
.hscroll-thumb {
    position: absolute;
    border-radius: 0 !important;
    background: rgba(100, 116, 139, .35);
    pointer-events: auto;
    cursor: pointer;
    transition: background .15s;
}

.vscroll-thumb {
    left: 0 !important;
    width: 5px !important;
}

.hscroll-thumb {
    top: auto !important;
    bottom: 0 !important;
    height: 5px !important;
}

.vscroll:hover .vscroll-thumb,
.hscroll:hover .hscroll-thumb,
.vscroll.is-dragging .vscroll-thumb,
.hscroll.is-dragging .hscroll-thumb {
    background: rgba(100, 116, 139, .7);
}

/* ===== Detail panel ===== */
.detail-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    justify-content: flex-end;
    background: rgba(14, 22, 31, 0.35);
}

.detail-panel {
    width: min(760px, 100%);
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--card);
    box-shadow: -8px 0 28px rgba(0, 0, 0, 0.2);
    position: relative;
}

.detail-backdrop.is-open .detail-panel {
    animation: slide-in 0.18s ease-out;
}

@keyframes slide-in {
    from {
        transform: translateX(32px);
        opacity: 0.6;
    }

    to {
        transform: none;
        opacity: 1;
    }
}

.detail-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}

.detail-head h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.detail-sub {
    margin: 2px 0 0;
    color: var(--mut);
    font-size: 12px;
}

.detail-close,
.dialog-close {
    border: 0;
    background: transparent;
    color: var(--mut);
    font-size: 22px;
    line-height: 1;
}

.detail-body {
    flex: 1;
    overflow: auto;
    padding: 8px 20px 24px;
}

.detail-section {
    margin-top: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.detail-section.is-locked {
    background: var(--lock);
}

.detail-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--head);
}

.detail-section-head h3 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
}

.detail-edit {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--ac);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.detail-edit:hover:not(:disabled) {
    background: rgba(26, 124, 240, 0.14);
}

.detail-edit:disabled {
    color: var(--mut);
    opacity: 0.5;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px 16px;
    padding: 12px;
}

.detail-label {
    font-size: 11.5px;
    color: var(--mut);
}

.detail-value {
    overflow-wrap: anywhere;
}

.detail-value.is-empty {
    color: var(--mut);
}

.btn-danger { height: 34px; padding: 0 16px; border: 0; border-radius: 6px; background: #c0392b; color: #fff; font-weight: 600; }
.btn-danger:hover:not(:disabled) { background: #a93226; }
.btn-danger:disabled { opacity: .45; }
.detail-foot { display: flex; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.confirm-backdrop { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(14, 22, 31, .45); }
.confirm-box { width: 100%; max-width: 420px; padding: 20px 22px; border-radius: 10px; background: var(--card); box-shadow: 0 12px 40px rgba(0, 0, 0, .3); }
.confirm-box h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.confirm-text { margin: 0 0 18px; color: var(--mut); font-size: 13px; line-height: 1.5; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ===== Section dialog ===== */
.dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(14, 22, 31, 0.5);
}

.dialog {
    width: 100%;
    max-width: 640px;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--card);
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.dialog-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.dialog-sub {
    margin: 2px 0 0;
    color: var(--mut);
    font-size: 12px;
}

.dialog form {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1;
}

.dialog-body {
    overflow: auto;
    padding: 16px 20px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 14px;
}

.field label {
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    color: var(--mut);
}

.field-wide {
    grid-column: 1 / -1;
}

.field.is-derived input {
    background: var(--head);
}

.req {
    color: var(--er);
}

.field-error {
    min-height: 16px;
    margin-top: 2px;
    font-size: 11.5px;
    color: var(--er);
}

.dialog-banner {
    margin: 0 20px 8px;
    padding: 8px 12px;
    border-radius: 6px;
    background: var(--erb);
    color: var(--er);
}

.dialog-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--line);
}

.dialog-foot .hint {
    flex: 1;
    color: var(--mut);
    font-size: 12px;
}

/* ===== Toast ===== */
.toast-root {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    z-index: 100;
    max-width: 90%;
}

.toast {
    padding: 9px 16px;
    border-radius: 6px;
    background: #1f2933;
    color: #fff;
    font-size: 12.5px;
}

.toast-success {
    background: var(--ok);
}

.toast-error {
    background: var(--er);
}

/* ===== Responsive and motion ===== */
@media (max-width: 640px) {
    .login {
        justify-content: center;
        padding: 20px;
    }

    .dialog-body,
    .columns-list {
        grid-template-columns: 1fr;
    }

    .columns-panel {
        width: min(400px, 90vw);
    }

    .search-input {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {

    .detail-backdrop.is-open .detail-panel,
    .refresh-btn.is-busy .icon,
    .page-enter {
        animation: none;
    }

    .sidebar,
    .nav-label,
    .nav-glow,
    .sidebar-toggle,
    .icon-chevron {
        transition: none;
    }

    .nav-btn.is-active .icon {
        animation: none;
    }

    .nav-glow.glow-move-a,
    .nav-glow.glow-move-b {
        animation: none;
    }
}

/* Attachments */
.field-attachment input[type="file"] { height: auto; padding: 6px 0; border: 0; background: transparent; }
.attach-current { font-size: 12px; color: var(--mut); margin-bottom: 4px; }
.attach-hint { font-size: 12px; color: var(--mut); margin-top: 4px; }
.detail-attachment { display: inline-flex; align-items: center; gap: 6px; margin: 8px 12px 0; padding: 4px 8px; border: 0; border-radius: 6px; background: transparent; color: var(--ac); font-size: 13px; cursor: pointer; }
.detail-attachment:hover { background: rgba(26, 124, 240, 0.1); }
.icon-paperclip { width: 14px; height: 14px; background: currentColor; -webkit-mask: var(--ic) center / contain no-repeat; mask: var(--ic) center / contain no-repeat; --ic: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48'/%3E%3C/svg%3E"); }




