/* ==========================================================================
   ThePeely — shared "mini-app" shell
   Used by crm.html, bookings.html, pos.html
   ========================================================================== */

.app-body {
  background: var(--off-white);
  min-height: 100vh;
}

.app-topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 200;
}

.app-topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-brand img { width: 28px; height: 28px; }
.app-brand .name { font-weight: 700; font-size: 1.05rem; }
.app-brand .sep { color: var(--gray); }
.app-brand .app-name { font-weight: 600; color: var(--charcoal-soft); }

/* The customer's own business name, shown next to ThePeely once they've set
   one (or when they're inside a team workspace). */
.app-brand .peely-company {
  font-weight: 700;
  font-size: 1.02rem;
  color: var(--charcoal);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-brand .peely-company-sep { color: var(--yellow-dark); font-weight: 700; }

@media (max-width: 640px) {
  .app-brand .peely-company { max-width: 110px; }
  .app-brand .name { display: none; }
  .app-brand .peely-company-sep { display: none; }
}

.app-back {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--charcoal-soft);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.app-back:hover { color: var(--charcoal); }

.app-topbar-actions { display: flex; align-items: center; gap: 12px; }

.tier-pill {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(28,28,30,0.06);
  color: var(--charcoal-soft);
}

.app-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}
.app-header h1 { margin-bottom: 4px; font-size: clamp(1.6rem, 3vw, 2.1rem); }
.app-header p { margin: 0; }

/* ---------- Limit banner ---------- */
.limit-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: rgba(255, 204, 41, 0.16);
  border: 1px solid rgba(242, 183, 5, 0.35);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  margin-bottom: 24px;
  font-size: 0.92rem;
}
.limit-banner strong { color: var(--charcoal); }
.limit-banner.is-full {
  background: rgba(28,28,30,0.05);
  border-color: var(--border);
}

/* ---------- Panels / cards ---------- */
.app-panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
}

.app-toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}
.app-toolbar input[type="text"],
.app-toolbar input[type="search"] {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.92rem;
  background: var(--off-white);
  min-width: 220px;
}

.btn-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28,28,30,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--white);
  border-radius: var(--radius-md);
  max-width: 440px;
  width: 100%;
  padding: 32px;
  position: relative;
  box-shadow: var(--shadow-lg);
}
.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--gray);
  line-height: 1;
}
.modal-box h3 { margin-bottom: 8px; }
.modal-box ul { padding-left: 20px; margin: 16px 0; color: var(--charcoal-soft); font-size: 0.92rem; }
.modal-box li { margin-bottom: 6px; }
.modal-price { font-size: 1.8rem; font-weight: 700; margin: 4px 0 0; }
.modal-price span { font-size: 0.95rem; font-weight: 500; color: var(--gray); }

.modal-box.modal-wide { max-width: 560px; max-height: 82vh; overflow-y: auto; }
.modal-box ol.modal-steps { padding-left: 20px; margin: 12px 0 20px; color: var(--charcoal-soft); font-size: 0.92rem; }
.modal-box ol.modal-steps li { margin-bottom: 8px; }
.modal-unique-heading { font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--gray); margin: 4px 0 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--charcoal);
  color: var(--white);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1100;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Simple table ---------- */
.app-table { width: 100%; border-collapse: collapse; }
.app-table th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.app-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
  vertical-align: middle;
}
.app-table tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 10px; }
.row-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--charcoal-soft);
  padding: 2px 4px;
}
.row-actions button:hover { color: var(--charcoal); }
.row-actions .danger:hover { color: #C0392B; }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray);
}

.tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tag-lead { background: rgba(58,58,60,0.08); color: var(--charcoal-soft); }
.tag-contacted { background: rgba(74,134,232,0.12); color: #2E5FB0; }
.tag-won { background: rgba(143,191,107,0.18); color: var(--green-dark); }
.tag-lost { background: rgba(192,57,43,0.1); color: #C0392B; }

/* ---------- Kanban (CRM) ---------- */
.kanban {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
@media (max-width: 900px) { .kanban { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .kanban { grid-template-columns: 1fr; } }

.kanban-col {
  background: var(--off-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  min-height: 120px;
}
.kanban-col h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray);
  margin: 0 0 12px;
  display: flex;
  justify-content: space-between;
}
.kanban-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
  font-size: 0.88rem;
}
.kanban-card .kc-name { font-weight: 600; margin-bottom: 2px; }
.kanban-card .kc-meta { color: var(--gray); font-size: 0.78rem; margin-bottom: 8px; }
.kanban-card select {
  width: 100%;
  font-size: 0.78rem;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-top: 4px;
}
.kanban-card .row-actions { margin-top: 8px; }

/* ---------- Booking slots ---------- */
.slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
  margin: 16px 0;
}
.slot-btn {
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--white);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.slot-btn.taken {
  background: rgba(28,28,30,0.04);
  color: var(--gray);
  cursor: not-allowed;
  text-decoration: line-through;
}
.slot-btn.selected {
  background: var(--charcoal);
  color: var(--white);
  border-color: var(--charcoal);
}

/* ---------- POS ---------- */
.pos-layout {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 24px;
  align-items: flex-start;
}
@media (max-width: 900px) { .pos-layout { grid-template-columns: 1fr; } }

.pos-products {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}
.pos-product {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 14px;
  cursor: pointer;
  text-align: left;
}
.pos-product:hover { border-color: var(--yellow-dark); }
.pos-product .pp-name { font-weight: 600; margin-bottom: 4px; font-size: 0.92rem; }
.pos-product .pp-price { color: var(--gray); font-size: 0.85rem; }

.cart-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.cart-line .cl-name { font-weight: 600; }
.cart-line .cl-qty {
  display: flex;
  align-items: center;
  gap: 6px;
}
.cart-line .cl-qty button {
  width: 22px; height: 22px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--off-white);
  cursor: pointer;
  font-weight: 700;
}

.cart-totals { margin-top: 16px; font-size: 0.92rem; }
.cart-totals .row { display: flex; justify-content: space-between; padding: 4px 0; }
.cart-totals .grand { font-size: 1.15rem; font-weight: 700; border-top: 1px solid var(--border); margin-top: 8px; padding-top: 10px; }

.receipt {
  background: var(--off-white);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 0.85rem;
  margin-top: 12px;
}
.receipt-line { display: flex; justify-content: space-between; padding: 2px 0; }

/* ---- Printing --------------------------------------------------------
   Two modes:
   1. Targeted: JS adds .peely-printing to <body> and .peely-print-target to
      one element (a receipt, an invoice, a report). Only that prints.
   2. Default: plain Ctrl+P on any app page hides chrome (nav, buttons,
      modals, toolbars) so the content prints cleanly instead of dumping
      the whole UI onto paper.
------------------------------------------------------------------------ */
@media print {
  .app-topbar, .nav, .footer, .limit-banner, .modal-overlay,
  .app-toolbar, .peely-toast, .btn, .app-back, .cat-tabs,
  .pos-scan-row, .row-actions, .install-banner {
    display: none !important;
  }
  body, .app-body { background: #fff !important; }
  .app-main { max-width: 100% !important; padding: 0 !important; margin: 0 !important; }
  .app-panel {
    border: none !important; box-shadow: none !important;
    padding: 0 !important; margin: 0 0 16px !important; break-inside: avoid;
  }
  a[href]::after { content: ""; }
  table { break-inside: auto; }
  tr { break-inside: avoid; }
  thead { display: table-header-group; }
}

/* Targeted print: only the flagged element is visible on paper. */
@media print {
  body.peely-printing * { visibility: hidden !important; }
  body.peely-printing .peely-print-target,
  body.peely-printing .peely-print-target * { visibility: visible !important; }
  body.peely-printing .peely-print-target {
    position: absolute !important;
    left: 0; top: 0; width: 100%;
    border: none !important; box-shadow: none !important;
    padding: 0 !important; margin: 0 !important;
  }
}

/* =====================================================================
   MOBILE
   Phones are where a POS gets used at a counter and a booking gets
   checked between clients, so these aren't cosmetic tweaks.
   Targets the real failure modes: inputs wider than the screen, tables
   with no escape hatch, a top bar carrying eight controls, tap targets
   too small to hit, and iOS zooming the page on every field focus.
===================================================================== */

/* --- Tablets and below ------------------------------------------- */
@media (max-width: 900px) {
  .app-main { padding: 24px 16px 64px; }
  .app-topbar-inner { padding: 12px 16px; gap: 10px; }
  .app-header { flex-direction: column; align-items: flex-start; gap: 12px; }
}

/* --- Phones ------------------------------------------------------- */
@media (max-width: 640px) {
  /* Top bar: let the controls wrap instead of squeezing, and keep the
     brand on its own line so the app name stays readable. */
  .app-topbar-inner { flex-wrap: wrap; row-gap: 10px; }
  .app-brand { width: 100%; }
  .app-topbar-actions {
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
  }
  .app-topbar-actions .btn { font-size: 0.8rem; padding: 7px 12px; }
  /* The signed-in email is the least useful thing here on a small
     screen — the workspace badge and the buttons matter more. */
  #auth-status > span:not(.peely-company) { font-size: 0.78rem; }

  /* Inputs: 16px minimum stops iOS zooming in on focus, and the fixed
     220px minimum was wider than the content box on a small phone. */
  .app-toolbar { gap: 8px; }
  .app-toolbar input[type="text"],
  .app-toolbar input[type="search"],
  .app-toolbar input[type="number"],
  .app-toolbar input[type="date"],
  .app-toolbar input[type="time"],
  .app-toolbar select,
  .app-panel input,
  .app-panel select,
  .app-panel textarea,
  .form-card input,
  .form-card select,
  .form-card textarea {
    font-size: 16px;
    min-width: 0;
    max-width: 100%;
  }
  .app-toolbar input[type="text"],
  .app-toolbar input[type="search"] { flex: 1 1 100%; }
  .app-toolbar .btn { flex: 1 1 auto; justify-content: center; }

  /* Tables: give them a horizontal scroll rather than letting a
     six-column product list blow out the page width. */
  .app-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .app-table th, .app-table td { padding: 10px 8px; font-size: 0.86rem; }

  /* Tap targets. 44px is the accessibility floor for a finger. */
  .row-actions { gap: 6px; }
  .row-actions button,
  .cl-qty button,
  .cat-tab,
  .pay-method {
    min-height: 44px;
    min-width: 44px;
  }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; }

  /* Panels and cards */
  .app-panel { padding: 18px 16px; }
  .limit-banner { flex-direction: column; align-items: flex-start; gap: 10px; }

  /* Modals: full-width with breathing room, and scrollable when the
     content is taller than the screen. */
  .modal-overlay { padding: 12px; align-items: flex-start; }
  .modal-box { padding: 24px 20px; margin-top: 24px; max-height: 88vh; overflow-y: auto; }
  .modal-box.modal-wide { max-height: 88vh; }

  /* POS */
  .pos-products { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .pos-scan-row { flex-direction: column; }
  .pos-scan-row input { font-size: 16px; }
  .cart-line { flex-wrap: wrap; gap: 6px; }

  /* Dashboard */
  .dash-app-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .ws-row { flex-direction: column; align-items: flex-start; }
}

/* --- Small phones (iPhone SE and similar) ------------------------- */
@media (max-width: 380px) {
  .app-main { padding: 20px 12px 56px; }
  .app-topbar-actions .btn { font-size: 0.76rem; padding: 7px 10px; }
  .pos-products { grid-template-columns: repeat(2, 1fr); }
  .dash-app-grid { grid-template-columns: repeat(2, 1fr); }
}
