:root {
  --ink: #1a1a1a;
  --sub: #6b7280;
  --border: #e5e7eb;
  --bubble-me: #1a1a1a;
  --bubble-agent: #f0f0f0;
  /* The nav's height is pinned here because the chat layout sizes itself
     against it (100vh minus this). It used to be a 53px literal duplicated
     in the chat rule, so anything that changed the nav's contents — a logo,
     a taller link — silently pushed the composer off the bottom of the
     screen. One value, used by both. */
  --nav-h: 53px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: #fafafa;
}

/* --- Login --- */

.login-body { background: #fafafa; }

.login-wrap {
  max-width: 420px;
  margin: 0 auto;
  padding: 80px 24px;
}

.login-mark { display: block; color: var(--ink); margin: 0 0 14px; }

.card h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 32px;
  font-weight: 400;
  margin: 0 0 12px;
}

.sub { color: var(--sub); font-size: 15px; line-height: 1.5; margin: 0 0 24px; }

form { display: flex; gap: 8px; margin-bottom: 12px; }

input[type="tel"], input[type="text"], input[type="number"] {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
}

button[type="submit"] {
  padding: 11px 18px;
  border: none;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  font-size: 14px;
  cursor: pointer;
}
button[type="submit"]:disabled { opacity: 0.5; cursor: default; }

.link-button {
  background: none;
  border: none;
  color: var(--sub);
  text-decoration: underline;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
}

.error { color: #d02c2c; font-size: 14px; }

[hidden] { display: none !important; }

/* --- Shared portal nav (dashboard/orders/account/vault) --- */

.portal-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: var(--nav-h);
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: white;
}
.portal-nav .nav-links { display: flex; gap: 18px; align-items: center; }
.portal-nav .nav-links a {
  color: var(--sub);
  text-decoration: none;
  font-size: 14px;
  padding: 4px 2px;
  border-bottom: 2px solid transparent;
}
.portal-nav .nav-links a:hover { color: var(--ink); }
.portal-nav .nav-links a.active { color: var(--ink); font-weight: 600; border-bottom-color: var(--ink); }
.portal-nav h2 { font-size: 16px; margin: 0; }

/* Brand: the mark plus the wordmark, as one link back to the chat. The
   whole thing is the target, not just the glyph — a logo people can see is
   a logo people will click, and a 24px circle is a small thing to hit. */
.portal-nav .brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  text-decoration: none;
  /* Pulled back by its own padding so the mark still lines up with the
     page gutter while the hover target extends past it. */
  padding: 6px 8px;
  margin-left: -8px;
  border-radius: 9px;
}
.portal-nav .brand:hover { background: #f4f4f5; }
.portal-nav .brand:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.portal-nav .brand-name { font-size: 16px; font-weight: 600; letter-spacing: -0.015em; }
.portal-nav .brand-mark {
  display: block;
  color: var(--ink);
  /* The gap and its bead sit at the top right, so rotating on hover swings
     them around the ring — the one moving part the mark has. */
  transition: transform 400ms cubic-bezier(0.22, 1, 0.36, 1);
}
.portal-nav .brand:hover .brand-mark { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) {
  .portal-nav .brand-mark { transition: none; }
  .portal-nav .brand:hover .brand-mark { transform: none; }
}

/* On a phone the nav already ran off the side of the screen before the logo
   existed — measured 408px of content in a 390px viewport, so "Vault" and
   "Log out" were simply unreachable. Drop the wordmark (the mark alone still
   identifies and still links) and tighten the spacing, rather than letting a
   wider brand make an existing overflow worse. */
@media (max-width: 600px) {
  .portal-nav { padding: 0 12px; }
  .portal-nav .brand { gap: 0; padding: 6px; margin-left: -6px; }
  .portal-nav .brand-name { display: none; }
  .portal-nav .nav-links { gap: 12px; }
  .portal-nav .nav-links a { font-size: 13px; }
}
.portal-nav button { background: none; border: none; color: var(--sub); cursor: pointer; font-size: 13px; }

.portal-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}
.portal-page h1 { font-family: Georgia, "Times New Roman", serif; font-size: 26px; font-weight: 400; margin: 0 0 6px; }
.portal-section {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
}
.portal-section h3 { font-size: 15px; margin: 0 0 14px; }
.saved-note { color: #15803d; font-size: 13px; }

/* Overrides the generic `form { display:flex }` (single-row, no-wrap,
   meant for the one-line login/vault-add forms) — these forms hold
   several fields plus a save button, which needs to wrap onto its own
   line on narrower screens instead of squeezing/overlapping inputs. */
.account-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px 16px; margin-bottom: 0; }
.account-form .field-row { flex: 1 1 130px; min-width: 110px; margin-bottom: 0; }
.account-form .save-row { flex-basis: 100%; display: flex; align-items: center; gap: 12px; margin-top: 2px; }
.account-form input, .account-form select { width: 100%; }

/* --- Orders list --- */

.order-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 14px;
}
.order-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.order-card-head .order-business { font-size: 15px; font-weight: 600; }
.order-card-head .order-total { font-size: 15px; font-weight: 600; }
.order-card .order-meta { color: var(--sub); font-size: 13px; margin: 4px 0 10px; }
.order-card .order-items { font-size: 14px; line-height: 1.6; margin: 0; padding: 0; list-style: none; }
.order-status {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  margin-left: 8px;
}
.order-status.completed { color: #15803d; background: #dcfce7; }

/* --- Feedback / logged problems --- */

.ticket-kind {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  margin-left: 8px;
  color: var(--sub);
  background: #f3f4f6;
}
.ticket-kind.bug { color: #b91c1c; background: #fee2e2; }
.ticket-kind.missing_capability { color: #92400e; background: #fef3c7; }
.ticket-kind.slow { color: #1e40af; background: #dbeafe; }
.ticket-detail { font-size: 14px; line-height: 1.5; margin: 0; color: var(--ink); }
.order-status.failed, .order-status.cancelled { color: #b91c1c; background: #fee2e2; }

/* --- Dashboard shell --- */

.portal-shell {
  display: flex;
  height: calc(100vh - var(--nav-h)); /* viewport minus .portal-nav's own height */
}

.chat-pane {
  width: 40%;
  min-width: 340px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: white;
}
.chat-pane.full { width: 100%; max-width: 720px; margin: 0 auto; border-right: none; }

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.chat-header h2 { font-size: 16px; margin: 0; }
.chat-header button { background: none; border: none; color: var(--sub); cursor: pointer; font-size: 13px; }
.chat-header-actions { display: flex; align-items: center; gap: 16px; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; line-height: 1.4; font-size: 14px; }
.msg.me { align-self: flex-end; background: var(--bubble-me); color: white; border-bottom-right-radius: 4px; }
.msg.agent { align-self: flex-start; background: var(--bubble-agent); border-bottom-left-radius: 4px; }
.msg.pending { opacity: 0.5; }
.msg img { max-width: 180px; border-radius: 8px; display: block; margin-top: 6px; }
.msg-time { font-size: 11px; opacity: 0.55; margin-top: 4px; }
.msg.me a { color: #9ecbff; }
.msg.agent a { color: #1a56db; }
.msg a { word-break: break-all; }

.chat-form {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.chat-form .photo-label { font-size: 18px; cursor: pointer; padding: 4px; }
.chat-form input[type="text"] { flex: 1; border-radius: 20px; }
.chat-form button[type="submit"] { border-radius: 20px; }

/* --- Edit modals (native <dialog>) --- */

.edit-modal {
  border: none;
  border-radius: 14px;
  padding: 0;
  width: 480px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 80px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}
.edit-modal.wide { width: 640px; }
.edit-modal::backdrop { background: rgba(0, 0, 0, 0.4); }

.edit-modal form,
.edit-modal .modal-body {
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 17px; margin: 0; }
.close-btn { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--sub); }

.modal-body { padding: 20px; overflow-y: auto; gap: 14px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.modal-error { color: #d02c2c; font-size: 13px; margin-right: auto; }

.primary-btn {
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  cursor: pointer;
  font-size: 14px;
}
.primary-btn:disabled { opacity: 0.5; cursor: default; }
.secondary-btn {
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  cursor: pointer;
  font-size: 14px;
}

.field-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field-row label { font-size: 13px; color: var(--sub); }
.field-row input, .field-row select, .field-row textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.field-row input:invalid { border-color: #d02c2c; }
.field-row textarea { min-height: 70px; resize: vertical; }
.field-row.checkbox { flex-direction: row; align-items: center; gap: 8px; }
.field-row.checkbox label { font-size: 14px; color: var(--ink); }
.field-error { color: #d02c2c; font-size: 12px; min-height: 14px; }

/* --- Hours editor (Google Maps style day rows) --- */

.hours-day-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.hours-day-row:last-child { border-bottom: none; }

.hours-day-row .day-label { width: 100px; font-weight: 600; font-size: 14px; padding-top: 8px; flex-shrink: 0; }

.hours-day-row .day-closed-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--sub);
  padding-top: 6px;
  flex-shrink: 0;
}

.hours-day-row .ranges { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.hours-day-row .range-row { display: flex; align-items: center; gap: 6px; }
.hours-day-row .range-row input[type="time"] {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.hours-day-row .range-row .remove-range-btn {
  background: none;
  border: none;
  color: var(--sub);
  cursor: pointer;
  font-size: 14px;
}
.hours-day-row .add-range-btn {
  align-self: flex-start;
  background: none;
  border: none;
  color: #1a56db;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 0;
}
.hours-day-row .copy-to-all-btn {
  background: none;
  border: none;
  color: var(--sub);
  cursor: pointer;
  font-size: 15px;
  padding-top: 6px;
  flex-shrink: 0;
}
.hours-day-row .closed-label { color: var(--sub); font-size: 13px; padding-top: 8px; }

/* --- Menu table (inside menu modal) --- */

.menu-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.menu-table th, .menu-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 14px; }
.menu-table input { width: 100%; border: 1px solid transparent; padding: 4px 6px; border-radius: 6px; font-size: 14px; }
.menu-table input:focus { border-color: var(--border); outline: none; }
.menu-table .remove-btn { background: none; border: none; color: #d02c2c; cursor: pointer; font-size: 16px; }

.add-item-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.add-item-form input { flex: 1; min-width: 100px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.add-item-form button { padding: 8px 16px; border: none; border-radius: 8px; background: var(--ink); color: white; cursor: pointer; }

/* --- Photo preview (chat composer) --- */

.photo-preview { max-width: 640px; margin: 0 auto; padding: 0 20px 10px; }
.photo-preview img { max-width: 120px; border-radius: 8px; }

/* --- Vault (connected third-party accounts) --- */

.vault-card { max-width: 480px; }
#vault-list { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 10px; }

.vault-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
}
.vault-entry-info { display: flex; align-items: center; gap: 10px; }
.vault-entry-name { font-size: 15px; font-weight: 600; text-transform: capitalize; }
.vault-entry-badge {
  font-size: 12px;
  font-weight: 600;
  color: #15803d;
  background: #dcfce7;
  padding: 3px 9px;
  border-radius: 999px;
}

#add-secret-btn { margin-bottom: 4px; }

#vault-form { flex-direction: column; gap: 8px; margin: 14px 0 8px; padding-top: 14px; border-top: 1px solid var(--border); }
#vault-form input { flex: none; }
#vault-form input[type="password"] {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
}
.vault-form-actions { display: flex; align-items: center; gap: 14px; }
