/* Budget — application styles.
   Mobile first: the sidebar is hidden below 900px and a bottom tab bar takes
   over, which is what makes the installed PWA feel native on a phone. */

:root {
    --bg:          #f6f7f9;
    --surface:     #ffffff;
    --surface-2:   #f0f2f5;
    --border:      #dfe3e8;
    --text:        #1a1d21;
    --text-muted:  #5c6470;
    --accent:      #2f6feb;
    --accent-text: #ffffff;
    --ok-bg:       #e7f6ec;
    --ok-text:     #14622f;
    --err-bg:      #fdecec;
    --err-text:    #9b1c1c;
    --warn-bg:     #fdf4e3;
    --warn-text:   #8a5a00;

    --radius:   10px;
    --radius-sm: 6px;
    --tabbar-h: 60px;

    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:         #0f1216;
        --surface:    #171b21;
        --surface-2:  #1e242c;
        --border:     #2b323b;
        --text:       #e6e9ee;
        --text-muted: #98a2b3;
        --accent:     #5b8def;
        --ok-bg:      #12281a;
        --ok-text:    #7ee2a8;
        --err-bg:     #2c1618;
        --err-text:   #f4a0a0;
        --warn-bg:    #2a2113;
        --warn-text:  #e8c07d;
    }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    /* Stops the pull-to-refresh bounce from feeling like a broken web page
       when the app is installed to the home screen. */
    overscroll-behavior-y: none;
}

code, .field__input--mono, pre {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 0.92em;
}

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

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--accent);
    color: var(--accent-text);
    padding: 0.6rem 1rem;
    z-index: 100;
}
.skip-link:focus { left: 0; }

/* ------------------------------------------------------------- top bar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: calc(0.7rem + var(--safe-top)) 1rem 0.7rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar__brand { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.topbar__logo { display: flex; width: 22px; height: 22px; color: var(--accent); flex: none; }
.topbar__logo svg, .sidebar__logo svg { width: 100%; height: 100%; }
.topbar__title {
    font-weight: 650;
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar__actions { display: flex; align-items: center; gap: 0.5rem; flex: none; }
.inline-form { display: inline; margin: 0; }

/* -------------------------------------------------------------- layout */

.shell { display: block; }

.main {
    padding: 1rem;
    /* Keep the last row clear of the fixed tab bar. */
    padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 1.5rem);
    max-width: 1100px;
    margin: 0 auto;
}

.sidebar { display: none; }

/* ------------------------------------------------------------- tab bar */

.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom);
}

.tabbar__link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    height: var(--tabbar-h);
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.7rem;
    /* A comfortable tap target that does not flash a highlight box on iOS. */
    -webkit-tap-highlight-color: transparent;
}
.tabbar__link.is-active { color: var(--accent); }
.tabbar__icon { display: flex; width: 22px; height: 22px; }
.tabbar__icon svg { width: 100%; height: 100%; }

/* ------------------------------------------------------- desktop shell */

@media (min-width: 900px) {
    .topbar { display: none; }
    .tabbar { display: none; }

    .shell {
        display: grid;
        grid-template-columns: 240px minmax(0, 1fr);
        min-height: 100vh;
    }

    .sidebar {
        display: flex;
        flex-direction: column;
        gap: 1.25rem;
        padding: 1.25rem 1rem;
        background: var(--surface);
        border-right: 1px solid var(--border);
        position: sticky;
        top: 0;
        height: 100vh;
    }

    .sidebar__brand {
        display: flex;
        align-items: center;
        gap: 0.6rem;
        font-weight: 700;
        font-size: 1.1rem;
        padding: 0 0.4rem;
    }
    .sidebar__logo { display: flex; width: 22px; height: 22px; color: var(--accent); }

    .sidebar__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }

    .sidebar__link {
        display: flex;
        align-items: center;
        gap: 0.7rem;
        padding: 0.55rem 0.7rem;
        border-radius: var(--radius-sm);
        text-decoration: none;
        color: var(--text);
        font-size: 0.94rem;
    }
    .sidebar__link:hover { background: var(--surface-2); }
    .sidebar__link.is-active { background: var(--accent); color: var(--accent-text); }
    .sidebar__icon { display: flex; width: 19px; height: 19px; }
    .sidebar__icon svg { width: 100%; height: 100%; }

    .sidebar__user {
        margin-top: auto;
        padding: 0.7rem;
        border-top: 1px solid var(--border);
    }
    .sidebar__username { font-weight: 600; font-size: 0.9rem; }
    .sidebar__meta { color: var(--text-muted); font-size: 0.78rem; }

    .main { padding: 2rem; padding-bottom: 3rem; }
}

/* --------------------------------------------------------------- pages */

.page__title { margin: 0 0 0.3rem; font-size: 1.5rem; letter-spacing: -0.01em; }
.page__lead  { margin: 0 0 1.25rem; color: var(--text-muted); }
.page__note  { margin-top: 1rem; color: var(--text-muted); font-size: 0.85rem; }

.cards {
    display: grid;
    gap: 0.85rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}
.card__title { margin: 0; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.card__value { margin: 0.4rem 0 0.2rem; font-size: 1.8rem; font-weight: 650; }
.card__value--sm { font-size: 1.15rem; word-break: break-all; }
.card__note { margin: 0; color: var(--text-muted); font-size: 0.85rem; }

.empty {
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 1rem;
    text-align: center;
    color: var(--text-muted);
}

.muted  { color: var(--text-muted); }
.nowrap { white-space: nowrap; }

/* -------------------------------------------------------------- subnav */

.subnav {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}
.subnav__link {
    padding: 0.55rem 0.85rem;
    text-decoration: none;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    font-size: 0.92rem;
}
.subnav__link.is-active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------------- tabs */

.tabs__list {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 1.1rem;
    overflow-x: auto;
}
.tabs__tab {
    padding: 0.5rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-muted);
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap;
}
.tabs__tab.is-active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* Without JS every panel stays visible, so the page is still usable. */
.tabs__panel { display: block; }
.js .tabs__panel { display: none; }
.js .tabs__panel.is-active { display: block; }

/* --------------------------------------------------------------- forms */

.form { display: grid; gap: 1rem; }
.form--wide { max-width: 760px; }
.form--inline {
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
    max-width: 760px;
}
.form--row { display: flex; gap: 0.4rem; align-items: center; }
.form__actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }

.fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin: 0;
    display: grid;
    gap: 0.9rem;
    background: var(--surface);
}
.fieldset legend {
    padding: 0 0.4rem;
    font-weight: 650;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.field { display: grid; gap: 0.3rem; align-content: start; }
.field--center { align-content: center; }
.field__label { font-size: 0.85rem; font-weight: 600; }

.field__input {
    width: 100%;
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    /* 16px minimum stops iOS Safari zooming the viewport on focus. */
    font-size: 16px;
    font-family: inherit;
}
.field__input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}
.field__input--mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.field__input--sm { padding: 0.35rem 0.5rem; font-size: 14px; min-width: 190px; }
textarea.field__input { resize: vertical; }

.field__hint { margin: 0; font-size: 0.8rem; color: var(--text-muted); }
.field__hint code { background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 4px; }

.grid { display: grid; gap: 0.9rem; }
@media (min-width: 700px) {
    .grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.switch { display: flex; align-items: center; gap: 0.55rem; font-size: 0.92rem; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.switch--sm { font-size: 0.82rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ------------------------------------------------------------- buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font: inherit;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    min-height: 42px;
}
.btn--primary   { background: var(--accent); color: var(--accent-text); }
.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn--ghost     { background: transparent; color: var(--text-muted); }
.btn--ghost:hover { color: var(--text); }
.btn--block     { width: 100%; }
.btn--sm        { padding: 0.35rem 0.7rem; min-height: 34px; font-size: 0.85rem; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* -------------------------------------------------------------- flashes */

.flashes { display: grid; gap: 0.5rem; margin-bottom: 1rem; }
.flash {
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    border: 1px solid transparent;
}
.flash--success { background: var(--ok-bg);   color: var(--ok-text); }
.flash--error   { background: var(--err-bg);  color: var(--err-text); }
.flash--warning { background: var(--warn-bg); color: var(--warn-text); }
.flash--info    { background: var(--surface-2); color: var(--text); }

.result {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.1rem;
    font-size: 0.9rem;
}
.result--ok   { background: var(--ok-bg);  color: var(--ok-text); }
.result--fail { background: var(--err-bg); color: var(--err-text); }
.result__list { margin: 0.5rem 0 0; padding-left: 1.1rem; }
.result__list li { margin-bottom: 0.2rem; word-break: break-word; }

.callout {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 0.9rem 1rem;
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
}
.callout p { margin: 0 0 0.5rem; }
.callout__warn {
    margin: 0.75rem 0 0;
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius-sm);
    background: var(--warn-bg);
    color: var(--warn-text);
}

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.25rem 0.9rem; margin: 0; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; word-break: break-all; }

/* --------------------------------------------------------------- table */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { padding: 0.65rem 0.8rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.table tr:last-child td { border-bottom: none; }
.table__sub { color: var(--text-muted); font-size: 0.8rem; }
.table__detail { word-break: break-word; max-width: 380px; }

.tag {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.78rem;
}
.tag--accent { background: var(--accent); color: var(--accent-text); }

/* ----------------------------------------------------------- inventory */

.page__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.page__head .page__title { margin-bottom: 0.3rem; }
.page__actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.form--search { margin-bottom: 1.25rem; flex-wrap: wrap; }

.card--link { text-decoration: none; color: inherit; display: block; }
.card--link:hover { border-color: var(--accent); }

.item-card { display: flex; gap: 0.75rem; align-items: flex-start; }
.item-card__thumb {
    width: 64px;
    height: 64px;
    flex: none;
    /* Photos are stored uncropped; the square crop is purely visual. */
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.item-card__thumb--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.1rem;
    color: var(--text-muted);
}
.item-card__thumb--empty svg { width: 100%; height: 100%; }
.item-card__body { min-width: 0; display: grid; gap: 0.1rem; }
.item-card__name { font-weight: 650; }
.item-card__meta { color: var(--text-muted); font-size: 0.85rem; word-break: break-all; }
.item-card__tags { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-top: 0.35rem; }

.gallery {
    display: grid;
    gap: 0.7rem;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}
.gallery__figure { margin: 0; display: grid; gap: 0.35rem; }
.gallery__img {
    width: 100%;
    aspect-ratio: 1;
    /* Stored uncropped; the square is a display choice we can change later. */
    object-fit: cover;
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}
.gallery__figure--primary .gallery__img { border-color: var(--accent); border-width: 2px; }
.gallery__actions { display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; }

.table--needs td { vertical-align: middle; }
.table__addrow { background: var(--surface-2); }
.field__input--num { min-width: 5.5rem; }

.filelist {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
    display: grid;
    gap: 0.2rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}
.filelist li { display: flex; justify-content: space-between; gap: 0.75rem; }
.filelist li.is-toobig { color: var(--err-text); }

.related { display: grid; gap: 0.35rem; }
.related__remove { justify-self: start; }

.section { margin-top: 2rem; }
.section__title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.75rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}
.section__actions { margin-top: 0.85rem; }

.kv--facts {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1rem;
    gap: 0.45rem 1rem;
}

.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}
.breadcrumb__sep { color: var(--border); }

.tag--warn { background: var(--warn-bg); color: var(--warn-text); }
.tag--err  { background: var(--err-bg);  color: var(--err-text); }

.btn--danger { background: var(--err-text); color: #fff; }

.danger { margin-top: 2.5rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.danger summary { cursor: pointer; color: var(--err-text); font-size: 0.9rem; }
.danger .callout { margin-top: 0.75rem; border-left-color: var(--err-text); }

/* Present to screen readers, removed from the visual layout. */
.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---------------------------------------------------------------- auth */

.app--bare { display: grid; place-items: center; min-height: 100dvh; padding: 1.25rem; }
.auth { width: 100%; max-width: 380px; }

.auth__card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}
.auth__title { margin: 0; font-size: 1.5rem; }
.auth__subtitle { margin: 0.15rem 0 1.25rem; color: var(--text-muted); font-size: 0.9rem; }
.auth__note { margin: 1rem 0 0; font-size: 0.8rem; color: var(--text-muted); }

.auth__divider {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    margin: 1.1rem 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}
.auth__divider::before, .auth__divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ------------------------------------------------------ offline banner */

.offline-banner {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 0.75rem);
    z-index: 40;
    background: var(--warn-bg);
    color: var(--warn-text);
    padding: 0.5rem 0.9rem;
    border-radius: 999px;
    font-size: 0.85rem;
    box-shadow: 0 2px 10px rgb(0 0 0 / 0.15);
}
@media (min-width: 900px) {
    .offline-banner { bottom: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
