:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-soft: #eef2f6;
    --text: #17212b;
    --muted: #657281;
    --line: #dbe2ea;
    --primary: #176b87;
    --primary-dark: #0f4d61;
    --accent: #c0841a;
    --danger: #b42318;
    --success: #147a43;
    --shadow: 0 10px 30px rgba(23, 33, 43, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Tahoma, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.7;
}

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

body:not(.login-page)::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 14% 8%, rgba(192, 132, 26, .10), transparent 24%),
        radial-gradient(circle at 84% 18%, rgba(23, 107, 135, .10), transparent 28%);
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    width: 260px;
    height: 100vh;
    padding: 22px;
    background: linear-gradient(180deg, #16212d 0%, #101923 100%);
    color: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-logo,
.login-logo {
    display: grid;
    place-items: center;
    width: 190px;
    height: 70px;
    border-radius: 8px;
    background: #285477;
    background-image: url('../img/logo-xcodee.png');
    background-repeat: no-repeat;
    background-size: 110%;
    background-position: center;
    background-blend-mode: multiply;
}

.brand-logo {
    width: 188px;
    height: 58px;
}


.brand small,
.topbar p,
.muted { color: var(--muted); }

.brand small {
    display: block;
    color: #b8c4d0;
    font-size: 12px;
}

.nav-links {
    display: grid;
    gap: 8px;
}

.nav-links a,
.logout-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border-radius: 8px;
    color: #d8e0e8;
}

.nav-links a.active,
.nav-links a:hover,
.logout-link:hover {
    background: rgba(255, 255, 255, .1);
    color: #fff;
}

.logout-link {
    margin-top: auto;
    border: 1px solid rgba(255, 255, 255, .14);
}

.content {
    position: relative;
    flex: 1;
    min-width: 0;
    padding: 28px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 22px;
}

.topbar h1,
.login-card h1 {
    margin: 0 0 4px;
    font-size: 26px;
}

.topbar p { margin: 0; }

.user-chip {
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
}

.grid,
.stats-grid {
    display: grid;
    gap: 16px;
}

.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.two-col { grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); align-items: start; }

.panel,
.stat-card,
.login-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.panel {
    padding: 18px;
    min-width: 0;
    overflow: hidden;
}
.stat-card { padding: 18px; }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; font-size: 28px; margin-top: 8px; }

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

.panel h2,
.panel h3 {
    margin: 0 0 14px;
    font-size: 19px;
}

.panel-header h2 { margin: 0; }

form { margin: 0; }

.form-grid {
    display: grid;
    gap: 12px;
}

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

label,
.field {
    display: grid;
    gap: 6px;
    color: var(--text);
    font-weight: 700;
}

.field-label {
    display: block;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

textarea { resize: vertical; }

.btn,
button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 9px 14px;
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.btn:hover,
button:hover { background: var(--primary-dark); }

.btn.secondary,
button.secondary {
    background: var(--surface-soft);
    color: var(--text);
}

.btn.danger,
button.danger { background: var(--danger); }

.btn.small,
button.small {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 13px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.table-wrap {
    overflow-x: auto;
}

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

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

th {
    background: #f0f4f8;
    color: #334155;
    font-size: 13px;
}

.number { direction: ltr; text-align: left; }
.balance-positive { color: var(--danger); font-weight: 800; }
.balance-zero { color: var(--success); font-weight: 800; }

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    border: 1px solid var(--line);
    background: #fff;
}

.alert.success { border-color: #b7e4ca; background: #ecfdf3; color: #05603a; }
.alert.error { border-color: #fecaca; background: #fff1f2; color: #991b1b; }

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(rgba(246, 247, 251, .86), rgba(246, 247, 251, .92)),
        url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="800" viewBox="0 0 1200 800"><rect width="1200" height="800" fill="%23e9eef5"/><path d="M0 210 C220 120 330 330 550 210 S910 70 1200 180 L1200 0 L0 0Z" fill="%23176b87" opacity=".18"/><path d="M0 690 C260 560 410 760 680 620 S1000 500 1200 600 L1200 800 L0 800Z" fill="%23c0841a" opacity=".18"/></svg>');
    background-size: cover;
}

.login-page .app-shell {
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 100vh;
}

.login-card {
    width: min(420px, 100%);
    padding: 30px;
    border-color: rgba(219, 226, 234, .85);
    backdrop-filter: blur(8px);
}

.login-card p {
    margin-top: 0;
    margin-bottom: 18px;
}

.login-logo {
    margin: 0 auto 24px;
    width: 220px;
    height: 82px;
}

.order-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(86px, 110px);
    gap: 10px;
    align-items: end;
    margin-bottom: 10px;
    min-width: 0;
}

.order-line > *,
.order-line select,
.order-line input {
    min-width: 0;
}

.line-price {
    min-height: 42px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--muted);
    width: 100%;
    grid-column: 1 / 2;
}

.order-line button {
    width: 100%;
    grid-column: 2 / 3;
}

.order-form [data-order-lines] {
    min-width: 0;
    overflow: hidden;
}

.searchable-select {
    position: relative;
    min-width: 0;
}

.searchable-select input[data-search-input] {
    padding-inline-start: 34px;
}

.searchable-select::before {
    content: "⌄";
    position: absolute;
    left: 12px;
    top: 10px;
    color: var(--muted);
    pointer-events: none;
    z-index: 2;
}

.searchable-options {
    position: absolute;
    top: calc(100% + 6px);
    inset-inline: 0;
    z-index: 20;
    display: none;
    max-height: 220px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}

.searchable-select.open .searchable-options {
    display: grid;
    gap: 4px;
}

.searchable-options button {
    justify-content: flex-start;
    width: 100%;
    min-height: 36px;
    padding: 7px 9px;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    text-align: right;
    font-weight: 600;
}

.searchable-options button:hover,
.searchable-options button.active {
    background: var(--surface-soft);
}

.searchable-options .empty-option {
    padding: 9px;
    color: var(--muted);
    font-weight: 400;
}

.print-only { display: none; }

@media (max-width: 980px) {
    .app-shell { display: block; }
    .sidebar {
        position: static;
        width: 100%;
        height: auto;
    }
    .nav-links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .content { padding: 18px; }
    .stats-grid,
    .two-col,
    .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .topbar { display: grid; }
    .nav-links { grid-template-columns: 1fr; }
    .order-line { grid-template-columns: 1fr; }
    .line-price,
    .order-line button { grid-column: 1 / -1; }
    table { min-width: 620px; }
}
