:root {
    --navy: #0039a0;
    --navy-deep: #002a78;
    --navy-ink: #1a2744;
    --cyan: #00bafd;
    --cyan-deep: #0096d6;
    --cyan-soft: #e7f6fd;
    --paper: #eef1f6;
    --white: #ffffff;
    --line: #c5ceda;
    --grid: #d5dce6;
    --header: #e7eef6;
    --muted: #5c6b82;
    --danger: #b42318;
    --danger-soft: #fdecea;
    --ok: #067647;
    --font: "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    min-height: 100vh;
    font-family: var(--font);
    font-size: 13px;
    line-height: 1.3;
    color: var(--navy-ink);
    background: var(--paper);
}

a { color: var(--navy); }

button, input, select { font: inherit; }

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

/* Login stays a sign-in screen, but the controls match the grid. */
.login-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1fr);
}

.login-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 28px;
    background: var(--navy);
}

.brand-card {
    width: min(380px, 100%);
    background: white;
    padding: 12px 14px 16px;
}

.brand-card img { display: block; width: 100%; height: auto; }
.brand-card p { margin: 4px 0 0; color: var(--navy); font-weight: 600; font-size: 13px; }

.login-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--paper);
}

.login-card { width: min(360px, 100%); }

.eyebrow {
    margin: 0 0 2px;
    color: var(--cyan-deep);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.login-card h1 { margin: 0; font-size: 20px; color: var(--navy); font-weight: 600; }

.lede, .summary {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.35;
}

form.stack { margin-top: 14px; display: grid; gap: 8px; }

label.field, div.field { display: grid; gap: 2px; font-weight: 600; font-size: 12px; color: var(--navy-ink); }

input[type="email"],
input[type="password"],
input[type="text"],
input[type="tel"],
input[type="url"],
select {
    width: 100%;
    height: 28px;
    border: 1px solid var(--line);
    border-radius: 2px;
    padding: 0 6px;
    background: white;
    color: var(--navy-ink);
}

textarea {
    width: 100%;
    min-height: 180px;
    border: 1px solid var(--line);
    border-radius: 2px;
    padding: 6px;
    background: white;
    color: var(--navy-ink);
    resize: vertical;
}

input:focus, select:focus, textarea:focus {
    outline: 1px solid var(--cyan);
    border-color: var(--navy);
}

.form-card > .field,
.form-card > .remember { margin-top: 8px; }

.remember {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 28px;
    padding: 0 10px;
    border: 1px solid var(--navy-deep);
    border-radius: 2px;
    background: var(--navy);
    color: white;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover { background: var(--navy-deep); }

.btn-ghost {
    background: white;
    color: var(--navy);
    border-color: var(--line);
}

.btn-ghost:hover { background: var(--cyan-soft); }

.form-error {
    margin: 8px 0 0;
    padding: 6px 8px;
    background: var(--danger-soft);
    color: var(--danger);
    font-weight: 600;
    font-size: 12px;
}

/* App shell */
.shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 248px 1fr;
}

.sidebar {
    display: flex;
    flex-direction: column;
    background: white;
    border-right: 1px solid var(--line);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
}

.logo-link {
    display: block;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
}

.logo-link img { display: block; width: 100%; height: auto; }

.nav { display: grid; }

.nav a {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 30px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--grid);
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--navy-ink);
}

.nav a svg { flex: 0 0 auto; }

.nav a:hover { background: var(--cyan-soft); }

.nav a.is-active {
    background: var(--cyan-soft);
    color: var(--navy);
    box-shadow: inset 3px 0 0 var(--navy);
}

.nav-group {
    border-bottom: 1px solid var(--grid);
}

.nav-parent {
    display: block;
    margin: 0;
    padding: 0;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.25;
    color: var(--navy-ink);
    cursor: pointer;
    list-style: none;
}

.nav-parent::marker,
.nav-parent::-webkit-details-marker {
    content: none;
    display: none;
}

.nav-parent-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 30px;
    padding: 6px 10px;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.25;
}

.nav-parent-row svg { flex: 0 0 auto; }

.nav-parent:hover { background: var(--cyan-soft); }

.nav-group.is-current > .nav-parent {
    color: var(--navy);
}

.nav-chevron {
    margin-left: auto;
    color: var(--muted);
    transition: transform 0.15s ease;
}

.nav-group[open] > .nav-parent .nav-chevron { transform: rotate(90deg); }

.nav-sub a {
    padding-left: 32px;
    border-bottom: 1px solid var(--grid);
}

.nav-sub a:last-child { border-bottom: 0; }

.sidebar-foot {
    margin-top: auto;
    padding: 8px;
    border-top: 1px solid var(--line);
}

.who { padding: 0 2px 6px; }
.who strong { display: block; color: var(--navy); font-size: 12px; }
.who span { color: var(--muted); font-size: 11px; }
.sidebar-foot form { margin: 0; }
.sidebar-foot .btn { width: 100%; }

.main { padding: 10px 12px 20px; min-width: 0; }

.page-head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: flex-end;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.page-head h1 {
    margin: 0;
    font-size: 16px;
    line-height: 1.2;
    font-weight: 600;
    color: var(--navy);
}

.page-head p { margin: 2px 0 0; max-width: 720px; }
.page-head > .btn { margin-left: auto; }
.page-toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.filter-bar { display: flex; align-items: flex-end; gap: 6px; flex-wrap: wrap; }
.filter-bar .field { width: 240px; }
input.code-input { text-transform: uppercase; letter-spacing: 0.08em; }

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    margin-bottom: 8px;
    border: 1px solid var(--line);
    background: white;
}

.stat {
    padding: 6px 8px;
    border-right: 1px solid var(--grid);
}

.stat:last-child { border-right: 0; }
.stat span { display: block; color: var(--muted); font-size: 11px; font-weight: 600; }
.stat strong { display: block; margin-top: 1px; font-size: 16px; font-weight: 600; color: var(--navy); }
.stat em { font-style: normal; color: var(--cyan-deep); font-weight: 600; font-size: 12px; }

.supplier-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.supplier-card {
    background: white;
    border: 1px solid var(--line);
    padding: 0;
}

.supplier-card header {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
    padding: 4px 8px;
    background: var(--header);
    border-bottom: 1px solid var(--line);
}

.supplier-card h2 { margin: 0; font-size: 13px; color: var(--navy); font-weight: 600; }
.supplier-card .summary { margin: 0; }
.supplier-card .count { margin: 0; color: var(--navy); font-weight: 600; font-size: 11px; white-space: nowrap; }

.company-list { list-style: none; margin: 0; padding: 0; }
.company-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 26px;
    padding: 2px 8px;
    border-top: 1px solid var(--grid);
}
.company-list li:first-child { border-top: 0; }
.company-list li strong { font-size: 12px; font-weight: 600; }

.toggle-form, .supplier-controls { margin: 0; display: flex; align-items: center; gap: 6px; }
.switch-state { min-width: 22px; font-size: 11px; font-weight: 600; color: var(--muted); }
.is-on + .switch-state,
.toggle-form:has(.is-on) .switch-state,
.supplier-row.is-on .switch-state,
.module-row.is-on .switch-state { color: var(--ok); }

.switch {
    position: relative;
    width: 32px;
    height: 16px;
    border: 0;
    border-radius: 99px;
    background: #b7c3d4;
    cursor: pointer;
    padding: 0;
}

.switch span {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: white;
    transition: transform 0.12s ease;
}

.switch.is-on { background: var(--cyan); }
.switch.is-on span { transform: translateX(16px); }
.switch:focus-visible { outline: 1px solid var(--navy); }
.switch:disabled { opacity: 0.7; cursor: wait; }

.table-wrap {
    overflow-x: auto;
    max-width: 100%;
    background: white;
    border: 1px solid var(--line);
}

table { width: 100%; border-collapse: collapse; min-width: 640px; }

th, td {
    text-align: left;
    padding: 3px 8px;
    border: 1px solid var(--grid);
    vertical-align: middle;
    white-space: nowrap;
}

th {
    background: var(--navy);
    color: white;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

td { font-weight: 400; font-size: 12px; background: white; }
tbody tr:nth-child(even) td { background: #f7f9fc; }
tbody tr:hover td { background: #e7f6fd; }
td .summary { margin: 0; font-size: 11px; }

.meter { height: 6px; background: #e6eef6; min-width: 120px; }
.meter i { display: block; height: 100%; background: var(--cyan); }

.pill {
    display: inline-flex;
    align-items: center;
    height: 16px;
    padding: 0 6px;
    background: var(--cyan-soft);
    color: var(--navy);
    font-size: 11px;
    font-weight: 600;
    text-transform: capitalize;
}

.pill.confirmed, .pill.active { background: #e7f8ef; color: var(--ok); }
.pill.cancelled, .pill.inactive { background: var(--danger-soft); color: var(--danger); }

.banner {
    margin: 0 0 8px;
    padding: 4px 8px;
    background: #e7f8ef;
    color: var(--ok);
    font-weight: 600;
    font-size: 12px;
    border: 1px solid #b7e4c7;
}

.form-card, .danger-form {
    background: white;
    border: 1px solid var(--line);
}

.form-card { padding: 8px 10px 10px; }
.form-card h2 {
    margin: 10px 0 6px;
    padding-bottom: 3px;
    border-bottom: 1px solid var(--grid);
    color: var(--navy);
    font-size: 13px;
    font-weight: 600;
}
.form-card h2:first-child { margin-top: 0; }
.form-card > .summary { margin-bottom: 6px; }

.term-panel {
    border-top: 1px solid var(--grid);
}
.term-panel:first-of-type { border-top: 0; }
.term-panel summary {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    padding: 4px 2px;
    color: var(--navy);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.25;
    cursor: pointer;
    list-style: none;
}
.term-panel summary::-webkit-details-marker,
.term-panel summary::marker { content: none; display: none; }
.term-panel summary:hover { color: var(--navy); }
.term-chevron {
    flex: 0 0 auto;
    color: var(--muted);
    transition: transform 0.15s ease;
}
.term-panel[open] > summary .term-chevron { transform: rotate(90deg); }
.term-state {
    margin-left: auto;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}
.term-state.is-written { color: var(--navy); }
.term-panel > .field { margin: 0 0 8px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px 8px;
}

.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.span-2 { grid-column: span 2; }
.field-error { color: var(--danger); font-size: 11px; font-weight: 600; }
.form-actions { display: flex; gap: 6px; margin-top: 10px; }

.danger-form { margin-top: 8px; padding: 8px 10px; }
.btn-danger { background: white; color: var(--danger); border-color: #f3c4c0; }
.btn-danger:hover { background: var(--danger-soft); }

.row-actions { text-align: right; }
.row-actions a { font-weight: 600; }

.module-access {
    list-style: none;
    margin: 0 0 12px;
    padding: 0;
    border: 1px solid var(--line);
}

.module-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 8px;
    border-top: 1px solid var(--grid);
    background: var(--header);
}

.module-row.is-on { background: var(--cyan-soft); }

.module-row:not(.is-on) .switch { background: #8ea0bb; }
.module-row:not(.is-on) .switch span { background: #d5dbe3; }
.module-row.is-on .switch span { background: white; }

.module-row:first-child { border-top: 0; }
.module-copy { min-width: 0; }
.module-copy strong { color: var(--navy); font-size: 12px; }
.module-copy span { margin-left: 8px; color: var(--muted); font-size: 12px; }
.module-copy p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.module-meta { color: var(--navy); }

.notice {
    margin: 0 0 8px;
    padding: 6px 8px;
    background: #e8f4ff;
    color: var(--navy);
    font-size: 12px;
    font-weight: 600;
    border: 1px solid #b9d7f5;
}

.notice a { color: var(--navy); font-weight: 700; }

.supplier-access {
    list-style: none;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    margin: 0;
    padding: 0;
    border: 1px solid var(--line);
}

.supplier-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 26px;
    padding: 2px 8px;
    border-bottom: 1px solid var(--grid);
    border-right: 1px solid var(--grid);
}

.supplier-row:nth-child(3n) { border-right: 0; }
.supplier-name { min-width: 0; }
.supplier-row strong { color: var(--navy); font-size: 12px; white-space: nowrap; }
.supplier-controls { flex: 0 0 auto; }

.api-edit {
    border: 0;
    background: transparent;
    color: var(--navy);
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    padding: 0;
}

.api-edit:hover { text-decoration: underline; }

.modal {
    width: min(420px, calc(100% - 24px));
    border: 1px solid var(--navy);
    border-radius: 2px;
    padding: 0;
}

.modal::backdrop { background: rgba(6, 32, 79, 0.45); }
.modal-body { display: grid; gap: 8px; padding: 12px; }
.modal [data-credential-fields] { display: grid; gap: 8px; }
.modal [data-credential-fields][hidden] { display: none; }
.env-toggle { display: flex; align-items: center; gap: 8px; }
.env-toggle .switch { background: var(--ok); }
.env-toggle .switch.is-on { background: var(--cyan); }
.env-label { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.env-label.is-active { color: var(--navy); }
.credential-env { display: grid; gap: 8px; }
.credential-env[hidden] { display: none; }
.modal-body h3 { margin: 0; color: var(--navy); font-size: 16px; }
.modal-error {
    margin: 0;
    padding: 4px 8px;
    background: var(--danger-soft);
    color: var(--danger);
    font-weight: 600;
    font-size: 12px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 6px; }

select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--navy) 50%), linear-gradient(135deg, var(--navy) 50%, transparent 50%);
    background-position: calc(100% - 14px) 12px, calc(100% - 9px) 12px;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 18px;
}

.empty { padding: 18px 12px; text-align: center; }
.empty h2 { margin: 0; color: var(--navy); font-size: 14px; }
.empty p { margin: 4px auto 0; max-width: 420px; }

.toast {
    position: fixed;
    right: 12px;
    bottom: 12px;
    max-width: 280px;
    padding: 6px 8px;
    background: var(--navy-ink);
    color: white;
    font-weight: 600;
    font-size: 12px;
}

.support-chat {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 7.5rem);
    min-height: 28rem;
    background: var(--white);
    border: 1px solid var(--line);
}

.support-log {
    flex: 1;
    overflow: auto;
    padding: 12px;
}

.support-empty, .support-error { margin: 0; color: var(--muted); }

.support-error {
    padding: 0 12px 8px;
    color: var(--danger);
    font-weight: 600;
}

.support-bubble {
    max-width: 40rem;
    margin: 0 0 8px;
    padding: 8px 10px;
    white-space: pre-wrap;
}

.support-bubble.is-user { margin-left: auto; background: var(--header); }

.support-bubble.is-assistant { margin-right: auto; background: var(--cyan-soft); }

.support-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid var(--line);
}

.support-form textarea {
    flex: 1;
    min-height: 2.6rem;
    resize: none;
    border: 1px solid var(--line);
    padding: 6px 8px;
    color: var(--navy-ink);
}

.support-form textarea:focus { outline: 2px solid var(--cyan); outline-offset: 1px; }

@media (max-width: 900px) {
    .login-shell, .shell, .stats, .supplier-grid, .form-grid, .form-grid-2, .supplier-access { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .supplier-row, .supplier-row:nth-child(3n) { border-right: 0; }
    .shell { display: block; }
    .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
    .main { padding: 8px; }
}

@media (prefers-reduced-motion: reduce) {
    .switch span { transition: none; }
}
