:root {
  color-scheme: dark;
  --bg: #0b0c0f;
  --card: #14161a;
  --surface: #1b1e23;
  --surface-hover: #22262c;
  --ink: #f5f4f1;
  --muted: #9a9da4;
  --line: #2b2f36;
  --accent: #f2cfc4;
  --accent-ink: #231917;
  --green: #254a36;
  --yellow: #57481f;
  --blue: #263d5d;
  --red: #5c292d;
  --shadow: 0 26px 90px #0009;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px TildaSans, Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }

button {
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 12px 18px;
  font-weight: 750;
  cursor: pointer;
}

button:disabled { opacity: .55; cursor: wait; }

input, select, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  padding: 12px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: #727780;
  box-shadow: 0 0 0 3px #7b849022;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

small { display: block; color: var(--muted); font-size: 12px; margin-top: 5px; }

.brand { color: var(--ink); font-size: 23px; font-weight: 950; letter-spacing: -1px; }
.error { color: #ff858d; min-height: 20px; }
.hint { color: var(--muted); }
.wide { grid-column: 1 / -1; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 20%, #242730 0, var(--bg) 48%);
}

.login-card {
  width: min(420px, 100%);
  padding: 38px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.login-card h1 { margin: 46px 0 40px; font-size: 34px; }
.login-card button { width: 100%; margin-top: 12px; }

header {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(24px, calc((100vw - 1360px) / 2));
  border-bottom: 1px solid var(--line);
  background: #101216e8;
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-brand { display: flex; align-items: baseline; gap: 12px; color: var(--muted); }
.view-tabs {
  display: flex;
  align-self: stretch;
  align-items: stretch;
  gap: 4px;
}

.view-tab {
  position: relative;
  padding: 0 18px;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.view-tab:hover { color: var(--ink); }
.view-tab.active { color: var(--ink); }
.view-tab.active::after {
  content: '';
  position: absolute;
  right: 15px;
  bottom: 0;
  left: 15px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
}

main { max-width: 1360px; margin: auto; padding: 28px 24px 60px; }

.toolbar {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto auto;
  gap: 10px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  white-space: nowrap;
}

.check input { width: auto; margin: 0; accent-color: var(--accent); }
.check.standalone { width: fit-content; margin-top: 14px; }

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

.stats div {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--card);
}

.stats b { display: block; font-size: 28px; }

.table {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--card);
}

.tr {
  display: grid;
  grid-template-columns: 1.15fr 1.7fr .7fr .8fr 1.1fr .85fr;
  width: 100%;
  gap: 14px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}

.tr:last-child { border-bottom: 0; }
.tr.head { color: var(--muted); font-size: 12px; }
.order-row { min-height: 76px; cursor: pointer; }
.order-row:hover { background: var(--surface-hover); }

.row-open {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 6px 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.client-cell { display: grid; gap: 4px; min-width: 0; }
.client-cell > b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.contact-copy {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 1px 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-copy:hover { color: var(--accent); text-decoration: underline; }

.quick-status {
  padding: 9px 32px 9px 10px;
  border-color: transparent;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
}

.s-ready_for_production, .s-ready, .s-completed, .s-placed { background: var(--green); }
.s-waiting_measurements { background: var(--yellow); }
.s-in_production, .s-shipped { background: var(--blue); }
.s-cancelled { background: var(--red); }

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

.production-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.production-head h1 { margin: 4px 0 5px; font-size: 34px; }
.production-head p { max-width: 740px; margin: 0; color: var(--muted); }
.production-head .eyebrow { color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; }
.production-toolbar { display: grid; grid-template-columns: 1.6fr repeat(3, minmax(170px, 1fr)); gap: 10px; }
.production-filter-field {
  display: grid;
  gap: 4px;
  padding: 7px 11px 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.production-filter-field span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; }
.production-filter-field input { min-width: 0; padding: 0; border: 0; border-radius: 0; background: transparent; }
.production-stats { margin-bottom: 12px; }

.production-batch {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--card);
}

#productionSelection { color: var(--muted); }
.production-table { overflow: hidden; border: 1px solid var(--line); border-radius: 17px; background: var(--card); }
.production-tr {
  display: grid;
  grid-template-columns: 38px minmax(340px, 1.65fr) minmax(230px, 1.15fr) minmax(180px, .9fr) minmax(175px, .8fr);
  gap: 14px;
  align-items: center;
  min-height: 96px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.production-tr:last-child { border-bottom: 0; }
.production-tr:hover:not(.production-th) { background: var(--surface-hover); }
.production-th { min-height: auto; padding-top: 11px; padding-bottom: 11px; color: var(--muted); font-size: 12px; }
.production-checkbox { display: grid; place-items: center; padding: 0; }
.production-checkbox input { width: 19px; height: 19px; margin: 0; accent-color: var(--accent); }
.production-order { display: grid; gap: 4px; min-width: 0; }
.production-open-order {
  width: fit-content;
  max-width: 100%;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.production-open-order:hover { text-decoration: underline; }
.production-order b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.material-list { display: flex; flex-wrap: wrap; gap: 6px; }
.material-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  color: var(--ink);
  font-size: 11px;
}
.material-chip i { width: 13px; height: 13px; flex: 0 0 auto; border: 1px solid #ffffff55; border-radius: 50%; background: var(--material); }
.production-priority { padding: 9px 32px 9px 10px; }
.production-control-panel { display:flex; align-items:center; gap:18px; flex-wrap:wrap; margin:0 0 18px; padding:16px 18px; border:1px solid var(--line); border-radius:18px; background:var(--panel); }
.production-control-panel > div { display:grid; gap:4px; margin-right:auto; }
.production-control-panel small { color:var(--muted); }
.production-control-panel.running { border-color:#4c9a6a; }
.production-control-panel.paused { border-color:#9d7827; }
.production-printers-panel { margin-top:24px; padding:18px; border:1px solid var(--line); border-radius:18px; background:var(--panel); }
.production-printers-panel summary { cursor:pointer; font-size:20px; font-weight:700; }
.printer-slot-card { margin-top:16px; padding:14px; border:1px solid var(--line); border-radius:14px; }
.printer-slot-card h3 { margin:0 0 10px; }
.printer-slot-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(210px,1fr)); gap:10px; }
.printer-slot-grid label { display:grid; gap:6px; color:var(--muted); }
.printer-slot-grid select { width:100%; }
.production-state { display: grid; gap: 3px; }
.production-state > span { width: fit-content; padding: 6px 9px; border-radius: 99px; background: var(--surface); font-size: 11px; font-weight: 750; }
.state-actionable .production-state > span { background: var(--green); }
.state-waiting .production-state > span { background: var(--yellow); }
.state-submitted .production-state > span { background: var(--blue); }
.state-problem .production-state > span { background: var(--red); }
.production-error {
  max-width: 360px;
  color: #ff9da4;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.35;
}
.production-quality-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.production-quality { padding: 7px 9px; border-radius: 8px; font-size: 11px; }
.production-quality.approve { background: #b9dec5; color: #102519; }
.production-quality.defect { border: 1px solid #854149; background: transparent; color: #ff9da4; }
.production-batch-actions { display:flex; align-items:center; gap:6px; margin-top:5px; }
.production-retry { width:fit-content; padding:7px 9px; border:1px solid #9d7827; border-radius:8px; background:transparent; color:#f4d58b; font-size:11px; }
.production-cancel { display:grid; width:30px; height:30px; flex:0 0 auto; place-items:center; padding:0; border:1px solid #854149; border-radius:8px; background:transparent; color:#ff9da4; font-size:20px; line-height:1; }

dialog {
  width: min(980px, calc(100% - 24px));
  max-height: calc(100vh - 30px);
  overflow: auto;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop { background: #000b; backdrop-filter: blur(4px); }

.close {
  float: right;
  padding: 0 4px;
  background: transparent;
  color: var(--muted);
  font-size: 28px;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 22px;
  padding-right: 36px;
}

.detail-meta { flex: 1; min-width: 0; }
.detail-kicker { color: var(--muted); font-size: 12px; }

.order-title-edit {
  display: flex;
  align-items: baseline;
  gap: 0;
  margin: 7px 0 10px;
  font-size: 30px;
  font-weight: 850;
  letter-spacing: -.8px;
}

.order-title-edit span { flex: 0 0 auto; }
.order-title-edit input {
  width: min(520px, 100%);
  padding: 0;
  border: 0;
  border-bottom: 1px dashed transparent;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  letter-spacing: inherit;
}

.order-title-edit input[readonly] { cursor: text; }
.order-title-edit input:hover, .order-title-edit input.editing { border-bottom-color: #737983; }
.order-title-edit input:focus { box-shadow: none; border-bottom-color: var(--accent); }

.date-editor {
  display: grid;
  grid-template-columns: auto minmax(190px, 240px);
  align-items: center;
  gap: 10px;
  width: fit-content;
}

.date-editor input { padding: 8px 10px; }

.order-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 26px;
  margin: 28px 0;
}

.field-column {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #111318;
}

.input-with-action { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.copy-field { padding: 0 13px; background: var(--surface-hover); color: var(--ink); border: 1px solid var(--line); }

.label-editor { position: relative; display: grid; grid-template-columns: 42px 1fr; gap: 8px; }
.color-trigger {
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--surface);
}

.color-dot {
  display: block;
  width: 18px;
  height: 18px;
  border: 2px solid #ffffff55;
  border-radius: 50%;
  background: var(--label-color, transparent);
}

.color-dot.none { background: linear-gradient(135deg, transparent 44%, #ff7c84 45%, #ff7c84 55%, transparent 56%); }

.color-palette {
  position: absolute;
  z-index: 10;
  top: 48px;
  left: 0;
  display: grid;
  grid-template-columns: repeat(3, 38px);
  gap: 6px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #252930;
  box-shadow: 0 14px 40px #0009;
}

.color-choice { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; background: transparent; }
.color-choice:hover { background: #ffffff12; }

.measurement-badge {
  display: flex;
  align-items: center;
  min-height: 46px;
  padding: 12px;
  border-radius: 10px;
  background: var(--yellow);
}

.measurement-badge.ok { background: var(--green); }

.ozon-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.ozon-title { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.ozon-title small, .ozon-state, .ozon-data span { color: var(--muted); }
.ozon-state { margin: 0; font-size: 13px; }
.ozon-data { display: grid; gap: 9px; }
.ozon-data > div { display: grid; gap: 3px; }
.ozon-data span { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.ozon-data > div > div { display: flex; flex-wrap: wrap; gap: 5px; }
.ozon-copy {
  width: fit-content;
  max-width: 100%;
  padding: 2px 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: left;
  overflow-wrap: anywhere;
}
.ozon-copy:hover { color: var(--accent); text-decoration: underline; }
.ozon-actions { display: grid; grid-template-columns: 1fr 1.25fr; gap: 8px; }
.ozon-actions button { padding: 10px 12px; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 28px;
}

.section-head h3 { margin: 0; }
.products { display: grid; gap: 10px; margin: 14px 0 24px; }

.products article {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 18px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #111318;
}

.products img, .image-placeholder {
  width: 120px;
  height: 120px;
  border-radius: 10px;
  background: var(--surface);
}

.products img { object-fit: cover; }
.image-placeholder { display: grid; place-items: center; color: var(--muted); text-align: center; }
.products dl div { display: flex; gap: 10px; }
.products dt { color: var(--muted); }
.products dd { margin: 0; }

.manual-measurement, .received-measurements {
  margin-top: 14px;
  padding: 12px;
  border-radius: 11px;
  background: var(--surface);
}

.measure-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }
.actions.split { justify-content: space-between; }
.actions.split > div { display: flex; gap: 8px; }
.secondary { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.danger { background: var(--red); color: #ffdadd; }

.item-row {
  display: grid;
  grid-template-columns: 1.4fr 70px 100px 105px 105px 105px 42px;
  gap: 8px;
  margin-bottom: 8px;
}

.remove { padding: 0; border: 1px solid var(--line); background: var(--surface); color: var(--muted); }

#toast {
  position: fixed;
  z-index: 100;
  bottom: 20px;
  left: 50%;
  padding: 12px 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #252930;
  color: var(--ink);
  opacity: 0;
  transform: translate(-50%, 20px);
  transition: .2s;
  pointer-events: none;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 950px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar input:first-child { grid-column: 1 / -1; }
  .tr { grid-template-columns: 1fr 1.5fr .7fr 1fr; }
  .tr > :nth-child(4), .tr > :nth-child(6) { display: none; }
  .order-fields { grid-template-columns: 1fr; }
  .item-row, .measure-grid { grid-template-columns: 1fr 1fr; }
  .item-row .remove { min-height: 40px; }
  .production-toolbar { grid-template-columns: 1fr 1fr; }
  .production-toolbar > #productionSearch { grid-column: 1 / -1; }
  .production-tr { grid-template-columns: 34px 1.4fr 1fr .9fr; }
  .production-tr > :nth-child(3) { display: none; }
}

@media (max-width: 600px) {
  header { height: auto; min-height: 68px; flex-wrap: wrap; padding: 10px 14px 0; }
  .header-brand span { display: none; }
  header > #newOrder { padding: 10px 12px; }
  .view-tabs { order: 3; width: 100%; height: 45px; justify-content: center; }
  .view-tab { flex: 1; }
  main { padding: 18px 12px 50px; }
  .toolbar, .stats, .grid { grid-template-columns: 1fr; }
  .toolbar input:first-child, .wide { grid-column: auto; }
  .stats { grid-template-columns: 1fr 1fr; gap: 7px; }
  .stats div { padding: 13px; }
  .tr { grid-template-columns: 1fr 1fr; padding: 13px; }
  .tr > :nth-child(3), .tr > :nth-child(4), .tr > :nth-child(6) { display: none; }
  dialog { padding: 24px 16px; }
  .detail-head { display: block; padding-right: 30px; }
  .detail-head > button { width: 100%; margin-top: 16px; }
  .order-title-edit { font-size: 25px; }
  .date-editor { grid-template-columns: 1fr; width: 100%; }
  .field-column { padding: 14px; }
  .ozon-actions { grid-template-columns: 1fr; }
  .products article { grid-template-columns: 82px 1fr; }
  .products img, .image-placeholder { width: 82px; height: 82px; }
  .actions.split { display: grid; }
  .actions.split > div { flex-wrap: wrap; }
  .login-card { padding: 26px; }
  .production-head { align-items: stretch; }
  .production-head h1 { font-size: 29px; }
  .production-head .secondary { align-self: flex-end; }
  .production-toolbar { grid-template-columns: 1fr; }
  .production-toolbar > #productionSearch { grid-column: auto; }
  .production-batch { grid-template-columns: 1fr; }
  .production-batch button { width: 100%; }
  .production-tr, .production-th { grid-template-columns: 30px 1fr; gap: 10px; }
  .production-th > :not(:nth-child(1)):not(:nth-child(2)) { display: none; }
  .production-tr > :nth-child(3), .production-tr > :nth-child(4), .production-tr > :nth-child(5) { grid-column: 2; display: block; }
  .production-tr { padding: 14px 12px; }
  .material-list { display: flex !important; }
  .production-priority { width: 100%; }
  .production-control-panel { align-items:stretch; }
  .production-control-panel button { width:100%; }
  .production-state { display: grid !important; }
}
