@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Newsreader:opsz,wght@6..72,500;6..72,600&display=swap');

:root {
    color-scheme: light;
    --ink: #1c302c;
    --ink-soft: #52635e;
    --forest: #183b35;
    --forest-deep: #102b27;
    --ochre: #d7ad45;
    --ochre-pale: #f3ead2;
    --paper: #f5f4ee;
    --white: #fffefa;
    --line: #d8ddd5;
    --line-strong: #c4cdc3;
    --sage: #e9eee7;
    --clay: #a6533d;
    --shadow: 0 16px 40px rgb(22 46 41 / 7%);
}

:root[data-theme='dark'] {
    color-scheme: dark;
    --ink: #edf1ec;
    --ink-soft: #b1bdb5;
    --forest: #2e6948;
    --forest-deep: #3b8059;
    --ochre: #dfba5a;
    --ochre-pale: #473d25;
    --paper: #151d19;
    --white: #202a24;
    --line: #36433c;
    --line-strong: #4b5a50;
    --sage: #2a3930;
    --clay: #e38a70;
    --shadow: 0 16px 40px rgb(0 0 0 / 28%);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }

body {
    margin: 0;
    color: var(--ink);
    font-family: 'DM Sans', 'Avenir Next', sans-serif;
    font-size: 14px;
    line-height: 1.5;
    background-color: var(--paper);
    background-image: linear-gradient(90deg, rgb(24 59 53 / 2%) 1px, transparent 1px), linear-gradient(rgb(24 59 53 / 2%) 1px, transparent 1px);
    background-size: 36px 36px;
}

:root[data-theme='dark'] body {
    background-image: linear-gradient(90deg, rgb(220 238 228 / 2%) 1px, transparent 1px), linear-gradient(rgb(220 238 228 / 2%) 1px, transparent 1px);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }

.app-shell { max-width: 1480px; margin: 0 auto; padding: 0 44px 64px; }

.topbar {
    min-height: 92px;
    display: flex;
    align-items: center;
    gap: 30px;
    border-bottom: 1px solid var(--line-strong);
}

.brand { display: flex; flex: 0 0 190px; align-items: center; }
.brand img { display: block; width: 172px; max-height: 58px; object-fit: contain; object-position: left center; }
.topbar-title { flex: 1; padding-left: 30px; border-left: 1px solid var(--line-strong); }
.eyebrow { display: block; color: var(--ink-soft); font-size: 10px; font-weight: 700; letter-spacing: .13em; }
.topbar-title h1 { margin: 2px 0 0; font-family: 'Newsreader', Georgia, serif; font-size: 24px; font-weight: 500; line-height: 1.15; }
.theme-control { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 11px; cursor: pointer; }
.theme-control input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.theme-switch { position: relative; width: 36px; height: 20px; border: 1px solid #aeb9af; border-radius: 12px; background: #e1e6df; transition: background .16s ease, border-color .16s ease; }
.theme-switch::after { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgb(0 0 0 / 18%); content: ''; transition: transform .16s ease; }
.theme-control input:checked + .theme-switch { border-color: var(--forest); background: var(--forest); }
.theme-control input:checked + .theme-switch::after { transform: translateX(16px); }
.theme-control input:focus-visible + .theme-switch { outline: 3px solid rgb(24 59 53 / 22%); outline-offset: 2px; }
:root[data-theme='dark'] .theme-switch { border-color: #54635a; background: #344139; }
:root[data-theme='dark'] .theme-control input:checked + .theme-switch { border-color: var(--forest); background: var(--forest); }
:root[data-theme='dark'] .theme-control input:focus-visible + .theme-switch { outline-color: rgb(137 193 159 / 35%); }

.connection-status { display: flex; align-items: center; gap: 9px; color: var(--ink-soft); font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ochre); box-shadow: 0 0 0 3px var(--ochre-pale); }
.connection-status.is-connected .status-dot { background: #4a8b63; box-shadow: 0 0 0 3px #dcecdf; }
.connection-status.is-error .status-dot { background: var(--clay); box-shadow: 0 0 0 3px #f4e3de; }
:root[data-theme='dark'] .connection-status.is-connected .status-dot { background: #75c98d; box-shadow: 0 0 0 3px #294133; }
:root[data-theme='dark'] .connection-status.is-error .status-dot { box-shadow: 0 0 0 3px #432d29; }
:root[data-theme='dark'] .brand img { filter: invert(1); }

.workspace { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(340px, .75fr); gap: 64px; align-items: start; padding-top: 40px; }
.order-column { min-width: 0; }
.section-heading, .side-heading { display: flex; justify-content: space-between; align-items: end; gap: 18px; }
.section-heading { padding-bottom: 24px; border-bottom: 1px solid var(--line-strong); }
.section-heading h2, .side-heading h2 { margin: 3px 0 0; font-family: 'Newsreader', Georgia, serif; font-size: 30px; font-weight: 500; line-height: 1.15; }
.required-note { padding-bottom: 3px; color: var(--ink-soft); font-size: 11px; }
.required-note span, .required-mark { color: var(--clay); }

.order-form { padding-top: 5px; }
.form-section { padding: 24px 0 26px; border-bottom: 1px solid var(--line); }
.form-section-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.step-number { color: #947333; font-size: 11px; font-weight: 700; letter-spacing: .08em; }
.form-section-heading h3 { margin: 0; font-size: 15px; font-weight: 700; }
.field-grid { display: grid; gap: 0 14px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { min-width: 0; margin-bottom: 15px; }
.field label { display: block; margin-bottom: 6px; color: var(--ink-soft); font-size: 11px; font-weight: 600; }
.field input, .field select, .field textarea {
    display: block;
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 4px;
    outline: none;
    background: var(--white);
    color: var(--ink);
    transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: #9eada2; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--forest); box-shadow: 0 0 0 3px rgb(24 59 53 / 11%); background: var(--white); }
:root[data-theme='dark'] .field input:focus, :root[data-theme='dark'] .field select:focus, :root[data-theme='dark'] .field textarea:focus { box-shadow: 0 0 0 3px rgb(137 193 159 / 18%); }
.field input::placeholder, .field textarea::placeholder { color: #9aa39b; }
#details { min-height: 156px; }
.delivery-section { border-bottom: 0; padding-bottom: 18px; }
.option-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 4px 0 14px; }
.option-toggle { display: flex; align-items: center; gap: 12px; min-height: 66px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 4px; background: rgb(255 254 250 / 65%); cursor: pointer; }
.option-toggle input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.toggle-mark { position: relative; flex: 0 0 34px; width: 34px; height: 20px; border: 1px solid #aeb9af; border-radius: 12px; background: #e1e6df; transition: background .16s ease, border .16s ease; }
.toggle-mark::after { position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgb(0 0 0 / 18%); content: ''; transition: transform .16s ease; }
.option-toggle input:checked + .toggle-mark { border-color: var(--forest); background: var(--forest); }
.option-toggle input:checked + .toggle-mark::after { transform: translateX(14px); }
.option-toggle input:focus-visible + .toggle-mark { outline: 3px solid rgb(24 59 53 / 22%); outline-offset: 2px; }
:root[data-theme='dark'] .option-toggle { background: rgb(255 255 255 / 3%); }
:root[data-theme='dark'] .toggle-mark { border-color: #64736a; background: #344139; }
:root[data-theme='dark'] .option-toggle input:focus-visible + .toggle-mark { outline-color: rgb(137 193 159 / 35%); }
.option-toggle strong, .option-toggle small { display: block; }
.option-toggle strong { font-size: 12px; }
.option-toggle small { margin-top: 2px; color: var(--ink-soft); font-size: 10px; }
.conditional-field { margin-top: 4px; padding: 14px; border-left: 2px solid var(--ochre); background: #f9f6ec; }
:root[data-theme='dark'] .conditional-field { background: #292b23; }
.hidden { display: none !important; }

.submit-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-top: 6px; padding-top: 20px; border-top: 1px solid var(--line-strong); }
.submit-row p { margin: 0; color: var(--ink-soft); font-size: 11px; }
.submit-actions { display: flex; flex: 0 0 auto; gap: 10px; }
.primary-button, .secondary-button { display: inline-flex; align-items: center; justify-content: center; gap: 24px; min-height: 46px; padding: 0 18px; border: 0; border-radius: 4px; font-weight: 700; transition: background .16s ease, transform .16s ease; }
.primary-button { min-width: 164px; color: #fff; background: var(--forest); }
.primary-button:hover { background: var(--forest-deep); transform: translateY(-1px); }
.alert-button { min-height: 46px; padding: 0 18px; border: 0; border-radius: 4px; color: #fff; background: var(--clay); font: inherit; font-weight: 700; transition: background .16s ease, transform .16s ease; }
.alert-button:hover { background: #8c3d2e; transform: translateY(-1px); }
:root[data-theme='dark'] .alert-button { background: #a54536; }
:root[data-theme='dark'] .alert-button:hover { background: #8f372b; }
.button-arrow { color: #e6c46c; font-size: 18px; }

.side-column { min-width: 0; padding-top: 2px; }
.side-section { padding: 0 0 27px; }
.customer-section { padding-bottom: 28px; border-bottom: 1px solid var(--line-strong); }
.history-section { padding-top: 26px; }
.side-heading { margin-bottom: 18px; }
.side-heading h2 { font-size: 24px; }
.count-badge { display: inline-flex; min-width: 26px; height: 26px; align-items: center; justify-content: center; padding: 0 7px; border: 1px solid var(--line); border-radius: 50%; color: var(--ink-soft); font-size: 11px; }
.order-search { margin-bottom: 12px; }
.customer-form-accordion { margin-bottom: 12px; }
.customer-form-accordion > summary { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-top: 1px solid var(--line); color: var(--ink-soft); font-size: 11px; font-weight: 700; cursor: pointer; list-style: none; }
.customer-form-accordion > summary::-webkit-details-marker { display: none; }
.customer-form-accordion > summary::after { color: var(--forest); content: '+'; font-size: 16px; }
.customer-form-accordion[open] > summary { margin-bottom: 10px; }
.customer-form-accordion[open] > summary::after { content: '-'; }
.customer-form .field { margin-bottom: 11px; }
.customer-form .field input, .customer-form .field textarea { min-height: 38px; padding: 8px 10px; }
.customer-form .field textarea { min-height: 60px; }
.customer-form .field-grid .field { margin-bottom: 11px; }
.button-row { display: flex; align-items: center; gap: 16px; margin-top: 3px; }
.secondary-button { min-height: 40px; padding: 0 15px; color: white; background: var(--forest); font-size: 12px; }
.secondary-button:hover { background: var(--forest-deep); }
.text-button { width: auto; min-height: 36px; padding: 0 4px; border: 0; background: transparent; color: var(--ink-soft); font-size: 11px; text-decoration: underline; text-decoration-color: #b6c0b7; text-underline-offset: 3px; }
.text-button:hover { color: var(--forest); text-decoration-color: var(--ochre); }
.customer-list, .orders-list { display: grid; gap: 8px; margin: 18px 0 0; padding: 0; list-style: none; }
.customer-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 0; border-top: 1px solid var(--line); }
.customer-info { min-width: 0; }
.customer-info strong, .customer-info small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.customer-info strong { font-size: 12px; }
.customer-info small { max-width: 245px; margin-top: 2px; color: var(--ink-soft); font-size: 10px; }
.customer-actions { display: flex; flex: 0 0 auto; gap: 8px; }
.customer-actions button, .order-load-button { width: auto; padding: 5px 8px; border: 1px solid var(--line); border-radius: 3px; background: transparent; color: var(--ink); font-size: 10px; }
.customer-actions button:hover, .order-load-button:hover { border-color: var(--forest); background: var(--sage); }
.empty-state { padding: 15px 0; color: var(--ink-soft); font-size: 11px; }
.orders-list { max-height: 320px; margin-top: 0; overflow-y: auto; overscroll-behavior: contain; }
.order-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.order-meta { min-width: 0; }
.order-project { display: flex; min-width: 0; align-items: baseline; font-size: 12px; font-weight: 700; white-space: nowrap; }
.order-project-number { overflow: hidden; text-overflow: ellipsis; }
.order-supplier { min-width: 0; overflow: hidden; margin-left: 6px; color: var(--ink-soft); font-size: 10px; font-weight: 500; text-overflow: ellipsis; }
.order-supplier::before { padding-right: 6px; content: '·'; }
.order-product { display: block; overflow: hidden; margin-top: 2px; color: var(--ink-soft); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.order-customer, .order-date { color: var(--ink-soft); font-size: 10px; }
.order-submeta { display: block; overflow: hidden; margin-top: 2px; text-overflow: ellipsis; white-space: nowrap; }
.order-load-button { grid-column: 2; grid-row: 1; min-width: 48px; color: var(--forest); font-weight: 700; }
.load-more-button { margin-top: 12px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 5; max-width: min(420px, calc(100vw - 32px)); padding: 13px 17px; border-left: 3px solid var(--ochre); background: var(--forest-deep); color: white; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .2s ease, transform .2s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { border-color: #dc8569; }

@media (max-width: 1080px) {
    .app-shell { padding-right: 28px; padding-left: 28px; }
    .workspace { grid-template-columns: minmax(0, 1.35fr) minmax(310px, .8fr); gap: 36px; }
    .three-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .app-shell { padding: 0 20px 40px; }
    .topbar { min-height: 78px; gap: 16px; }
    .brand { flex-basis: 130px; }
    .brand img { width: 125px; }
    .topbar-title { padding-left: 16px; }
    .topbar-title h1 { font-size: 19px; }
    .connection-status { font-size: 0; }
    .theme-control-label { display: none; }
    .workspace { grid-template-columns: 1fr; gap: 44px; padding-top: 28px; }
    .side-column { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; }
    .customer-section { border: 0; padding-bottom: 0; }
    .history-section { padding-top: 0; }
}

@media (max-width: 540px) {
    .app-shell { padding-right: 16px; padding-left: 16px; }
    .topbar { min-height: 70px; gap: 11px; }
    .brand { flex-basis: 92px; }
    .brand img { width: 90px; }
    .topbar-title { padding-left: 11px; }
    .topbar-title .eyebrow { font-size: 8px; }
    .topbar-title h1 { font-size: 17px; }
    .section-heading h2 { font-size: 27px; }
    .required-note { max-width: 80px; text-align: right; }
    .two-columns, .three-columns, .option-grid { grid-template-columns: 1fr; }
    .form-section { padding: 21px 0; }
    .side-column { grid-template-columns: 1fr; gap: 0; }
    .customer-section { padding-bottom: 24px; border-bottom: 1px solid var(--line-strong); }
    .history-section { padding-top: 24px; }
    .submit-row { align-items: stretch; flex-direction: column; }
    .submit-actions { flex-direction: column; }
    .primary-button, .alert-button { width: 100%; }
    .customer-info small { max-width: 190px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}