:root {
  --ink: #14231f;
  --muted: #60716c;
  --paper: #f4f7f5;
  --surface: #ffffff;
  --surface-soft: #edf3f0;
  --line: #d9e4df;
  --brand: #0a5c4d;
  --brand-deep: #073d34;
  --brand-soft: #ddf3ea;
  --accent: #d0ec57;
  --blue: #2f6ee5;
  --amber: #a96400;
  --red: #b33232;
  --shadow: 0 18px 50px rgba(15, 49, 40, .11);
  --radius: 18px;
  --sidebar: 278px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { min-height: 100vh; margin: 0; color: var(--ink); background: var(--paper); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden] { display: none !important; }

.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; padding: .75rem 1rem; color: white; background: var(--brand-deep); border-radius: 9px; }
.skip-link:focus { top: 1rem; }
.offline-banner { position: fixed; inset: 0 0 auto; z-index: 80; padding: .55rem 1rem; color: #3c2a00; text-align: center; background: #ffe39a; font-weight: 750; font-size: .82rem; }

.app-shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 1.2rem 1rem; color: #eaf7f3; background: linear-gradient(180deg, #073d34 0%, #062f29 100%); overflow-y: auto; z-index: 50; }
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .3rem .3rem 1.1rem; }
.brand { display: flex; align-items: center; gap: .75rem; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; color: var(--accent); background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); border-radius: 13px; }
.brand-mark svg { width: 27px; }
.brand strong { display: block; letter-spacing: .13em; font-size: .7rem; color: var(--accent); }
.brand small { display: block; margin-top: .08rem; font-size: .96rem; font-weight: 760; color: white; }
.sidebar-close { display: none; color: white; }

.utility-chip { display: grid; grid-template-columns: auto 1fr; gap: .68rem; align-items: center; margin: .3rem .15rem 1rem; padding: .82rem; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); border-radius: 14px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(208,236,87,.12); }
.utility-chip strong, .utility-chip small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.utility-chip strong { font-size: .76rem; }
.utility-chip small { margin-top: .2rem; color: #a9c5bc; font-size: .68rem; }

.nav-list { display: grid; gap: .28rem; }
.nav-list a { display: grid; grid-template-columns: 28px 1fr; gap: .62rem; align-items: center; min-height: 46px; padding: .68rem .78rem; color: #bcd2cb; text-decoration: none; border-radius: 12px; font-weight: 660; font-size: .82rem; transition: .15s ease; }
.nav-list a:hover { color: white; background: rgba(255,255,255,.07); }
.nav-list a[aria-current="page"] { color: #082f28; background: var(--accent); box-shadow: 0 8px 22px rgba(0,0,0,.13); }
.nav-list a > span:first-child { font-size: 1.08rem; text-align: center; }
.sidebar-footer { margin-top: auto; display: grid; gap: .8rem; padding: 1.2rem .3rem .2rem; }
.sidebar-footer > a { color: #96b7ad; font-size: .72rem; text-decoration: none; }
.language-switch { display: grid; grid-template-columns: 1fr 1fr; padding: .22rem; border: 1px solid rgba(255,255,255,.12); border-radius: 10px; background: rgba(0,0,0,.12); }
.language-switch button { padding: .45rem; color: #a9c5bc; border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-size: .7rem; font-weight: 800; }
.language-switch button[aria-pressed="true"] { color: var(--brand-deep); background: white; }

.main-column { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 35; display: flex; align-items: center; min-height: 82px; padding: .8rem clamp(1rem, 2.7vw, 2.7rem); background: rgba(244,247,245,.9); border-bottom: 1px solid rgba(217,228,223,.8); backdrop-filter: blur(15px); }
.menu-button { display: none; margin-right: .75rem; }
.topbar-title { min-width: 0; }
.topbar-title > span { display: block; color: var(--brand); text-transform: uppercase; letter-spacing: .12em; font-size: .62rem; font-weight: 860; }
.topbar-title h1 { margin: .13rem 0 0; font-size: clamp(1.18rem, 2vw, 1.5rem); line-height: 1.2; }
.topbar-actions { display: flex; align-items: center; gap: .65rem; margin-left: auto; }
.environment-badge { padding: .38rem .55rem; color: #664000; background: #ffe1a3; border-radius: 8px; font-size: .62rem; font-weight: 850; letter-spacing: .08em; }
.quick-action, .profile-button, .icon-button { border: 0; cursor: pointer; }
.quick-action { display: flex; align-items: center; gap: .45rem; min-height: 42px; padding: .55rem .78rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; font-size: .75rem; font-weight: 700; }
.icon-button { display: inline-grid; place-items: center; width: 40px; height: 40px; color: var(--ink); background: transparent; border-radius: 11px; font-size: 1.2rem; }
.icon-button:hover { background: rgba(10,92,77,.08); }
.profile-menu { position: relative; }
.profile-button { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .6rem; min-width: 210px; padding: .38rem .55rem; color: var(--ink); text-align: left; background: transparent; border-radius: 13px; }
.profile-button:hover { background: rgba(10,92,77,.06); }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; color: white; background: linear-gradient(145deg, var(--brand), #16826d); border-radius: 12px; font-size: .7rem; font-weight: 860; }
.profile-copy { min-width: 0; }
.profile-copy strong, .profile-copy small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.profile-copy strong { font-size: .73rem; }
.profile-copy small { margin-top: .15rem; color: var(--muted); font-size: .63rem; }
.profile-popover { position: absolute; right: 0; top: calc(100% + .5rem); min-width: 190px; padding: .4rem; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); }
.profile-popover a { display: block; padding: .7rem; text-decoration: none; border-radius: 9px; font-size: .75rem; font-weight: 680; }
.profile-popover a:hover { background: var(--surface-soft); }

.workspace { min-height: calc(100vh - 82px); padding: clamp(1rem, 2.7vw, 2.7rem); }
.loading-state, .signed-out { min-height: calc(100vh - 150px); display: grid; place-items: center; text-align: center; }
.loading-state > * { grid-column: 1; }
.loading-state h2 { margin: 1rem 0 .3rem; font-size: 1.08rem; }
.loading-state p { margin: 0; color: var(--muted); font-size: .8rem; }
.loader { width: 38px; height: 38px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.signed-out-card { width: min(520px, 100%); padding: clamp(1.5rem, 5vw, 3rem); background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.signed-out-mark { display: grid; place-items: center; width: 58px; height: 58px; margin: 0 auto 1.2rem; color: var(--accent); background: var(--brand-deep); border-radius: 18px; font-size: .8rem; font-weight: 900; letter-spacing: .08em; }
.signed-out-card h2 { margin: .35rem 0 .7rem; }
.signed-out-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.65; }
.local-login-form { display: grid; gap: .65rem; margin: 1.1rem 0; text-align: left; }
.local-login-divider { margin: .2rem 0 0; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; text-align: center; }
.local-login-form label { display: grid; gap: .3rem; font-size: .74rem; font-weight: 700; color: var(--ink); }
.local-login-form input { min-height: 40px; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 9px; font-size: .82rem; background: var(--surface); color: var(--ink); }
.local-login-error { margin: 0; padding: .5rem .65rem; color: var(--red); background: rgba(179,50,50,.08); border-radius: 9px; font-size: .76rem; }

.view-stack { display: grid; gap: 1.15rem; }
.hero-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.hero-copy h2 { margin: 0; font-size: clamp(1.45rem, 3vw, 2.1rem); letter-spacing: -.03em; }
.hero-copy p { max-width: 700px; margin: .45rem 0 0; color: var(--muted); line-height: 1.55; font-size: .86rem; }
.eyebrow { margin: 0; color: var(--brand); text-transform: uppercase; letter-spacing: .12em; font-size: .62rem; font-weight: 870; }
.hero-actions, .toolbar-actions { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 42px; padding: .6rem .9rem; color: var(--ink); text-decoration: none; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; cursor: pointer; font-size: .74rem; font-weight: 760; }
.button:hover { transform: translateY(-1px); box-shadow: 0 7px 18px rgba(15,49,40,.08); }
.button.primary { color: white; background: var(--brand); border-color: var(--brand); }
.button.accent { color: var(--brand-deep); background: var(--accent); border-color: var(--accent); }
.button.danger { color: var(--red); border-color: rgba(179,50,50,.25); }
.button.small { min-height: 34px; padding: .42rem .65rem; font-size: .68rem; }
.button:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .85rem; }
.metric-card { position: relative; min-height: 140px; padding: 1rem; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.metric-card::after { content: ""; position: absolute; right: -32px; bottom: -38px; width: 100px; height: 100px; background: var(--brand-soft); border-radius: 50%; }
.metric-label { display: block; color: var(--muted); font-size: .69rem; font-weight: 700; }
.metric-value { display: block; margin-top: .65rem; font-size: clamp(1.35rem, 2.4vw, 2rem); line-height: 1; letter-spacing: -.04em; }
.metric-note { display: block; margin-top: .65rem; color: var(--brand); font-size: .65rem; font-weight: 750; }
.metric-icon { position: absolute; right: .9rem; top: .9rem; display: grid; place-items: center; width: 34px; height: 34px; color: var(--brand); background: var(--brand-soft); border-radius: 10px; font-weight: 900; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(285px, .8fr); gap: .9rem; }
.content-grid.equal { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: 1rem 1.05rem; border-bottom: 1px solid var(--line); }
.panel-header h3 { margin: 0; font-size: .9rem; }
.panel-header p { margin: .25rem 0 0; color: var(--muted); font-size: .66rem; }
.panel-body { padding: 1rem; }
.panel-footer { padding: .8rem 1rem; background: var(--surface-soft); border-top: 1px solid var(--line); }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .73rem; }
th, td { padding: .78rem .86rem; text-align: left; border-bottom: 1px solid #e8efec; vertical-align: middle; }
th { color: var(--muted); text-transform: uppercase; letter-spacing: .07em; background: #fbfcfb; font-size: .58rem; font-weight: 850; }
tbody tr:hover { background: #f8fbf9; }
tbody tr:last-child td { border-bottom: 0; }
.cell-title { display: block; font-weight: 750; }
.cell-subtitle { display: block; margin-top: .15rem; color: var(--muted); font-size: .64rem; }
.amount { font-variant-numeric: tabular-nums; font-weight: 780; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .67rem; }

.status { display: inline-flex; align-items: center; gap: .3rem; padding: .28rem .48rem; border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: .58rem; font-weight: 830; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.active, .status.paid, .status.approved, .status.succeeded, .status.completed, .status.normal { color: #0d725e; background: #e2f6ef; }
.status.open, .status.scheduled, .status.partial, .status.draft, .status.pending { color: #805600; background: #fff1c7; }
.status.past_due, .status.failed, .status.urgent, .status.collections, .status.decrease { color: var(--red); background: #fee8e8; }
.status.inactive, .status.cancelled, .status.void, .status.removed { color: #666; background: #ecefee; }

.list-stack { display: grid; gap: .55rem; }
.list-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: .7rem; align-items: center; padding: .7rem; border: 1px solid var(--line); border-radius: 12px; }
.list-icon { display: grid; place-items: center; width: 36px; height: 36px; color: var(--brand); background: var(--brand-soft); border-radius: 10px; font-size: .72rem; font-weight: 850; }
.list-copy { min-width: 0; }
.list-copy strong, .list-copy small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.list-copy strong { font-size: .72rem; }
.list-copy small { margin-top: .18rem; color: var(--muted); font-size: .63rem; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .8rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 15px; }
.search-field { position: relative; flex: 1; max-width: 440px; }
.search-field span { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-field input { width: 100%; min-height: 42px; padding: .55rem .7rem .55rem 2.2rem; color: var(--ink); background: #fafcfb; border: 1px solid var(--line); border-radius: 11px; outline: none; }
.search-field input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(10,92,77,.1); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: grid; gap: .32rem; }
.field.full { grid-column: 1 / -1; }
.field label { color: #344a43; font-size: .64rem; font-weight: 760; }
.field input, .field select, .field textarea { width: 100%; min-height: 42px; padding: .62rem .7rem; color: var(--ink); background: #fbfdfc; border: 1px solid var(--line); border-radius: 10px; outline: none; }
.field textarea { min-height: 92px; resize: vertical; }
.field-help { color: var(--muted); font-size: .6rem; line-height: 1.45; }
.form-actions { display: flex; justify-content: flex-end; gap: .55rem; margin-top: .9rem; }
.checkbox-row { display: flex; align-items: center; gap: .5rem; font-size: .7rem; }

.empty-state { padding: 2.4rem 1rem; text-align: center; }
.empty-state strong { display: block; font-size: .9rem; }
.empty-state p { max-width: 440px; margin: .5rem auto 0; color: var(--muted); line-height: 1.55; font-size: .72rem; }

.notice { padding: .8rem .9rem; color: #24463e; background: var(--brand-soft); border: 1px solid #bfe4d6; border-radius: 12px; font-size: .7rem; line-height: 1.55; }
.notice.warning { color: #674500; background: #fff3ce; border-color: #efd691; }
.notice.danger { color: #7f2525; background: #feeaea; border-color: #f4c1c1; }

.aging-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .65rem; }
.aging-card { padding: .9rem; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.aging-card span { display: block; color: var(--muted); font-size: .62rem; }
.aging-card strong { display: block; margin-top: .45rem; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.aging-card.total { color: white; background: var(--brand-deep); border-color: var(--brand-deep); }
.aging-card.total span { color: #b7d2c9; }

.security-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; }
.security-card { padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.security-card .security-icon { display: grid; place-items: center; width: 40px; height: 40px; color: var(--brand); background: var(--brand-soft); border-radius: 12px; }
.security-card h3 { margin: .8rem 0 .4rem; font-size: .82rem; }
.security-card p { margin: 0; color: var(--muted); font-size: .68rem; line-height: 1.55; }
.security-card .status { margin-top: .8rem; }

.app-dialog { width: min(700px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); padding: 0; background: var(--surface); border: 0; border-radius: 20px; box-shadow: 0 28px 90px rgba(0,0,0,.25); }
.app-dialog::backdrop { background: rgba(5,24,20,.55); backdrop-filter: blur(4px); }
.dialog-shell { margin: 0; }
.dialog-header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.05rem 1.2rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: .2rem 0 0; font-size: 1.08rem; }
.dialog-content { padding: 1.2rem; overflow: auto; }
.toast-region { position: fixed; z-index: 100; right: 1rem; bottom: 1rem; display: grid; gap: .55rem; width: min(360px, calc(100vw - 2rem)); }
.toast { padding: .8rem .9rem; color: white; background: var(--brand-deep); border-radius: 12px; box-shadow: var(--shadow); font-size: .72rem; line-height: 1.45; animation: toast-in .2s ease-out; }
.toast.error { background: #842b2b; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.drawer-backdrop { position: fixed; inset: 0; z-index: 45; background: rgba(4,24,20,.5); }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .aging-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .security-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 940px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: min(310px, 88vw); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 20px 0 60px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close, .menu-button { display: inline-grid; }
  .content-grid, .content-grid.equal { grid-template-columns: 1fr; }
  .topbar { padding: .7rem 1rem; }
  .workspace { padding: 1rem; }
}

@media (max-width: 700px) {
  .topbar { min-height: 72px; }
  .workspace { min-height: calc(100vh - 72px); }
  .topbar-title > span, .quick-action span:last-child, .profile-copy { display: none; }
  .profile-button { min-width: auto; grid-template-columns: auto auto; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-card { min-height: 125px; }
  .hero-row, .toolbar { align-items: stretch; flex-direction: column; }
  .search-field { max-width: none; }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .aging-grid, .security-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  th, td { padding: .68rem .72rem; }
}

@media (max-width: 430px) {
  .metric-grid, .aging-grid, .security-grid { grid-template-columns: 1fr; }
  .hero-actions, .toolbar-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .hero-actions .button, .toolbar-actions .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
