:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --line: #dde2eb;
  --ink: #1f2937;
  --sub: #5f6b7a;
  --accent: #0f9d6c;
  --urgent: #dc2626;
  --navy: #142033;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 28%, rgba(47, 111, 237, 0.10) 0 140px, transparent 141px),
    radial-gradient(circle at 88% 40%, rgba(47, 111, 237, 0.10) 0 170px, transparent 171px),
    linear-gradient(180deg, #f8fbff 0, var(--bg) 260px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  justify-content: stretch;
  align-items: center;
  gap: 12px;
  width: min(460px, 100%);
  margin: 0 auto;
  padding: 12px 14px;
  background: #fff;
  color: var(--navy);
  border-bottom: 1px solid #edf2f8;
  box-shadow: none;
}

.topbar h1 {
  justify-self: center;
  margin: 0;
  font-size: 1.12rem;
  font-weight: 900;
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 0 0 auto;
  max-width: 100%;
  overflow: visible;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.controls .app-nav,
.controls .manu-settings {
  display: none !important;
}

#dateInput,
#refreshBtn {
  border: 1px solid #cfd6e2;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.9rem;
}

#dateInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.app-nav a {
  flex: 0 0 auto;
  min-height: 36px;
  border: 1px solid #cfd6e2;
  border-radius: 8px;
  padding: 7px 10px;
  background: #f8fafc;
  color: #0f172a;
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.app-nav a:hover {
  background: #edf2f7;
}

.app-nav a[aria-current="page"] {
  border-color: #2563eb;
  color: #1d4ed8;
  background: #eff6ff;
}

#refreshBtn {
  min-height: 36px;
  border: 1px solid #3fb5aa;
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  padding: 6px 12px;
  font-weight: 900;
  cursor: pointer;
}

.app-alert {
  max-width: 920px;
  margin: 12px auto 0;
  padding: 10px 14px;
  border: 1px solid #f8c9a8;
  border-radius: 8px;
  background: #fff7ed;
  color: #9a3412;
  font-size: 14px;
  line-height: 1.5;
}

.app-alert.hidden {
  display: none;
}

.new-order-alert {
  position: sticky;
  top: 58px;
  z-index: 9;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 10px;
  align-items: center;
  width: min(460px, 100%);
  margin: 0 auto;
  padding: 10px 12px;
  border-bottom: 1px solid #fecaca;
  background: linear-gradient(135deg, #fff7ed, #fee2e2);
  color: #7f1d1d;
  box-shadow: 0 10px 22px rgba(127, 29, 29, 0.12);
}

.new-order-alert.hidden {
  display: none;
}

.new-order-alert strong {
  font-size: 0.98rem;
  font-weight: 950;
}

.new-order-alert span {
  grid-column: 1;
  color: #9a3412;
  font-size: 0.82rem;
  font-weight: 750;
  line-height: 1.35;
}

.new-order-alert button {
  grid-row: 1 / span 2;
  grid-column: 2;
  min-height: 34px;
  border: 1px solid #dc2626;
  border-radius: 999px;
  background: #ffffff;
  color: #b91c1c;
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.new-order-alert button.is-ready {
  border-color: #16a34a;
  color: #166534;
}

body.has-unconfirmed-orders .topbar {
  box-shadow: inset 4px 0 0 #dc2626, 0 6px 18px rgba(220, 38, 38, 0.12);
}

body.new-order-flash {
  animation: staffPageFlash 0.8s ease-in-out 3;
}

@keyframes staffPageFlash {
  0%, 100% { background-color: transparent; }
  45% { background-color: #fff1f2; }
}

main {
  max-width: 460px;
  margin: 0 auto;
  padding: 12px 10px 86px;
  background: #fff;
  min-height: calc(100vh - 58px);
}

.staff-guide {
  display: none;
}

.staff-guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.staff-flow-copy {
  margin: 0;
  color: #334155;
  font-size: 0.9rem;
  line-height: 1.45;
}

.staff-guide-hide {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  color: #52606d;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.staff-guide-hide input {
  width: 16px;
  height: 16px;
}

.workflow-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: stretch;
  gap: 8px;
  margin: 0;
}

.workflow-step {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.workflow-step strong,
.workflow-step small {
  display: block;
}

.workflow-step strong {
  font-size: 0.9rem;
}

.workflow-step small {
  margin-top: 1px;
  color: var(--sub);
  font-size: 0.76rem;
}

.workflow-no {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 900;
}

.workflow-arrow {
  display: grid;
  place-items: center;
  color: #64748b;
  font-weight: 900;
}

.workflow-step-unconfirmed {
  border-color: #fecaca;
  background: #fff8f8;
}

.workflow-step-unconfirmed .workflow-no {
  background: #dc2626;
}

.workflow-step-confirmed {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.workflow-step-confirmed .workflow-no {
  background: #2563eb;
}

.workflow-step-paid {
  border-color: #bbf7d0;
  background: #f0fdf4;
}

.workflow-step-paid .workflow-no {
  background: #16a34a;
}

#statusText {
  display: none;
  margin: 0 0 8px;
  color: #334155;
  font-size: 0.82rem;
  background: #eef4ff;
  border: 1px solid #d3def5;
  border-radius: 8px;
  padding: 5px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#orders,
#confirmedOrders,
#tableSummaries,
#groups,
#paidGroups {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

#ordersView,
#checkoutView {
  display: grid;
  gap: 12px;
}

#ordersView.hidden,
#checkoutView.hidden {
  display: none;
}

.section-title {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: #334155;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::before {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.section-title-live::before {
  content: "今やる";
  background: #dbeafe;
  color: #1d4ed8;
}

.section-title-history::before {
  content: "履歴";
  background: #f1f5f9;
  color: #475569;
}

.section-block {
  margin: 0 0 10px;
  padding: 0;
  border-radius: 0;
  border: 0;
}

.section-block-live {
  background: transparent;
}

.section-block-history {
  display: none !important;
  background: transparent;
}

.staff-history-mode .section-block-live {
  display: none !important;
}

.staff-history-mode .section-block-history {
  display: block !important;
}

.staff-current-mode .section-block-live {
  display: block !important;
}

.staff-current-mode .section-block-history {
  display: none !important;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 2px 0 10px;
  padding: 4px;
  border-radius: 12px;
  background: #eef3fb;
}

.staff-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 14px;
}

.staff-summary-card {
  min-height: 58px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid #dce5f1;
  border-radius: 12px;
  background: #fff;
  color: var(--navy);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
}

.summary-icon {
  color: var(--navy);
  font-size: 1.15rem;
  font-weight: 900;
}

.staff-summary-card span:not(.summary-icon) {
  font-size: 0.86rem;
  font-weight: 900;
}

.staff-summary-card strong {
  color: #dc2626;
  font-size: 1.15rem;
  white-space: nowrap;
}

.staff-note {
  display: none;
  margin: 0 0 10px;
  border: 1px solid #d3def5;
  border-radius: 8px;
  background: #f8fbff;
  color: #334155;
  font-size: 0.86rem;
}

.staff-note summary {
  cursor: pointer;
  padding: 7px 10px;
  font-weight: 800;
  line-height: 1.35;
}

.staff-note p {
  margin: 0;
  padding: 0 10px 9px;
  line-height: 1.55;
}

.tab-btn {
  position: relative;
  min-height: 40px;
  border: 0;
  background: transparent;
  color: var(--navy);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 0.95rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: none;
}

.tab-btn.is-active {
  background: linear-gradient(135deg, #24aa9c, #0f8f7a);
  color: #fff;
}

.tab-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.tab-btn.has-pending .tab-badge {
  animation: badgePulse 1.2s ease-in-out infinite;
}

.tab-btn.has-alert {
  animation: tabPulse 0.7s ease-in-out 2;
}

@keyframes tabPulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes badgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.16); }
}

.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 12px 12px 82px;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
  overflow: hidden;
}

.card::before {
  content: "◴";
  position: absolute;
  left: 14px;
  top: 22px;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #e7f7f4;
  color: var(--navy);
  font-size: 1.4rem;
  font-weight: 900;
}

.card-urgent::before {
  content: "◵";
}

.card-urgent {
  border-color: #d9e7ee;
  background: #fff;
  box-shadow: 0 7px 20px rgba(15, 23, 42, 0.08);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 4px;
}

.card-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--navy);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
}

.pill-unconfirmed {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.pill-confirmed {
  background: #dbeafe;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.pill-paid {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.pill-cancelled {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.meta {
  margin: 0 0 5px;
  font-size: 0.86rem;
  color: var(--sub);
}

.items {
  margin: 0 0 8px;
  white-space: pre-wrap;
  line-height: 1.45;
  color: var(--navy);
  font-weight: 700;
}

.order-detail {
  margin: -2px 0 8px;
  color: var(--sub);
  font-size: 0.78rem;
}

.order-detail summary {
  width: fit-content;
  cursor: pointer;
  color: #1d4ed8;
  font-weight: 800;
  line-height: 1.4;
}

.order-detail .meta {
  margin: 3px 0 0;
  font-size: 0.78rem;
}

.row {
  display: grid;
  grid-template-columns: 1fr;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.subtotal {
  font-weight: 700;
  color: var(--navy);
  text-align: right;
  font-size: 1.08rem;
  font-weight: 900;
}

.confirm-btn {
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #24aa9c, #0f8f7a);
  color: #fff;
  padding: 11px 12px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(15, 143, 122, 0.2);
}

.confirm-btn::after,
.pay-btn::after,
.table-pay-btn::after {
  content: "›";
  float: right;
  font-size: 1.3rem;
  line-height: 0.9;
}

.confirm-btn::before {
  content: "";
}

.confirm-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.cancel-btn {
  border: 1px solid #6b7280;
  border-radius: 999px;
  background: #fff;
  color: #64748b;
  padding: 7px 10px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(75, 85, 99, 0.18);
}

.cancel-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.pay-btn {
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #24aa9c, #0f8f7a);
  color: #fff;
  padding: 11px 12px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(15, 143, 122, 0.2);
}

.pay-btn::before {
  content: "";
}

.pay-btn[data-action="undo-paid"]::before {
  content: "";
}

.pay-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.adjust-btn {
  border: 1px solid #0284c7;
  border-radius: 999px;
  background: #fff;
  color: #0369a1;
  padding: 7px 10px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(3, 105, 161, 0.2);
}

.adjust-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.table-pay-btn {
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, #24aa9c, #0f8f7a);
  color: #fff;
  padding: 11px 12px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(15, 157, 108, 0.2);
}

.table-pay-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.staff-bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 1200;
  width: min(460px, 100%);
  transform: translateX(-50%);
  display: grid !important;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid #edf2f8;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -12px 28px rgba(18, 32, 51, 0.12);
}

@supports not (bottom: env(safe-area-inset-bottom)) {
  .staff-bottom-nav {
    padding-bottom: 8px;
  }
}

.staff-bottom-btn {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #64748b;
  font-size: 0.78rem;
  font-weight: 900;
  cursor: pointer;
}

.staff-bottom-btn span {
  font-size: 1.25rem;
  line-height: 1;
}

.staff-bottom-btn.is-active {
  color: var(--accent);
  background: #e8f7f5;
}

.confirm-btn:hover,
.cancel-btn:hover,
.pay-btn:hover,
.adjust-btn:hover,
.table-pay-btn:hover {
  filter: brightness(1.05);
}

.empty {
  border: 1px dashed #cfd6e2;
  border-radius: 10px;
  padding: 16px;
  color: var(--sub);
  background: #fff;
}

.hidden {
  display: none;
}

.section-title-live::before {
  content: "対応中";
}

.section-title-history::before {
  content: "履歴";
}

@media (min-width: 641px) {
  .topbar,
  main,
  .staff-bottom-nav {
    width: min(920px, 100%);
    max-width: 920px;
  }

  main {
    padding: 16px 14px 92px;
  }

  #orders,
  #confirmedOrders,
  #tableSummaries,
  #groups,
  #paidGroups {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #ordersView,
  #checkoutView {
    gap: 14px;
  }
}

@media (max-width: 640px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    padding: 8px;
    gap: 8px;
  }

  .topbar h1 {
    font-size: 0.95rem;
    white-space: nowrap;
  }

  .controls {
    align-items: center;
    justify-content: flex-end;
    flex-direction: row;
    flex: 0 0 auto;
    width: auto;
    gap: 5px;
    flex-wrap: nowrap;
  }

  .app-nav {
    align-items: center;
    flex-direction: row;
    justify-content: flex-end;
    width: auto;
    flex-wrap: nowrap;
  }

  .app-nav a {
    width: auto;
    min-height: 28px;
    padding: 4px 7px;
    border-radius: 5px;
    font-size: 12px;
    text-align: center;
  }

  #refreshBtn {
    width: auto;
    min-height: 32px;
    padding: 4px 9px;
    font-size: 12px;
  }

  #dateInput {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
  }

  .new-order-alert {
    top: 54px;
    grid-template-columns: 1fr;
  }

  .new-order-alert span,
  .new-order-alert button {
    grid-column: 1;
    grid-row: auto;
  }

  main {
    padding: 8px 8px 86px;
  }

  .staff-guide {
    margin-bottom: 8px;
    padding: 7px;
  }

  .staff-guide-head {
    align-items: center;
    margin-bottom: 6px;
  }

  .staff-flow-copy,
  .staff-guide-hide {
    font-size: 0.78rem;
  }

  .workflow-strip {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .workflow-arrow {
    display: none;
  }

  .workflow-step {
    min-height: 40px;
    padding: 6px 8px;
  }

  .workflow-step small {
    display: inline;
    margin-left: 6px;
  }

  .tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .staff-note {
    font-size: 0.82rem;
    margin-bottom: 8px;
  }

  .staff-note summary {
    padding: 6px 8px;
  }

  .staff-note p {
    padding: 0 8px 8px;
  }

  .row {
    align-items: stretch;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    gap: 6px;
  }

  .confirm-btn,
  .cancel-btn,
  .pay-btn,
  .adjust-btn,
  .table-pay-btn {
    min-height: 32px;
    padding: 5px 8px;
    font-size: 13px;
  }

  .card {
    padding: 12px 10px 10px 70px;
  }

  .card::before {
    left: 12px;
    top: 20px;
    width: 44px;
    height: 44px;
  }

  .empty {
    padding: 9px;
  }

  .section-title {
    font-size: 0.84rem;
  }

  .section-title::before {
    display: none;
  }
}
