:root {
    --sidebar-width: 280px;
    --navy: #0f3d4c;
    --navy-dark: #0a2b36;
    --navy-mid: #16495c;
    --accent: #1d9e75;
    --accent-dark: #167a5a;
    --bg: #eef2f5;
    --card: #ffffff;
    --text: #1a1a1a;
    --muted: #5b6770;
    --line: #d7dee4;
    --danger: #b42318;
    --shadow: 0 8px 24px rgba(15, 61, 76, 0.08);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app-shell {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--navy);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: auto;
    z-index: 30;
}

.brand {
    padding: 1.25rem 1.1rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand strong {
    display: block;
    font-size: 1.2rem;
    letter-spacing: 0.04em;
}

.brand span {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.72);
}

.sidebar-nav {
    padding: 0.75rem 0.7rem 1.5rem;
}

.nav-group {
    margin-bottom: 0.85rem;
}

.nav-group-title {
    margin: 0 0.85rem 0.35rem;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.55);
    font-weight: 700;
}

.stat-card strong {
    display: block;
    margin-top: 0.35rem;
    font-size: 1.25rem;
    line-height: 1.25;
    word-break: break-word;
}

a.table-btn,
a.btn-secondary,
a.big-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.module-page {
    display: grid;
    gap: 1rem;
}

.module-banner {
    padding: 0.9rem 1.1rem;
    border-radius: 14px;
    background: #fff7ed;
    border: 1px solid #fdba74;
}

.module-badge {
    display: inline-block;
    margin-bottom: 0.35rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: #9a3412;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
}

.module-list {
    margin: 0.4rem 0 0;
    padding-left: 1.2rem;
}

.module-list li {
    margin: 0.35rem 0;
}

.quick-actions {
    margin: 0 0 1rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.55rem 0;
}

.detail-item span {
    color: var(--muted);
    font-size: 0.85rem;
}

@media (max-width: 900px) {
    .quick-actions {
        grid-template-columns: 1fr 1fr;
    }
}

.nav-parent,
.nav-link {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.55rem;
    min-height: 46px;
    padding: 0.65rem 0.85rem;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #fff;
    font: inherit;
    font-size: 0.98rem;
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.nav-parent:hover,
.nav-link:hover,
.nav-parent:focus-visible,
.nav-link:focus-visible {
    background: var(--navy-mid);
    outline: none;
}

.nav-parent.active,
.nav-link.active {
    background: var(--accent);
}

.nav-caret {
    font-size: 0.8rem;
    opacity: 0.8;
}

.nav-children {
    display: none;
    padding: 0.15rem 0 0.35rem 0.55rem;
}

.nav-group.open .nav-children {
    display: block;
}

.nav-child {
    display: block;
    min-height: 44px;
    padding: 0.55rem 0.8rem;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-size: 0.95rem;
}

.nav-child:hover,
.nav-child.active {
    background: rgba(255, 255, 255, 0.12);
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-height: 72px;
    padding: 0.75rem 1.25rem;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 10;
    flex-wrap: wrap;
}

.topbar-brand {
    font-weight: 800;
    font-size: 1.15rem;
    color: var(--navy);
    text-decoration: none;
    white-space: nowrap;
}

.page-title {
    margin: 0;
    font-size: 1.1rem;
    color: var(--muted);
    font-weight: 600;
}

.top-search {
    flex: 1;
    min-width: 160px;
}

.top-search input {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55rem 0.8rem;
    font-size: 1rem;
}

.topbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0.45rem 0.8rem;
    border-radius: 10px;
    background: var(--navy);
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.92rem;
    white-space: nowrap;
}

.topbar-btn:hover {
    background: var(--accent-dark);
}

button.topbar-btn {
    border: 0;
    cursor: pointer;
    font-family: inherit;
}

.session-label {
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}

body.needs-login .sidebar,
body.needs-login .top-search,
body.needs-login .topbar-btn[href],
body.needs-login #session-label,
body.needs-login #logout-btn,
body.needs-login .menu-toggle {
    display: none;
}

body.needs-login .app-shell {
    display: block;
}

body.needs-login .app-main {
    margin: 0;
}

.login-page {
    min-height: 60vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    width: min(460px, 100%);
}

.login-card label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0.7rem;
    font-weight: 600;
    font-size: 0.92rem;
}

.login-card input {
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55rem 0.75rem;
    font-size: 1rem;
}

.pw-field {
    position: relative;
    display: block;
    width: 100%;
}

.pw-field input,
.form-grid .pw-field input,
.login-card .pw-field input {
    width: 100%;
    padding-right: 2.9rem;
}

.pw-toggle {
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.pw-toggle:hover,
.pw-toggle:focus-visible {
    background: #f4f7f9;
    outline: none;
}

.pw-toggle.is-open {
    color: var(--navy);
}

.pw-toggle.is-open::after {
    content: "";
    position: absolute;
    left: 10px;
    right: 10px;
    top: 50%;
    height: 2px;
    background: var(--navy);
    transform: translateY(-50%) rotate(-28deg);
}

.pw-rules {
    margin: 0.4rem 0 0.2rem;
    padding-left: 1.1rem;
    font-size: 0.92rem;
}

.pw-ok {
    color: var(--accent-dark);
    margin: 0.15rem 0;
}

.pw-miss {
    color: var(--danger);
    margin: 0.15rem 0;
}

.nav-icon {
    width: 1.6rem;
    flex: 0 0 auto;
}

.menu-toggle {
    display: none;
    min-height: 48px;
    padding: 0.6rem 0.9rem;
    border: 0;
    border-radius: 10px;
    background: var(--navy);
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}

.app-content {
    padding: 1.25rem;
}

.page-head p,
.muted {
    color: var(--muted);
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.9rem;
    margin: 1rem 0 1.25rem;
}

.stat-card,
.panel,
.coming-soon {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.stat-card {
    padding: 1rem 1.1rem;
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 0.9rem;
}

.stat-card strong {
    display: block;
    margin-top: 0.35rem;
    font-size: 1.25rem;
    line-height: 1.25;
    word-break: break-word;
}

.panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.panel {
    padding: 1rem 1.1rem;
}

.panel h2 {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
}

.list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.list li {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.7rem 0;
    border-top: 1px solid var(--line);
    font-size: 0.98rem;
}

.list li:first-child {
    border-top: 0;
}

.coming-soon {
    padding: 1.25rem;
}

.coming-soon h2 {
    margin: 0 0 0.5rem;
}

.sub-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.sub-grid a,
.big-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 56px;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    background: var(--navy);
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    text-align: center;
}

.sub-grid a:hover,
.big-btn:hover {
    background: var(--accent-dark);
}

.lookup-wrap .page {
    margin: 0;
    padding: 0;
    max-width: none;
}

.error-text {
    color: var(--danger);
}

.sidebar-backdrop {
    display: none;
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        transform: translateX(-105%);
        transition: transform 0.2s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .menu-toggle {
        display: inline-flex;
        align-items: center;
    }

    .page-title {
        display: none;
    }

    .sidebar-backdrop:not([hidden]) {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 20;
    }
}

.products-toolbar {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.9rem;
}

.product-search {
    flex: 1;
    min-width: 200px;
    min-height: 52px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.7rem 0.9rem;
    font-size: 1.05rem;
}

.products-toolbar .big-btn {
    min-width: 140px;
}

.products-alert {
    margin: 0 0 0.9rem;
    padding: 0.75rem 0.9rem;
    border-radius: 10px;
    font-weight: 600;
}

.products-alert.success {
    background: #ecfdf3;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.products-alert.error {
    background: #fef2f2;
    color: var(--danger);
    border: 1px solid #fecaca;
}

.found-card {
    margin-bottom: 0.9rem;
}

.product-form {
    margin-bottom: 1rem;
}

.product-photos {
    margin-top: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--line);
}

.product-photos h3,
.product-photos h2 {
    margin: 0 0 0.35rem;
}

.product-photo-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin: 0.75rem 0;
}

.product-photo-item {
    width: 140px;
    margin: 0;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.5rem;
}

.product-photo-item.is-primary {
    border-color: #0b3d4a;
    box-shadow: 0 0 0 2px rgba(11, 61, 74, 0.25);
}

.product-photo-item img {
    display: block;
    width: 100%;
    height: 110px;
    object-fit: cover;
    border-radius: 8px;
    background: #e8eef2;
}

.product-photo-badge {
    display: block;
    margin: 0.4rem 0;
    font-size: 0.78rem;
    font-weight: 700;
    color: #0b3d4a;
}

.product-photo-badge.muted-badge {
    color: #64748b;
    font-weight: 600;
}

.product-photo-actions {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.product-photo-empty {
    margin: 0.5rem 0;
    color: #64748b;
}

.product-photo-upload {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
}

.product-photo-upload input[type="file"] {
    min-height: 44px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.form-grid label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-weight: 600;
    font-size: 0.92rem;
}

.form-grid input {
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55rem 0.75rem;
    font-size: 1rem;
}

.form-grid input[readonly] {
    background: #f4f7f9;
    color: var(--text);
    cursor: default;
}

.form-grid .full {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-top: 0.9rem;
}

.btn-secondary {
    min-height: 56px;
    padding: 0.8rem 1rem;
    border: 0;
    border-radius: 12px;
    background: #64748b;
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.table-wrap {
    overflow-x: auto;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 860px;
}

.data-table th,
.data-table td {
    padding: 0.7rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    font-size: 0.95rem;
}

.data-table th {
    background: #f8fafc;
    font-size: 0.85rem;
    color: var(--muted);
}

.data-table tr.row-hit {
    background: #ecfdf3;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.table-btn {
    min-height: 40px;
    padding: 0.35rem 0.6rem;
    border: 0;
    border-radius: 8px;
    background: var(--navy);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.table-btn.danger {
    background: var(--danger);
}

@media (max-width: 700px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
}

.btn-stock-out {
    background: #9a3412;
}

.btn-stock-out:hover {
    background: #7c2d12;
}

.stock-barcode-row {
    display: flex;
    gap: 0.55rem;
    align-items: stretch;
}

.stock-barcode-row input {
    flex: 1;
}

.stock-barcode-row .big-btn {
    min-width: 110px;
    min-height: 46px;
}

.stock-section {
    margin-top: 1.15rem;
}

.stock-section h2 {
    margin: 0;
    padding: 0.85rem 0.9rem 0.35rem;
    font-size: 1.05rem;
}

.stock-section > .muted {
    margin: 0;
    padding: 0 0.9rem 0.7rem;
}

.stock-status {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.85rem;
}

.stock-status.ok {
    background: #ecfdf3;
    color: #166534;
}

.stock-status.critical {
    background: #fef2f2;
    color: var(--danger);
}

.purchases-page .found-card .form-grid {
    margin-top: 0.35rem;
}

.data-table tr.row-inactive {
    opacity: 0.72;
}

.customer-sales-title {
    margin: 1rem 0 0.6rem;
    font-size: 1.05rem;
}

.cu-pay-box {
    margin-top: 1rem;
    padding: 0.9rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #f8fafc;
}

.cu-pay-box h3 {
    margin: 0 0 0.65rem;
    font-size: 1.08rem;
}

.kasa-filter {
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: end;
}

.kasa-filter label {
    display: grid;
    gap: 0.25rem;
    font-size: 0.85rem;
    color: var(--muted);
}

.kasa-forms {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}

.ledger-table {
    min-width: 1180px;
}

.sales-barcode-bar .product-search {
    min-height: 64px;
    font-size: 1.2rem;
}

.sales-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.9fr);
    gap: 1rem;
    align-items: start;
    margin-bottom: 1rem;
}

.sales-cart-table {
    border: 0;
    box-shadow: none;
}

.sales-cart-table .data-table {
    min-width: 520px;
}

.sales-grand {
    margin: 0.85rem 0.2rem 0;
    font-size: 1.15rem;
}

.sales-add-actions {
    align-self: end;
    margin-top: 0;
}

.form-grid select {
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55rem 0.75rem;
    font-size: 1rem;
    background: #fff;
}

.pay-fieldset {
    border: 1px solid var(--line);
    border-radius: 12px;
    margin: 0.85rem 0 0.5rem;
    padding: 0.7rem 0.9rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem 1.25rem;
}

.pay-fieldset legend {
    font-weight: 700;
    padding: 0 0.35rem;
}

.pay-fieldset label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
}

.qty-stepper {
    display: flex;
    align-items: stretch;
    gap: 0.35rem;
}

.qty-stepper input {
    width: 72px;
    min-height: 42px;
    text-align: center;
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 1rem;
}

.qty-stepper button {
    min-width: 42px;
    min-height: 42px;
    border: 0;
    border-radius: 10px;
    background: var(--navy);
    color: #fff;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
}

@media (max-width: 980px) {
    .sales-layout {
        grid-template-columns: 1fr;
    }
}

.receipt-paper,
.price-label {
    background: #fff;
}

.label-sheet {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1rem;
}

.price-label {
    width: 220px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.65rem 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    align-items: center;
    text-align: center;
}

.price-label .barcode-svg {
    width: 100%;
    height: 48px;
}

.label-barcode-text {
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.85rem;
}

.label-price {
    font-size: 1.15rem;
    font-weight: 700;
}

.label-bulk {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.35rem 0.75rem;
    max-height: 280px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.65rem 0.8rem;
}

.label-check {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
}

.row-unread td {
    font-weight: 700;
}

@media print {
    .sidebar,
    .topbar,
    .sidebar-backdrop,
    .no-print,
    .menu-toggle {
        display: none !important;
    }

    .app-shell,
    .app-main,
    .app-content {
        display: block;
        min-height: 0;
        background: #fff;
        box-shadow: none;
    }

    .receipt-paper,
    .price-label {
        box-shadow: none;
        break-inside: avoid;
    }
}
