body { min-width: 0; overflow-x: hidden; }

button, input, select, textarea {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
}

input, select, textarea {
  width: 100%;
  min-width: 0;
  padding: 9px 11px;
}

input, select { height: var(--control-height); }
textarea { min-height: 88px; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #b9c1cc; }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  outline: 2px solid color-mix(in srgb, var(--primary) 28%, transparent);
  outline-offset: 0;
}

button {
  min-height: var(--control-height);
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 600;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

button:hover:not(:disabled) { background: var(--surface-secondary); }
button:active:not(:disabled) { background: #f0f2f5; }
button:disabled { cursor: not-allowed; opacity: .5; filter: saturate(.6); }
.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.secondary { background: var(--surface); }
.danger { color: var(--danger); border-color: #e6b5ae; background: var(--surface); }
.danger:hover:not(:disabled) { background: var(--danger-soft); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}

.muted { color: var(--text-secondary); }
.error, .required { color: var(--danger); }
.error { min-height: 1em; line-height: 1.5; white-space: pre-line; }
.grow { flex: 1; min-width: 0; }
.eyebrow {
  display: block;
  margin: 0 0 4px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
}
.brand-mark img { display: block; width: 44px; height: 44px; }
.brand-copy { display: grid; gap: 2px; min-width: 0; }
.brand-copy strong { font-size: 17px; line-height: 1.15; }
.brand-copy small { color: var(--text-secondary); font-size: 12px; white-space: nowrap; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(400px, 100%); padding: 32px; display: grid; gap: 8px; }
.login-brand-mark { margin-bottom: 6px; }
.login-card .eyebrow { margin: 0; }
.login-card h1 { margin: 0 0 10px; font-size: 30px; line-height: 1.25; }
.login-card label { display: grid; gap: 6px; margin-top: 7px; font-size: 13px; font-weight: 600; }
.login-card .primary { width: 100%; margin-top: 12px; }
.login-card .error { margin: 4px 0 0; }

.topbar {
  width: min(100%, 1280px);
  margin: 0 auto;
  padding: 28px 32px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.top-actions { display: flex; align-items: center; gap: 8px; }
.compact-button { min-height: 32px; padding: 0 10px; font-size: 13px; }
.status {
  min-height: 40px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--success);
  font-size: 12px;
  font-weight: 600;
}
.status::before {
  content: "";
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  background: center / contain no-repeat url('/assets/icons/sync-synced.svg');
}
.status.is-error { color: var(--danger); }
.status.is-error::before { background-image: url('/assets/icons/sync-error.svg'); }
.status.is-pending { color: var(--text-secondary); }
.status.is-pending::before { background-image: url('/assets/icons/sync-pending.svg'); }

.shell { width: min(100%, 1280px); margin: 0 auto; padding: 20px 32px 40px; }
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}
.page-head h1 { margin: 0; font-size: 30px; line-height: 1.2; }
.page-head p { margin: 8px 0 0; line-height: 1.6; }
.case-heading { align-items: center; }

.toolbar {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}
.toolbar label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.toolbar input { width: auto; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric {
  min-width: 0;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}
.metric > span { display: block; color: var(--text-secondary); font-size: 12px; }
.metric strong { display: block; margin-top: 10px; font-size: 28px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.metric strong small { color: var(--text-muted); font-size: 12px; font-weight: 600; }
.list-panel { overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); box-shadow: var(--shadow-card); }
.panel-head { padding: 18px 20px 0; }
.panel-head h2 { margin: 0; font-size: 18px; line-height: 1.3; }
.panel-head p { margin: 5px 0 0; color: var(--text-secondary); font-size: 12px; }
.table-wrap { width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; }
table { width: 100%; min-width: 820px; border-collapse: collapse; }
th, td { padding: 13px 16px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: var(--surface-secondary); color: var(--text-secondary); font-size: 12px; font-weight: 650; white-space: nowrap; }
tbody tr { transition: background 120ms ease; }
tbody tr:hover { background: #f8fbff; }
.reservation-time { color: var(--primary); font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.reservation-customer strong { display: block; }
.reservation-items { max-width: 360px; line-height: 1.55; }
.reservation-total { font-variant-numeric: tabular-nums; white-space: nowrap; }
.sub { display: block; margin-top: 3px; color: var(--text-secondary); font-size: 12px; line-height: 1.45; }
.row-action { width: 1%; white-space: nowrap; }
.row-action button { min-height: 32px; padding: 0 10px; font-size: 13px; }
.empty { padding: 48px 20px; text-align: center; color: var(--text-secondary); }
.table-footer { min-height: 44px; padding: 12px 16px; background: var(--surface-secondary); color: var(--text-secondary); font-size: 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  width: max-content;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; overflow-x: auto; }
.tab {
  min-height: 36px;
  padding: 0 11px;
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);
  white-space: nowrap;
}
.tab:hover:not(:disabled) { background: var(--surface-secondary); color: var(--text); }
.tab.active { background: var(--primary-soft); color: var(--primary); }

.panel { padding: 22px; }
.panel h2 { margin: 0 0 8px; font-size: 19px; line-height: 1.3; }
.section-head, .actions, .dialog-head, .customer-header { display: flex; align-items: center; gap: 12px; }
.section-head { justify-content: space-between; }
.section-head p { margin: 5px 0 0; font-size: 12px; line-height: 1.55; }
.actions { justify-content: flex-end; flex-wrap: wrap; margin-top: 20px; }
hr { margin: 24px 0; border: 0; border-top: 1px solid var(--border); }

.quantity-list { display: grid; gap: 8px; margin: 14px 0; }
.quantity-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 40px 64px 40px 40px;
  gap: 6px;
  align-items: center;
}
.quantity-row button { min-width: 40px; padding: 0; font-size: 18px; }
.quantity-row button:last-child { color: var(--danger); }
.quantity-number { text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.quantity-label { display: grid; gap: 6px; min-width: 0; font-size: 12px; }
.quantity-row > button { align-self: end; }
.quantity-label > span:first-child { color: var(--text-secondary); overflow-wrap: anywhere; }
.quantity-label .quantity-number { height: var(--control-height); display: grid; place-items: center; }
#reservationInputSummary { overflow-wrap: anywhere; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px 12px; }
.form-grid label, .dialog-body > label, .detail-form label {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}
.form-grid .wide { grid-column: 1 / -1; }
.quantity-extra { grid-column: 1 / -1; }
.quantity-extra:empty { display: none; }
.page-head .case-number { margin: 5px 0 0; color: var(--text-secondary); font-size: 12px; font-weight: 500; overflow-wrap: anywhere; }
.settings-group { display: grid; gap: 10px; }
.settings-group > b { font-size: 13px; }
.field-config-list { display: grid; gap: 10px; }
.field-config-row { display: grid; grid-template-columns: minmax(100px,1fr) auto; gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-table); background: var(--surface); }
.field-config-controls { display: flex; align-items: center; gap: 6px; grid-column: 1 / -1; grid-row: 2; justify-content: flex-end; }
.field-config-controls > label { display: flex; align-items: center; gap: 4px; white-space: nowrap; font-size: 12px; }
.field-config-row input[type=checkbox] { width: 18px; min-height: 18px; }
.field-config-row button, .preset-row button { min-height: 32px; padding: 0 10px; font-size: 13px; }
.field-config-controls button { min-width: 32px; }
.field-config-add { justify-self: start; }
.settings-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 2px; }
.preset-list { display: grid; gap: 9px; }
.preset-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: center; }
#inputSettingsDialog .danger { color: var(--danger); border-color: #e6b5ae; }
#inputSettingsDialog .danger:hover { background: var(--danger-soft); }
.settings-button { width: 40px; min-width: 40px; padding: 0; }
.detail-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(100px, 1fr)) auto;
  gap: 8px;
  align-items: end;
  margin: 18px 0;
}
.detail-list, .reconciliation { display: grid; gap: 8px; margin-top: 16px; }
.detail-row, .reconcile-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-table);
  background: var(--surface);
}
.reconcile-row { grid-template-columns: 1fr; background: var(--surface-secondary); }

.customer-shell { min-height: 100vh; background: var(--bg); }
.customer-header {
  width: min(100%, 1280px);
  margin: 0 auto;
  padding: 28px 32px 0;
  justify-content: space-between;
}
.customer-main { max-width: 760px; margin: 0 auto; padding: 20px 32px 40px; }
.customer-card { padding: 28px; }
.customer-card h1 { margin: 4px 0 10px; font-size: 30px; line-height: 1.25; }
.customer-card > p:not(.step) { color: var(--text-secondary); line-height: 1.6; }
.step { margin: 0; color: var(--primary); font-size: 12px; font-weight: 700; letter-spacing: .08em; }
.full { width: 100%; margin-top: 22px; }
.terms-list { display: grid; gap: 12px; margin: 20px 0; }
.term-row { padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-table); }
.term-row label { display: flex; align-items: flex-start; gap: 12px; font-weight: 600; line-height: 1.5; }
.term-row input { width: 22px; height: 22px; min-height: 22px; margin-top: 0; flex: 0 0 auto; }
.link-button { min-height: 32px; margin: 7px 0 0 34px; padding: 0; border: 0; background: transparent; color: var(--primary); font-size: 13px; }
.link-button:hover:not(:disabled) { background: transparent; color: var(--primary-hover); }
#signatureCanvas {
  display: block;
  width: 100%;
  height: 240px;
  margin: 18px 0;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  touch-action: none;
}
.complete { padding: 60px 28px; text-align: center; }
.complete h1 { color: var(--success); }

dialog {
  width: min(620px, calc(100% - 32px));
  max-height: calc(100dvh - 40px);
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-dialog);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .2);
}
dialog::backdrop { background: rgba(16, 24, 40, .5); }
.dialog-body { max-height: calc(100dvh - 40px); padding: 24px; display: grid; gap: 16px; overflow-y: auto; }
.dialog-head { align-items: flex-start; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 20px; line-height: 1.3; }
.dialog-body h3 { margin: 5px 0 -4px; font-size: 16px; }
.icon-button {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  flex: 0 0 40px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
}
.icon-button:hover:not(:disabled) { background: var(--surface-secondary); color: var(--text); }
.terms-body { line-height: 1.8; white-space: pre-line; }
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: var(--radius-control);
  background: #25282d;
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .16);
}

@media (max-width: 1023px) {
  .topbar, .customer-header { padding: 24px 24px 0; }
  .shell, .customer-main { padding: 18px 24px 28px; }
  .page-head { align-items: stretch; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-form button { grid-column: 1 / -1; }
  .detail-row { grid-template-columns: 1fr auto; }
  .detail-row span:nth-child(n + 3) { grid-column: 1 / -1; }
}

@media (max-width: 599px) {
  .login-shell { display: block; padding: 16px; }
  .login-card { width: 100%; margin: 10vh auto 0; padding: 24px 20px; }
  .login-card h1 { font-size: 22px; }
  .brand-mark, .brand-mark img { width: 40px; height: 40px; }
  .brand-mark { border-radius: 10px; }
  .brand-copy small { display: none; }
  .topbar, .customer-header { padding: 18px 16px 0; }
  .shell, .customer-main { padding: 18px 16px 28px; }
  .top-actions { gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  #inputSettingsButton { width: 44px; min-height: 44px; padding: 0; }
  .field-config-row { grid-template-columns: minmax(100px,1fr) auto 32px 32px; }
  .field-config-row > button:last-of-type { grid-column: 1 / -1; }
  .top-actions .status { width: 44px; padding: 0; font-size: 0; justify-content: center; }
  .compact-button { width: 44px; min-height: 44px; padding: 0; }
  .compact-button .button-label { display: none; }
  .page-head { align-items: flex-start; flex-direction: column; gap: 16px; margin-bottom: 16px; }
  .page-head h1, .customer-card h1 { font-size: 22px; }
  .page-head p { margin-top: 6px; font-size: 13px; }
  .page-head > .primary { width: 100%; }
  .case-heading { flex-direction: row; align-items: center; }
  .case-heading h1 { font-size: 18px; overflow-wrap: anywhere; }
  .case-heading #backButton { width: 44px; min-width: 44px; padding: 0; font-size: 0; }
  .metrics { gap: 8px; }
  .metric { padding: 14px; }
  .metric strong { font-size: 24px; }
  .panel-head { padding: 16px 16px 0; }
  .panel-head p { display: none; }
  .toolbar { align-items: stretch; flex-wrap: wrap; padding: 12px; }
  .toolbar label { width: 100%; justify-content: space-between; }
  .toolbar input { width: min(190px, 64vw); }
  .toolbar #todayButton { flex: 1; }
  .table-wrap { overflow: visible; }
  table, tbody { display: block; min-width: 0; width: 100%; }
  thead { display: none; }
  tbody { display: grid; gap: 8px; padding: 10px 12px 12px; }
  tbody tr {
    position: relative;
    display: grid;
    grid-template-columns: 70px minmax(0, 1fr) auto;
    gap: 8px 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-table);
    background: var(--surface);
  }
  tbody td { display: block; min-width: 0; padding: 0; border: 0; }
  tbody td::before { content: attr(data-label); display: block; margin-bottom: 2px; color: var(--text-secondary); font-size: 11px; font-weight: 600; }
  tbody .reservation-time { grid-column: 1; grid-row: 1; padding-top: 16px; font-size: 20px; }
  tbody .reservation-time::before, tbody .reservation-customer::before, tbody .row-action::before { display: none; }
  tbody .reservation-customer { grid-column: 2 / 4; grid-row: 1; }
  tbody .reservation-items { grid-column: 1 / 4; grid-row: 2; max-width: none; }
  tbody .reservation-total { grid-column: 1 / 2; grid-row: 3; }
  tbody td:nth-child(5) { grid-column: 2 / 3; grid-row: 3; align-self: end; }
  tbody .row-action { grid-column: 3; grid-row: 3; width: auto; }
  tbody .row-action button { min-height: 44px; }
  .table-footer { padding: 11px 14px; }
  .tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .tab { min-height: 44px; padding: 0 8px; }
  .panel { padding: 16px; }
  .section-head { align-items: flex-start; }
  .form-grid, .detail-form { grid-template-columns: 1fr; }
  .quantity-row { grid-template-columns: minmax(100px, 1fr) 44px 48px 44px 44px; }
  .quantity-row button { min-height: 44px; }
  .actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .actions button { width: 100%; }
  #receiptPanel .actions { grid-template-columns: 1fr; }
  .customer-header > .secondary { width: 44px; padding: 0; font-size: 0; }
  .customer-card { padding: 20px; }
  dialog { width: 100%; max-width: none; max-height: 100dvh; margin: auto 0 0; border-radius: 14px 14px 0 0; }
  .dialog-body { max-height: 100dvh; padding: 18px 16px 20px; }
  .icon-button { width: 44px; height: 44px; flex-basis: 44px; }
  .settings-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .field-config-row button, .preset-row button { min-height: 44px; }
  .toast { left: 16px; right: 16px; bottom: 16px; max-width: none; }
}

@media (max-width: 390px) {
  .metrics { grid-template-columns: 1fr; }
  .tabs { grid-template-columns: 1fr; }
  .quantity-row { grid-template-columns: minmax(92px, 1fr) 40px 38px 40px 40px; gap: 4px; }
  .actions { grid-template-columns: 1fr; }
}
