:root {
    color-scheme: light;
    --background: #f5f7fb;
    --surface: #ffffff;
    --text: #17233c;
    --muted: #526078;
    --border: #dce3ee;
    --accent: #2053aa;
    --accent-hover: #184387;
    --danger: #9b2922;
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--text); background: var(--background); }
[hidden] { display: none !important; }
a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
    outline: 3px solid #638ddd;
    outline-offset: 2px;
}
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.55rem, 3vw, 2.05rem); letter-spacing: -.035em; }
h2 { font-size: 1.25rem; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .6; cursor: wait; }
form { margin: 0; }

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem 1.4rem;
    min-height: 66px;
    padding: .7rem clamp(1rem, 4vw, 3rem);
    background: #14213b;
    color: #eef4ff;
}
.topbar a { color: inherit; text-decoration: none; }
.topbar a:hover { text-decoration: underline; }
.brand { font-size: 1.06rem; font-weight: 700; }
.topbar nav, .account, .toolbar { display: flex; gap: .55rem; align-items: center; flex-wrap: wrap; }
.topbar nav { gap: 1rem; color: #cad9f3; }
.account { margin-left: auto; }

.container { padding: 1.5rem clamp(1rem, 4vw, 3rem) 3rem; }
.orders { padding-inline: clamp(.65rem, 2vw, 1.5rem); }
.admin { max-width: 1280px; margin: auto; }
.title-row, .dialog-head { display: flex; align-items: center; justify-content: space-between; gap: .85rem; }
.title-row { margin-bottom: 1.15rem; }
.tabs { display: flex; align-items: center; flex-wrap: wrap; gap: .3rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs a { padding: .58rem .85rem; border-bottom: 3px solid transparent; color: var(--muted); text-decoration: none; }
.tabs a[aria-current] { border-color: var(--accent); color: var(--accent); font-weight: 650; }
.tabs a:hover { background: #e9eff9; }
.tabs span { margin-left: .15rem; font-variant-numeric: tabular-nums; font-weight: 650; }
.admin-tabs { margin-top: .9rem; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: .38rem .72rem;
    border: 1px solid var(--border);
    border-radius: .43rem;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    white-space: nowrap;
}
.button:hover { background: #ebf1fb; }
.button.primary { color: white; background: var(--accent); border-color: var(--accent); }
.button.primary:hover { background: var(--accent-hover); }
.button.ghost { background: transparent; border-color: transparent; }
.button.ghost:hover { background: #dfe8f7; color: var(--text); }
.topbar .ghost { color: inherit; border-color: #677593; }
.topbar .ghost:hover { color: var(--text); }
.button.compact { min-height: 28px; padding: .12rem .4rem; font-size: .78rem; }
.danger-link { color: var(--danger); }

.filters { display: flex; flex-wrap: wrap; align-items: end; gap: .65rem; margin-bottom: 1rem; }
label { display: grid; gap: .25rem; font-weight: 600; font-size: .86rem; }
label.check { display: flex; align-items: center; font-weight: 500; gap: .38rem; }
input:not([type="checkbox"]), select, textarea {
    min-width: 0;
    width: 100%;
    padding: .42rem .53rem;
    border: 1px solid #cbd6e7;
    border-radius: .37rem;
    min-height: 36px;
    background: white;
    color: var(--text);
    font-weight: 400;
}
textarea { resize: vertical; }
input[type="color"] { max-width: 7rem; padding: .15rem; }
.fields { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(min(202px, 100%), 1fr)); }
.fields .wide { grid-column: 1 / -1; }
.stack { display: grid; gap: .85rem; }
.stack > .button, .stack > .toolbar { justify-self: start; }
.secondary-form { margin-top: .7rem; }
.panel, .auth, .empty {
    padding: 1rem;
    margin-bottom: .72rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: .58rem;
}
.panel summary { cursor: pointer; font-weight: 650; }
.panel summary small { margin-left: .5rem; font-weight: 450; }
.panel[open] summary { margin-bottom: .85rem; }
.split { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
.auth { max-width: 430px; margin: clamp(2rem, 10vh, 7rem) auto; padding: 1.5rem; width: calc(100% - 2rem); }
.auth h1 { margin-bottom: .9rem; font-size: 1.55rem; }
.auth .muted { margin-top: 1rem; }
.muted, small { color: var(--muted); }
.notice { padding: .7rem .9rem; color: #0c6939; background: #e0f6e9; border-radius: .4rem; margin-bottom: .75rem; }
.notice.error, .message.error, .form-error { color: var(--danger); background: #fff0ef; }
.form-error { padding: .6rem; }

.table-wrap { overflow: auto; background: white; border: 1px solid var(--border); border-radius: .55rem; }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { padding: .47rem .6rem; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); text-align: left; }
th { text-align: center; }
th:last-child, td:last-child { border-right: 0; }
thead th { position: sticky; top: 0; z-index: 1; background: #eaf0fa; color: #243756; font-weight: 650; }
th a { text-decoration: none; }
th a:hover { text-decoration: underline; }
.order-scroll { overflow-x: auto; padding-bottom: .25rem; }
.order-table { table-layout: fixed; width: var(--table-width); font-size: .82rem; border-left: 1px solid var(--border); }
.order-table td { vertical-align: middle; text-align: center; padding: 0; overflow-wrap: anywhere; }
.order-table th { padding: .42rem .32rem; overflow-wrap: anywhere; }
.order-table th.resizable { padding-right: .68rem; }
.resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: .65rem;
    cursor: col-resize;
    touch-action: none;
    user-select: none;
}
.resize-handle:hover, .resize-handle[data-resizing], .resize-handle:focus-visible {
    border-right: 3px solid var(--accent);
    background: #2053aa20;
}
.resize-handle[aria-busy="true"] { cursor: wait; }
.order-table tbody + tbody > tr:first-child > td { border-top: 2px solid #a8b7d0; }
.order-table td { background: var(--cell-bg, white); color: var(--cell-fg, var(--text)); }
.order-table tbody[data-phase="shipped"] .order-phase { background: #394554; color: white; }
.order-table tbody[data-phase="ready"] .order-phase, .order-table tr[data-phase="ready"] > .row-phase { background: #a5ef97; color: #174420; }
.order-table tbody[data-phase="bending"] .order-phase, .order-table tr[data-phase="bending"] > .row-phase { background: #ddd0f7; color: #41286b; }
.order-code { font-weight: 700; white-space: nowrap; }
.cell, .cell-text { display: block; width: 100%; padding: .42rem .32rem; min-height: 32px; white-space: pre-wrap; }
.cell { border: 0; background: transparent; color: inherit; font-weight: inherit; text-align: inherit; }
.cell:hover { box-shadow: inset 0 0 0 2px #4279c4; }
.cell:focus-visible { outline-offset: -3px; }
.cell[aria-busy="true"] { cursor: wait; opacity: .7; }
.cell[data-unsaved] { box-shadow: inset 0 -2px var(--danger); }
.cell[data-editing] { visibility: hidden; }
.order-table td.editing-cell { position: relative; z-index: 2; }
.editor { position: absolute; inset: 0 auto auto 0; width: max(100%, 8.5rem); padding: .12rem; background: var(--surface); }
.editor input, .editor select { min-height: 29px; padding: .18rem; }
.inline-order { max-width: 720px; }
.inline-order-fields { display: flex; flex-wrap: wrap; gap: .65rem; align-items: end; }
.inline-order-fields label { flex: 1 1 14rem; }
.row-actions { min-width: 124px; padding: .24rem !important; }
.row-actions .button { margin: .06rem; }
.pagination { display: flex; gap: .75rem; align-items: center; justify-content: center; margin-top: 1rem; }
.swatch { display: inline-block; width: .9rem; height: .9rem; margin-right: .24rem; border: 1px solid #aebbd1; vertical-align: middle; }

dialog { width: min(43rem, calc(100% - 2rem)); max-height: 88%; border: 1px solid var(--border); border-radius: .7rem; padding: 1.15rem; color: var(--text); }
dialog::backdrop { background: #10203b88; }
.dialog-head { margin-bottom: .8rem; }
.client-list { margin-top: .7rem; max-height: 58vh; }
.message { position: fixed; right: 1rem; bottom: 1rem; max-width: min(24rem, calc(100% - 2rem)); z-index: 5; padding: .7rem 1rem; border-radius: .4rem; background: #d9f5e5; box-shadow: 0 4px 20px #17233c22; }

@media (max-width: 560px) {
    .title-row { align-items: flex-start; flex-direction: column; }
    .topbar nav { order: 3; width: 100%; }
    .filters label { flex: 1 1 9rem; }
}
