:root {
  --red: #d71920;
  --red-dark: #a90f15;
  --ink: #141414;
  --muted: #6b7280;
  --line: #dfe3e8;
  --surface: #ffffff;
  --page: #f3f4f6;
  --success: #14804a;
  --warning: #fff5c2;
  --warning-line: #dfbc24;
  --shadow: 0 12px 30px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--page);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button, input, select, textarea { font: inherit; }
button { touch-action: manipulation; }

.topbar {
  min-height: 74px;
  padding: 12px clamp(16px, 3vw, 34px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: #111;
  color: #fff;
  border-bottom: 4px solid var(--red);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 9px;
  display: grid; place-items: center;
  color: #fff; background: var(--red);
  font-weight: 900; font-size: 1.3rem;
}
.brand strong { display: block; font-size: 1.06rem; letter-spacing: .04em; }
.brand span { display: block; margin-top: 2px; color: #b9bec7; font-size: .82rem; }

.factory-control { display: flex; align-items: center; gap: 8px; }
.factory-label { color: #c9cdd4; font-size: .86rem; font-weight: 700; margin-right: 4px; }
.factory-btn {
  min-width: 76px; min-height: 43px; padding: 10px 16px;
  border: 1px solid #454545; border-radius: 8px;
  background: #292929; color: #fff; cursor: pointer; font-weight: 800;
}
.factory-btn.active { background: var(--red); border-color: var(--red); }

.demo-bar {
  padding: 9px 16px;
  text-align: center;
  background: #fff3cd;
  border-bottom: 1px solid #ead28a;
  color: #614d09;
  font-size: .88rem;
}
.demo-bar strong { font-weight: 800; }

.workspace { width: min(1180px, calc(100% - 32px)); margin: 22px auto 50px; }

.view-tabs {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px; max-width: 540px; margin: 0 auto 22px;
  padding: 6px; background: #e4e7eb; border-radius: 12px;
}
.tab-btn {
  min-height: 52px; border: 0; border-radius: 8px;
  background: transparent; color: #4b5563; cursor: pointer;
  font-weight: 800; font-size: 1rem;
}
.tab-btn.active { background: #fff; color: #111; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.tab-count {
  display: inline-grid; place-items: center;
  min-width: 26px; height: 26px; margin-left: 6px; padding: 0 7px;
  border-radius: 99px; color: #fff; background: var(--red); font-size: .82rem;
}

.view { display: none; }
.view.active { display: block; animation: appear .2s ease-out; }
@keyframes appear { from { opacity: 0; transform: translateY(4px); } }

.panel {
  max-width: 780px; margin: 0 auto; padding: clamp(20px, 4vw, 34px);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: var(--shadow);
}
.panel-heading { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 26px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(1.55rem, 4vw, 2rem); }
.panel-heading p { margin-bottom: 0; color: var(--muted); line-height: 1.45; }
.fab-chip {
  flex: 0 0 auto; padding: 8px 12px; border-radius: 7px;
  color: #fff; background: #111; font-weight: 900; letter-spacing: .04em;
}

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.field.full { grid-column: 1 / -1; }
.field.hidden { display: none; }
label { display: block; margin: 0 0 7px; color: #374151; font-size: .88rem; font-weight: 800; }
.required::after { content: " *"; color: var(--red); }
input, select, textarea {
  width: 100%; min-height: 52px; padding: 12px 14px;
  border: 2px solid var(--line); border-radius: 9px;
  color: #111; background: #fbfbfc; font-size: 1rem;
}
textarea { min-height: 92px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(215,25,32,.12); border-color: var(--red); }

.submit-btn {
  width: 100%; min-height: 58px; margin-top: 24px; border: 0; border-radius: 10px;
  color: #fff; background: var(--red); cursor: pointer;
  font-weight: 900; font-size: 1.05rem; letter-spacing: .02em;
}
.submit-btn:hover { background: var(--red-dark); }
.submit-btn:disabled { opacity: .65; cursor: wait; }

.items-section {
  grid-column: 1 / -1; padding: 18px;
  border: 2px solid var(--line); border-radius: 12px; background: #f8f9fb;
}
.items-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 13px; }
.items-heading strong { font-size: 1rem; }
.items-heading span { color: var(--muted); font-size: .84rem; }
.item-row {
  display: grid; grid-template-columns: 1fr 1fr .7fr 1.25fr auto;
  gap: 10px; align-items: end; padding: 14px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.item-row + .item-row { margin-top: 10px; }
.item-row label { font-size: .8rem; }
.item-row input, .item-row select { min-height: 48px; padding: 10px 11px; }
.item-field.hidden { display: none; }
.remove-item {
  width: 48px; height: 48px; border: 1px solid #efc2c4; border-radius: 8px;
  color: #a20e14; background: #fff3f3; cursor: pointer; font-size: 1.25rem; font-weight: 900;
}
.add-item {
  min-height: 46px; margin-top: 12px; padding: 10px 15px;
  border: 2px solid #111; border-radius: 8px; color: #111; background: #fff;
  cursor: pointer; font-weight: 900;
}
.item-list { display: grid; gap: 7px; margin-top: 10px; }
.item-badge { display: block; width: fit-content; }

.queue-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  gap: 18px; margin-bottom: 18px;
}
.queue-head h1 { margin-bottom: 4px; }
.queue-head p { color: var(--muted); margin-bottom: 0; }
.queue-total { font-size: .95rem; color: #4b5563; font-weight: 800; white-space: nowrap; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 18px; }
.card {
  min-height: 340px; padding: 21px;
  display: flex; flex-direction: column;
  background: var(--warning); border: 1px solid #ead56d;
  border-left: 7px solid var(--warning-line); border-radius: 10px;
  box-shadow: 4px 7px 18px rgba(75, 62, 0, .10);
}
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding-bottom: 13px; border-bottom: 1px dashed #c8ae3e; }
.card-ticket { font-size: 1.5rem; font-weight: 950; }
.card-time { color: #655d3a; font-size: .82rem; text-align: right; line-height: 1.35; }
.card-body { flex: 1; padding: 14px 0 8px; }
.detail { margin: 0 0 9px; color: #302c1e; line-height: 1.35; }
.detail strong { color: #111; }
.type-badge { display: inline-block; padding: 5px 9px; border-radius: 6px; background: #111; color: #fff; font-weight: 900; }
.cause { color: #a20e14; font-weight: 800; }
.complete-btn {
  width: 100%; min-height: 52px; border: 0; border-radius: 8px;
  color: #fff; background: var(--success); cursor: pointer; font-weight: 900;
}
.complete-btn:hover { background: #0d6338; }

.empty {
  grid-column: 1 / -1; padding: 56px 20px; text-align: center;
  background: #fff; border: 2px dashed #cfd4db; border-radius: 14px; color: var(--muted);
}
.empty-icon { display: block; margin-bottom: 12px; font-size: 2.5rem; }
.empty strong { display: block; color: #303640; font-size: 1.1rem; margin-bottom: 5px; }

.toast {
  position: fixed; z-index: 20; left: 50%; bottom: 24px;
  transform: translate(-50%, 16px); padding: 13px 18px;
  border-radius: 9px; color: #fff; background: #111;
  box-shadow: 0 10px 28px rgba(0,0,0,.25); opacity: 0; pointer-events: none;
  transition: .2s ease; text-align: center; font-weight: 700;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 700px) {
  .topbar { align-items: stretch; flex-direction: column; gap: 12px; }
  .factory-control { justify-content: space-between; }
  .factory-btn { flex: 1; }
  .factory-label { display: none; }
  .workspace { width: min(100% - 20px, 1180px); margin-top: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .items-section { grid-column: auto; }
  .items-heading { align-items: flex-start; flex-direction: column; gap: 3px; }
  .item-row { grid-template-columns: 1fr 1fr; }
  .item-row .item-field:last-of-type { grid-column: 1 / -1; }
  .remove-item { grid-column: 1 / -1; width: 100%; }
  .panel-heading, .queue-head { align-items: flex-start; }
  .queue-head { flex-direction: column; gap: 7px; }
  .cards { grid-template-columns: 1fr; }
}
