/* AMBIO — base styles. Brand colors taken from the logo. */
:root {
    --brand-green: #1b4b2a;
    --brand-green-dark: #133820;
    --brand-leaf: #74a043;
    --brand-red: #c4121a;

    --bg: #f5f6f4;
    --surface: #ffffff;
    --text: #1d2420;
    --text-muted: #66706a;
    --border: #dfe3df;

    --radius: 8px;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 1px 8px rgb(0 0 0 / 0.04);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

img { max-width: 100%; }

/* ---------------------------------------------------------------- layout */
.app {
    display: grid;
    grid-template-columns: 232px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--brand-green);
    color: #fff;
    padding-block: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sidebar__brand {
    display: block;
    margin-inline: 16px;
    padding: 10px;
    background: #fff;
    border-radius: var(--radius);
}

.sidebar__brand img { display: block; margin-inline: auto; max-height: 72px; }

.sidebar__nav { display: flex; flex-direction: column; }

.nav-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    color: rgb(255 255 255 / 0.88);
    text-decoration: none;
    border-inline-start: 3px solid transparent;
}

.nav-item:hover { background: var(--brand-green-dark); color: #fff; }

.nav-item.is-active {
    background: var(--brand-green-dark);
    border-inline-start-color: var(--brand-red);
    color: #fff;
    font-weight: 600;
}

.nav-item.is-soon { color: rgb(255 255 255 / 0.45); cursor: default; }
.nav-item.is-soon:hover { background: none; }
.nav-item small { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }

.shell { display: flex; flex-direction: column; min-width: 0; }

.topbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 16px;
    padding: 10px 28px;
    background: var(--surface);
    border-block-end: 1px solid var(--border);
}

.topbar__user { color: var(--text-muted); }
.topbar form { margin: 0; }

.content { padding: 28px; }

.page-title { margin: 0 0 24px; font-size: 24px; font-weight: 600; }

/* ----------------------------------------------------------------- tiles */
.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
}

.tile__label { margin: 0; font-size: 13px; font-weight: 500; color: var(--text-muted); }
.tile__value { margin: 6px 0 4px; font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile__hint { margin: 0; font-size: 12px; color: var(--text-muted); }

/* ----------------------------------------------------------------- forms */
.form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; }

.field input, .field select, .field textarea {
    font: inherit;
    font-size: 15px;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
}

.field ::placeholder { color: #a9b1ab; }

.field input:focus, .field select:focus, .field textarea:focus {
    outline: 2px solid var(--brand-leaf);
    outline-offset: -1px;
    border-color: var(--brand-leaf);
}

.btn {
    font: inherit;
    font-weight: 500;
    padding: 9px 16px;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
}

.btn--primary { background: var(--brand-green); color: #fff; }
.btn--primary:hover { background: var(--brand-green-dark); }
.btn--ghost { background: none; border-color: var(--border); color: var(--text); }
.btn--ghost:hover { background: var(--bg); }
.btn--block { width: 100%; }

.alert { margin: 0 0 14px; padding: 10px 12px; border-radius: 6px; font-size: 14px; }
.alert--error { background: #fdecec; color: var(--brand-red); }
.alert--info { background: #eef5e8; color: var(--brand-green); }

/* ----------------------------------------------------------------- login */
.login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 16px;
}

.login__card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 32px 28px;
}

.login__logo { display: block; margin-inline: auto; max-height: 120px; }
.login__tagline { text-align: center; color: var(--text-muted); margin: 8px 0 24px; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 760px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { padding-block: 12px; }
    .sidebar__nav { flex-direction: row; overflow-x: auto; }
    .nav-item { white-space: nowrap; border-inline-start: none; }
    .content { padding: 20px 16px; }
}

/* ----------------------------------------------------------------- cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 24px;
    max-width: 960px;
}

.card__intro { margin: 0 0 16px; color: var(--text-muted); }

/* ------------------------------------------------------------------ tabs */
.tabs {
    display: flex;
    gap: 4px;
    margin: -8px 0 20px;
    border-block-end: 1px solid var(--border);
}

.tabs__item {
    padding: 8px 14px;
    color: var(--text-muted);
    text-decoration: none;
    border-block-end: 2px solid transparent;
    margin-block-end: -1px;
}

.tabs__item:hover { color: var(--text); }
.tabs__item.is-active { color: var(--brand-green); border-block-end-color: var(--brand-green); font-weight: 600; }

/* ------------------------------------------------------- form layout */
.form__section {
    border: none;
    margin: 0;
    padding: 0 0 8px;
}

/* Blocks after the first are set apart by a rule and generous space above. */
.form__section:not(:first-child) {
    margin-block-start: 20px;
    padding-block-start: 28px;
    border-block-start: 1px solid var(--border);
}

.form__section legend {
    display: flex;
    align-items: center;
    gap: 10px;
    float: left;
    width: 100%;
    margin: 0 0 18px;
    padding: 0;
    font-weight: 700;
    font-size: 18px;
    line-height: 1.3;
    color: var(--brand-green);
}

.form__section legend::before {
    content: "";
    width: 4px;
    height: 1.2em;
    border-radius: 2px;
    background: var(--brand-leaf);
}

/* A floated legend leaves the content to flow below it (every sibling, so a hidden input right after the legend cannot let the grid slide up beside it). */
.form__section legend ~ * { clear: both; }

.form__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 18px 24px;
}

.form__actions { display: flex; justify-content: flex-end; gap: 8px; padding-block-start: 4px; }

.field__hint { font-weight: 400; color: var(--text-muted); font-size: 12px; }
.field__error { font-weight: 400; color: var(--brand-red); font-size: 12px; }
.field__error:empty { display: none; }
.field:has(.field__error:not(:empty)) input { border-color: var(--brand-red); }

.inline-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 12px;
    margin-block-end: 16px;
}

.inline-form .field { min-width: 120px; }
.inline-form .field--grow { flex: 1; min-width: 200px; }
.inline-form .btn { margin-block-start: 22px; }

/* ----------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; }

.table th {
    text-align: start;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    padding: 8px 10px;
    border-block-end: 1px solid var(--border);
}

.table td { padding: 10px; border-block-end: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-block-end: none; }
.table .num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .strong { font-weight: 600; }
.table .actions { text-align: end; white-space: nowrap; }
.table .actions .btn + .btn { margin-inline-start: 4px; }
.table .actions form.inline { display: inline; margin-inline-start: 4px; }
.table tr.is-muted td { color: var(--text-muted); }
.table td .inline-form { margin: 0; }

/* ---------------------------------------------------------------- badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    background: #eef1ee;
    color: var(--text);
}

.badge--green { background: #e6f0df; color: var(--brand-green); }
.badge--grey { background: #f0f0f0; color: var(--text-muted); }

.btn--small { padding: 4px 10px; font-size: 13px; }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.htmx-request { opacity: 0.6; transition: opacity 150ms; }

/* ------------------------------------------------------- page structure */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-block-end: 24px;
}

.page-header .page-title { margin: 0; display: flex; align-items: center; gap: 10px; }

.breadcrumb { margin: 0 0 4px; font-size: 13px; color: var(--text-muted); }
.breadcrumb a { color: var(--text-muted); }

a { color: var(--brand-green); }
a.btn { text-decoration: none; display: inline-block; }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }

.card--flush { padding: 0; max-width: none; }
.card--flush .table th:first-child, .card--flush .table td:first-child { padding-inline-start: 20px; }
.card--flush .table th:last-child, .card--flush .table td:last-child { padding-inline-end: 20px; }
.card--flush .table th { padding-block-start: 14px; }
.table td a { text-decoration: none; }
.table td a:hover { text-decoration: underline; }
.table td .badge { margin-inline-start: 6px; vertical-align: 1px; }

/* --------------------------------------------------------------- filters */
.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-block-end: 16px;
}

.filters .field--grow { flex: 1; min-width: 240px; }

.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--brand-green); }

select { font: inherit; }
.filters select, .filters input[type="search"] {
    font-size: 15px;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}

.field--wide { grid-column: span 2; }
@media (max-width: 760px) { .field--wide { grid-column: auto; } }

/* --------------------------------------------------------- pager / empty */
.pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-block-start: 12px;
}

.pager .muted { margin-inline-end: 8px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: default; }

.empty { text-align: center; padding-block: 40px; max-width: none; }
.empty__title { margin: 0 0 16px; color: var(--text-muted); }

.danger-zone {
    max-width: 960px;
    margin-block-start: 20px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.danger-zone p { margin: 0; }

/* --------------------------------------------- segmented radio control */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; width: fit-content; }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented span { display: block; padding: 9px 16px; font-weight: 500; background: #fff; }
.segmented label + label span { border-inline-start: 1px solid var(--border); }
.segmented input:checked + span { background: var(--brand-green); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--brand-leaf); outline-offset: -2px; }

/* ----------------------------------------------------------------- stock */
.page-header__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.section-title { margin: 28px 0 12px; font-size: 17px; font-weight: 600; }
.card__title { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.card--wide { max-width: none; }
.tiles { margin-block-end: 20px; }
.tile--alert { border-color: #f1b9bb; background: #fff7f7; }
.tile--alert .tile__value { color: var(--brand-red); }
.tile__value small { font-size: 14px; font-weight: 500; color: var(--text-muted); }

.badge--red { background: #fdecec; color: var(--brand-red); }
.qty-in { color: var(--brand-green); }
.qty-out { color: var(--brand-red); }

.serial-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-block-start: 4px; }
.chip {
    display: inline-block;
    padding: 1px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 12px;
    background: var(--bg);
    color: var(--text);
}
a.chip { text-decoration: none; }
a.chip:hover { border-color: var(--brand-green); }

.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px 12px; padding-block: 4px; }
.checkbox-grid .checkbox span { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }

.lines-table td { vertical-align: top; }
.lines-table input, .lines-table select {
    width: 100%;
    font: inherit;
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}
.lines-table input[type="number"] { max-width: 140px; text-align: end; }
.lines-table td.num { min-width: 110px; }
.lines-table__product { min-width: 280px; }
.lines-table tbody + tbody { border-block-start: 1px solid var(--border); }
.lines-table tr.lines-table__serials td { padding-block-start: 0; }
.lines-table tfoot td { border-block-end: none; padding-block-start: 14px; }
.lines-table .field__error { display: block; text-align: start; }

.form__actions-hint { margin-inline-end: auto; max-width: 520px; align-self: center; }

.facts { display: flex; flex-wrap: wrap; gap: 12px 40px; margin: 0 0 12px; }
.facts dt { font-size: 12px; color: var(--text-muted); }
.facts dd { margin: 2px 0 0; }

.empty__actions { display: flex; justify-content: center; gap: 8px; }

/* -------------------------------------------------------------- invoices */
.page-header__actions form { margin: 0; }
.lines-table .input--short { max-width: 90px; }
.invoice-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-block: 16px; }
.invoice-summary .card { max-width: none; }
.totals-table td { padding-block: 6px; }
.totals-table__grand td { font-weight: 700; font-size: 16px; color: var(--brand-green); border-block-start: 2px solid var(--brand-green); }

/* ------------------------------------------------------- dashboard blocks */
.block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-inline-start: 4px solid var(--brand-green);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px 20px;
    margin-block-end: 24px;
}
.block__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-block-end: 14px; }
.block__title { margin: 0; font-size: 17px; font-weight: 600; color: var(--brand-green); }
.block__link { font-size: 13px; }
.block .tile { background: var(--bg); box-shadow: none; }
.block .tile--alert { background: #fff7f7; }
.block .card { max-width: none; box-shadow: none; }
.block .tiles + .card { margin-block-start: 16px; }
.tile--warn { border-color: #e6cf8f; background: #fffaeb; }
.block .tile--warn { background: #fffaeb; }
.card__heading { margin: 0; padding: 14px 20px 6px; font-size: 14px; font-weight: 600; }
.card__empty { margin: 0; padding: 6px 20px 18px; }
