@import url('tokens.css');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-family);
    background: var(--bg-app);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

/* -- Header -- */

.app-header {
    flex-shrink: 0;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--app-pad);
    background: var(--bg-app);
    box-shadow: var(--shadow-header);
    z-index: var(--z-header);
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 2.5vw;
}

.header-circle {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-circle);
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-circle);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--duration-fast) ease;
    position: relative;
}

.header-circle:active { background: var(--border-light); }

.header-circle svg {
    width: 50%;
    height: 50%;
    fill: var(--text-body);
}

.header-circle .badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: var(--brand-red);
    color: var(--text-on-brand);
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.header-circle .badge:empty,
.header-circle .badge[data-count="0"] { display: none; }

.header-logo {
    height: 32px;
    display: flex;
    align-items: center;
}

.header-logo svg {
    height: 100%;
    width: auto;
}

/* -- Smart Reorder Strip -- */

.smart-reorder {
    flex-shrink: 0;
    height: 44px;
    margin: var(--app-pad) var(--app-pad) 0;
    background: var(--bg-smart-reorder);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4vw;
    cursor: pointer;
    transition: box-shadow var(--duration-fast) ease;
}

.smart-reorder:active { box-shadow: var(--shadow-card); }

.smart-reorder-label {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-body);
}

.smart-reorder-arrow {
    width: 20px;
    height: 20px;
    fill: var(--text-muted);
}

/* -- Category Grid -- */

.category-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: var(--tile-gap);
    padding: var(--app-pad);
    min-height: 0;
}

/* -- Category Tile -- */

.category-tile {
    position: relative;
    border-radius: var(--radius-tile);
    overflow: hidden;
    cursor: pointer;
    transition: transform var(--duration-fast) var(--ease-out);
}

.category-tile:active { transform: scale(0.97); }

.category-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.category-tile .tile-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 18% 6% 5%;
    background: var(--bg-tile-gradient);
    display: flex;
    align-items: flex-end;
}

.category-tile .tile-label span {
    color: var(--text-on-image);
    font-size: var(--text-xs);
    font-weight: 700;
    line-height: 1.15;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* -- Panel Backdrop -- */

.panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: var(--z-panel-backdrop);
    opacity: 0;
    visibility: hidden;
    transition:
        opacity var(--duration-normal) ease,
        visibility 0ms linear var(--duration-normal);
}

.panel-backdrop.visible {
    opacity: 1;
    visibility: visible;
    transition:
        opacity var(--duration-normal) ease,
        visibility 0ms linear 0ms;
}

/* -- Subcategory Panel -- */

.subcategory-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 88vh;
    height: 88dvh;
    background: var(--bg-panel);
    border-radius: var(--radius-panel) var(--radius-panel) 0 0;
    box-shadow: var(--shadow-panel);
    z-index: var(--z-panel);
    transform: translate3d(0, 100%, 0);
    visibility: hidden;
    transition:
        transform var(--duration-slow) var(--ease-out),
        visibility 0ms linear var(--duration-slow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.subcategory-panel.open {
    transform: translate3d(0, 0, 0);
    visibility: visible;
    transition:
        transform var(--duration-slow) var(--ease-out),
        visibility 0ms linear 0ms;
}

.panel-header {
    display: flex;
    align-items: center;
    padding: 16px var(--app-pad) 10px;
    gap: 12px;
    flex-shrink: 0;
}

.panel-back {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-circle);
    background: var(--bg-app);
    border: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.panel-back svg {
    width: 18px;
    height: 18px;
    fill: var(--text-body);
}

.panel-title {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--text-primary);
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 0 var(--app-pad) var(--app-pad);
    -webkit-overflow-scrolling: touch;
}

/* -- Subcategory Card -- */

.subcat-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: background var(--duration-fast) ease;
}

.subcat-card:active { background: rgba(0,0,0,0.03); }
.subcat-card:last-child { border-bottom: none; }

.subcat-thumb {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    flex-shrink: 0;
}

.subcat-name {
    flex: 1;
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-primary);
}

.subcat-chevron {
    width: 20px;
    height: 20px;
    fill: var(--text-muted);
    flex-shrink: 0;
}

/* -- Dimmed main screen when panel is open -- */

body.panel-open .app-shell {
    opacity: 0.4;
    transition: opacity var(--duration-normal) ease;
    pointer-events: none;
}

/* -- Product Card -- */

.product-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
}

.product-card:active { background: rgba(0,0,0,0.03); }
.product-card:last-child { border-bottom: none; }

.product-thumb {
    width: 72px;
    height: 72px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-app);
}

.product-thumb-empty {
    background: var(--border-light);
}

.product-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.product-name {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.product-meta {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.product-price {
    font-size: var(--text-base);
    font-weight: 700;
    color: var(--text-primary);
    flex-shrink: 0;
    white-space: nowrap;
}

/* -- States -- */

.state-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    gap: 10px;
}

.state-message .state-title { font-size: var(--text-base); font-weight: 600; color: var(--text-primary); }
.state-message .state-body { font-size: var(--text-sm); color: var(--text-muted); line-height: 1.5; }
