:root {
    --bg: #f5f6f1;
    --panel: #ffffff;
    --text: #1d2528;
    --muted: #667276;
    --line: #dfe4df;
    --primary: #176b5b;
    --primary-dark: #0f4d41;
    --accent: #c54d2f;
    --gold: #d89b21;
    --blue: #286aa6;
    --violet: #6d4bb3;
    --rose: #b9436d;
    --warn: #a15c00;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    transition: grid-template-columns 0.2s ease;
}

.app-shell.sidebar-collapsed {
    grid-template-columns: 56px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 22px 16px;
    background: linear-gradient(180deg, #ffffff 0%, #f7fbf4 58%, #fff3df 100%);
    border-right: 1px solid var(--line);
    box-shadow: 6px 0 22px rgba(29, 37, 40, 0.08);
}

.sidebar-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 36px;
    gap: 8px;
    align-items: start;
}

.brand {
    color: var(--primary-dark);
    font-size: 20px;
    font-weight: 700;
    text-decoration: none;
    line-height: 1.15;
    padding: 10px 8px 16px;
    border-bottom: 3px solid var(--gold);
}

.sidebar-toggle {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 8px;
    background: linear-gradient(135deg, #33464d, #536a72);
    font-size: 18px;
    line-height: 1;
}

nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

nav a {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    text-decoration: none;
    font-size: 15px;
    font-weight: 700;
    padding: 11px 12px;
    border-radius: 8px;
    border: 1px solid transparent;
}

.nav-text {
    min-width: 0;
}

.nav-icon {
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    display: grid;
    place-items: center;
    color: var(--primary-dark);
}

.nav-icon svg {
    width: 21px;
    height: 21px;
    display: block;
    fill: currentColor;
}

nav a:hover {
    background: #edf2ee;
    color: var(--primary-dark);
}

nav a.active {
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 8px 16px rgba(23, 107, 91, 0.22);
}

nav a.active .nav-icon {
    color: #ffffff;
}

nav a:nth-child(2n):not(.active) {
    border-left: 4px solid var(--gold);
}

nav a:nth-child(3n):not(.active) {
    border-left: 4px solid var(--blue);
}

nav a:nth-child(4n):not(.active) {
    border-left: 4px solid var(--rose);
}

.sidebar-collapsed .sidebar {
    padding: 18px 8px;
}

.sidebar-collapsed .sidebar-header {
    grid-template-columns: 1fr;
}

.sidebar-collapsed .brand {
    display: none;
}

.sidebar-collapsed .sidebar-toggle {
    width: 100%;
}

.sidebar-collapsed nav {
    display: flex;
    gap: 8px;
}

.sidebar-collapsed nav a {
    width: 40px;
    height: 40px;
    justify-content: center;
    padding: 0;
    border-left-width: 0;
}

.sidebar-collapsed nav a:nth-child(n):not(.active) {
    border-left-width: 0;
}

.sidebar-collapsed .nav-icon {
    width: 28px;
    height: 28px;
}

.sidebar-collapsed .nav-icon svg {
    width: 24px;
    height: 24px;
}

.sidebar-collapsed .nav-text {
    display: none;
}

.container {
    width: min(1220px, calc(100% - 28px));
    margin: 24px auto;
}

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

.panel,
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
}

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

h1 {
    margin: 0 0 18px;
    font-size: 28px;
}

h2 {
    margin: 0 0 12px;
    font-size: 19px;
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.section-title h2 {
    margin: 0;
}

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

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    align-items: end;
}

label {
    display: grid;
    gap: 6px;
    font-size: 14px;
    color: var(--muted);
}

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

.field-help {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.field-with-help {
    position: relative;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px;
    font: inherit;
    background: #fff;
    color: var(--text);
}

button,
.button {
    border: 0;
    border-radius: 6px;
    padding: 10px 14px;
    background: linear-gradient(135deg, var(--primary), #209174);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

button.secondary,
.button.secondary {
    background: linear-gradient(135deg, #33464d, #536a72);
}

button.edit-button,
.button.edit-button {
    background: linear-gradient(135deg, #d87a18, #f09a2a);
}

button.new-button,
.button.new-button {
    background: linear-gradient(135deg, #286aa6, #33a4c9);
}

button.danger,
.button.danger {
    background: linear-gradient(135deg, #8b2d20, #b13b2b);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

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

th {
    background: #edf2ee;
    font-size: 13px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.actions form {
    margin: 0;
}

.alert {
    padding: 12px;
    border-radius: 7px;
    margin-bottom: 14px;
    border: 1px solid var(--line);
    background: #fff;
    transition: opacity 0.25s ease, transform 0.25s ease, margin 0.25s ease, padding 0.25s ease;
}

.alert.is-hiding {
    opacity: 0;
    transform: translateY(-6px);
    margin: 0;
    padding-top: 0;
    padding-bottom: 0;
}

.alert.error {
    border-color: #d9a7a0;
    color: #8b1e12;
}

.alert.ok {
    border-color: #9acbb8;
    color: #0f624e;
    background: #f0fbf6;
}

.login-box {
    max-width: 390px;
    margin: 80px auto;
}

.ticket {
    font-size: 22px;
    font-weight: 800;
    color: var(--accent);
}

.ticket-box {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin: 14px 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8faf7;
}

.ticket-box span,
.ticket-box strong {
    display: block;
}

.pay-ticket-form {
    margin-top: 14px;
}

.thumb {
    width: 86px;
    height: 64px;
    object-fit: contain;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: #ffffff;
}

.image-empty {
    color: var(--muted);
    font-size: 13px;
}

.current-product-image {
    margin-top: 14px;
    display: grid;
    gap: 8px;
    width: 220px;
}

.current-product-image img {
    width: 220px;
    height: 165px;
    object-fit: contain;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
}

.sales-screen {
    display: grid;
    gap: 16px;
}

.sales-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 16px;
    align-items: start;
}

.sales-products {
    display: grid;
    gap: 16px;
}

.sale-controls {
    display: grid;
    grid-template-columns: 1.4fr repeat(3, minmax(150px, 0.6fr));
    gap: 12px;
    align-items: end;
}

.sale-controls input,
.sale-controls select {
    min-height: 48px;
    font-size: 17px;
}

.category-panel {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.category-panel h2 {
    margin-bottom: 10px;
}

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

.category-button {
    min-height: 86px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 6px;
    border: 2px solid var(--line);
    border-radius: 8px;
    background: #f9fbf8;
    color: var(--text);
    text-decoration: none;
    font-size: 16px;
    font-weight: 800;
    text-align: center;
    box-shadow: 0 4px 10px rgba(29, 37, 40, 0.06);
}

.category-button:nth-child(2n) .category-icon {
    background: #fff0c7;
    color: #7a4b00;
}

.category-button:nth-child(3n) .category-icon {
    background: #dcecff;
    color: #174c85;
}

.category-button:nth-child(4n) .category-icon {
    background: #fde2ec;
    color: #8d254c;
}

.category-icon {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #dfe9e3;
    color: var(--primary-dark);
    font-size: 17px;
}

.category-text {
    line-height: 1.1;
}

.category-count {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.category-button.active {
    background: linear-gradient(135deg, var(--primary), #1d8a6f);
    border-color: var(--primary);
    color: #ffffff;
}

.category-button.active .category-icon {
    background: #ffffff;
    color: var(--primary-dark);
}

.category-button.active .category-count {
    color: #dceee8;
}

.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 16px;
}

.item-form {
    margin: 0;
}

.item-form .item-card {
    position: relative;
    width: 100%;
    min-height: 270px;
    padding: 0;
    overflow: hidden;
    display: grid;
    grid-template-rows: 160px 64px 46px;
    border: 1px solid #cbd8cf;
    border-radius: 8px;
    background: #ffffff;
    color: var(--text);
    text-align: left;
    box-shadow: 0 6px 16px rgba(29, 37, 40, 0.08);
}

.item-form:nth-child(4n + 1) .item-card {
    border-top: 5px solid var(--primary);
}

.item-form:nth-child(4n + 2) .item-card {
    border-top: 5px solid var(--gold);
}

.item-form:nth-child(4n + 3) .item-card {
    border-top: 5px solid var(--blue);
}

.item-form:nth-child(4n + 4) .item-card {
    border-top: 5px solid var(--rose);
}

.item-form .item-card:active {
    transform: scale(0.98);
}

.item-form .item-card:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.item-image {
    display: grid;
    place-items: center;
    background: #ffffff;
    overflow: hidden;
    border-bottom: 1px solid var(--line);
}

.item-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.item-image span {
    width: 72px;
    height: 72px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--blue));
    color: #fff;
    font-size: 36px;
    font-weight: 800;
}

.item-name {
    padding: 12px 12px 6px;
    min-height: 0;
    font-size: 17px;
    font-weight: 800;
    line-height: 1.2;
    overflow: hidden;
    background: #ffffff;
}

.item-meta {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 8px;
    padding: 8px 12px 12px;
    background: #ffffff;
}

.item-meta strong {
    color: var(--accent);
    font-size: 19px;
}

.item-meta small {
    color: var(--muted);
    font-size: 12px;
}

.in-cart-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 6px 8px;
    border-radius: 999px;
    background: var(--accent);
    color: #ffffff;
    font-size: 12px;
    font-weight: 800;
}

.cart-panel {
    position: sticky;
    top: 16px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    gap: 14px;
    height: calc(100vh - 32px);
    max-height: calc(100vh - 32px);
    background: linear-gradient(180deg, #ffffff 0%, #fffaf0 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 8px 22px rgba(29, 37, 40, 0.08);
}

.cart-header,
.cart-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.cart-header h2 {
    margin: 0;
}

.cart-header strong {
    color: var(--primary);
}

.cart-list {
    display: grid;
    align-content: start;
    gap: 10px;
    min-height: 0;
    max-height: none;
    overflow: auto;
    padding-right: 4px;
}

.cart-item {
    display: grid;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f9fbf8;
}

.cart-item span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-top: 3px;
}

.cart-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cart-actions form {
    margin: 0;
}

.qty-button {
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 8px;
    font-size: 20px;
}

.remove-button {
    min-height: 38px;
    padding: 8px 10px;
    background: #8b2d20;
}

.compact-button {
    min-height: 34px;
    padding: 8px 12px;
    font-size: 13px;
}

.cart-total {
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.cart-total span {
    color: var(--muted);
    font-weight: 800;
}

.cart-total strong {
    color: var(--accent);
    font-size: 28px;
}

.checkout-form {
    display: grid;
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    background: #fffaf0;
}

.checkout-button {
    min-height: 56px;
    font-size: 19px;
}

.purchase-form {
    display: grid;
    gap: 16px;
}

.purchase-submit {
    justify-self: end;
    min-width: 180px;
    min-height: 42px;
    padding: 10px 18px;
}

.purchase-detail {
    display: grid;
    gap: 12px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.purchase-detail-head,
.purchase-total {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.purchase-lines {
    display: grid;
    gap: 10px;
}

.purchase-line {
    display: grid;
    grid-template-columns: minmax(260px, 1.4fr) minmax(120px, 0.6fr) minmax(140px, 0.7fr) minmax(110px, 0.5fr) auto;
    gap: 10px;
    align-items: end;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f9fbf8;
}

.purchase-subtotal {
    display: grid;
    gap: 6px;
}

.purchase-subtotal strong {
    min-height: 40px;
    display: flex;
    align-items: center;
    color: var(--accent);
}

.purchase-total {
    justify-content: flex-end;
    padding-top: 8px;
    border-top: 1px solid var(--line);
    font-weight: 800;
}

.purchase-total strong {
    color: var(--accent);
    font-size: 24px;
}

.full-button {
    width: 100%;
}

.choice-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.choice-buttons label {
    display: block;
}

.choice-buttons input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.choice-buttons span {
    min-height: 48px;
    display: grid;
    place-items: center;
    border: 2px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: var(--text);
    font-weight: 800;
    cursor: pointer;
}

.choice-buttons input:checked + span {
    background: linear-gradient(135deg, var(--primary), #209174);
    border-color: var(--primary);
    color: #ffffff;
    box-shadow: 0 8px 16px rgba(23, 107, 91, 0.2);
}

@media (max-width: 720px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .app-shell.sidebar-collapsed {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        padding: 14px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .sidebar-header {
        grid-template-columns: minmax(0, 1fr) 42px;
    }

    .sidebar-toggle {
        display: none;
    }

    .sidebar-collapsed .brand {
        display: block;
    }

    .sidebar-collapsed .nav-text {
        display: inline;
    }

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

    .sale-controls {
        grid-template-columns: 1fr 1fr;
    }

    .sales-layout {
        grid-template-columns: 1fr;
    }

    .cart-panel {
        position: static;
    }

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

    .purchase-detail-head,
    .section-title,
    .purchase-total {
        align-items: stretch;
        flex-direction: column;
    }

    .purchase-submit {
        justify-self: stretch;
    }

    .purchase-line {
        grid-template-columns: 1fr;
    }
}
