/* ============================================================
   Restaurant Tools — Embedded Styles (Phase 10)
   Scoped under .restaurant-embed so they don't leak into the
   rest of the light-themed /portal. Originally adapted from
   restaurant.css (the standalone /restaurant page) but with the
   login-screen / sidebar / topbar / app-shell rules stripped —
   the embedded view only ever renders module content into a
   single container, so none of that chrome is needed here.
   ============================================================ */

.restaurant-embed {
  /* Dark-theme tokens matching the portal dashboard.
     Scoped — won't leak out of .restaurant-embed. */
  --bg: #0a0a0a;
  --bg-card: #131313;
  --bg-hover: rgba(255,255,255,0.04);
  --bg-input: rgba(255,255,255,0.06);
  --border: rgba(255,255,255,0.06);
  --border-focus: rgba(212,175,55,0.55);
  --accent: #D4AF37;
  --accent-bright: #E8C847;
  --accent-dim: rgba(212,175,55,0.12);
  --text: #e8e8e8;
  --muted: rgba(255,255,255,0.55);
  --muted2: rgba(255,255,255,0.35);
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --radius: 14px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: calc(100vh - 120px);
  border-radius: 16px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  overflow-y: auto;
}

.restaurant-embed .rt-content {
  padding: 24px;
  animation: rt-fadeIn 0.18s ease;
}

/* Global touch-friendly sizing for all buttons/inputs inside restaurant tools */
.restaurant-embed button,
.restaurant-embed [role="button"] {
  min-height: 44px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.restaurant-embed input[type="text"],
.restaurant-embed input[type="email"],
.restaurant-embed input[type="number"],
.restaurant-embed input[type="password"],
.restaurant-embed input[type="date"],
.restaurant-embed input[type="color"],
.restaurant-embed select,
.restaurant-embed textarea {
  min-height: 44px;
  touch-action: manipulation;
  box-sizing: border-box;
}
.restaurant-embed input[type="checkbox"] {
  width: 20px;
  height: 20px;
  touch-action: manipulation;
}
.restaurant-embed label:has(input[type="checkbox"]) {
  min-height: 44px;
  display: flex;
  align-items: center;
  touch-action: manipulation;
  cursor: pointer;
}
.restaurant-embed td button {
  padding: 10px 16px;
  font-size: 13px;
}
@keyframes rt-fadeIn { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

.restaurant-embed .rt-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.restaurant-embed .rt-toolbar h2 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}
.restaurant-embed .rt-toolbar .rt-subnav {
  display: flex;
  gap: 6px;
  margin-left: auto;
  flex-wrap: wrap;
}
.restaurant-embed .rt-toolbar .rt-subnav button {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font);
}
.restaurant-embed .rt-toolbar .rt-subnav button:hover { color: rgba(255,255,255,0.7); border-color: rgba(255,255,255,0.12); }
.restaurant-embed .rt-toolbar .rt-subnav button.active {
  color: #e8e8e8;
  border-color: rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
}

/* ── Form fields ── */
.restaurant-embed .field { margin-bottom: 16px; }
.restaurant-embed .field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.restaurant-embed .field input,
.restaurant-embed .field select,
.restaurant-embed .field textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
.restaurant-embed .field select option {
  background: #1a1a1a;
  color: #e8e8e8;
}
.restaurant-embed .field input:focus,
.restaurant-embed .field select:focus,
.restaurant-embed .field textarea:focus { border-color: var(--border-focus); }
.restaurant-embed .field input::placeholder,
.restaurant-embed .field textarea::placeholder { color: var(--muted2); }

/* ── Buttons ── */
.restaurant-embed .btn-primary {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  width: 100%;
  padding: 11px 20px;
  background: transparent;
  color: #fff;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 2.2),
              box-shadow 0.3s ease;
}
.restaurant-embed .btn-primary::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -2;
  border-radius: inherit;
  overflow: hidden;
  backdrop-filter: url(#liquid-glass);
  -webkit-backdrop-filter: blur(6px);
}
.restaurant-embed .btn-primary::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  overflow: hidden;
  pointer-events: none;
  box-shadow:
    0 0 8px rgba(0,0,0,0.03),
    0 2px 6px rgba(0,0,0,0.08),
    inset 3px 3px 0.5px -3.5px rgba(255,255,255,0.09),
    inset -3px -3px 0.5px -3.5px rgba(255,255,255,0.85),
    inset 1px 1px 1px -0.5px rgba(255,255,255,0.6),
    inset -1px -1px 1px -0.5px rgba(255,255,255,0.6),
    inset 0 0 6px 6px rgba(255,255,255,0.12),
    inset 0 0 2px 2px rgba(255,255,255,0.06),
    0 0 12px rgba(0,0,0,0.15);
}
.restaurant-embed .btn-primary:hover { transform: scale(1.04); }
.restaurant-embed .btn-primary:active { transform: scale(0.97); }
.restaurant-embed .btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.restaurant-embed .btn-secondary {
  width: 100%;
  padding: 10px 20px;
  background: rgba(255,255,255,0.04);
  color: rgba(255,255,255,0.6);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.restaurant-embed .btn-secondary:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.8);
}

.restaurant-embed .btn-ghost {
  background: none;
  border: none;
  color: var(--muted);
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  padding: 8px;
}
.restaurant-embed .btn-ghost:hover { color: var(--text); }

.restaurant-embed .error-msg {
  color: var(--bad);
  font-size: 13px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: 10px;
}

/* ── Dashboard / KPI cards ── */
.restaurant-embed .kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.restaurant-embed .kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.restaurant-embed .kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 8px;
}
.restaurant-embed .kpi-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
}
.restaurant-embed .kpi-sub {
  font-size: 12px;
  color: var(--muted2);
  margin-top: 4px;
}

/* ── Generic cards ── */
.restaurant-embed .card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  color: var(--text);
}
.restaurant-embed .card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.restaurant-embed .card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

/* ── Tables ── */
.restaurant-embed .data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.restaurant-embed .data-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.restaurant-embed .data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.restaurant-embed .data-table tr:hover td { background: var(--bg-hover); }
.restaurant-embed .data-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.restaurant-embed .status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}
.restaurant-embed .status-dot.online { background: var(--good); }
.restaurant-embed .status-dot.offline { background: var(--muted2); }

/* ── Code display (invite codes etc.) ── */
.restaurant-embed .code-display {
  text-align: center;
  padding: 24px;
  background: var(--accent-dim);
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  margin: 16px 0;
}
.restaurant-embed .code-display .code {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: 10px;
  color: var(--accent);
  font-family: 'Courier New', monospace;
}
.restaurant-embed .code-display .code-info {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

/* ── Empty state ── */
.restaurant-embed .empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.restaurant-embed .empty-state h3 {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 8px;
}

/* ── Loading spinner ── */
.restaurant-embed .loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: var(--muted);
  font-size: 13px;
  gap: 10px;
}
.restaurant-embed .loading-spinner::before {
  content: '';
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: rt-spin 0.6s linear infinite;
}
@keyframes rt-spin { to { transform: rotate(360deg); } }

/* ── Module-specific (allergy/86er) selection rows ── */
.restaurant-embed .ac-item-btn,
.restaurant-embed .es-item-row {
  background: transparent;
  transition: background 0.1s;
}
.restaurant-embed .ac-item-btn:hover,
.restaurant-embed .es-item-row:hover {
  background: var(--bg-hover) !important;
}
.restaurant-embed .ac-item-btn.ac-selected {
  background: var(--accent-dim) !important;
  border-left-color: var(--accent) !important;
}

/* ── Allergen tags / chips ── */
.restaurant-embed .allergen-tag {
  display: inline-block;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
  color: var(--warn);
  background: rgba(245,158,11,0.06);
  border-left: 2px solid var(--warn);
  letter-spacing: 0.2px;
}
.restaurant-embed .allergen-chip {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
}
.restaurant-embed .allergen-chip.selected {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ── Headings inside the embed (override portal h1/h2/h3 styles) ── */
.restaurant-embed h1,
.restaurant-embed h2,
.restaurant-embed h3,
.restaurant-embed h4 { color: var(--text); margin: 0; font-family: var(--font); }
.restaurant-embed p { color: inherit; margin: 0; }
.restaurant-embed a { color: var(--accent); }
.restaurant-embed *,
.restaurant-embed *::before,
.restaurant-embed *::after { box-sizing: border-box; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .restaurant-embed #dashGrid,
  .restaurant-embed #acLayout,
  .restaurant-embed #es86Layout,
  .restaurant-embed #ts-step1-grid { grid-template-columns: 1fr !important; }
  .restaurant-embed .data-table th,
  .restaurant-embed .data-table td { padding: 8px 10px; font-size: 12px; }

  /* Toolbar: stack title and sub-nav vertically so the tabs don't
     get squished against the title on narrow screens. */
  .restaurant-embed .rt-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 16px;
  }
  .restaurant-embed .rt-toolbar .rt-subnav {
    margin-left: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }
  .restaurant-embed .rt-toolbar .rt-subnav::-webkit-scrollbar { display: none; }
  .restaurant-embed .rt-toolbar .rt-subnav button { flex-shrink: 0; }

  /* Allergy checker: allergens panel stacks on top, show as horizontal wrap */
  .restaurant-embed .ac-panels .card:first-child > div:last-child {
    flex-direction: row !important;
    flex-wrap: wrap !important;
  }

  /* TipSplit Step 3 review tables: scroll horizontally instead of
     overflowing the card on narrow phones. */
  .restaurant-embed .card > table,
  .restaurant-embed .data-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Step 1 calendar grid stacked → presets row stays usable */
  .restaurant-embed .ts-preset { font-size: 11px; }

  /* 86er left-panel max-height was tied to viewport — recalc with
     room for the toolbar + page chrome on mobile. */
  .restaurant-embed #es86Layout > .card[style*="max-height"] {
    max-height: none !important;
  }
}
@media (max-width: 640px) {
  .restaurant-embed { border-radius: 0; border-left: none; border-right: none; }
  .restaurant-embed .rt-content { padding: 12px; }
  .restaurant-embed .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .restaurant-embed .kpi-card { padding: 14px; }
  .restaurant-embed .kpi-value { font-size: 22px; }
  .restaurant-embed .card { padding: 14px; }
  .restaurant-embed .card-header { flex-wrap: wrap; gap: 8px; }

  /* Modals: full-width on tiny screens so action buttons don't
     get cropped behind the safe area. */
  .restaurant-embed-modal,
  .restaurant-embed [role="dialog"] {
    max-width: 100% !important;
    margin: 0 !important;
  }

  /* Catch-all collapse for inline `1fr 1fr` and `1fr 1fr 1fr` grids
     used throughout the tool modules (PreShift create form, TipSplit
     wizard, modal forms, etc). The 7-column calendar widget uses
     `repeat(7,1fr)` so it's untouched by this selector. */
  .restaurant-embed [style*="grid-template-columns:1fr 1fr"],
  .restaurant-embed [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Inputs at 16px to prevent iOS focus zoom. */
  .restaurant-embed input,
  .restaurant-embed select,
  .restaurant-embed textarea { font-size: 16px !important; }

  /* Staff rows in Manage: let the trailing meta drop below the
     name+badges block instead of pinching it on narrow phones. */
  .restaurant-embed .staff-row {
    flex-wrap: wrap;
    row-gap: 4px;
  }
  .restaurant-embed .staff-row > div:last-child {
    flex-basis: 100%;
    margin-left: 18px;
  }
}

/* ============================================================
   PHASE A (2026-04-11): Touchscreen polish
   All rules here target tablet/phone/touch devices so the
   restaurant portal feels native on The Keg's demo hardware.
   Desktop-with-mouse is unchanged.
   ============================================================ */

/* Kill the 300 ms tap delay + the ugly iOS blue tap highlight on
   interactive elements. We provide our own :active feedback below. */
.restaurant-embed button,
.restaurant-embed a,
.restaurant-embed [role="button"],
.restaurant-embed label,
.restaurant-embed input[type="checkbox"],
.restaurant-embed input[type="radio"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Modals created inline by restaurant-modules/*.js attach to
   document.body with `position:fixed; inset:0; flex-center`. These
   selectors reach them without requiring `.restaurant-embed` as an
   ancestor — the attribute matcher catches any inline-styled overlay
   following the shared pattern. On narrow phones the inner dialog
   goes edge-to-edge so action buttons don't clip off-screen. */
@media (max-width: 640px) {
  body > div[style*="position:fixed"][style*="inset:0"][style*="justify-content:center"] {
    padding: 0 !important;
    align-items: stretch !important;
  }
  body > div[style*="position:fixed"][style*="inset:0"][style*="justify-content:center"] > div {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 100% !important;
    height: 100% !important;
    border-radius: 0 !important;
    border-left: none !important;
    border-right: none !important;
    margin: 0 !important;
    overflow-y: auto !important;
    padding-top: max(18px, env(safe-area-inset-top)) !important;
    padding-bottom: max(18px, env(safe-area-inset-bottom)) !important;
  }
}

/* Minimum 44×44 tap targets on touch devices or narrow widths.
   Desktop-with-mouse stays dense. The third breakpoint catches
   devices that report fine pointers but are still narrow (rare
   but possible on split-screen tablets). */
@media (hover: none), (pointer: coarse), (max-width: 768px) {
  .restaurant-embed button,
  .restaurant-embed .btn-primary,
  .restaurant-embed .btn-secondary,
  .restaurant-embed .btn-ghost,
  body > div[style*="position:fixed"][style*="inset:0"] button {
    min-height: 44px;
    min-width: 44px;
  }
  .restaurant-embed .rt-toolbar .rt-subnav button {
    padding: 10px 16px;
    font-size: 13px;
  }
  body > div[style*="position:fixed"][style*="inset:0"] button[id$="Close"],
  body > div[style*="position:fixed"][style*="inset:0"] button[aria-label="Close"],
  .restaurant-embed button[aria-label="Close"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 22px !important;
  }
  /* Checkbox/radio inputs need to be finger-friendly too. The
     default 13×13 native checkbox is unusable on touch. */
  .restaurant-embed input[type="checkbox"],
  .restaurant-embed input[type="radio"] {
    width: 20px !important;
    height: 20px !important;
  }
}

/* Replace :hover-only feedback with :active press states on touch
   devices. Users on iPad can't hover, so the row/button highlight
   rules earlier in this file do nothing — these :active rules give
   immediate tactile confirmation on tap. */
@media (hover: none) {
  .restaurant-embed .rt-toolbar .rt-subnav button:active {
    background: rgba(255,255,255,0.12) !important;
    color: #e8e8e8 !important;
  }
  .restaurant-embed .data-table tbody tr:active td {
    background: var(--bg-hover) !important;
  }
  .restaurant-embed .ac-item-btn:active,
  .restaurant-embed .es-item-row:active {
    background: var(--bg-hover) !important;
  }
  .restaurant-embed .btn-secondary:active {
    background: rgba(255,255,255,0.12) !important;
    transform: scale(0.98);
  }
  .restaurant-embed .allergen-chip:active {
    background: var(--accent-dim) !important;
    border-color: var(--accent) !important;
  }
}

/* Safe-area padding for notched phones. At ≤640px the embed goes
   edge-to-edge (border-radius:0), so content would otherwise sit
   under the Dynamic Island or home indicator. */
@media (max-width: 640px) {
  .restaurant-embed {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .restaurant-embed .rt-content {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

/* Readable labels + table headers at phone size. 11 px is fine on
   a desktop monitor at arm's length but invisible on a 6″ phone. */
@media (max-width: 640px) {
  .restaurant-embed .kpi-label,
  .restaurant-embed .data-table th,
  .restaurant-embed .allergen-tag {
    font-size: 12px !important;
  }
  .restaurant-embed .field label {
    font-size: 13px !important;
  }
}
