* {
    box-sizing: border-box;
    margin: 0;
    padding: 0
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f3f4f6;
    color: #1f2937;
    line-height: 1.5
}

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem
}

.auth-card {
    background: #fff;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, .1);
    width: 100%;
    max-width: 400px
}

.auth-card h1 {
    text-align: center;
    color: #2563eb;
    margin-bottom: .5rem
}

.subtitle {
    text-align: center;
    color: #6b7280;
    margin-bottom: 1.5rem
}

label {
    display: block;
    margin: .8rem 0 .3rem;
    font-weight: 500;
    font-size: .9rem
}

input,
select {
    width: 100%;
    padding: .7rem;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 1rem
}

input:focus,
select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15)
}

.select2-container {
   width: 100% !important;
}

.select2-container .select2-selection--single {
   min-height: 44px;
   border: 1px solid #d1d5db;
   border-radius: 8px;
}

.select2-container .select2-selection--single .select2-selection__rendered {
   line-height: 42px;
}

.select2-container .select2-selection--single .select2-selection__arrow {
   height: 42px;
}

.btn {
    display: inline-block;
    padding: .7rem 1.2rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: .95rem;
    text-decoration: none;
    text-align: center
}

.btn.primary {
    background: #2563eb;
    color: #fff
}

.btn.primary:hover {
    background: #1d4ed8
}

.btn.success {
    background: #10b981;
    color: #fff
}

.btn.danger {
    background: #ef4444;
    color: #fff
}

.btn.small {
    padding: .3rem .7rem;
    font-size: .85rem
}

.btn.full {
    width: 100%
}

.alert {
    padding: .8rem;
    border-radius: 8px;
    margin-bottom: 1rem
}

.alert.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5
}

.alert.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7
}

.alert.warn {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d
}

.topbar {
    background: #2563eb;
    color: #fff;
    padding: .8rem 1rem;
    display: flex;
    align-items: center;
    gap: .8rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 5px rgba(0, 0, 0, .1)
}

.topbar .brand {
    font-weight: 700;
    font-size: 1.1rem;
    flex: 1
}

.topbar .user-info {
    font-size: .85rem;
    opacity: .9
}

.menu-toggle {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer
}

.sidebar {
    position: fixed;
    top: 56px;
    left: -260px;
    width: 250px;
    height: calc(100% - 56px);
    background: #fff;
    box-shadow: 2px 0 10px rgba(0, 0, 0, .1);
    transition: left .3s;
    z-index: 90;
    overflow-y: auto
}

.sidebar.open {
    left: 0
}

.sidebar ul {
    list-style: none;
    padding: 1rem 0
}

.sidebar li a {
    display: block;
    padding: .8rem 1.2rem;
    color: #374151;
    text-decoration: none;
    border-left: 3px solid transparent
}

.sidebar li a:hover,
.sidebar li a.active {
    background: #eff6ff;
    color: #2563eb;
    border-left-color: #2563eb
}

.sidebar .logout {
    color: #ef4444
}

.content {
    padding: 1rem;
    padding-top: 1rem;
    margin-top: 56px
}

h2 {
    margin-bottom: 1rem;
    color: #1f2937
}

h3 {
    margin: 1.5rem 0 .8rem;
    color: #374151
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin: 1rem 0
}

.stat-card {
    background: #fff;
    padding: 1.2rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .06);
    text-align: center
}

.stat-card h3 {
    font-size: 2rem;
    color: #2563eb;
    margin: 0
}

.stat-card p {
    color: #6b7280;
    font-size: .9rem;
    margin-top: .3rem
}

.form-card {
    background: #fff;
    padding: 1.2rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .06);
    margin: 1rem 0
}

.form-card hr {
    margin: 1rem 0;
    border: none;
    border-top: 1px solid #e5e7eb
}

table.dataTable {
    background: #fff;
    border-radius: 8px;
    overflow: hidden
}

.summary {
    background: #eff6ff;
    padding: 1rem;
    border-radius: 8px;
    margin: 1rem 0
}

.summary p {
    margin: .3rem 0;
    display: flex;
    justify-content: space-between;
    gap: .75rem
}

.summary strong {
    white-space: nowrap
}

.sale-items-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .8rem;
    margin: .5rem 0 .8rem
}

.sale-items-toolbar h3 {
    margin: 0;
    font-size: 1rem
}

.add-sale-item {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    min-height: 40px;
    padding: .5rem .8rem;
    background: #e0f2fe;
    color: #075985
}

.add-sale-item:hover {
    background: #bae6fd
}

.add-sale-item span {
    font-size: 1.25rem;
    line-height: 1
}

.sale-items {
    display: grid;
    gap: .65rem
}

.sale-item-row {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(140px, 160px) minmax(85px, 105px) minmax(100px, 125px) auto;
    align-items: end;
    gap: .75rem;
    padding: .8rem;
    border: 1px solid #dbe3ea;
    border-radius: 8px;
    background: #f8fafc;
    animation: sale-item-enter .18s ease-out
}

.sale-field label {
    margin: 0 0 .35rem
}

.sale-line-summary {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    padding: .35rem 0;
    color: #64748b;
    font-size: .82rem
}

.sale-line-unit-price {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    padding: .35rem 0;
    color: #64748b;
    font-size: .82rem
}

.sale-line-unit-price strong {
    color: #334155;
    font-size: .95rem;
    font-variant-numeric: tabular-nums
}

.sale-line-summary strong {
    color: #172554;
    font-size: 1rem;
    font-variant-numeric: tabular-nums
}

.quantity-control {
    display: grid;
    grid-template-columns: 40px minmax(40px, 1fr) 40px;
    min-height: 44px;
    overflow: hidden;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff
}

.quantity-control .quantity-step {
    border: 0;
    background: #f1f5f9;
    color: #334155;
    font-size: 1.2rem;
    cursor: pointer
}

.quantity-control .quantity-step:hover {
    background: #e2e8f0
}

.quantity-control .sale-quantity {
    width: 100%;
    min-width: 0;
    min-height: 42px;
    padding: .35rem .15rem;
    border: 0;
    border-right: 1px solid #e2e8f0;
    border-left: 1px solid #e2e8f0;
    border-radius: 0;
    text-align: center;
    font-variant-numeric: tabular-nums
}

.quantity-control .sale-quantity:focus {
    box-shadow: inset 0 0 0 2px rgba(37, 99, 235, .2)
}

.sale-line-actions {
    display: flex;
    align-items: center;
    gap: .25rem
}

.clear-sale-item,
.remove-sale-item {
    width: 40px;
    height: 40px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: #475569;
    font-size: .8rem;
    line-height: 1;
    cursor: pointer
}

.remove-sale-item {
    color: #b91c1c;
    font-size: 1.5rem
}

.clear-sale-item:hover,
.remove-sale-item:hover {
    border-color: #fecaca;
    background: #fee2e2
}

.remove-sale-item[hidden] {
    display: none
}

@keyframes sale-item-enter {
    from { opacity: 0; transform: translateY(-4px) }
    to { opacity: 1; transform: translateY(0) }
}

@media (max-width: 640px) {
    .sale-item-row {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: .55rem .7rem
    }

    .sale-product-field {
        grid-column: 1 / -1;
        grid-row: 1
    }

    .sale-quantity-field {
        grid-column: 1;
        grid-row: 2
    }

    .sale-line-summary {
        grid-column: 2;
        grid-row: 2;
        align-self: center
    }

    .sale-line-unit-price {
        grid-column: 1;
        grid-row: 3
    }

    .sale-line-actions {
        grid-column: 2;
        grid-row: 3;
        justify-content: flex-end
    }
}

@media (max-width: 420px) {
    .sale-items-toolbar {
        align-items: flex-start;
        flex-direction: column
    }
}

.badge {
    padding: .2rem .6rem;
    border-radius: 12px;
    font-size: .8rem;
    font-weight: 600
}

.badge.success {
    background: #d1fae5;
    color: #065f46
}

.badge.danger {
    background: #fee2e2;
    color: #991b1b
}

.badge.warn {
    background: #fef3c7;
    color: #92400e
}

.card-list {
    display: grid;
    gap: 1rem;
    margin-top: 1rem
}

.card {
    background: #fff;
    padding: 1rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .06)
}

.card h3 {
    margin: 0 0 .5rem
}

.card .actions {
    display: flex;
    gap: .5rem;
    margin-top: .8rem;
    flex-wrap: wrap
}

@media(min-width:768px) {
    .sidebar {
        left: 0
    }

    .content {
        margin-left: 250px
    }

    .menu-toggle {
        display: none
    }
}

@media print {

    .topbar,
    .sidebar,
    .menu-overlay,
    .btn,
    .menu-toggle {
        display: none !important
    }

    .content {
        margin: 0;
        padding: 0
    }
}

:root {
    --topbar-height: 56px
}

html {
    min-width: 320px;
    scroll-behavior: smooth
}

body {
    min-height: 100vh;
    overflow-x: hidden
}

.topbar {
    min-height: var(--topbar-height);
    padding-inline: clamp(1rem, 3vw, 2.5rem)
}

.topbar .user-info {
    max-width: 45%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap
}

.content {
    min-width: 0;
    margin-top: 0;
    padding: clamp(1rem, 2.5vw, 2.5rem)
}

.content > h2:first-child {
    margin-top: 0
}

.form-card {
    width: 100%;
    max-width: 800px
}

.form-card input,
.form-card select,
.auth-card input,
.auth-card select {
    min-height: 44px
}

.btn {
    min-height: 42px
}

.dataTables_wrapper {
    width: 100%;
    max-width: 100%;
    margin: 1rem 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch
}

.dataTables_wrapper table.dataTable {
    width: 100% !important
}

.menu-overlay {
    display: none
}

@media (min-width: 768px) {
    .content {
        width: calc(100% - 250px);
        margin-left: 250px;
        margin-right: auto
    }

    .sidebar {
        top: var(--topbar-height);
        height: calc(100vh - var(--topbar-height))
    }
}

@media (min-width: 1440px) {
    .content {
        max-width: 1800px;
        padding: 2.5rem clamp(2.5rem, 4vw, 5rem)
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
        gap: 1.25rem
    }
}

@media (max-width: 767px) {
    .topbar {
        gap: .55rem;
        padding-inline: .75rem
    }

    .topbar .brand {
        font-size: 1rem
    }

    .topbar .user-info {
        max-width: 42%;
        font-size: .75rem
    }

    .menu-toggle {
        flex: 0 0 40px;
        min-width: 40px;
        min-height: 40px
    }

    .sidebar {
        top: var(--topbar-height);
        left: 0;
        width: min(280px, 85vw);
        height: calc(100vh - var(--topbar-height));
        height: calc(100dvh - var(--topbar-height));
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 110
    }

    .sidebar.open {
        left: 0;
        transform: translateX(0)
    }

    .menu-overlay {
        position: fixed;
        inset: var(--topbar-height) 0 0;
        z-index: 105;
        width: 100%;
        height: calc(100vh - var(--topbar-height));
        height: calc(100dvh - var(--topbar-height));
        padding: 0;
        border: 0;
        background: rgba(17, 24, 39, .45);
        opacity: 0;
        visibility: hidden;
        transition: opacity .25s ease, visibility .25s ease
    }

    .menu-overlay.open {
        display: block;
        opacity: 1;
        visibility: visible
    }

    .content {
        width: 100%;
        margin: 0;
        padding: 1rem
    }

    h2 {
        font-size: 1.35rem;
        overflow-wrap: anywhere
    }

    h3 {
        font-size: 1.1rem
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .7rem
    }

    .stat-card {
        padding: .9rem .65rem
    }

    .stat-card h3 {
        font-size: 1.6rem
    }

    .stat-card p {
        font-size: .8rem;
        overflow-wrap: anywhere
    }

    .form-card {
        padding: 1rem
    }

    .form-card .btn,
    .content > .btn {
        width: 100%;
        margin: .25rem 0
    }

    .card .actions .btn {
        flex: 1 1 auto
    }

    .dataTables_wrapper {
        font-size: .85rem
    }

    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none;
        width: 100%;
        margin: .5rem 0;
        text-align: left
    }

    .dataTables_wrapper .dataTables_filter label {
        display: flex;
        align-items: center;
        gap: .4rem
    }

    .dataTables_wrapper .dataTables_filter input {
        min-width: 0;
        width: 100%;
        margin-left: 0
    }
}

@media (max-width: 380px) {
    .content {
        padding: .75rem
    }

    .stats-grid {
        grid-template-columns: 1fr
    }

    .auth-card {
        padding: 1.4rem
    }
}