:root {
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --gridline: #e1e0d9;
  --brand: #d9483a;
  --brand-dark: #c0392b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255, 255, 255, 0.10);
    --gridline: #2c2c2a;
    --brand: #ef8a7a;
    --brand-dark: #d9483a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  line-height: 1.5;
}

header.site {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--brand-dark);
  color: #fff;
  padding: 14px 20px;
  min-height: 36px;
}

header.site .brand { min-width: 0; display: flex; align-items: center; gap: 12px; }
header.site .brand-logo-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 4px;
  box-sizing: border-box;
  flex-shrink: 0;
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
header.site .brand-logo { height: 36px; width: 36px; object-fit: contain; }
header.site h1 { margin: 0; font-size: 1.5rem; }
header.site p { margin: 4px 0 0; color: rgba(255, 255, 255, 0.75); font-size: 0.95rem; }

/* ── Standard title-bar icon buttons (Home / Back / Settings / Profile) ──────
   Matches dashboard.fity.ca, cwaMITEL, and cwaJPODdash — reuse this exact icon
   set/markup everywhere instead of inventing new button styles per app. */
.title-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  position: relative;
}

.title-divider {
  width: 1px;
  height: 22px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0 2px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.2);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.icon-btn:hover { background: rgba(0, 0, 0, 0.35); }
.icon-btn svg { width: 18px; height: 18px; fill: #ffffff; }

/* White + brand-red instead of the green every sibling app uses - green-on-red clashes (and is
   rough for colorblind users too); this ties into the white logo-box treatment already in the
   header instead of introducing an unrelated third color. Same convention as cwaGRCITdash. */
.icon-btn.signed-in { background: #ffffff; }
.icon-btn.signed-in svg { fill: var(--brand-dark); }
.icon-btn.signed-in:hover { background: #f0f0f0; }

.dropdown-menu-custom {
  display: none;
  position: absolute;
  top: 44px;
  right: 0;
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  min-width: 200px;
  padding: 0.4rem;
  z-index: 30;
}

.dropdown-menu-custom.show { display: block; }

.dropdown-menu-custom .label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0.4rem 0.7rem 0.2rem;
}

.dropdown-menu-custom .item {
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  font-size: 0.87rem;
  cursor: pointer;
}

.dropdown-menu-custom .item:hover { background: var(--page); }

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 20px 64px;
}

.breadcrumb {
  font-size: 0.85rem;
  margin-bottom: 4px;
}
.breadcrumb a { color: var(--brand-dark); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

.section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* ── Launcher grid — action cards ─────────────────────────────────────────── */
/* max-width raised from 480px (which only ever fit 2 columns of a 160px card) so 3 cards can sit
   side by side once there's room, instead of always wrapping to 2 regardless of screen width. A
   CSS var, not a repeated magic number, so .section-divider below can never drift out of sync
   with it again the way it just did when this width changed but that one didn't. */
:root { --app-grid-max-width: 660px; }
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.5rem;
  padding: 1.5rem 0;
  max-width: var(--app-grid-max-width);
}

/* Divider between the two app-grid sections on the home page. */
.section-divider {
  border: none;
  border-top: 3px solid var(--brand-dark);
  margin: 0.5rem 0 1.5rem;
  max-width: var(--app-grid-max-width);
}

.app-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1.75rem 1rem;
  border-radius: 12px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.app-card:hover { transform: translateY(-3px); background: var(--page); }

.app-card__icon-wrap { display: flex; align-items: center; justify-content: center; height: 44px; }
.app-card__icon { width: 44px; height: 44px; color: var(--brand); }
.app-card__logo { max-width: 130px; max-height: 44px; width: auto; height: auto; object-fit: contain; }
.app-card__label { font-size: 1rem; font-weight: 700; letter-spacing: 0.02em; }

/* ── Site list — flat list of FTP root folders within a space. Deliberately
   plain (not big tiles) since a space can hold dozens of entries. ─────────── */
.site-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: -8px 0 18px;
}

.site-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-1);
}

.site-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0.85rem 1.1rem;
  color: var(--text-primary);
  text-decoration: none;
  border-bottom: 1px solid var(--gridline);
}

.site-row:last-child { border-bottom: none; }
.site-row:hover { background: var(--page); }

.site-row__name { font-size: 0.95rem; font-weight: 600; }
.site-row__icon { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }

/* ── Domain cards — hosts grouped by base domain, one card each, with the
   individual hosts tucked inside a native <details> disclosure. ───────────── */
.domain-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.domain-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-1);
  overflow: hidden;
}

.domain-card summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.95rem 1.1rem;
}

.domain-card summary::-webkit-details-marker { display: none; }

.domain-card__name { font-size: 0.98rem; font-weight: 700; }

.domain-card__badge {
  margin-left: auto;
  background: var(--brand-dark);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.domain-card summary::after {
  content: '';
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.domain-card[open] summary::after { transform: rotate(45deg); margin-top: 4px; }

.domain-card__hosts { border-top: 1px solid var(--gridline); }
.domain-card__hosts .site-row { padding-left: 1.1rem; padding-right: 1.1rem; }

/* ── PIN sign-in gate — locked cards + login modal. Client-side only: the
   PIN check runs in auth.js, so this is a casual-access gate, not real
   security (anyone reading the JS source can see the PIN). ────────────────── */
.lockable.locked { opacity: 0.4; }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.open { display: flex; }

.modal-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 90%;
  max-width: 380px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.modal-header {
  background: var(--brand-dark);
  color: #fff;
  padding: 14px 18px;
  font-size: 15px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover { opacity: 0.7; }
.modal-body { padding: 18px 20px 20px; }

.form-field { margin-bottom: 14px; }
.form-field:last-of-type { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.text-input {
  width: 100%;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.text-input:focus { outline: none; border-color: var(--brand); }

.btn {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: var(--brand-dark);
  color: #fff;
  margin-top: 16px;
}

.btn:hover { filter: brightness(1.1); }
.btn:disabled { opacity: 0.6; cursor: default; }

.form-error { margin-top: 10px; font-size: 0.78rem; color: #e5484d; }
.form-error:empty { display: none; }

/* ── Form Sign — local prototype: PDF rendered inline via pdf.js (canvas),
   with a highlighted, clickable tag over the signature blank. Rendering to
   canvas — rather than an <iframe> pointed at a blob: URL — is what makes
   this work the same way on mobile as on desktop; the native iframe/embed
   PDF viewer isn't available on mobile Chrome. ─────────────────────────────── */
.pdf-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.pdf-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.pdf-canvas { display: block; max-width: 100%; height: auto; }

.field-tag {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(255, 221, 87, 0.55);
  border: 2px dashed #c9a227;
  border-radius: 6px;
  color: #5c4a06;
  font-size: 0.74rem;
  font-weight: 800;
  cursor: pointer;
  padding: 0;
  animation: field-pulse 1.8s ease-in-out infinite;
}

.field-tag:hover { background: rgba(255, 221, 87, 0.8); }

.field-tag.signed {
  background: rgba(88, 197, 120, 0.35);
  border-color: #2f9e52;
  color: #245c34;
  animation: none;
}

@keyframes field-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 196, 0, 0.35); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 196, 0, 0); }
}

.sig-pad {
  display: block;
  width: 100%;
  max-width: 320px;
  height: 140px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  touch-action: none;
  cursor: crosshair;
}

.sig-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 0;
}

.btn-secondary:hover { background: var(--page); }

/* ── Sign List — recipients table + Add modal. ──────────────────────────────── */
.toolbar-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-1);
}

.data-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }

.data-table th, .data-table td {
  text-align: left;
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}

.data-table th {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 800;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--page); }

.row-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 2px 8px;
  border-radius: 6px;
}

.row-delete:hover { background: var(--border); color: #e5484d; }

.empty-state {
  padding: 2.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Phone/role verify dialog's summary rows (Date/Time, IP, User ID, Last Login) - same layout
   cwaGRCITdash's own login uses. Was missing here even though the login modal that needs it has
   worked correctly since the real-auth switch - just never visually verified until now. */
.verify-info { margin-bottom: 14px; font-size: 0.82rem; }
.verify-info__row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px solid var(--border); }
.verify-info__row:last-child { border-bottom: none; }
.verify-info__row span { color: var(--text-muted); }
.verify-info__row b { text-align: right; font-weight: 700; }
