:root {
    --brand: #7a2c54;
    --brand-dark: #5c2040;
    --ink: #23202a;
    --muted: #6b6470;
    --line: #e4dde6;
    --bg: #faf8fb;
    --card: #ffffff;
    --ok: #1e7a3d;
    --ok-bg: #e7f6ec;
    --warn: #9a5b00;
    --warn-bg: #fdf1dd;
    --err: #b3261e;
    --err-bg: #fbe9e7;
    --radius: 10px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
* { -webkit-tap-highlight-color: transparent; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-y: none;
}

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

.topbar {
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    padding-top: calc(12px + var(--safe-top));
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar .brand { font-weight: 700; font-size: 1.1rem; color: #fff; text-decoration: none; }
.topbar .owner { font-size: .85rem; opacity: .9; }
.topbar .logout { color: #fff; font-size: .85rem; margin-left: 12px; }

.nav {
    display: flex;
    gap: 2px;
    overflow-x: auto;
    background: var(--brand-dark);
    padding: 0 8px;
}
.nav a {
    color: #f2e6ee;
    text-decoration: none;
    padding: 10px 12px;
    font-size: .9rem;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
}
.nav a.active { color: #fff; border-bottom-color: #fff; font-weight: 600; }

/* Bottom tab bar: the primary nav on phones, hidden on wider screens. */
.bottom-nav {
    display: none;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    background: #fff;
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + var(--safe-bottom));
    box-shadow: 0 -2px 10px rgba(0,0,0,.06);
}
.bottom-nav-inner { display: flex; justify-content: space-around; }
.bottom-nav a, .bottom-nav .bn-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--muted);
    text-decoration: none;
    font-size: .68rem;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 10px;
    flex: 1 1 0;
    min-width: 0;
    cursor: pointer;
    background: none;
    border: none;
}
.bottom-nav a svg, .bottom-nav .bn-item svg { width: 22px; height: 22px; }
.bottom-nav a.active, .bottom-nav .bn-item.active { color: var(--brand); }

.bn-more { position: relative; }
.bn-more > summary {
    list-style: none;
    cursor: pointer;
}
.bn-more > summary::-webkit-details-marker { display: none; }
.bn-more-panel {
    position: absolute;
    bottom: calc(100% + 10px);
    right: -6px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0,0,0,.12);
    min-width: 160px;
    padding: 6px;
    z-index: 31;
}
.bn-more-panel a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--ink);
    text-decoration: none;
    font-size: .88rem;
    font-weight: 500;
}
.bn-more-panel a:hover { background: var(--bg); }
.bn-more-panel svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }

.bn-backdrop { display: none; position: fixed; inset: 0; z-index: 29; background: rgba(0,0,0,.15); }
.bottom-nav:has(.bn-more[open]) .bn-backdrop { display: block; }

.container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 16px;
}

/* Floating action button */
.fab {
    position: fixed;
    right: 18px;
    bottom: calc(18px + var(--safe-bottom));
    z-index: 25;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(122,44,84,.45);
    text-decoration: none;
    border: none;
}
.fab svg { width: 26px; height: 26px; }
.fab:active { background: var(--brand-dark); }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

h1 { font-size: 1.4rem; margin: 0 0 12px; }
h2 { font-size: 1.15rem; margin: 0 0 10px; }

.grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
}
.stat .label { font-size: .8rem; color: var(--muted); }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.table-wrap { overflow-x: auto; }

label { display: block; font-size: .85rem; font-weight: 600; margin: 12px 0 4px; }
label:first-child { margin-top: 0; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 1rem;
    background: #fff;
    color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.hint { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.field-error { color: var(--err); font-size: .8rem; margin-top: 4px; }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > * { flex: 1 1 180px; }

.btn {
    display: inline-block;
    background: var(--brand);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--brand); border: 1px solid var(--brand); }
.btn-secondary:hover { background: #f6ecf1; }
.btn-danger { background: var(--err); }
.btn-sm { padding: 6px 12px; font-size: .82rem; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-err { background: var(--err-bg); color: var(--err); }
.badge-muted { background: #eee; color: var(--muted); }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: .9rem; }
.alert-error { background: var(--err-bg); color: var(--err); }
.alert-success { background: var(--ok-bg); color: var(--ok); }

.search-box { margin-bottom: 14px; }

/* Stock list: card grid (used at every width, styled to look native on a phone) */
.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}
.item-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    display: flex;
    gap: 12px;
    position: relative;
}
.item-card .thumb {
    width: 60px; height: 60px;
    border-radius: 10px;
    background: var(--bg);
    border: 1px solid var(--line);
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
    color: var(--line);
}
.item-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-card .thumb svg { width: 28px; height: 28px; }
.item-card .body { flex: 1; min-width: 0; padding-right: 22px; }
.item-card .title { font-weight: 700; font-size: .96rem; line-height: 1.25; }
.item-card .tags { font-size: .76rem; color: var(--muted); margin-top: 1px; }
.item-card .meta { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.item-card .price-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.item-card .price { font-weight: 700; }
.item-card .select-check { position: absolute; top: 10px; right: 10px; width: 18px; height: 18px; }
.item-card .quick-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* Overflow ("more actions") menu, built from <details>/<summary> — no JS needed */
.item-menu { position: relative; }
.item-menu summary {
    list-style: none;
    cursor: pointer;
    width: 32px; height: 32px;
    border-radius: 8px;
    border: 1px solid var(--line);
    display: flex; align-items: center; justify-content: center;
    color: var(--muted);
}
.item-menu summary::-webkit-details-marker { display: none; }
.item-menu[open] summary { background: var(--bg); }
.item-menu .menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(0,0,0,.12);
    min-width: 150px;
    padding: 6px;
    z-index: 5;
}
.item-menu .menu-panel button, .item-menu .menu-panel a {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 9px 10px;
    border-radius: 7px;
    font-size: .86rem;
    color: var(--ink);
    text-decoration: none;
    cursor: pointer;
}
.item-menu .menu-panel button:hover, .item-menu .menu-panel a:hover { background: var(--bg); }
.item-menu .menu-panel .danger { color: var(--err); }
.item-menu .menu-panel button, .item-menu .menu-panel a { display: flex; align-items: center; gap: 8px; }
.item-menu .menu-panel svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--muted); }
.item-menu .menu-panel .danger svg { color: var(--err); }
.item-menu summary svg { width: 18px; height: 18px; }

.inline-icon { width: 15px; height: 15px; vertical-align: -2px; }

.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { text-align: center; color: var(--brand); }

.sale-item-row { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 10px; flex-wrap: wrap; }
.sale-item-row .grow { flex: 2 1 220px; }
.sale-item-row .small { flex: 1 1 90px; }
.remove-row { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; cursor: pointer; }

.muted { color: var(--muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }

@media (max-width: 480px) {
    .container { padding: 10px; }
    table, thead, tbody, th, td, tr { display: block; }
    thead tr { position: absolute; top: -9999px; left: -9999px; }
    td { border: none; border-bottom: 1px solid var(--line); padding: 6px 4px; }
    td::before { content: attr(data-label); display: block; font-size: .72rem; color: var(--muted); font-weight: 600; }
    tr { border-bottom: 2px solid var(--line); margin-bottom: 8px; display: block; }
}

/* App-shell switch: bottom tab bar replaces the top nav strip on phones/small tablets. */
@media (max-width: 768px) {
    .nav { display: none; }
    .bottom-nav { display: block; }
    body { padding-bottom: calc(64px + var(--safe-bottom)); }
    .container { padding: 12px; }
    h1 { font-size: 1.25rem; }
    .fab { bottom: calc(76px + var(--safe-bottom)); }
}
@media (min-width: 769px) {
    .fab { display: none; }
}
