:root {
  --teal-900: #0f766e;
  --teal-800: #0d9488;
  --teal-700: #14b8a6;
  --teal-600: #2dd4bf;
  --teal-100: #ccfbf1;
  --teal-50: #f0fdfa;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #eef2f6;
  --card: #ffffff;
  --danger: #e11d48;
  --warn: #b45309;
  --ok: #16a34a;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Outfit", "DM Sans", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
}
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 8% -8%, rgba(45, 212, 191, 0.16), transparent 55%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.desktop-only { display: flex; }

.login-screen {
  height: 100%;
  display: grid;
  place-items: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  overflow: auto;
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: 22px;
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(226, 232, 240, 0.9);
}
.login-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}
.login-brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}
.login-brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--teal-50);
  color: var(--teal-800);
  flex-shrink: 0;
}
.brand-mark--light {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  width: 36px;
  height: 36px;
}

.field-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}
.field-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-size: 1rem;
  background: #fff;
}
.field-input:focus {
  outline: 2px solid rgba(13, 148, 136, 0.35);
  border-color: var(--teal-700);
}
.login-divider {
  display: grid;
  place-items: center;
  margin: 14px 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  position: relative;
}
.login-divider::before {
  content: "";
  position: absolute;
  inset: 50% 0 auto;
  border-top: 1px solid var(--line);
}
.login-divider span {
  position: relative;
  background: #fff;
  padding: 0 10px;
}
.new-packer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 12px;
}
.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 10px 0 0;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 11px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-block { width: 100%; margin-top: 4px; }
.btn-primary {
  background: linear-gradient(180deg, var(--teal-700), var(--teal-800));
  color: #fff;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  padding: 10px 12px;
  font-size: 0.85rem;
}
.btn-done {
  background: linear-gradient(180deg, #22c55e, #16a34a);
  color: #fff;
  min-width: 96px;
  border-radius: 12px;
  padding: 11px 14px;
}
.btn-done:disabled {
  background: #94a3b8;
}

.app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.topbar {
  flex-shrink: 0;
  background: linear-gradient(135deg, #0f766e 0%, #14b8a6 55%, #2dd4bf 120%);
  color: #fff;
  padding: calc(10px + var(--safe-top)) 14px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.22);
}
.topbar-left {
  min-width: 0;
  flex: 1 1 auto;
}
.brand-row {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}
.brand-text { min-width: 0; }
.brand-title {
  font-family: var(--display);
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.brand-sub {
  font-size: 0.72rem;
  opacity: 0.9;
  font-weight: 600;
}
.stat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.72rem;
  font-weight: 600;
}
.pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #86efac;
  box-shadow: 0 0 0 2px rgba(134, 239, 172, 0.25);
}
.pill .dot.clock {
  background: transparent;
  box-shadow: none;
  width: auto;
  height: auto;
}
.pill .dot.clock::before { content: "⏱"; font-size: 0.7rem; }

.order-hero {
  margin-left: auto;
  background: rgba(15, 23, 42, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 6px 12px;
  font-family: var(--display);
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.1;
  flex-shrink: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.rating-cards {
  display: flex;
  gap: 8px;
}
.rating-card {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 100px;
}
.rating-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.85;
  font-weight: 700;
}
.rating-value {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 800;
  margin-top: 2px;
  display: flex;
  align-items: baseline;
  gap: 5px;
}
.rating-value .stars {
  font-size: 0.65rem;
  letter-spacing: 1px;
  color: #fde68a;
}
.rating-meta {
  font-size: 0.68rem;
  opacity: 0.85;
  margin-top: 1px;
}
.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.user-switch {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.user-switch-label {
  font-size: 0.6rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.85;
}
.user-switch-select {
  appearance: none;
  border: none;
  border-radius: 10px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%230f766e' stroke-width='3'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 10px center;
  color: var(--teal-900);
  font: inherit;
  font-weight: 700;
  font-size: 0.88rem;
  padding: 9px 28px 9px 12px;
  min-width: 120px;
  max-width: min(200px, 42vw);
  cursor: pointer;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(300px, 1.15fr);
  gap: 12px;
  padding: 12px;
  padding-bottom: calc(12px + var(--safe-bottom));
  overflow: hidden;
}

.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(226, 232, 240, 0.9);
  padding: 14px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-bar {
  display: flex;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #f8fafc;
}
.search-bar input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 12px 14px;
  font: inherit;
  font-size: 1rem;
  outline: none;
}
.search-btn {
  border: none;
  background: transparent;
  color: var(--teal-800);
  padding: 0 14px;
  cursor: pointer;
}

.stage-banner {
  flex-shrink: 0;
  margin-top: 10px;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.35;
}
.stage-banner.is-ok {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}
.stage-banner.is-blocked {
  background: #fff7ed;
  color: var(--warn);
  border: 1px solid #fdba74;
}

.empty-state {
  flex: 1;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 6px;
  padding: 20px 10px;
  color: var(--muted);
  min-height: 0;
}
.empty-state h2 {
  margin: 6px 0 0;
  color: var(--ink);
  font-family: var(--display);
  font-size: 1.05rem;
}
.empty-state p {
  margin: 0;
  max-width: 260px;
  justify-self: center;
  font-size: 0.88rem;
}
.empty-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  justify-self: center;
  background: var(--teal-50);
  color: var(--teal-700);
}

.order-details {
  margin-top: 12px;
  display: grid;
  gap: 10px;
  overflow: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.metrics-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.info-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: linear-gradient(180deg, #fff, #f8fafc);
}
.info-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.info-head h3 {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.info-icon { font-size: 0.9rem; }
.info-body {
  margin: 0;
  line-height: 1.45;
  font-weight: 600;
  font-size: 0.95rem;
  word-break: break-word;
}
.info-metric {
  margin: 0;
  font-family: var(--display);
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--teal-900);
}
.info-metric--sm { font-size: 1.25rem; }

.comments-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.comment-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-left: 3px solid var(--teal-700);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.4;
  color: #334155;
  white-space: pre-wrap;
  word-break: break-word;
}
.comment-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.progress {
  margin-top: 8px;
  height: 7px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22c55e, #16a34a);
  transition: width 0.35s ease;
}

.pieces-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-shrink: 0;
}
.pieces-title {
  display: flex;
  align-items: center;
  gap: 8px;
}
.pieces-title h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.05rem;
}
.remaining-badge {
  background: var(--teal-50);
  color: var(--teal-900);
  border: 1px solid var(--teal-100);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.72rem;
  font-weight: 800;
}

.pieces-list {
  display: grid;
  gap: 10px;
  overflow: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}
.piece-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  background: #fff;
}
.piece-row.is-packed { opacity: 0.7; background: #f8fafc; }
.piece-row.is-locked .btn-done { background: #94a3b8; }
.piece-row.flash { animation: packFlash 0.55s ease; }
@keyframes packFlash {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.45); }
  100% { box-shadow: none; }
}
.piece-thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--teal-50), #fff);
  border: 1px dashed #99f6e4;
  display: grid;
  place-items: center;
  color: var(--teal-800);
  font-size: 0.62rem;
  font-weight: 800;
  text-transform: uppercase;
  text-align: center;
  padding: 4px;
}
.piece-meta { min-width: 0; }
.piece-dims {
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.piece-sub {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  background: #0f172a;
  color: #fff;
  padding: 11px 16px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  z-index: 50;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.25);
  text-align: center;
}

@media (max-width: 960px) {
  .desktop-only { display: none !important; }
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 0.95fr) minmax(0, 1.05fr);
    overflow: hidden;
  }
  .order-hero {
    font-size: 1.15rem;
    padding: 5px 10px;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: calc(8px + var(--safe-top)) 10px 10px;
    gap: 8px;
  }
  .brand-sub { display: none; }
  .topbar-right { width: 100%; }
  .topbar-actions {
    width: 100%;
  }
  .user-switch { flex: 1; }
  .user-switch-select {
    width: 100%;
    max-width: none;
  }
  .workspace {
    padding: 8px;
    gap: 8px;
    padding-bottom: calc(8px + var(--safe-bottom));
  }
  .panel { padding: 10px; border-radius: 14px; }
  .piece-row {
    grid-template-columns: 48px 1fr;
    gap: 10px;
  }
  .piece-row .btn-done {
    grid-column: 1 / -1;
    width: 100%;
  }
  .piece-thumb { width: 48px; height: 48px; }
  .metrics-row { gap: 8px; }
  .info-metric { font-size: 1.4rem; }
}

@media (max-width: 420px) {
  .stat-pills { gap: 4px; }
  .pill { font-size: 0.68rem; padding: 3px 7px; }
}
