:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --panel-soft: #f8fafc;
    --text: #102033;
    --muted: #64748b;
    --border: #e5eaf1;
    --primary: #1d4ed8;
    --primary-strong: #163ea8;
    --secondary: #e2e8f0;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --info: #0f766e;
    --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
    --radius: 18px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

body.auth-body {
    min-height: 100vh;
    background:
        radial-gradient(circle at top right, rgba(29, 78, 216, 0.18), transparent 28%),
        radial-gradient(circle at bottom left, rgba(15, 118, 110, 0.18), transparent 26%),
        var(--bg);
}

.auth-container {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 18px;
}

.auth-container.wide {
    padding-top: 48px;
    padding-bottom: 48px;
}

.auth-card {
    width: min(680px, 100%);
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(229, 234, 241, 0.9);
    border-radius: 28px;
    box-shadow: var(--shadow);
    padding: 32px;
    backdrop-filter: blur(8px);
}

.auth-brand,
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.brand-mark {
    width: 54px;
    height: 54px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary), #22c55e);
    color: white;
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 1.35rem;
    box-shadow: 0 10px 30px rgba(29, 78, 216, 0.26);
}

.auth-brand h1,
.sidebar-brand strong,
.topbar-title h1,
.page-intro h2,
.card-header h3,
.card h2,
.card h3 {
    margin: 0;
}

.auth-brand p,
.sidebar-brand span,
.topbar-title p,
.page-intro p,
.muted {
    color: var(--muted);
    margin: 4px 0 0;
}

.stack-lg {
    display: flex;
    flex-direction: column;
    gap: 22px;
}

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

.stack-inline.end {
    justify-content: flex-end;
}

.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }

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

.sidebar {
    background: #0f172a;
    color: #e2e8f0;
    padding: 24px 20px;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.sidebar .brand-mark {
    width: 46px;
    height: 46px;
    border-radius: 14px;
}

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

.sidebar-nav a {
    color: #cbd5e1;
    padding: 12px 14px;
    border-radius: 14px;
    text-decoration: none;
    transition: background .18s ease, color .18s ease, transform .18s ease;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    transform: translateX(2px);
}

.sidebar-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.main-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 28px 0;
}

.topbar-title h1 {
    font-size: 1.5rem;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 10px 14px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    color: white;
    font-weight: 700;
    background: linear-gradient(135deg, #0f766e, #2563eb);
}

.content {
    padding: 24px 28px 32px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.page-intro {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.page-intro h2 {
    font-size: 1.35rem;
}

.card,
.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.04);
}

.card {
    padding: 20px;
}

.card.soft {
    background: var(--panel-soft);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

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

.stats-grid.compact .stat-card {
    padding-top: 18px;
    padding-bottom: 18px;
}

.stat-card {
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-card strong {
    font-size: 1.55rem;
}

.stat-label {
    color: var(--muted);
    font-size: 0.95rem;
}

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

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

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

.details-grid {
    align-items: start;
}

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

.form-grid.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-grid.cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

label {
    font-size: 0.92rem;
    color: var(--muted);
    font-weight: 600;
}

input,
select,
textarea,
pre.code-box {
    width: 100%;
    border: 1px solid var(--border);
    background: white;
    color: var(--text);
    border-radius: 14px;
    padding: 12px 14px;
    outline: none;
    transition: border-color .18s ease, box-shadow .18s ease;
}

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(29, 78, 216, 0.5);
    box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.12);
}

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

.inline-form {
    display: flex;
    gap: 12px;
    align-items: end;
    flex-wrap: wrap;
}

.inline-form.wide .field {
    min-width: 180px;
}

.btn {
    border: none;
    border-radius: 14px;
    padding: 11px 15px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}

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

.btn.full {
    width: 100%;
}

.btn-small {
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.88rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #2563eb);
    color: white;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.24);
}

.btn-secondary {
    background: #e2e8f0;
    color: #0f172a;
}

.btn-danger {
    background: rgba(220, 38, 38, 0.12);
    color: var(--danger);
}

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

.icon-btn {
    border: 1px solid var(--border);
    background: white;
    color: var(--text);
    border-radius: 14px;
    width: 42px;
    height: 42px;
    cursor: pointer;
    display: none;
}

.alert {
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid transparent;
    font-size: 0.95rem;
}

.alert.success {
    background: rgba(22, 163, 74, 0.11);
    border-color: rgba(22, 163, 74, 0.24);
    color: #166534;
}

.alert.warning {
    background: rgba(217, 119, 6, 0.11);
    border-color: rgba(217, 119, 6, 0.24);
    color: #92400e;
}

.alert.danger {
    background: rgba(220, 38, 38, 0.11);
    border-color: rgba(220, 38, 38, 0.24);
    color: #991b1b;
}

.alert.info {
    background: rgba(15, 118, 110, 0.11);
    border-color: rgba(15, 118, 110, 0.24);
    color: #115e59;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 640px;
}

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

.data-table thead th {
    color: var(--muted);
    font-size: 0.86rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.data-table tbody tr:hover {
    background: rgba(15, 23, 42, 0.02);
}

.data-table .empty {
    text-align: center;
    color: var(--muted);
    padding: 22px;
}

.actions-col {
    white-space: nowrap;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.badge {
    display: inline-flex;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 0.83rem;
    font-weight: 700;
    align-items: center;
    justify-content: center;
}

.badge.success {
    background: rgba(22, 163, 74, 0.12);
    color: #166534;
}

.badge.warning {
    background: rgba(217, 119, 6, 0.12);
    color: #92400e;
}

.badge.danger {
    background: rgba(220, 38, 38, 0.12);
    color: #991b1b;
}

.badge.info {
    background: rgba(37, 99, 235, 0.12);
    color: #1d4ed8;
}

.invoice-table input,
.invoice-table select {
    min-width: 110px;
}

.plain-list {
    margin: 0;
    padding-left: 18px;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.code-box {
    overflow: auto;
    background: #0f172a;
    color: #e2e8f0;
    border: none;
}

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

canvas {
    width: 100% !important;
}

@media (max-width: 1200px) {
    .stats-grid,
    .form-grid.cols-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

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

    .sidebar {
        position: fixed;
        z-index: 40;
        inset: 0 auto 0 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform .22s ease;
    }

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

    .icon-btn {
        display: inline-grid;
        place-items: center;
    }

    .grid.cols-2,
    .grid.cols-3,
    .stats-grid,
    .form-grid.cols-3,
    .form-grid.cols-4 {
        grid-template-columns: 1fr;
    }

    .topbar,
    .content {
        padding-left: 18px;
        padding-right: 18px;
    }
}

@media (max-width: 640px) {
    .auth-card,
    .card,
    .stat-card {
        padding: 18px;
    }

    .topbar {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .page-intro,
    .card-header {
        flex-direction: column;
        align-items: stretch;
    }

    .inline-form {
        flex-direction: column;
        align-items: stretch;
    }

    .user-chip {
        width: 100%;
    }
}

.stretch-line {
    width: 100%;
}

.stretch-line > input {
    flex: 1 1 280px;
}

.barcode-preview,
.barcode-svg {
    width: 100%;
    max-width: 460px;
}

.print-body {
    background: #eef2f7;
    color: #0f172a;
}

.print-toolbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.print-page {
    width: min(1024px, calc(100% - 32px));
    margin: 24px auto 40px;
}

.print-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 28px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
}

.print-brand {
    font-weight: 800;
    letter-spacing: 0.03em;
    color: var(--primary);
    text-transform: uppercase;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.invoice-meta {
    min-width: 240px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.print-grid {
    display: grid;
    gap: 16px;
}

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

.print-panel {
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    background: #f8fafc;
}

.print-panel h3,
.print-panel p {
    margin-top: 0;
}

.print-table {
    min-width: 100%;
}

.print-footer {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: end;
    margin-top: 24px;
    flex-wrap: wrap;
}

.signature-line {
    margin-top: 40px;
    width: 220px;
    border-top: 1px solid #94a3b8;
}

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

.barcode-label {
    border: 1px dashed #cbd5e1;
    border-radius: 16px;
    padding: 14px;
    background: white;
    break-inside: avoid;
}

.label-top,
.label-bottom {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
}

.label-top {
    margin-bottom: 10px;
}

.label-bottom {
    margin-top: 10px;
    font-size: 0.88rem;
    color: var(--muted);
}

@media (max-width: 860px) {
    .print-grid-2,
    .label-grid {
        grid-template-columns: 1fr;
    }
}

@media print {
    body.print-body {
        background: white;
    }

    .no-print,
    .print-toolbar {
        display: none !important;
    }

    .print-page {
        width: 100%;
        margin: 0;
    }

    .print-card {
        border: none;
        box-shadow: none;
        padding: 0;
        border-radius: 0;
    }

    .barcode-label {
        page-break-inside: avoid;
    }
}
