:root {
  color-scheme: light;
  --primary: #036ce5;
  --primary-hover: #075bbd;
  --primary-soft: #eaf4ff;
  --text: #172b3a;
  --muted: #5a6f7d;
  --subtle: #81939f;
  --border: #dce6ec;
  --border-strong: #c8d6de;
  --surface: #ffffff;
  --surface-soft: #f5f8fa;
  --surface-blue: #f2f8ff;
  --success: #21855b;
  --warning: #b96a13;
  --danger: #c23d4b;
  --shadow-sm: 0 1px 2px rgb(29 55 74 / 5%);
  --shadow-md: 0 10px 30px rgb(29 55 74 / 9%);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --header-height: 64px;
  --nav-width: 240px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 88px; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button, label, select { touch-action: manipulation; }
button { cursor: pointer; }

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: #fff;
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app-header {
  position: sticky;
  z-index: 40;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--header-height);
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  background: rgb(255 255 255 / 96%);
  backdrop-filter: blur(10px);
}

.brand-block, .header-meta, .logo-control, .nav-intro, .nav-sync, .page-heading, .section-heading,
.group-heading, .save-bar, .save-bar > div, .notice, .empty-state { display: flex; align-items: center; }

.brand-block { gap: 14px; }
.brand-logo { width: 68px; height: 30px; object-fit: contain; }
.brand-divider { width: 1px; height: 30px; background: var(--border); }
.brand-block p { margin: 0; }
.app-name { font-weight: 700; font-size: 14px; }
.app-context { color: var(--muted); font-size: 12px; }
.header-meta { gap: 20px; color: var(--muted); font-size: 12px; }
.demo-badge { padding: 4px 10px; border: 1px solid #f0d5a8; border-radius: 999px; background: #fff8eb; color: #875013; font-weight: 600; }
.sync-state { display: inline-flex; align-items: center; gap: 7px; }
.sync-state i { width: 7px; height: 7px; border-radius: 50%; background: #27a56f; box-shadow: 0 0 0 3px #daf3e7; }

.layout { display: grid; grid-template-columns: var(--nav-width) minmax(0, 1fr); min-height: calc(100vh - var(--header-height)); }

.settings-nav {
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  display: flex;
  flex-direction: column;
  padding: 22px 14px 18px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.nav-intro { gap: 10px; padding: 0 8px 20px; border-bottom: 1px solid var(--border); }
.nav-icon, .section-icon, .empty-icon { display: grid; place-items: center; flex: 0 0 auto; }
.nav-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); }
.nav-intro strong, .nav-intro small { display: block; }
.nav-intro strong { font-size: 14px; }
.nav-intro small { max-width: 150px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.settings-nav nav { display: grid; gap: 3px; padding-top: 16px; }
.nav-link { display: flex; align-items: center; gap: 11px; min-height: 42px; padding: 0 11px; border-radius: 9px; color: #49606e; font-weight: 500; text-decoration: none; transition: background-color .18s ease, color .18s ease; }
.nav-link svg { width: 18px; height: 18px; }
.nav-link:hover { background: var(--surface-soft); color: var(--text); }
.nav-link.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 650; }
.nav-sync { gap: 10px; margin-top: auto; padding: 14px 9px 0; border-top: 1px solid var(--border); color: var(--muted); }
.nav-sync svg { width: 17px; height: 17px; }
.nav-sync span, .nav-sync strong { display: block; font-size: 10px; }
.nav-sync strong { margin-top: 2px; color: var(--text); font-weight: 600; }

.content { min-width: 0; padding: 30px clamp(20px, 4vw, 52px) 120px; }
#settings-form { width: min(100%, 1050px); margin: 0 auto; }
.page-heading { justify-content: space-between; gap: 32px; margin-bottom: 18px; }
.page-heading h1 { margin: 2px 0 6px; font-size: clamp(25px, 3vw, 32px); line-height: 1.2; letter-spacing: -.025em; text-wrap: balance; }
.page-heading p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--primary) !important; font-size: 11px; font-weight: 750; letter-spacing: .09em; text-transform: uppercase; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px; border: 1px solid transparent; border-radius: 9px; font-weight: 650; transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease, color .18s ease; }
.button svg { width: 17px; height: 17px; }
.button-primary { border-color: var(--primary); background: var(--primary); color: #fff; box-shadow: 0 3px 8px rgb(3 108 229 / 18%); }
.button-primary:hover { border-color: var(--primary-hover); background: var(--primary-hover); }
.button-secondary { border-color: var(--border-strong); background: var(--surface); color: var(--text); }
.button-secondary:hover { border-color: #9db2bf; background: var(--surface-soft); }
.button-ghost { background: transparent; color: var(--muted); }
.button-ghost:hover { background: var(--surface-soft); color: var(--text); }
.button-small { min-height: 36px; padding-inline: 12px; font-size: 12px; }
.button:focus-visible, input:focus-visible, select:focus-visible, .nav-link:focus-visible, .color-option:focus-within { outline: 3px solid rgb(3 108 229 / 22%); outline-offset: 2px; }

.notice { gap: 10px; margin-bottom: 28px; padding: 12px 15px; border: 1px solid #cde1f8; border-radius: var(--radius-md); background: var(--surface-blue); color: #37566c; }
.notice svg { flex: 0 0 auto; width: 18px; height: 18px; color: var(--primary); }
.notice p { margin: 0; }

.settings-section { margin-top: 32px; scroll-margin-top: 84px; }
.section-heading { gap: 12px; margin-bottom: 12px; }
.section-icon { width: 38px; height: 38px; border: 1px solid #d7e7f8; border-radius: 10px; background: var(--surface-blue); color: var(--primary); }
.section-icon svg { width: 19px; height: 19px; }
.section-heading h2, .section-heading p { margin: 0; }
.section-heading h2 { font-size: 18px; line-height: 1.35; }
.section-heading p { margin-top: 2px; color: var(--muted); font-size: 12px; }

.settings-card { padding: 24px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
.field-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.logo-row { padding-bottom: 22px; border-bottom: 1px solid var(--border); }
.field-copy label, .field > span, .field legend { display: block; margin-bottom: 7px; color: var(--text); font-weight: 650; }
.field-copy p { max-width: 480px; margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.logo-control { flex: 0 0 auto; gap: 12px; }
.logo-preview { display: grid; place-items: center; width: 106px; height: 56px; overflow: hidden; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.logo-preview img { width: 84px; height: 42px; object-fit: contain; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }

.form-grid { display: grid; gap: 18px; margin-top: 22px; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.single-bottom-gap { margin-top: 0; padding-bottom: 22px; }
.field { display: block; min-width: 0; }
.field input, .field select { width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: #fff; color: var(--text); transition: border-color .18s ease, box-shadow .18s ease; }
.field input:hover, .field select:hover { border-color: #9db2bf; }
.field input:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgb(3 108 229 / 10%); outline: none; }
.field small { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; }
.input-prefix, .input-suffix { display: flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-soft); }
.input-prefix:focus-within, .input-suffix:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgb(3 108 229 / 10%); }
.input-prefix > span, .input-suffix > span { display: flex; align-items: center; padding: 0 10px; color: var(--muted); font-size: 12px; }
.input-prefix input, .input-suffix input { flex: 1 1 auto; width: auto; min-width: 0; border: 0; border-left: 1px solid var(--border); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.input-prefix input:focus, .input-suffix input:focus { box-shadow: none; }

.color-fieldset { margin: 22px 0 0; padding: 0; border: 0; }
.color-fieldset legend { margin-bottom: 9px; font-weight: 650; }
.color-options { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.color-option { position: relative; display: grid; grid-template-columns: 30px 1fr; grid-template-rows: auto auto; column-gap: 9px; padding: 10px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; transition: border-color .18s ease, background-color .18s ease; }
.color-option:hover { border-color: #aabdc8; }
.color-option.is-selected { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }
.color-option input { position: absolute; opacity: 0; pointer-events: none; }
.color-option > span { grid-row: 1 / span 2; width: 30px; height: 30px; border: 3px solid #fff; border-radius: 50%; background: var(--swatch); box-shadow: 0 0 0 1px rgb(23 43 58 / 13%); }
.color-option b { align-self: end; font-size: 11px; }
.color-option small { color: var(--muted); font-size: 10px; }

.status-card { padding: 0; overflow: hidden; }
.status-group { padding: 22px 24px 24px; }
.return-group { border-top: 1px solid var(--border); background: #fcfdfe; }
.group-heading { justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.group-heading h3, .group-heading p { margin: 0; }
.group-heading h3 { font-size: 14px; }
.group-heading p { margin-top: 3px; color: var(--muted); font-size: 11px; }
.count-badge { padding: 3px 8px; border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: 10px; font-weight: 650; }
.mapping-table { border: 1px solid var(--border); border-radius: 11px; overflow: hidden; }
.mapping-row { display: grid; grid-template-columns: 12px minmax(160px, .8fr) 22px minmax(190px, 1.2fr); align-items: center; gap: 12px; min-height: 52px; padding: 6px 12px; border-top: 1px solid var(--border); background: #fff; }
.mapping-row:first-child { border-top: 0; }
.mapping-row label { font-weight: 550; }
.mapping-row > svg { width: 15px; height: 15px; color: #9aabb5; }
.mapping-row select { width: 100%; min-height: 36px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-soft); color: var(--text); }
.status-dot { width: 9px; height: 9px; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px currentColor; background: currentColor; }
.status-new { color: #4b88cf; }.status-work { color: #815bd1; }.status-ready { color: #cf8b1e; }.status-delivery { color: #1c94a3; }.status-done { color: #278764; }.status-partial { color: #bd6b35; }.status-cancel { color: #c24a57; }

.toggle-list { padding-block: 4px; }
.toggle-row { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 24px; min-height: 76px; padding: 16px 20px; border-top: 1px solid var(--border); cursor: pointer; }
.toggle-row:first-child { border-top: 0; }
.toggle-row strong, .toggle-row small { display: block; }
.toggle-row strong { margin-bottom: 3px; font-size: 13px; }
.toggle-row small { color: var(--muted); font-size: 11px; }
.toggle-row input { position: absolute; opacity: 0; }
.toggle-row i { position: relative; flex: 0 0 42px; width: 42px; height: 24px; border-radius: 99px; background: #c7d2d9; box-shadow: inset 0 0 0 1px rgb(23 43 58 / 8%); transition: background-color .18s ease; }
.toggle-row i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgb(23 43 58 / 25%); transition: transform .18s ease; }
.toggle-row input:checked + i { background: var(--primary); }
.toggle-row input:checked + i::after { transform: translateX(18px); }
.toggle-row input:focus-visible + i { outline: 3px solid rgb(3 108 229 / 22%); outline-offset: 3px; }
.nested-field { display: grid; grid-template-columns: minmax(160px, 230px) 1fr; align-items: end; gap: 20px; margin: 0 20px 12px; padding: 16px; border-radius: 10px; background: var(--surface-soft); }
.nested-field p { align-self: center; margin: 0; color: var(--muted); font-size: 11px; }
.nested-field .field > span { font-size: 12px; }
.input-suffix input { border: 0; border-right: 1px solid var(--border); border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.toggle-list.inset { margin: 0 -24px -24px; padding: 0 4px; border-top: 1px solid var(--border); }

.empty-state { justify-content: flex-start; gap: 16px; }
.empty-icon { width: 48px; height: 48px; border-radius: 13px; background: var(--surface-soft); color: #6e8492; }
.empty-state h3, .empty-state p { margin: 0; }
.empty-state h3 { font-size: 14px; }
.empty-state p { max-width: 620px; margin-top: 4px; color: var(--muted); font-size: 11px; }
.empty-state .button { margin-left: auto; flex: 0 0 auto; }

.save-bar { position: sticky; z-index: 30; bottom: 14px; justify-content: space-between; gap: 20px; margin-top: 34px; padding: 12px 14px 12px 18px; border: 1px solid var(--border-strong); border-radius: 13px; background: rgb(255 255 255 / 96%); box-shadow: var(--shadow-md); backdrop-filter: blur(12px); }
.save-bar p { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--muted); font-size: 11px; }
.save-bar > div { gap: 8px; }
.unsaved-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); }
.save-bar.is-saved .unsaved-dot { background: var(--success); }

.toast { position: fixed; z-index: 100; right: 22px; bottom: 22px; display: flex; align-items: center; gap: 11px; max-width: 390px; padding: 13px 16px; border: 1px solid #b8e1cf; border-radius: 12px; background: #f4fcf8; box-shadow: var(--shadow-md); opacity: 0; transform: translateY(18px); pointer-events: none; transition: opacity .22s ease, transform .22s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast > span { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: #dff5ea; color: var(--success); }
.toast svg { width: 18px; height: 18px; }
.toast strong, .toast small { display: block; }
.toast strong { font-size: 12px; }
.toast small { margin-top: 2px; color: var(--muted); font-size: 10px; }

@media (max-width: 900px) {
  :root { --nav-width: 190px; }
  .content { padding-inline: 22px; }
  .three-columns { grid-template-columns: 1fr 1fr; }
  .three-columns .field:last-child { grid-column: 1 / -1; }
  .color-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  :root { --header-height: 58px; }
  .app-header { padding-inline: 14px; }
  .brand-divider, .app-context, .sync-state { display: none; }
  .brand-logo { width: 58px; }
  .layout { display: block; }
  .settings-nav { position: sticky; z-index: 35; top: var(--header-height); width: 100%; height: auto; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .nav-intro, .nav-sync { display: none; }
  .settings-nav nav { display: flex; gap: 5px; padding: 0; width: max-content; }
  .nav-link { min-height: 38px; padding-inline: 12px; }
  .nav-link svg { display: none; }
  .content { padding: 22px 14px 108px; }
  .page-heading { align-items: flex-start; }
  .page-heading .button { display: none; }
  .two-columns, .three-columns { grid-template-columns: 1fr; }
  .three-columns .field:last-child { grid-column: auto; }
  .field-row { display: block; }
  .logo-control { margin-top: 14px; }
  .mapping-row { grid-template-columns: 10px minmax(115px, .8fr) 14px minmax(150px, 1fr); gap: 8px; }
  .empty-state { align-items: flex-start; flex-wrap: wrap; }
  .empty-state .button { margin-left: 64px; }
  .save-bar { bottom: 8px; }
  .save-bar p, .save-bar .button-ghost { display: none; }
  .save-bar > div, .save-bar .button-primary { width: 100%; }
}

@media (max-width: 480px) {
  .settings-card { padding: 18px; }
  .color-options { grid-template-columns: 1fr 1fr; }
  .status-group { padding: 18px; }
  .mapping-row { grid-template-columns: 10px 1fr; padding-block: 9px; }
  .mapping-row > svg { display: none; }
  .mapping-row select { grid-column: 2; }
  .toggle-row { padding-inline: 8px; }
  .nested-field { grid-template-columns: 1fr; margin-inline: 8px; }
  .toggle-list.inset { margin-inline: -18px; margin-bottom: -18px; }
}

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