:root {
    --bg: #f5f9ff;
    --surface: #ffffff;
    --surface-soft: #eef7ff;
    --text: #0f172a;
    --muted: #64748b;
    --line: #dbeafe;
    --blue: #0f5bd7;
    --blue-dark: #0b3f91;
    --cyan: #06b6d4;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --shadow: 0 18px 45px rgba(15, 91, 215, 0.12);
    --radius: 8px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
}

body.dark {
    --bg: #07111f;
    --surface: #0f1d32;
    --surface-soft: #122b47;
    --text: #e5f2ff;
    --muted: #9fb3c8;
    --line: #1f3c5c;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

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

button,
input,
select,
textarea {
    font: inherit;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(320px, 0.86fr) 1.14fr;
    background:
        radial-gradient(circle at 80% 12%, rgba(6, 182, 212, 0.2), transparent 30%),
        linear-gradient(135deg, #eaf6ff 0%, #f8fbff 38%, #dbeafe 100%);
}

.auth-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.auth-card {
    width: min(100%, 430px);
    padding: 34px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(14, 165, 233, 0.18);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.auth-visual {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 56px;
    color: #fff;
    background:
        linear-gradient(135deg, rgba(7, 56, 130, 0.86), rgba(8, 145, 178, 0.76)),
        url("data:image/svg+xml,%3Csvg width='900' height='900' viewBox='0 0 900 900' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='900' height='900' fill='%230b5bd3'/%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.28' stroke-width='4'%3E%3Cpath d='M123 460c106-97 232-121 378-72 92 31 174 29 246-6'/%3E%3Cpath d='M88 584c133-71 282-79 448-24 84 28 171 22 260-19'/%3E%3Cpath d='M170 310c98-66 215-80 350-40 86 26 163 23 232-9'/%3E%3C/g%3E%3Cg fill='%23ffffff' fill-opacity='.88'%3E%3Cpath d='M515 233c70 7 128 35 174 85-43 48-99 76-168 84l-58-83 52-86z'/%3E%3Ccircle cx='640' cy='316' r='10' fill='%23065f86'/%3E%3Cpath d='M410 319l53-86-12 86 12 83z' fill='%23bae6fd'/%3E%3C/g%3E%3C/svg%3E") center / cover;
}

.auth-visual h1 {
    max-width: 620px;
    margin: 0 0 14px;
    font-size: clamp(38px, 5vw, 72px);
    line-height: 0.98;
    letter-spacing: 0;
}

.auth-visual p {
    max-width: 560px;
    margin: 0;
    color: rgba(255, 255, 255, 0.84);
    font-size: 17px;
    line-height: 1.65;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.brand-mark {
    width: 58px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.brand-title {
    display: block;
    font-size: 18px;
    font-weight: 800;
}

.brand-subtitle {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px 1fr;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 22px 16px;
    background: #071a32;
    color: #d8eaff;
    display: flex;
    flex-direction: column;
    gap: 22px;
    z-index: 30;
}

.sidebar .brand-subtitle {
    color: #8fb9e8;
}

.nav-section {
    display: grid;
    gap: 7px;
}

.nav-label {
    padding: 0 12px 6px;
    font-size: 11px;
    color: #7da8da;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 42px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: #c7dcf4;
    transition: 0.18s ease;
}

.nav-link:hover,
.nav-link.active {
    color: #fff;
    background: rgba(14, 165, 233, 0.15);
}

.nav-link.active {
    box-shadow: inset 3px 0 0 var(--cyan);
}

.nav-link svg,
.icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.sidebar-footer {
    margin-top: auto;
}

.profile-card {
    min-height: 74px;
    padding: 15px 16px;
    display: flex;
    align-items: center;
    gap: 13px;
    border: 1px solid rgba(147, 197, 253, 0.18);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.05);
    color: #e8f3ff;
    transition: 0.18s ease;
}

.profile-card:hover,
.profile-card.active {
    border-color: rgba(56, 189, 248, 0.48);
    background: rgba(14, 165, 233, 0.12);
}

.profile-card.active {
    box-shadow: inset 3px 0 0 var(--cyan);
}

.profile-card .avatar {
    width: 42px;
    height: 42px;
    font-size: 15px;
    background: #0ea5e9;
}

.profile-card-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.profile-card-text strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
}

.profile-card .muted {
    display: block;
    color: #81a7d0;
    font-size: 13px;
    line-height: 1.25;
}

.app-main {
    min-width: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 76px;
    padding: 16px 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    background: rgba(245, 249, 255, 0.86);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--line);
}

body.dark .topbar {
    background: rgba(7, 17, 31, 0.86);
}

.page-title h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.page-title p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.topbar-actions,
.action-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    min-width: 0;
}

.filter-row {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 12px;
}

.filter-row .form-field {
    flex: 1 1 180px;
}

.content {
    padding: 26px;
}

.grid {
    display: grid;
    gap: 18px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.two-col {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(340px, 0.8fr);
    gap: 18px;
}

.three-col {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.card,
.panel,
.stat-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 8px 28px rgba(15, 91, 215, 0.07);
}

.stat-card {
    position: relative;
    overflow: hidden;
    padding: 18px;
}

.stat-card::after {
    content: "";
    position: absolute;
    inset: auto -36px -42px auto;
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: rgba(6, 182, 212, 0.11);
}

.stat-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.stat-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, var(--blue), var(--cyan));
}

.stat-label {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 13px;
}

.stat-value {
    margin: 0;
    font-size: clamp(22px, 2vw, 30px);
    line-height: 1.05;
    font-weight: 800;
}

.stat-note {
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.panel {
    padding: 18px;
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.panel-title {
    margin: 0;
    font-size: 16px;
}

.panel-subtitle {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.chart-wrap {
    position: relative;
    min-height: 300px;
}

.chart-wrap.compact {
    min-height: 240px;
}

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th,
td {
    padding: 13px 14px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    font-size: 13px;
}

th {
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    background: var(--surface-soft);
}

tr:last-child td {
    border-bottom: 0;
}

.table-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.btn {
    min-height: 38px;
    padding: 9px 13px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: 0.18s ease;
    font-weight: 700;
    font-size: 13px;
    white-space: nowrap;
}

.btn-primary {
    color: #fff;
    background: linear-gradient(135deg, var(--blue), var(--cyan));
    box-shadow: 0 12px 24px rgba(6, 182, 212, 0.2);
}

.btn-secondary {
    color: var(--blue-dark);
    border-color: var(--line);
    background: var(--surface);
}

.btn-danger {
    color: #fff;
    background: var(--danger);
}

.btn-stock {
    color: #047857;
    border-color: #a7f3d0;
    background: #ecfdf5;
}

.dark .btn-stock {
    color: #a7f3d0;
    border-color: rgba(16, 185, 129, 0.42);
    background: rgba(16, 185, 129, 0.14);
}

.btn-ghost {
    color: var(--muted);
    background: transparent;
    border-color: var(--line);
}

.btn-icon {
    width: 38px;
    padding: 0;
}

.btn:hover {
    transform: translateY(-1px);
}

.filter-row .btn {
    align-self: flex-end;
    min-height: 44px;
    padding-inline: 18px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.form-field {
    display: grid;
    gap: 7px;
}

.form-field.full {
    grid-column: 1 / -1;
}

label {
    color: var(--text);
    font-weight: 700;
    font-size: 12px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    padding: 11px 12px;
    outline: none;
    transition: 0.18s ease;
}

textarea {
    resize: vertical;
    min-height: 92px;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.14);
}

.field-error {
    color: var(--danger);
    font-size: 12px;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 24px;
    padding: 4px 9px;
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--blue-dark);
    font-weight: 800;
    font-size: 11px;
}

.badge.success {
    color: #047857;
    background: #dcfce7;
}

.badge.warning {
    color: #9a3412;
    background: #ffedd5;
}

.badge.danger {
    color: #991b1b;
    background: #fee2e2;
}

.badge.cyan {
    color: #0e7490;
    background: #cffafe;
}

.product-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.swatch,
.avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--blue), var(--cyan));
}

.avatar {
    border-radius: 50%;
}

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

.metric-list {
    display: grid;
    gap: 12px;
}

.metric-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.metric-item.compact {
    min-height: 43px;
    padding: 10px 11px;
}

.modal.transaction-modal {
    width: min(1180px, calc(100vw - 24px));
}

.transaction-items {
    display: grid;
    gap: 12px;
    margin-bottom: 12px;
}

.transaction-item {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-soft);
}

.transaction-item-grid {
    display: grid;
    grid-template-columns: minmax(420px, 2.2fr) minmax(120px, 0.55fr) minmax(160px, 0.8fr) minmax(150px, 0.75fr) 42px;
    align-items: end;
    gap: 12px;
}

.transaction-item-action {
    align-self: end;
}

.transaction-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 14px;
}

.product-search {
    position: relative;
}

.product-search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 70;
    display: none;
    max-height: 264px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.16);
}

.product-search-results.active {
    display: grid;
    gap: 5px;
}

.product-search-option {
    width: 100%;
    min-height: 46px;
    padding: 8px 10px;
    border: 0;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--text);
    background: transparent;
    cursor: pointer;
    text-align: left;
}

.product-search-option:hover {
    background: var(--surface-soft);
}

.product-search-option strong,
.product-search-option small {
    display: block;
}

.product-search-option small,
.product-search-option > span:last-child,
.product-search-empty {
    color: var(--muted);
    font-size: 12px;
}

.product-search-empty {
    padding: 12px;
}

.progress {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-soft);
}

.progress span {
    display: block;
    height: 100%;
    width: var(--value, 0%);
    border-radius: inherit;
    background: linear-gradient(90deg, var(--blue), var(--cyan));
}

.flash {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    padding: 13px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: 0 8px 22px rgba(15, 91, 215, 0.07);
}

.flash.success {
    border-color: #bbf7d0;
    color: #065f46;
}

.flash.error {
    border-color: #fecaca;
    color: #991b1b;
}

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 16px;
}

.pager-summary {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.pager-pages {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pager-link,
.pager-dots {
    display: inline-flex;
    min-width: 34px;
    min-height: 34px;
    align-items: center;
    justify-content: center;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    transition: 0.18s ease;
}

.pager-link:hover {
    border-color: var(--cyan);
    color: var(--blue);
}

.pager-link.active {
    border-color: var(--blue);
    color: #fff;
    background: var(--blue);
    font-weight: 700;
}

.pager-link.disabled {
    opacity: 0.45;
    pointer-events: none;
}

.pager-dots {
    min-width: 26px;
    padding-inline: 4px;
    border-color: transparent;
    background: transparent;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(2, 8, 23, 0.54);
}

.modal-backdrop.active {
    display: flex;
}

.modal {
    width: min(720px, 100%);
    max-height: min(760px, 92vh);
    overflow-y: auto;
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--line);
    box-shadow: 0 26px 70px rgba(2, 8, 23, 0.24);
}

.modal-header,
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

.modal-footer {
    border-top: 1px solid var(--line);
    border-bottom: 0;
    justify-content: flex-end;
}

.modal-body {
    padding: 18px;
}

.mobile-menu {
    display: none;
}

.empty-state {
    padding: 38px;
    text-align: center;
    color: var(--muted);
}

.dark .btn-secondary,
.dark .btn-ghost {
    color: #dbeafe;
}

@media (max-width: 1180px) {
    .stat-grid,
    .three-col {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .two-col {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 1120px) {
    .transaction-item-grid {
        grid-template-columns: minmax(320px, 1.4fr) minmax(120px, 0.6fr) minmax(160px, 0.8fr);
    }

    .transaction-item-action {
        grid-column: 1 / -1;
    }
}

@media (max-width: 860px) {
    .auth-page {
        grid-template-columns: 1fr;
    }

    .auth-visual {
        min-height: 340px;
        padding: 32px;
    }

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

    .sidebar {
        position: fixed;
        transform: translateX(-105%);
        transition: 0.2s ease;
        width: 280px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-menu {
        display: inline-flex;
    }

    .topbar {
        padding: 14px 16px;
        align-items: flex-start;
    }

    .content {
        padding: 16px;
    }

    .stat-grid,
    .three-col,
    .form-grid,
    .transaction-summary {
        grid-template-columns: 1fr;
    }

    .transaction-item-grid {
        grid-template-columns: 1fr;
    }

    .transaction-item-action .btn {
        width: 100%;
    }

    .topbar-actions {
        margin-left: auto;
    }

    .topbar > .topbar-actions:first-child {
        flex: 1 1 auto;
        margin-left: 0;
    }

    .topbar > .topbar-actions:last-child {
        flex: 0 0 auto;
        justify-content: flex-end;
    }

    .page-title {
        min-width: 0;
    }

    .page-title h1 {
        font-size: 19px;
    }

}

@media (max-width: 560px) {
    body {
        overflow-x: hidden;
    }

    .auth-panel,
    .auth-card {
        padding: 22px;
    }

    .page-title p,
    .topbar .badge,
    .hide-mobile {
        display: none;
    }

    .panel-header,
    .filter-row {
        align-items: stretch;
        flex-direction: column;
        width: 100%;
        max-width: 100%;
        overflow: hidden;
    }

    .topbar {
        flex-wrap: wrap;
        gap: 12px;
    }

    .topbar > .topbar-actions:first-child,
    .topbar > .topbar-actions:last-child {
        width: 100%;
    }

    .topbar > .topbar-actions:last-child {
        justify-content: space-between;
    }

    .topbar form {
        margin-left: auto;
    }

    .topbar .btn:not(.btn-icon) {
        width: auto;
    }

    .panel {
        padding: 14px;
        width: 100%;
        max-width: 100%;
        overflow: hidden;
    }

    .grid {
        gap: 14px;
    }

    .filter-row .form-field {
        flex: 1 1 auto;
        width: 100%;
        max-width: 100%;
        min-width: 0 !important;
    }

    .filter-row .btn {
        width: 100%;
        max-width: 100%;
        align-self: stretch;
        justify-content: center;
    }

    .filter-row input,
    .filter-row select {
        max-width: 100%;
        min-width: 0;
    }

    .action-row {
        width: 100%;
        align-items: stretch;
        flex-direction: column;
    }

    .action-row .btn {
        width: 100%;
    }

    .stat-card {
        padding: 15px;
    }

    .stat-top {
        gap: 10px;
    }

    .stat-icon {
        width: 38px;
        height: 38px;
    }

    .metric-item {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
    }

    .table-wrapper {
        margin-inline: -2px;
        box-shadow: inset -18px 0 20px -24px rgba(15, 23, 42, 0.38);
    }

    table {
        min-width: 680px;
    }

    th,
    td {
        padding: 11px 12px;
        font-size: 12px;
    }

    .modal-backdrop {
        align-items: stretch;
        padding: 8px;
    }

    .modal {
        max-height: calc(100vh - 16px);
        border-radius: 10px;
    }

    .modal-header,
    .modal-footer,
    .modal-body {
        padding: 14px;
    }

    .pager {
        justify-content: center;
    }

    .pager-summary {
        width: 100%;
        text-align: center;
    }

    .btn {
        width: 100%;
    }

    .btn-icon {
        width: 38px;
    }

}
