:root {
    --ivory: #f4eee4;
    --cream: #fffaf3;
    --paper: #fffdf8;
    --ink: #2b1c16;
    --muted: #8a7668;
    --line: #e6d8c8;
    --wine: #7b2e34;
    --wine-dark: #5e2126;
    --gold: #c4a574;
    --gold-deep: #9b7a4c;
    --sage: #4f5d4e;
    --ok: #2f6b4f;
    --danger: #9b2c2c;
    --shadow: 0 18px 50px rgba(43, 28, 22, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { overflow-x: hidden; }
body {
    font-family: Outfit, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--ivory);
    min-height: 100vh;
    overflow-x: hidden;
}
.btn-short { display: none; }

h1, h2, h3, .brand strong {
    font-family: "Cormorant Garamond", Georgia, serif;
    font-weight: 600;
    letter-spacing: 0.01em;
}

a { color: inherit; }

.auth-body {
    background:
        radial-gradient(1200px 500px at 10% -10%, rgba(196, 165, 116, 0.25), transparent 50%),
        radial-gradient(900px 400px at 100% 100%, rgba(123, 46, 52, 0.18), transparent 45%),
        var(--ivory);
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 16px;
    grid-template-columns: minmax(0, 420px) minmax(0, 440px);
    gap: 28px;
    max-width: 980px;
    margin: 0 auto;
}

.auth-side {
    color: var(--ink);
}
.auth-logo {
    width: min(280px, 100%);
    height: auto;
    display: block;
    margin: 0 auto 16px;
    border-radius: 24px;
}
.auth-side h1 {
    font-size: 64px;
    line-height: 0.9;
    margin: 8px 0 16px;
}
.brand-kicker {
    text-transform: uppercase;
    letter-spacing: 0.22em;
    font-size: 12px;
    color: var(--gold-deep);
    margin: 0 0 8px;
}
.auth-card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 24px;
    padding: 32px;
    box-shadow: var(--shadow);
}
.auth-card h1, .auth-card h2 { margin: 0 0 8px; font-size: 36px; }
.auth-lead { color: var(--muted); margin: 0 0 18px; }

.stack { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
input, select {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--cream);
    color: var(--ink);
    border-radius: 12px;
    padding: 12px 14px;
    font: inherit;
    outline: none;
}
input:focus, select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(196, 165, 116, 0.25); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 999px;
    padding: 11px 18px;
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary { background: var(--wine); color: #fff; }
.btn-primary:hover { background: var(--wine-dark); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 0; padding-inline: 10px; }

.alert {
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: 14px;
}
.alert-error, .alert-danger { background: #f8e7e5; color: var(--danger); }
.alert-success { background: #e7f3ec; color: var(--ok); }

.app-body { background: linear-gradient(#f7f1e8, #f3ebe0 220px, #f4eee4); }
.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    padding: 12px 28px;
    background: rgba(255, 253, 248, 0.92);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(12px);
}
.topbar-bar { display: contents; }
.brand { display: flex; align-items: center; gap: 12px; grid-column: 1; }
.brand-logo {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    object-fit: cover;
    background: #f3ebe3;
    box-shadow: 0 0 0 1px var(--line);
    flex-shrink: 0;
}
.brand small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.balance-box {
    display: flex;
    align-items: stretch;
    gap: 18px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 10px 18px;
    box-shadow: var(--shadow);
    justify-self: center;
    grid-column: 2;
}
.balance-box span { display: block; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.balance-box strong { font-size: 20px; font-family: "Cormorant Garamond", serif; }
.balance-divider {
    width: 1px;
    flex: 0 0 1px;
    align-self: stretch;
    background: var(--line);
}
.topbar-user { justify-self: end; display: flex; align-items: center; gap: 10px; color: var(--muted); grid-column: 3; }

.wrap { width: min(1280px, calc(100% - 32px)); margin: 24px auto 64px; }
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-bottom: 22px;
}
.tabs { display: flex; background: #efe6d8; border-radius: 999px; padding: 4px; }
.tab {
    padding: 8px 16px;
    border-radius: 999px;
    text-decoration: none;
    color: var(--muted);
    font-size: 14px;
}
.tab.is-active { background: var(--paper); color: var(--ink); box-shadow: 0 4px 14px rgba(43,28,22,.08); }
.toolbar-meta { color: var(--muted); display: flex; gap: 14px; font-size: 13px; }
.search { display: flex; gap: 8px; margin-left: auto; }
.search input { min-width: 220px; }

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}
.product-card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 22px;
    overflow: hidden;
    box-shadow: var(--shadow);
}
.product-visual { position: relative; height: 220px; background: #efe4d4; }
.product-visual img { width: 100%; height: 100%; object-fit: cover; display: block; }
.no-photo { height: 100%; display: grid; place-items: center; color: var(--muted); }
.stock-badge {
    position: absolute; left: 12px; top: 12px;
    background: rgba(255,253,248,.94);
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
}
.stock-badge.is-empty { background: #f8e7e5; color: var(--danger); }
.product-body { padding: 16px 18px 18px; }
.product-body h3 { margin: 0 0 6px; font-size: 26px; }
.cost-line { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.price-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.price-pills span {
    background: #f3eadc;
    border-radius: 14px;
    padding: 6px 10px;
    font-size: 12px;
    display: inline-flex;
    flex-direction: column;
    gap: 2px;
}
.price-pills em {
    font-style: normal;
    color: var(--muted);
    font-size: 11px;
    font-weight: 400;
}
.platform-table { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; font-size: 12px; }
.pt-head, .pt-row {
    display: grid;
    grid-template-columns: 1.2fr 0.9fr 0.9fr 1fr 1fr 0.7fr;
    gap: 6px;
    padding: 8px 10px;
    align-items: center;
}
.pt-head { background: #f6eee3; color: var(--muted); font-weight: 600; }
.pt-row + .pt-row { border-top: 1px solid var(--line); }
.pt-row small { display: block; color: var(--muted); font-size: 11px; }
.positive { color: var(--ok); }
.negative { color: var(--danger); }
.card-actions { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.card-actions form { margin-left: auto; }

.empty {
    text-align: center;
    padding: 70px 20px;
    background: var(--paper);
    border: 1px dashed var(--line);
    border-radius: 24px;
}
.empty h3 { font-size: 32px; margin-bottom: 8px; }

.table-wrap {
    overflow: auto;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 18px;
}
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: top; }
.data-table th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.data-table small { display: block; color: var(--muted); }
.muted { color: var(--muted); text-align: center !important; }

.modal {
    position: fixed; inset: 0;
    background: rgba(43, 28, 22, 0.38);
    display: grid; place-items: center;
    padding: 20px;
    z-index: 40;
}
.modal[hidden] { display: none !important; }
.modal-card {
    width: min(640px, 100%);
    background: var(--paper);
    border-radius: 22px;
    padding: 22px;
    box-shadow: var(--shadow);
    max-height: calc(100vh - 40px);
    overflow: auto;
}
.platform-fields {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 12px;
    background: #fbf6ee;
}
.platform-fields h3 {
    margin: 0 0 10px;
    font-size: 20px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h2 { margin: 0; font-size: 30px; }
.icon-close { border: 0; background: transparent; font-size: 28px; cursor: pointer; color: var(--muted); }
.grid-2, .grid-3 { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.sale-preview {
    background: #f6eee3;
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 14px;
    color: var(--ink);
}
.field-hint { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.field-hint a { color: var(--wine); }
label small { color: var(--muted); font-weight: 400; }
.modal-card-wide { width: min(720px, 100%); }
.bulk-list {
    max-height: 280px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 6px;
}
.bulk-row {
    display: grid;
    grid-template-columns: 1fr 90px;
    gap: 10px;
    align-items: center;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
}
.bulk-row:last-child { border-bottom: 0; }
.bulk-row small { display: block; }
.settings-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
    gap: 22px;
    align-items: start;
}
.settings-card, .settings-preview {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 22px;
    box-shadow: var(--shadow);
}
.settings-preview ul { list-style: none; padding: 0; margin: 0 0 12px; }
.settings-preview li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
}

@media (max-width: 1100px) {
    .topbar {
        position: static;
        display: block;
        padding: 0;
        background: transparent;
        border: 0;
        backdrop-filter: none;
    }
    .topbar-bar {
        position: sticky;
        top: 0;
        z-index: 30;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 10px 16px;
        padding-top: max(10px, env(safe-area-inset-top));
        background: rgba(255, 253, 248, 0.96);
        border-bottom: 1px solid var(--line);
        backdrop-filter: blur(12px);
        min-width: 0;
    }
    .brand, .topbar-user { grid-column: auto; justify-self: auto; }
    .balance-box {
        margin: 10px 16px 0;
        justify-self: stretch;
        grid-column: auto;
    }
}

@media (max-width: 900px) {
    .auth-shell { grid-template-columns: 1fr; padding: 20px 14px; gap: 16px; }
    .auth-side { text-align: center; }
    .auth-side h1 { font-size: 42px; }
    .auth-card { padding: 22px 18px; border-radius: 18px; }
    .search { margin-left: 0; width: 100%; }
    .search input { min-width: 0; flex: 1; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .settings-layout { grid-template-columns: 1fr; }
    .pt-head, .pt-row { grid-template-columns: 1.2fr 1fr 1fr 0.7fr; }
    .pt-head span:nth-child(2),
    .pt-head span:nth-child(3),
    .pt-row span:nth-child(2),
    .pt-row span:nth-child(3) { display: none; }
    .product-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .topbar-bar {
        padding: 8px 12px;
        padding-top: max(8px, env(safe-area-inset-top));
        min-height: 52px;
        gap: 8px;
    }
    .brand { gap: 8px; min-width: 0; }
    .brand-logo { width: 34px; height: 34px; border-radius: 9px; }
    .brand strong { font-size: 16px; line-height: 1.1; }
    .brand small { display: none; }
    .topbar-user { gap: 6px; flex-shrink: 0; }
    .topbar-name { display: none; }
    .btn-full { display: none; }
    .btn-short { display: inline; }
    .topbar-user .btn {
        padding: 7px 10px;
        font-size: 13px;
    }
    .balance-box {
        margin: 10px 12px 0;
        padding: 8px 10px;
        gap: 8px;
        border-radius: 14px;
        justify-content: space-between;
        box-shadow: none;
    }
    .balance-box > div:not(.balance-divider) { flex: 1; min-width: 0; text-align: center; }
    .balance-box span { font-size: 9px; letter-spacing: 0.04em; }
    .balance-box strong { font-size: 15px; white-space: nowrap; }

    .wrap { width: calc(100% - 20px); margin: 14px auto 40px; }
    .toolbar { gap: 8px; margin-bottom: 14px; }
    .toolbar-meta { width: 100%; font-size: 12px; }
    .tabs { width: 100%; }
    .tab { flex: 1; text-align: center; padding: 8px 10px; }
    .toolbar .btn { flex: 1; min-width: calc(50% - 8px); }

    .product-visual { height: 180px; }
    .product-body { padding: 12px 14px 14px; }
    .product-body h3 { font-size: 22px; }
    .card-actions { flex-wrap: wrap; }
    .card-actions form { margin-left: 0; }
    .card-actions .btn { flex: 1; }

    .platform-table { font-size: 11px; overflow-x: auto; }
    .pt-head, .pt-row { padding: 7px 8px; gap: 4px; }

    .table-wrap {
        margin: 0 -10px;
        border-radius: 0;
        border-left: 0;
        border-right: 0;
        -webkit-overflow-scrolling: touch;
    }
    .data-table { min-width: 720px; }

    .modal {
        padding: 0;
        align-items: end;
        place-items: end center;
    }
    .modal-card, .modal-card-wide {
        width: 100%;
        max-height: min(92dvh, calc(100vh - env(safe-area-inset-top)));
        border-radius: 18px 18px 0 0;
        padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
    }
    .modal-head h2 { font-size: 22px; }
    .bulk-list { max-height: 36vh; }
}

