:root {
    --bg: #0b0b0c;
    --surface: #141416;
    --surface-2: #1b1c1f;
    --surface-3: #24252a;
    --text: #f4f4f5;
    --muted: #9b9ca3;
    --line: rgba(255, 255, 255, 0.09);
    --accent: #e6eef3;
    --danger: #e27373;
    --ok: #8fd2bd;
    --radius: 14px;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

img {
    display: block;
    max-width: 100%;
}

a {
    color: inherit;
}

.site-shell {
    width: min(100%, 1180px);
    min-height: 100vh;
    margin: 0 auto;
    padding: 14px 16px 40px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: minmax(170px, 1fr) auto;
    gap: 14px;
    align-items: center;
    min-height: 64px;
    padding: 8px 0 13px;
    border-bottom: 1px solid var(--line);
    background: rgba(11, 11, 12, 0.92);
    backdrop-filter: blur(18px);
}

.brand {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    border: 0;
    padding: 0;
    color: var(--text);
    background: transparent;
    text-align: left;
}

.brand-mark {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 12px;
    background: var(--surface-2);
    font-weight: 850;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.brand-text {
    min-width: 0;
    font-size: 19px;
    font-weight: 780;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-action {
    justify-self: end;
    min-width: 104px;
}

.tab-button {
    min-height: 38px;
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 8px 12px;
    color: var(--muted);
    background: transparent;
    transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.tab-button.active {
    color: var(--text);
    border-color: var(--line);
    background: var(--surface-2);
}

.view {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding-top: 18px;
    animation: fadeIn 160ms ease both;
}

.screen-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    font-size: clamp(28px, 4vw, 42px);
    line-height: 1.04;
}

h2 {
    font-size: 22px;
}

h3 {
    font-size: 16px;
}

p {
    line-height: 1.5;
}

.muted {
    color: var(--muted);
}

.button,
.icon-button,
.input,
.textarea,
.select {
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--text);
    background: var(--surface-2);
}

.button {
    min-height: 44px;
    padding: 10px 14px;
    font-weight: 720;
    transition: transform 140ms ease, background-color 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.button:hover,
.icon-button:hover {
    background: var(--surface-3);
}

.button:active,
.icon-button:active,
.product-card:active {
    transform: scale(0.985);
}

.button.primary {
    color: #0d0e0f;
    border-color: var(--accent);
    background: var(--accent);
}

.button.ghost {
    background: transparent;
}

.button.small {
    min-height: 38px;
    padding: 8px 12px;
}

.button.full {
    width: 100%;
}

.button[disabled] {
    cursor: default;
    opacity: 0.5;
}

.icon-button {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    padding: 0;
    font-size: 18px;
}

.icon-button.favorite.active {
    color: #ffffff;
    animation: heartPop 220ms ease;
}

.input,
.textarea,
.select {
    width: 100%;
    min-height: 44px;
    padding: 11px 12px;
    outline: none;
}

.textarea {
    min-height: 110px;
    resize: vertical;
}

.input:focus,
.textarea:focus,
.select:focus {
    border-color: rgba(255, 255, 255, 0.22);
}

.segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 4px;
    background: var(--surface);
}

.segmented button {
    min-height: 36px;
    border: 0;
    border-radius: 10px;
    padding: 7px 9px;
    color: var(--muted);
    background: transparent;
}

.segmented button.active {
    color: var(--text);
    background: var(--surface-3);
}

.chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 0 4px;
    scrollbar-width: thin;
}

.chip {
    flex: 0 0 auto;
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 12px;
    color: var(--muted);
    background: var(--surface);
}

.chip.active {
    color: var(--text);
    background: var(--surface-2);
}

.ad-banner {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    aspect-ratio: 16 / 9;
}

.ad-banner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.load-more {
    margin-top: 14px;
}

.load-error {
    width: min(100%, 560px);
    margin: 56px auto;
    display: grid;
    gap: 14px;
    text-align: center;
}

.load-error p {
    color: var(--muted);
}

.load-error-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.load-error-actions .button {
    text-decoration: none;
}

.debug-overlay {
    position: fixed;
    right: 10px;
    bottom: 10px;
    z-index: 9999;
    width: min(420px, calc(100vw - 20px));
    max-height: 48vh;
    overflow: auto;
    margin: 0;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    background: rgba(8, 8, 10, 0.92);
    color: #f4f4f5;
    font: 11px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
    white-space: pre-wrap;
    pointer-events: none;
}

.product-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    border: 0;
    padding: 0;
    color: var(--text);
    background: transparent;
    text-align: left;
    transition: transform 160ms ease, opacity 160ms ease;
}

.product-card:hover {
    transform: translateY(-2px);
}

.product-media {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    aspect-ratio: 1 / 1;
}

.product-media img,
.detail-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-heart {
    position: absolute;
    right: 8px;
    top: 8px;
    width: 36px;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--text);
    background: rgba(10, 10, 11, 0.7);
    backdrop-filter: blur(12px);
}

.product-info {
    display: grid;
    gap: 4px;
}

.product-title {
    font-weight: 720;
    line-height: 1.25;
}

.product-description {
    display: -webkit-box;
    overflow: hidden;
    min-height: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.product-price {
    font-weight: 780;
}

.badge {
    display: inline-flex;
    width: max-content;
    min-height: 25px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 4px 8px;
    color: var(--muted);
    background: var(--surface);
    font-size: 12px;
}

.panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
    background: var(--surface);
}

.empty {
    padding: 30px 18px;
    text-align: center;
    color: var(--muted);
}

.detail-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
    gap: 22px;
    align-items: start;
}

.detail-media-column {
    display: grid;
    gap: 12px;
}

.detail-image {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    aspect-ratio: 16 / 9;
}

.carousel-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text);
    background: rgba(10, 10, 11, 0.62);
    backdrop-filter: blur(12px);
}

.carousel-arrow.prev {
    left: 12px;
}

.carousel-arrow.next {
    right: 12px;
}

.carousel-count {
    position: absolute;
    right: 12px;
    bottom: 12px;
    border-radius: 999px;
    padding: 5px 9px;
    color: var(--text);
    background: rgba(10, 10, 11, 0.62);
    font-size: 12px;
}

.detail-content {
    display: grid;
    gap: 14px;
}

.detail-description {
    white-space: pre-line;
}

.detail-actions {
    display: grid;
    grid-template-columns: 1fr 48px;
    gap: 10px;
}

.detail-side-actions {
    display: grid;
    gap: 10px;
}

.profile-layout,
.orders-list,
.admin-list {
    display: grid;
    gap: 12px;
}

.profile-layout {
    grid-template-columns: minmax(0, 1fr) 260px;
    align-items: stretch;
}

.profile-card {
    display: grid;
    gap: 14px;
}

.profile-main {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 14px;
    align-items: center;
}

.profile-avatar {
    width: 72px;
    height: 72px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 18px;
    color: var(--text);
    background: var(--surface-2);
    font-size: 20px;
    font-weight: 850;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 48px;
    border-top: 1px solid var(--line);
    padding-top: 12px;
}

.profile-actions {
    display: grid;
    grid-template-rows: repeat(4, minmax(42px, 1fr));
    gap: 10px;
    align-self: stretch;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    background: var(--surface);
}

.profile-actions .button {
    width: 100%;
    min-height: 0;
    height: 100%;
}

.profile-admin-button {
    margin-top: 4px;
}

.profile-select {
    width: min(220px, 48vw);
    flex: 0 0 auto;
}

.switch {
    position: relative;
    width: 50px;
    height: 30px;
    flex: 0 0 auto;
}

.switch input {
    position: absolute;
    inset: 0;
    opacity: 0;
}

.switch-track {
    position: absolute;
    inset: 0;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-2);
    transition: background-color 160ms ease, border-color 160ms ease;
}

.switch-track::after {
    content: "";
    position: absolute;
    top: 4px;
    left: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--muted);
    transition: transform 180ms ease, background-color 160ms ease;
}

.switch input:checked + .switch-track {
    border-color: rgba(255, 255, 255, 0.24);
    background: var(--accent);
}

.switch input:checked + .switch-track::after {
    transform: translateX(20px);
    background: #0d0e0f;
}

.order-card {
    display: grid;
    gap: 7px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    background: var(--surface);
}

.policy-text {
    margin: 0;
    white-space: pre-wrap;
    color: var(--text);
    font: inherit;
    line-height: 1.58;
}

.footer {
    display: grid;
    grid-template-columns: minmax(260px, 1.4fr) minmax(170px, 0.8fr) minmax(140px, 0.65fr) minmax(180px, 0.8fr);
    gap: clamp(20px, 4vw, 54px);
    align-items: start;
    margin-top: 42px;
    padding: 28px 0 8px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 14px;
}

.footer h2,
.footer h3 {
    color: var(--text);
}

.footer h2 {
    font-size: 22px;
}

.footer h3 {
    margin-bottom: 6px;
    font-size: 14px;
}

.footer-brand,
.footer-column {
    display: grid;
    gap: 9px;
    align-content: start;
}

.footer-brand p {
    max-width: 360px;
    color: var(--muted);
}

.footer button,
.footer a {
    border: 0;
    padding: 0;
    color: var(--muted);
    background: transparent;
    text-decoration: none;
    text-align: left;
}

.footer a:hover,
.footer button:hover {
    color: var(--text);
}

.modal-layer {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(14px);
}

.modal {
    width: min(100%, 520px);
    max-height: min(86vh, 760px);
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 18px;
    background: var(--surface);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
    animation: modalIn 180ms ease both;
}

.modal.wide {
    width: min(100%, 860px);
}

.modal-head,
.modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.modal-body,
.form-grid {
    display: grid;
    gap: 12px;
}

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

.field {
    display: grid;
    gap: 7px;
}

.field label {
    color: var(--muted);
    font-size: 13px;
}

.field.full {
    grid-column: 1 / -1;
}

.consent {
    display: grid;
    grid-template-columns: 22px 1fr;
    gap: 10px;
    align-items: start;
    color: var(--muted);
}

.consent button {
    border: 0;
    padding: 0;
    color: var(--text);
    background: transparent;
    text-decoration: underline;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 90;
    max-width: 340px;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    color: var(--text);
    background: var(--surface-2);
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
    transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
    opacity: 1;
    transform: translateY(0);
}

.admin-layout {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr);
    gap: 16px;
}

.admin-nav {
    position: sticky;
    top: 84px;
    display: grid;
    gap: 7px;
    align-self: start;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px;
    background: var(--surface);
}

.admin-nav button {
    min-height: 40px;
    border: 0;
    border-radius: 10px;
    padding: 9px 10px;
    color: var(--muted);
    background: transparent;
    text-align: left;
}

.admin-nav button.active {
    color: var(--text);
    background: var(--surface-2);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
}

.stat-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    background: var(--surface);
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.stat-card strong {
    display: block;
    margin-top: 8px;
    font-size: 24px;
}

.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.admin-scroll {
    max-height: 560px;
    overflow: auto;
}

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

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 11px 12px;
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 650;
}

.admin-card {
    display: grid;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    background: var(--surface);
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

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

.skeleton {
    min-height: 210px;
    border-radius: var(--radius);
    background: linear-gradient(90deg, var(--surface), var(--surface-2), var(--surface));
    background-size: 220% 100%;
    animation: shimmer 1.2s ease infinite;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes shimmer {
    from { background-position: 120% 0; }
    to { background-position: -120% 0; }
}

@keyframes heartPop {
    0% { transform: scale(0.85); }
    60% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

@media (max-width: 900px) {
    .site-shell {
        padding: 10px 12px 92px;
    }

    .topbar {
        grid-template-columns: minmax(130px, 1fr) auto;
    }

    .market-grid,
    .skeleton-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }

    .detail-layout,
    .profile-layout,
    .admin-layout {
        grid-template-columns: 1fr;
    }

    .profile-actions {
        grid-template-columns: 1fr;
        grid-template-rows: none;
    }

    .profile-select {
        width: min(220px, 52vw);
    }

    .footer {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 24px;
    }

    .admin-nav {
        position: static;
        display: flex;
        overflow-x: auto;
    }

    .admin-nav button {
        flex: 0 0 auto;
        white-space: nowrap;
    }

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

    .form-grid.two {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 460px) {
    .brand-text {
        font-size: 17px;
    }

    .brand-mark,
    .profile-avatar {
        width: 38px;
        height: 38px;
    }

    .profile-main {
        grid-template-columns: 48px minmax(0, 1fr);
    }

    .profile-avatar {
        width: 48px;
        height: 48px;
        border-radius: 14px;
        font-size: 16px;
    }

    .market-grid,
    .skeleton-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .product-title,
    .product-price {
        font-size: 14px;
    }

    .detail-actions {
        grid-template-columns: 1fr 46px;
    }

    .footer {
        grid-template-columns: 1fr;
    }
}
