:root {
    color-scheme: light;
    --ink: #17221f;
    --ink-strong: #0e2923;
    --muted: #5a6c66;
    --brand: #0f7664;
    --brand-strong: #0a5c4e;
    --brand-soft: #e6f4f0;
    --surface: #ffffff;
    --surface-soft: #f4f8f6;
    --canvas: #edf3f0;
    --line: #d5e0dc;
    --line-strong: #aabdb6;
    --danger: #a33a32;
    --danger-soft: #fff0ee;
    --success: #176b54;
    --success-soft: #e8f6f0;
    --shadow-sm: 0 1px 2px rgb(14 41 35 / 5%), 0 8px 24px rgb(14 41 35 / 5%);
    --shadow-md: 0 18px 48px rgb(14 41 35 / 10%);
    --radius-sm: .55rem;
    --radius-md: .9rem;
    --radius-lg: 1.25rem;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--canvas);
    font-synthesis: none;
    text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at 90% 0, rgb(15 118 100 / 8%), transparent 30rem),
        linear-gradient(180deg, #f8faf9 0, var(--canvas) 28rem);
    line-height: 1.55;
    overflow-wrap: break-word;
}

a { color: var(--brand-strong); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img, svg { max-width: 100%; }
h1, h2, h3 { color: var(--ink-strong); line-height: 1.15; text-wrap: balance; }
h1 { margin: .45rem 0 .8rem; font-size: clamp(2rem, 5vw, 3.35rem); letter-spacing: -.04em; }
h2 { font-size: clamp(1.15rem, 2vw, 1.4rem); }
p { text-wrap: pretty; }
:focus-visible { outline: 3px solid #19a58c; outline-offset: 3px; }
::selection { color: #fff; background: var(--brand); }

.skip-link {
    position: fixed;
    z-index: 100;
    top: .75rem;
    left: .75rem;
    transform: translateY(-180%);
    border-radius: var(--radius-sm);
    padding: .7rem 1rem;
    background: var(--ink-strong);
    color: #fff;
    font-weight: 800;
    text-decoration: none;
}
.skip-link:focus { transform: translateY(0); }

.auth-shell,
.page-shell { width: min(100% - 2rem, 74rem); margin: 0 auto; padding: 1rem 0 4rem; }
.page-shell--narrow { width: min(100% - 2rem, 48rem); }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding-block: 2rem; }
.auth-card,
.welcome-card { background: rgb(255 255 255 / 94%); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: clamp(1.5rem, 5vw, 3rem); }
.auth-card { width: min(100%, 30rem); border-top: .35rem solid var(--brand); }
.welcome-card { text-align: center; }

.app-header {
    position: sticky;
    z-index: 20;
    top: .75rem;
    margin-bottom: clamp(2rem, 5vw, 4rem);
    border: 1px solid rgb(213 224 220 / 88%);
    border-radius: var(--radius-lg);
    background: rgb(255 255 255 / 92%);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(16px);
}
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem .75rem; min-height: 4.75rem; padding: .7rem .8rem .7rem 1rem; }
.brand { display: inline-flex; align-items: center; gap: .75rem; min-width: 44px; min-height: 44px; color: var(--ink-strong); text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 2.75rem; height: 2.75rem; flex: 0 0 2.75rem; border-radius: .75rem; background: var(--brand); color: #fff; font-size: .85rem; font-weight: 900; letter-spacing: .04em; box-shadow: inset 0 0 0 1px rgb(255 255 255 / 18%); }
.brand-copy { display: grid; line-height: 1.08; }
.brand-copy strong { font-size: 1rem; letter-spacing: -.01em; }
.brand-copy small { margin-top: .3rem; color: var(--muted); font-size: .72rem; font-weight: 650; }
.session-bar { display: flex; align-items: stretch; order: 2; gap: .4rem; min-width: 0; max-width: 100%; margin-left: auto; }
.session-chip, .tenant-chip { display: flex; flex-direction: column; justify-content: center; gap: .12rem; min-width: 0; min-height: 46px; max-width: min(100%, 16rem); overflow: hidden; border: 1px solid var(--line); border-radius: .7rem; padding: .35rem .8rem; background: #fff; color: var(--ink-strong); line-height: 1.1; text-decoration: none; }
.tenant-chip { background: var(--surface-soft); }
.tenant-chip-kicker { color: var(--brand-strong); font-size: .68rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.session-chip strong, .tenant-chip strong { display: block; overflow: hidden; min-width: 0; max-width: 100%; font-size: .92rem; text-overflow: ellipsis; white-space: nowrap; }
.tenant-chip:hover, .tenant-chip[aria-current="page"] { border-color: var(--brand); background: var(--brand-soft); }
.nav-toggle { display: none; align-items: center; order: 3; gap: .6rem; min-height: 44px; min-width: 44px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .55rem .75rem; background: var(--surface); color: var(--ink-strong); font-weight: 800; }
.nav-toggle-icon { display: grid; gap: 3px; width: 1rem; }
.nav-toggle-icon i { display: block; height: 2px; border-radius: 2px; background: currentColor; }
.nav-panel { display: flex; align-items: center; justify-content: space-between; gap: .5rem .75rem; border-top: 1px solid var(--line); padding: .45rem .7rem .55rem; }
.nav-main { display: flex; align-items: center; flex: 1 1 auto; flex-wrap: wrap; gap: .35rem .5rem; min-width: 0; }
.nav-primary { display: flex; align-items: center; flex-wrap: wrap; gap: .15rem; min-width: 0; }
.nav-menus { display: flex; align-items: center; gap: .15rem; margin-left: auto; }
.nav-group-label { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.nav-link, .link-button { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; border-radius: .55rem; padding: .55rem .62rem; color: #40534d; font-size: .84rem; font-weight: 750; text-decoration: none; white-space: nowrap; }
.nav-link--step { background: var(--surface-soft); }
.nav-link:hover, .nav-more summary:hover { background: var(--brand-soft); color: var(--brand-strong); }
.nav-link[aria-current="page"] { background: var(--brand); color: #fff; }
.nav-more { position: relative; }
.nav-more summary { display: inline-block; min-height: 44px; min-width: 44px; border-radius: .55rem; padding: 0 .68rem; color: #40534d; font-size: .84rem; font-weight: 750; white-space: nowrap; cursor: pointer; list-style: none; }
.nav-more summary::-webkit-details-marker { display: none; }
.nav-more summary > span { display: flex; align-items: center; justify-content: space-between; gap: .4rem; min-height: 44px; }
.nav-more summary > span::after { content: ""; width: .42rem; height: .42rem; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: translateY(-.1rem) rotate(45deg); flex: 0 0 auto; }
.nav-more[open] summary > span::after { transform: translateY(.12rem) rotate(225deg); }
.nav-more[open] summary, .nav-more.contains-current summary { background: var(--brand-soft); color: var(--brand-strong); }
.nav-menu-content { position: absolute; z-index: 30; top: calc(100% + .4rem); right: 0; display: grid; gap: .15rem; width: min(19rem, calc(100vw - 2rem)); border: 1px solid var(--line); border-radius: var(--radius-md); padding: .4rem; background: var(--surface); box-shadow: var(--shadow-md); }
.nav-menu-content .nav-link { display: grid; align-content: center; gap: .05rem; min-height: 46px; white-space: normal; line-height: 1.2; }
.nav-menu-content .nav-link small { color: var(--muted); font-size: .75rem; font-weight: 650; }
.nav-menu-content .nav-link:hover small, .nav-menu-content .nav-link[aria-current="page"] small { color: inherit; }
.nav-menu-label { margin: .55rem .55rem .1rem; color: var(--muted); font-size: .68rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.logout-form { display: block; margin: 0; }
.link-button { border: 1px solid #edbbb5; background: #fff; color: var(--danger); }
.link-button:hover { background: var(--danger-soft); color: #842f28; }

.page-heading { max-width: 52rem; margin-bottom: clamp(1.5rem, 4vw, 2.5rem); }
.page-heading h1 { margin-bottom: .65rem; }
.eyebrow, .status-label { margin: 0; color: var(--brand); font-size: .75rem; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.lead { max-width: 68ch; margin: 0; color: var(--muted); font-size: clamp(1rem, 2vw, 1.12rem); line-height: 1.65; }
.signed-in, .muted, .hint { color: var(--muted); }
.hint { font-size: .9rem; }

form { display: grid; gap: .55rem; margin-top: 1.25rem; }
label { margin-top: .35rem; color: var(--ink-strong); font-size: .9rem; font-weight: 750; }
input, select, textarea {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    padding: .72rem .8rem;
    background: #fff;
    color: var(--ink);
    transition: border-color 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
input:hover, select:hover, textarea:hover { border-color: #78968c; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgb(15 118 100 / 12%); outline: 0; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); background: #fffafa; box-shadow: 0 0 0 3px rgb(163 58 50 / 10%); }
input[type="file"] { padding: .5rem; }
textarea { min-height: 7rem; resize: vertical; }

.button, .primary-button, .secondary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: .7rem 1rem;
    background: var(--brand);
    color: #fff;
    font: inherit;
    font-weight: 800;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    box-shadow: 0 2px 8px rgb(15 118 100 / 16%);
    transition: transform 150ms ease, background 150ms ease, box-shadow 150ms ease;
}
form > .button, form > .primary-button, form > .secondary-button { margin-top: .65rem; }
.button:hover, .primary-button:hover { background: var(--brand-strong); box-shadow: 0 5px 14px rgb(15 118 100 / 20%); transform: translateY(-1px); }
.button--secondary, .secondary-button { border-color: #8fb8ad; background: #fff; color: var(--brand-strong); box-shadow: none; }
.button--secondary:hover, .secondary-button:hover { background: var(--brand-soft); border-color: var(--brand); transform: translateY(-1px); }
.button--compact { margin-top: 0; padding: .5rem .75rem; }
button[aria-disabled="true"] { cursor: wait; opacity: .7; }
.text-link { display: inline-flex; align-items: center; min-width: 44px; min-height: 44px; color: var(--brand-strong); font-weight: 800; }
.auth-switch { margin: 1.25rem 0 0; }
.auth-switch .button { width: 100%; }

.notice, .form-error, .success-message { margin: 1rem 0; border: 1px solid transparent; border-radius: var(--radius-sm); padding: .8rem 1rem; }
.notice--success, .success-message { border-color: #a8d8c7; background: var(--success-soft); color: #155744; }
.notice--error, .form-error { border-color: #edbbb5; background: var(--danger-soft); color: #842f28; }
.form-error { box-shadow: inset 4px 0 var(--danger); }
.form-error p:first-child { margin-top: 0; }
.form-error p:last-child { margin-bottom: 0; }
.form-error ul { margin: .35rem 0 0; padding-left: 1.2rem; }
.field-error { margin: -.15rem 0 .35rem; color: var(--danger); font-size: .86rem; font-weight: 650; }

.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); gap: 1rem; }
.feature-card, .form-card, .record-card, .list-card, .summary-card, .tenant-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: rgb(255 255 255 / 96%);
    box-shadow: var(--shadow-sm);
}
.feature-card { display: flex; align-items: center; gap: 1rem; min-height: 8.5rem; padding: 1.2rem; color: var(--ink-strong); text-decoration: none; transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease; }
a.feature-card:hover, a.record-card:hover { border-color: #83b8a9; box-shadow: 0 .8rem 2rem rgb(14 41 35 / 10%); transform: translateY(-2px); }
.feature-card span:last-child { display: grid; gap: .3rem; }
.feature-card strong { font-size: 1.02rem; }
.feature-card small { color: var(--muted); line-height: 1.4; }
.feature-icon { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; min-width: 3.1rem; min-height: 3.1rem; border-radius: .8rem; padding: .4rem; background: var(--brand-soft); color: var(--brand-strong); font-weight: 900; }
.feature-card:nth-child(3n + 2) .feature-icon { background: #fff0e7; color: #9b4b20; }
.feature-card--account { background: var(--surface-soft); }

.module-layout { display: grid; grid-template-columns: minmax(17rem, 22rem) minmax(0, 1fr); align-items: start; gap: 1.25rem; margin-block: 1.25rem; }
.form-card, .list-card, .summary-card { padding: clamp(1.1rem, 3vw, 1.5rem); }
.form-card h2, .list-card h2, .summary-card h2 { margin: 0 0 .65rem; }
.form-card > h2:not(:first-child), .list-card > h2:not(:first-child) { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.records, .tenant-list { display: grid; gap: .85rem; min-width: 0; }
.record-card { display: grid; grid-template-columns: minmax(0, 1fr) minmax(8rem, auto); align-items: start; gap: 1rem; padding: 1.1rem; color: inherit; text-decoration: none; }
.record-card h2 { margin: .25rem 0 .45rem; font-size: 1.08rem; }
.record-card p { margin: .3rem 0; }
.record-card form { margin: 0; }
.list-card .record-card { margin-top: .65rem; }
.tenant-card { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.2rem; }
.tenant-card h2 { margin: .2rem 0; }
.tenant-card form { margin: 0; }
.tenant-card--active { border-color: var(--brand); box-shadow: inset .3rem 0 var(--brand), var(--shadow-sm); }
.active-badge { border-radius: 999px; padding: .45rem .75rem; background: var(--brand-soft); color: var(--success); font-size: .85rem; font-weight: 800; }

.empty-state { border: 1px dashed var(--line-strong); border-radius: var(--radius-md); padding: 1.6rem; background: var(--surface-soft); color: var(--muted); text-align: center; }
.summary-total { margin-top: 1.5rem; border-radius: var(--radius-md); padding: 1rem 1.25rem; background: var(--ink-strong); color: #fff; font-size: 1.1rem; }
.period-tabs { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 1.5rem; }
.period-tabs .button { width: auto; margin: 0; }
.period-tabs [aria-current="page"], .period-tabs .button:not(.button--secondary) { background: var(--brand); color: #fff; }
.usage-summary, .component-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.usage-score { color: var(--brand); font-size: clamp(2.5rem, 8vw, 4rem); }
.component-grid article { border-left: .25rem solid var(--brand); padding-left: 1rem; }
.metric-table { display: grid; gap: .1rem; }
.metric-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1rem; min-height: 48px; border-bottom: 1px solid var(--line); padding: .65rem .1rem; }
.metric-row:last-child { border-bottom: 0; }
.metric-row a { display: inline-flex; align-items: center; min-height: 44px; color: var(--brand-strong); font-weight: 800; }

@media (max-width: 64rem) {
    .nav-toggle { display: inline-flex; order: 2; margin-left: auto; }
    .session-bar { flex: 1 1 100%; order: 3; width: 100%; margin-left: 0; }
    .session-chip, .tenant-chip { flex: 1 1 0; max-width: none; }
    .app-header[data-enhanced="true"][data-open="false"] .nav-panel { display: none; }
    .nav-panel { display: grid; align-items: stretch; padding: .65rem; }
    .nav-main { display: grid; gap: .85rem; }
    .nav-group-label { position: static; width: auto; height: auto; margin: 0 0 .35rem; overflow: visible; clip: auto; color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
    .nav-primary { display: grid; grid-template-columns: 1fr; gap: .35rem; width: 100%; }

    .nav-link { justify-content: flex-start; white-space: normal; }
    .nav-menus { display: grid; gap: .35rem; width: 100%; margin: 0; }
    .nav-more, .nav-more summary { width: 100%; }
    .nav-more summary { white-space: normal; }
    .nav-menu-content { position: static; width: 100%; margin-top: .35rem; box-shadow: none; }
    .logout-form { border-top: 1px solid var(--line); padding-top: .65rem; }
    .logout-form .link-button { justify-content: center; width: 100%; }
}

@media (min-width: 40rem) and (max-width: 64rem) {
    .nav-primary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 48rem) and (max-width: 64rem) {
    .nav-primary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 48rem) {
    .module-layout, .record-card { grid-template-columns: 1fr; }
    .record-card form { width: 100%; }
    .record-card form .button, .record-card form .secondary-button { width: 100%; }
}

@media (max-width: 35rem) {
    .auth-shell, .page-shell { width: min(100% - 1rem, 74rem); padding-top: .5rem; }
    .app-header { top: .25rem; border-radius: .85rem; margin-bottom: 2rem; }
    .topbar { min-height: 4.25rem; padding: .55rem; }
    .brand-mark { width: 2.5rem; height: 2.5rem; flex-basis: 2.5rem; }
    .brand-copy small { display: none; }
    .session-bar { flex-direction: column; }
    .tenant-card .button, .tenant-card form { width: 100%; }
    .metric-row { align-items: flex-start; flex-direction: column; }
    .button, .primary-button, .secondary-button { width: 100%; }
    .period-tabs .button { width: auto; flex: 1 1 8rem; }
}

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