:root {
  --bg: #f8f4fb;
  --surface: rgba(255, 255, 255, .78);
  --card: #fff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #0f172a;
  --accent: #8b1ac8;
  --accent-2: #d946ef;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #f59e0b;
  --shadow: 0 18px 48px rgba(99, 50, 130, .14);
  --soft-shadow: 0 10px 24px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at top left, rgba(217, 70, 239, .18), transparent 34vw),
    linear-gradient(180deg, #fff 0, var(--bg) 28vh, #f7f2f7 100%);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.staff-app {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
}

.staff-login {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  width: min(100%, 640px);
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 18px max(26px, env(safe-area-inset-bottom));
}

.staff-panel {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  width: min(100%, 1180px);
  margin: 0 auto;
}

.staff-logo {
  width: clamp(170px, 26vw, 260px);
  height: auto;
}

.staff-login h1 {
  margin-bottom: 0;
  font-size: clamp(34px, 7vw, 64px);
  line-height: 1.02;
  letter-spacing: -.05em;
}

.staff-login p {
  max-width: 560px;
  font-size: clamp(18px, 2.7vw, 26px);
  line-height: 1.42;
}

.staff-login .primary-btn {
  width: 100%;
  min-height: clamp(58px, 8vw, 82px);
  border-radius: 20px;
  font-size: clamp(17px, 2.4vw, 24px);
}

h1, h2, p { margin-top: 0; }
.muted { color: var(--muted); }
.eyebrow {
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

button {
  border: 0;
  border-radius: 20px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, .9);
  color: var(--text);
  font-weight: 900;
  font-size: 15px;
  box-shadow: var(--soft-shadow);
  cursor: pointer;
}

.primary-btn,
.order-actions button.primary {
  background: var(--brand);
  color: #fff;
}

.staff-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin: -4px -4px 12px;
  padding: 12px 12px 14px;
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 28px;
  background: linear-gradient(135deg, rgba(255, 255, 255, .9), rgba(255, 255, 255, .62));
  backdrop-filter: blur(18px);
  box-shadow: var(--soft-shadow);
}

.staff-header h1 {
  margin-bottom: 2px;
  font-size: clamp(34px, 5vw, 52px);
  line-height: .95;
  letter-spacing: -.05em;
}

.icon-btn {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 24px;
  box-shadow: 0 14px 30px rgba(15, 23, 42, .24);
}

.staff-controls,
.date-row,
.filter-row,
.stats-row {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.staff-controls {
  grid-template-columns: repeat(5, 1fr);
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, .78);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--soft-shadow);
  backdrop-filter: blur(16px);
}
.staff-control-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  padding: 12px;
  border-radius: 22px;
  border: 0;
  background: rgba(255, 255, 255, .95);
  color: var(--text);
  font: inherit;
  font-weight: 950;
  text-decoration: none;
  text-align: center;
  box-shadow: var(--soft-shadow);
}
.staff-controls button {
  min-height: 58px;
  box-shadow: none;
}
.staff-controls button,
.staff-control-link,
.filter-row button,
.date-row button {
  transition: transform .14s ease, background .14s ease, box-shadow .14s ease;
}
.staff-controls button:active,
.staff-control-link:active,
.filter-row button:active,
.date-row button:active,
.order-actions button:active {
  transform: scale(.97);
}
.date-row {
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 28px;
  padding: 12px;
  box-shadow: var(--soft-shadow);
  backdrop-filter: blur(16px);
}
.date-row label {
  font-weight: 950;
}
.date-row input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  color: var(--text);
  background: #fff;
  font: inherit;
  font-weight: 800;
}
.filter-row {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 8px;
  border-radius: 26px;
  background: rgba(255, 255, 255, .72);
  box-shadow: var(--soft-shadow);
}
.filter-row button {
  min-height: 54px;
  box-shadow: none;
}
.filter-row button.active,
.staff-controls button.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 12px 26px rgba(139, 26, 200, .28);
}

#orders-pause-toggle.paused {
  background: #dc2626;
  color: #fff;
  animation: pausePulse 1.4s infinite;
}

@keyframes pausePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .35); }
  50% { box-shadow: 0 0 0 10px rgba(220, 38, 38, 0); }
}

.stats-row { grid-template-columns: repeat(3, 1fr); }
.stats-row article,
.stats-row button {
  background: rgba(255, 255, 255, .88);
  border: 1px solid rgba(255, 255, 255, .78);
  border-radius: 26px;
  padding: 16px;
  box-shadow: var(--soft-shadow);
  text-align: left;
}
.stats-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.stats-row strong {
  display: block;
  margin-top: 6px;
  font-size: 30px;
}

.alert-box {
  margin: 8px 0 12px;
  border-radius: 18px;
  padding: 16px;
  background: #fee2e2;
  color: #991b1b;
  font-weight: 950;
  font-size: 20px;
  display: grid;
  gap: 10px;
  animation: pulse-alert .75s infinite;
}
.alert-box span {
  font-size: 15px;
  color: #7f1d1d;
}
.alert-box button {
  background: #991b1b;
  color: #fff;
}

body.new-order-alerting {
  animation: page-flash .75s infinite;
}

@keyframes pulse-alert {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(.985); }
}

@keyframes page-flash {
  0%, 100% { background: var(--bg); }
  50% { background: #fee2e2; }
}

.orders-list {
  display: grid;
  gap: 14px;
  padding-bottom: 26px;
  flex: 1;
}

.order-card {
  position: relative;
  overflow: hidden;
  background: rgba(255, 255, 255, .94);
  border: 1px solid rgba(255, 255, 255, .78);
  border-left: 0;
  border-radius: 30px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.order-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 8px;
  background: var(--warn);
}
.order-card.status-preparing::before { background: #2563eb; }
.order-card.status-ready::before { background: var(--ok); }
.order-card.status-accepted::before { background: #0ea5e9; }
.order-card.status-cancel_requested::before { background: #a21caf; }
.order-card.status-completed::before { background: #64748b; }
.order-card.status-cancelled::before { background: var(--danger); }
.order-card.status-preparing { border-left-color: #2563eb; }
.order-card.status-ready { border-left-color: var(--ok); }
.order-card.status-accepted { border-left-color: #0ea5e9; }
.order-card.status-cancel_requested { border-left-color: #a21caf; background: #fff1fb; }
.order-card.status-completed { border-left-color: #64748b; opacity: .82; }
.order-card.status-cancelled { border-left-color: var(--danger); opacity: .72; }

.order-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(170px, 34%);
  gap: 12px;
  align-items: stretch;
}
.order-info {
  min-width: 0;
}
.order-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.order-number {
  font-size: clamp(24px, 3.8vw, 34px);
  font-weight: 950;
}
.order-total {
  font-size: clamp(22px, 3.2vw, 30px);
  font-weight: 950;
  white-space: nowrap;
}
.order-meta {
  margin: 10px 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.5;
}
.pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 10px;
  background: #f3f4f6;
  font-size: 12px;
  font-weight: 900;
}
.pill.paid { background: #dcfce7; color: #166534; }

.order-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 10px;
}
.order-actions button {
  flex: 0 0 auto;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 13px;
  background: #f9fafb;
  font-size: 13px;
  line-height: 1.1;
  box-shadow: none;
}
.order-actions .danger {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fecaca;
}
.order-actions button.action-busy,
.dialog-actions button.action-busy {
  background: #f59e0b !important;
  color: #fff !important;
  border-color: #f59e0b !important;
}
.order-actions button.action-success,
.dialog-actions button.action-success {
  background: #dc2626 !important;
  color: #fff !important;
  border-color: #dc2626 !important;
  box-shadow: 0 0 0 4px rgba(220, 38, 38, .16);
}
.order-actions button:disabled,
.dialog-actions button:disabled {
  opacity: .9;
  cursor: progress;
}
.order-detail-zone {
  min-height: 132px;
  border: 0;
  border-radius: 24px;
  background: linear-gradient(135deg, #faf5ff, #fff);
  color: var(--accent);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  box-shadow: inset 0 0 0 1px #eadcff;
  text-align: center;
}
.order-detail-zone span {
  font-size: 18px;
  font-weight: 950;
}
.order-detail-zone small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.order-detail-zone:active {
  transform: scale(.98);
}

.empty-state {
  padding: 35px 18px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, .86);
  border: 1px dashed #d1d5db;
  border-radius: 30px;
  box-shadow: var(--soft-shadow);
}

.order-dialog {
  width: min(760px, calc(100vw - 24px));
  max-height: 88dvh;
  border: 0;
  border-radius: 24px;
  padding: 0;
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.order-dialog::backdrop {
  background: rgba(15, 23, 42, .45);
}
.dialog-head {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  z-index: 1;
}
.dialog-head h2 {
  margin: 0;
}
.dialog-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.dialog-head button {
  padding: 9px 13px;
  border-radius: 999px;
  background: #f3f4f6;
}
.dialog-head .dialog-complete {
  background: #16a34a;
  color: #fff;
}
#dialog-content {
  max-height: calc(88dvh - 86px);
  overflow: auto;
  padding: 18px;
}
.detail-placeholder {
  min-height: 150px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
}
.detail-placeholder strong {
  color: var(--text);
  font-size: 22px;
}
.detail-placeholder span {
  max-width: 280px;
}
.detail-line {
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}
.detail-options {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

@media (max-width: 560px) {
  .staff-app {
    padding-left: 14px;
    padding-right: 14px;
  }
  .staff-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .staff-controls button,
  .staff-control-link {
    min-height: 50px;
    border-radius: 18px;
    font-size: 14px;
  }
  .date-row {
    grid-template-columns: 1fr auto;
  }
  .date-row label {
    grid-column: 1 / -1;
  }
  .order-actions {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }
  .order-actions::-webkit-scrollbar { display: none; }
  .order-main {
    grid-template-columns: 1fr;
  }
  .order-detail-zone {
    min-height: 58px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .staff-login {
    padding-top: 18px;
  }
  .staff-panel {
    max-width: 1200px;
    margin: 0 auto;
  }
  .staff-controls {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
  }
  .orders-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .order-main {
    grid-template-columns: 1fr;
  }
  .order-detail-zone {
    min-height: 56px;
  }
}

/* KDS layout v19 */
:root {
  --kds-new: #8b1ac8;
  --kds-preparing: #2563eb;
  --kds-ready: #f59e0b;
  --kds-completed: #16a34a;
  --kds-cancelled: #dc2626;
}

.staff-panel {
  width: min(100%, 1440px);
}

.stats-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stats-row article,
.stats-row button {
  overflow: hidden;
  color: #fff;
  border: 0;
  min-height: 96px;
}

.stats-row article span,
.stats-row button span {
  color: rgba(255, 255, 255, .86);
  font-size: 16px;
}

.stats-row article strong,
.stats-row button strong {
  font-size: 42px;
  line-height: 1;
}

.stats-row button.active {
  box-shadow: inset 0 0 0 4px #111827, 0 18px 42px rgba(15, 23, 42, .18);
}

.stat-new { background: var(--kds-new) !important; }
.stat-preparing { background: var(--kds-preparing) !important; }
.stat-ready { background: var(--kds-ready) !important; }
.stat-completed { background: var(--kds-completed) !important; }

.kds-workspace {
  display: grid;
  gap: 16px;
  align-items: start;
  flex: 1;
}

.order-detail-pane {
  display: none;
}

.order-card {
  border-radius: 24px;
  border: 3px solid transparent;
  border-left: 12px solid var(--kds-new);
  padding: 18px 18px 16px;
  background: #fff;
}

.order-card::before {
  display: none;
}

.order-card.status-bucket-new { border-left-color: var(--kds-new); }
.order-card.status-bucket-preparing { border-left-color: var(--kds-preparing); }
.order-card.status-bucket-ready { border-left-color: var(--kds-ready); }
.order-card.status-bucket-completed { border-left-color: var(--kds-completed); }
.order-card.status-bucket-cancelled { border-left-color: var(--kds-cancelled); }
.order-card.selected {
  border-color: #111827;
  box-shadow: 0 18px 46px rgba(15, 23, 42, .22);
}
.order-card.is-overdue {
  border-left-color: var(--kds-cancelled);
  background: #fff5f5;
}
.order-card.is-new-flash {
  animation: newOrderFlash 3.2s ease-in-out;
}

@keyframes newOrderFlash {
  0%, 100% { background: #fff; }
  16%, 52% { background: #faf5ff; border-color: var(--kds-new); }
  34%, 70% { background: #fef3c7; border-color: #f59e0b; }
}

.order-select-zone {
  position: absolute;
  inset: 0;
  z-index: 1;
  border: 0;
  border-radius: 24px;
  background: transparent;
  box-shadow: none;
}

.order-top,
.order-kpis,
.order-customer,
.order-items,
.order-items-empty,
.order-actions {
  position: relative;
  z-index: 2;
}

.order-top {
  align-items: flex-start;
  margin-bottom: 14px;
}

.order-identity {
  min-width: 0;
}

.order-number {
  font-size: 40px;
  line-height: 1;
  letter-spacing: 0;
}

.order-money {
  font-size: 36px;
  line-height: 1;
  font-weight: 950;
  white-space: nowrap;
}

.order-kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 10px 0 12px;
}

.order-kpis div,
.detail-kpis div {
  border-radius: 18px;
  padding: 12px;
  background: #f8fafc;
}

.order-kpis span,
.detail-kpis span {
  display: block;
  color: #64748b;
  font-size: 13px;
  font-weight: 900;
}

.order-kpis strong,
.detail-kpis strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
  line-height: 1.08;
  font-weight: 950;
}

.order-kpis .overdue,
.detail-kpis .overdue {
  background: #fee2e2;
  color: #991b1b;
}

.order-kpis .overdue span,
.detail-kpis .overdue span {
  color: #991b1b;
}

.order-customer {
  display: grid;
  gap: 5px;
  margin: 8px 0 12px;
  font-size: 18px;
}

.order-customer a,
.detail-customer a {
  color: #111827;
  font-weight: 950;
}

.order-customer p {
  margin: 4px 0 0;
  border-radius: 14px;
  padding: 10px;
  background: #fff7ed;
  color: #7c2d12;
  font-weight: 900;
}

.order-items {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.order-items li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid #e5e7eb;
}

.order-items strong {
  font-size: 20px;
  line-height: 1.18;
}

.order-items b {
  font-size: 24px;
}

.order-items small,
.order-items em {
  grid-column: 1 / -1;
  color: #64748b;
  font-style: normal;
  font-weight: 800;
}

.order-items-empty {
  padding: 14px;
  border-radius: 16px;
  background: #f8fafc;
  color: #64748b;
  font-weight: 900;
}

.order-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 60px;
  gap: 10px;
  margin-top: 14px;
}

.order-actions button {
  min-height: 60px;
  border-radius: 18px;
  font-size: 18px;
}

.order-actions button.primary {
  background: #111827;
  color: #fff;
}

.order-more {
  position: relative;
  z-index: 4;
}

.order-more summary {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: 18px;
  background: #f1f5f9;
  font-size: 30px;
  font-weight: 950;
  list-style: none;
  cursor: pointer;
}

.order-more summary::-webkit-details-marker {
  display: none;
}

.order-more-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 10;
  display: grid;
  gap: 8px;
  min-width: 180px;
  padding: 10px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 18px 42px rgba(15, 23, 42, .2);
}

.order-more-menu button {
  width: 100%;
  justify-content: flex-start;
  min-height: 48px;
  border-radius: 14px;
  font-size: 15px;
}

.detail-kds-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
  border-radius: 22px;
  padding: 16px;
  background: #111827;
  color: #fff;
}

.detail-kds-head.status-bucket-new { background: var(--kds-new); }
.detail-kds-head.status-bucket-preparing { background: var(--kds-preparing); }
.detail-kds-head.status-bucket-ready { background: var(--kds-ready); }
.detail-kds-head.status-bucket-completed { background: var(--kds-completed); }
.detail-kds-head.is-overdue { background: var(--kds-cancelled); }

.detail-kds-head span {
  display: block;
  font-size: 14px;
  font-weight: 900;
  opacity: .86;
}

.detail-kds-head strong,
.detail-kds-head b {
  display: block;
  font-size: 34px;
  line-height: 1;
}

.detail-kpis {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.detail-customer,
.detail-note {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  border-radius: 18px;
  padding: 14px;
  background: #f8fafc;
}

.detail-customer strong {
  font-size: 22px;
}

.detail-note p {
  margin: 0;
  color: #7c2d12;
  font-weight: 900;
}

.detail-items {
  display: grid;
  gap: 10px;
}

.detail-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px 0;
}

.detail-line strong {
  font-size: 21px;
}

.detail-line > span {
  font-weight: 950;
}

@media (min-width: 900px) and (orientation: landscape) {
  .kds-workspace {
    grid-template-columns: minmax(0, 1fr) minmax(360px, 31%);
  }

  .order-detail-pane {
    position: sticky;
    top: 118px;
    display: block;
    max-height: calc(100dvh - 136px);
    overflow: auto;
    border-radius: 28px;
    padding: 16px;
    background: #fff;
    box-shadow: var(--shadow);
  }

  .orders-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .order-dialog {
    display: none;
  }
}

@media (max-width: 760px) {
  .stats-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .order-number {
    font-size: 34px;
  }

  .order-money {
    font-size: 30px;
  }

  .order-kpis {
    grid-template-columns: 1fr;
  }
}
