/* ============ База ============ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: #0f1115;
    color: #e9ecf1;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 18px;
    -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }

button {
    font-family: inherit;
    cursor: pointer;
}

/* ============ Верхняя панель ============ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #1a1d24;
    border-bottom: 1px solid #2a2e38;
}

.topbar-left, .topbar-right {
    display: flex;
    gap: 8px;
    flex: 1;
    flex-wrap: wrap;
    align-items: center;
}
.topbar-right { justify-content: flex-end; }

.topbar-center {
    flex: 2;
    text-align: center;
    font-size: 22px;
    font-weight: 600;
    color: #cfd3dc;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.crumb { padding: 0 8px; }

.seller-form { display: inline; margin: 0; padding: 0; }

.btn-logout {
    background: #2a2e38;
    padding: 8px 12px;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-logout:hover { background: #5b3a1a; }
.seller-name { font-weight: 700; }
.logout-icon { opacity: 0.75; }

/* ============ Панель открытого чека ============ */
.cart-bar {
    position: sticky;
    top: 64px;
    z-index: 9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    background: linear-gradient(180deg, #1f3a2a, #1a2f23);
    border-bottom: 1px solid #2a4a35;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.cart-info {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
    min-width: 0;
}
.cart-label  { font-size: 18px; color: #a5d6b3; }
.cart-total  { font-size: 34px; font-weight: 800; color: #fff; line-height: 1; }
.cart-count  { font-size: 18px; color: #a5d6b3; }

/* ============ Кнопки ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 18px;
    font-weight: 600;
    text-align: center;
    color: #fff;
    background: #2a2e38;
    transition: background 0.1s, transform 0.05s;
    user-select: none;
}

.btn:hover  { background: #353a47; }
.btn:active { transform: scale(0.97); }

.btn-nav      { background: #2a2e38; }
.btn-primary  { background: #3a6df0; }
.btn-primary:hover { background: #5380ff; }
.btn-undo     { background: #5b3a1a; }
.btn-undo:hover { background: #7a4f25; }

.btn-finalize {
    background: #2fa84f;
    font-size: 22px;
    padding: 14px 24px;
    box-shadow: 0 4px 12px rgba(47, 168, 79, 0.4);
}
.btn-finalize:hover { background: #3ec362; }

/* ============ Контент ============ */
.page {
    padding: 20px 16px 80px;
    max-width: 1400px;
    margin: 0 auto;
}

.empty {
    font-size: 20px;
    color: #aab0bc;
    text-align: center;
    margin-top: 48px;
}

.empty code {
    background: #2a2e38;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 18px;
}

/* ============ Главная ============ */
.home {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding-top: 24px;
}

.home-greeting {
    font-size: 22px;
    color: #aab0bc;
}
.home-greeting b { color: #fff; }

.home-counter {
    text-align: center;
    background: #1a1d24;
    padding: 28px 56px;
    border-radius: 16px;
    border: 1px solid #2a2e38;
    min-width: 280px;
}
.counter-label    { font-size: 18px; color: #aab0bc; }
.counter-value    { font-size: 84px; font-weight: 800; color: #fff; line-height: 1; margin-top: 4px; }
.counter-revenue  { font-size: 24px; color: #5db377; margin-top: 12px; }

.home-start {
    width: 100%;
    max-width: 480px;
}
.btn-start {
    width: 100%;
    border: none;
    color: #fff;
    background: #3a6df0;
    font-size: 40px;
    font-weight: 800;
    padding: 32px 24px;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.1s, transform 0.05s;
    box-shadow: 0 8px 24px rgba(58, 109, 240, 0.35);
}
.btn-start:hover  { background: #5380ff; }
.btn-start:active { transform: scale(0.98); }

.home-stats-link  { margin-top: 4px; }

/* ============ Логин (PIN-пад) ============ */
.login {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding-top: 60px;
    max-width: 380px;
    margin: 0 auto;
}

.login-title {
    font-size: 30px;
    font-weight: 800;
    margin: 0;
    color: #fff;
}

.pinpad-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
}

.pin-display {
    font-size: 44px;
    font-weight: 800;
    letter-spacing: 18px;
    color: #fff;
    background: #1a1d24;
    border: 2px solid #2a2e38;
    border-radius: 14px;
    padding: 16px 24px;
    width: 100%;
    min-height: 80px;
    text-align: center;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pin-error {
    color: #ff7373;
    background: #4a1a1a;
    border: 1px solid #c33a3a;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 600;
}

.pinpad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    width: 100%;
}

.pin-btn {
    border: none;
    border-radius: 14px;
    padding: 28px 0;
    font-size: 36px;
    font-weight: 700;
    color: #fff;
    background: #2a2e38;
    cursor: pointer;
    transition: background 0.1s, transform 0.05s;
    user-select: none;
}
.pin-btn:hover    { background: #353a47; }
.pin-btn:active   { transform: scale(0.96); }
.pin-clear        { background: #5b3a1a; }
.pin-clear:hover  { background: #7a4f25; }
.pin-submit       { background: #2fa84f; }
.pin-submit:hover { background: #3ec362; }

/* ============ Сетка плиток ============ */
.grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.tile {
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 160px;
    padding: 16px;
    background: #1a1d24;
    border: 2px solid #2a2e38;
    border-radius: 14px;
    color: #fff;
    font-size: 24px;
    font-weight: 600;
    text-align: center;
    transition: background 0.1s, transform 0.05s, border-color 0.1s;
    overflow: hidden;
    word-break: break-word;
}

.tile:hover  { background: #232732; border-color: #3a3f4d; }
.tile:active { transform: scale(0.98); }

.tile-project,
.tile-category {
    min-height: 180px;
    font-size: 28px;
}

.tile-item {
    min-height: 220px;
    cursor: pointer;
}

.tile-photo {
    display: block;
    width: 100%;
    flex: 1;
    overflow: hidden;
    border-radius: 8px;
    margin-bottom: 8px;
    background: #0f1115;
}

.tile-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tile-title {
    font-size: 22px;
    line-height: 1.2;
}

.tile-price {
    display: block;
    margin-top: 6px;
    font-size: 22px;
    font-weight: 800;
    color: #5db377;
}

.tile-project .tile-title,
.tile-category .tile-title {
    font-size: 28px;
}

/* Подсказка "выбрать размер" */
.size-hint {
    display: block;
    margin-top: 4px;
    font-size: 14px;
    color: #aab0bc;
    font-weight: 600;
}
.tile-group {
    border-color: #3a6df0;
}
.tile-group:hover {
    border-color: #5380ff;
}

/* Остаток в углу */
.stock-badge {
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 36px;
    font-weight: 800;
    line-height: 1;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    border-radius: 10px;
    padding: 4px 10px;
    min-width: 48px;
    text-align: center;
    pointer-events: none;
}

/* Уход в минус — красная подсветка */
.tile.negative {
    background: #4a1a1a;
    border-color: #c33a3a;
}
.tile.negative:hover { background: #5b2222; }
.tile.negative .stock-badge {
    background: #c33a3a;
    color: #fff;
}
.tile.negative .tile-price { color: #ffb3b3; }

/* ============ Модалка выбора размера ============ */
.size-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.size-modal[hidden] { display: none; }

.size-modal-bg {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(2px);
}

.size-modal-content {
    position: relative;
    z-index: 1;
    background: #1a1d24;
    border: 1px solid #2a2e38;
    border-radius: 16px;
    padding: 24px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.size-modal-title {
    margin: 0 0 16px;
    font-size: 26px;
    font-weight: 800;
    color: #fff;
    text-align: center;
    word-break: break-word;
}

.size-modal-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    margin-bottom: 16px;
}

.tile-size {
    position: relative;
    border: 2px solid #2a2e38;
    border-radius: 14px;
    background: #2a2e38;
    color: #fff;
    padding: 28px 16px;
    cursor: pointer;
    transition: background 0.1s, transform 0.05s;
    min-height: 130px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.tile-size:hover    { background: #353a47; }
.tile-size:active   { transform: scale(0.97); }
.tile-size.negative {
    background: #4a1a1a;
    border-color: #c33a3a;
}
.tile-size.negative .stock-badge {
    background: #c33a3a;
}

.size-label {
    font-size: 40px;
    font-weight: 800;
    line-height: 1;
}

.size-modal-close {
    width: 100%;
    background: #2a2e38;
    font-size: 18px;
}

/* ============ Модалка чека (предпросмотр перед продажей) ============ */
.cart-modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.cart-modal[hidden] { display: none; }

.cart-modal-bg {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(2px);
}

.cart-modal-content {
    position: relative;
    z-index: 1;
    background: #1a1d24;
    border: 1px solid #2a2e38;
    border-radius: 16px;
    padding: 20px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.cart-modal-title {
    margin: 0 0 12px;
    font-size: 24px;
    font-weight: 800;
    color: #fff;
    text-align: center;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: baseline;
    gap: 10px;
}
.cart-modal-title #cart-modal-total { color: #5db377; font-weight: 800; }
.cart-modal-count { color: #aab0bc; font-size: 16px; font-weight: 500; }

.cart-modal-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
    min-height: 60px;
    border-top: 1px solid #2a2e38;
    border-bottom: 1px solid #2a2e38;
}

.cart-modal-line {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 8px;
    border-bottom: 1px solid #232732;
    font-size: 18px;
}
.cart-modal-line:last-child { border-bottom: none; }

.cart-line-name {
    flex: 1;
    color: #fff;
    word-break: break-word;
}
.cart-line-price {
    color: #5db377;
    font-weight: 700;
    white-space: nowrap;
    margin-right: 4px;
}
.cart-line-remove {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: #4a1a1a;
    border: 1px solid #c33a3a;
    color: #fff;
    font-size: 20px;
    font-weight: 800;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
    transition: background 0.1s, transform 0.05s;
}
.cart-line-remove:hover { background: #5b2222; }
.cart-line-remove:active { transform: scale(0.95); }

.cart-modal-empty {
    padding: 24px;
    text-align: center;
    color: #aab0bc;
    font-size: 18px;
}

.cart-modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}
.cart-modal-close-btn {
    flex: 1;
    padding: 14px;
}
.cart-modal-finalize-form {
    flex: 2;
    margin: 0;
    display: flex;
}
.cart-modal-finalize-form button {
    width: 100%;
}
.cart-modal-finalize-form button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

/* ============ Тост ============ */
.toast {
    position: fixed;
    left: 50%;
    bottom: 32px;
    transform: translateX(-50%) translateY(40px);
    background: #1f2632;
    color: #fff;
    font-size: 22px;
    font-weight: 600;
    padding: 14px 24px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    border: 1px solid #3a6df0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s, transform 0.15s;
    z-index: 100;
    max-width: 90vw;
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.error {
    border-color: #c33a3a;
    background: #4a1a1a;
}

/* ============ Статистика ============ */
.stats-summary {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 20px;
}

.summary-card {
    background: #1a1d24;
    padding: 16px 20px;
    border-radius: 12px;
    border: 1px solid #2a2e38;
}
.summary-label { color: #aab0bc; font-size: 14px; }
.summary-value { font-size: 28px; font-weight: 800; margin-top: 4px; line-height: 1.1; }

.stats-actions {
    margin-bottom: 16px;
    display: flex;
    gap: 12px;
}

.table-wrap {
    overflow-x: auto;
    background: #1a1d24;
    border-radius: 12px;
    border: 1px solid #2a2e38;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 18px;
}

.stats-table th,
.stats-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid #2a2e38;
    white-space: nowrap;
}

.stats-table th {
    background: #232732;
    cursor: pointer;
    user-select: none;
    font-weight: 700;
}

.stats-table th[data-sort]::after {
    content: " ↕";
    color: #6c7280;
    font-size: 14px;
}
.stats-table th.sort-asc::after  { content: " ▲"; color: #fff; }
.stats-table th.sort-desc::after { content: " ▼"; color: #fff; }

.stats-table tbody tr:hover { background: #232732; }

.row-negative {
    background: #3a1a1a !important;
    color: #ffb3b3;
}
.row-negative:hover { background: #4a2222 !important; }

.shortages {
    margin-top: 32px;
}
.shortages h2 {
    margin-bottom: 4px;
}
.shortages .hint {
    color: #aab0bc;
    margin-top: 0;
    margin-bottom: 12px;
}

/* ============ Адаптив ============ */
@media (max-width: 600px) {
    html, body { font-size: 16px; }

    .topbar { padding: 8px; gap: 6px; }
    .topbar-center {
        font-size: 16px;
        flex: 1;
        order: 3;
        width: 100%;
        text-align: center;
        padding-top: 4px;
    }
    .topbar-left, .topbar-right { flex: 1; }

    .cart-bar { padding: 8px 12px; top: 88px; }
    .cart-total { font-size: 26px; }
    .cart-label, .cart-count { font-size: 14px; }
    .btn-finalize { font-size: 18px; padding: 10px 14px; }

    .btn { font-size: 16px; padding: 10px 12px; }
    .btn-logout { font-size: 12px; padding: 6px 10px; }

    .home { padding-top: 16px; gap: 18px; }
    .home-counter { padding: 20px 32px; }
    .counter-value { font-size: 64px; }
    .btn-start { font-size: 30px; padding: 24px 16px; }

    .pin-display { font-size: 32px; letter-spacing: 12px; min-height: 64px; padding: 12px; }
    .pin-btn { font-size: 28px; padding: 22px 0; }

    .grid {
        gap: 12px;
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
    .tile {
        min-height: 130px;
        padding: 10px;
        font-size: 20px;
    }
    .tile-project, .tile-category { min-height: 140px; }
    .tile-project .tile-title,
    .tile-category .tile-title { font-size: 22px; }
    .tile-item { min-height: 180px; }
    .tile-title { font-size: 18px; }
    .tile-price { font-size: 18px; }
    .stock-badge {
        font-size: 28px;
        min-width: 40px;
        padding: 3px 8px;
    }

    .size-modal-content { padding: 16px; }
    .size-modal-title { font-size: 22px; }
    .tile-size { min-height: 100px; padding: 18px 12px; }
    .size-label { font-size: 30px; }

    .cart-modal-content { padding: 14px; }
    .cart-modal-title { font-size: 20px; }
    .cart-modal-line { font-size: 16px; padding: 10px 4px; }
    .cart-line-remove { width: 36px; height: 36px; font-size: 18px; }
}
