/* ============================================================
   InHouse Survey — Component Library
   Depends on inhouse-tokens.css. Default theme = parchment.
   Apply .theme-forest on <body> for dark surveyor-portal variant.
   ============================================================ */

/* ------------------------------------------------------------
   LAYOUT
   ------------------------------------------------------------ */
.container          { max-width: var(--max-content); margin: 0 auto; padding: 0 var(--sp-3); }
.container-reading  { max-width: var(--max-reading); margin: 0 auto; padding: 0 var(--sp-3); }

.stack    > * + * { margin-top: var(--sp-3); }
.stack-sm > * + * { margin-top: var(--sp-2); }
.stack-lg > * + * { margin-top: var(--sp-4); }

.cluster         { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.cluster-between { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }

.grid-2      { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--sp-3); }
.grid-golden { display: grid; grid-template-columns: var(--grid-golden-a) var(--grid-golden-b); gap: var(--sp-4); }
@media (max-width: 900px) { .grid-golden { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------
   APP SHELL
   ------------------------------------------------------------ */
.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
@media (max-width: 900px) { .app-shell { grid-template-columns: 1fr; } }

.app-sidebar {
  background: var(--ih-primary);
  color: var(--ih-text-on-dark);
  padding: var(--sp-4) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  border-right: 1px solid var(--ih-primary-deep);
}
@media (max-width: 900px) {
  .app-sidebar { border-right: none; border-bottom: 1px solid var(--ih-primary-deep); }
}

.app-sidebar .brand-block { padding: var(--sp-1) 0 var(--sp-3); border-bottom: 1px solid rgba(242,237,229,0.1); }

.app-nav { display: flex; flex-direction: column; gap: 2px; margin-top: var(--sp-3); }
.app-nav a {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 10px var(--sp-2);
  border-radius: var(--r-card);
  color: rgba(242, 237, 229, 0.72);
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: background var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.app-nav a:hover { background: rgba(255, 255, 255, 0.06); color: var(--ih-text-on-dark); }
.app-nav a.active { background: var(--ih-accent-wash); color: var(--ih-accent-light); }
.app-nav a .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.5; }

.app-sidebar .user-chip {
  margin-top: auto;
  display: flex; align-items: center; gap: var(--sp-2);
  padding-top: var(--sp-3);
  border-top: 1px solid rgba(242,237,229,0.1);
  font-size: var(--fs-sm);
  color: rgba(242,237,229,0.75);
}
.user-chip .avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--ih-accent);
  color: var(--ih-text-on-dark);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: var(--fs-xs);
  letter-spacing: var(--tracking-wide);
}

.app-main { padding: var(--sp-4) var(--sp-4); overflow-x: hidden; background: var(--ih-bg); color: var(--ih-text); }
@media (max-width: 600px) { .app-main { padding: var(--sp-3); } }

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--ih-border);
}
.app-header h1 { font-family: var(--ih-font-display); font-size: var(--fs-3xl); color: var(--ih-primary); }
.app-header .subtitle { color: var(--ih-text-mid); font-size: var(--fs-sm); margin-top: var(--sp-1); }

/* ------------------------------------------------------------
   BUTTONS
   ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  padding: 11px 22px;
  font-family: var(--ih-font-body);
  font-size: var(--fs-sm);
  font-weight: 600;
  border-radius: var(--r-input);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-standard),
              background var(--dur-fast) var(--ease-standard),
              border-color var(--dur-fast) var(--ease-standard),
              color var(--dur-fast) var(--ease-standard);
  text-decoration: none;
  line-height: 1;
  letter-spacing: 0.01em;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary   { background: var(--ih-accent); color: var(--ih-text-on-dark); }
.btn-primary:hover { background: #A8642C; color: var(--ih-text-on-dark); }

.btn-forest    { background: var(--ih-primary); color: var(--ih-text-on-dark); }
.btn-forest:hover { background: var(--ih-primary-deep); color: var(--ih-text-on-dark); }

.btn-secondary { background: transparent; color: var(--ih-primary); border-color: var(--ih-border); }
.btn-secondary:hover { background: var(--ih-bg-mid); border-color: var(--ih-primary); }

.btn-ghost     { background: transparent; color: var(--ih-text-mid); border-color: transparent; }
.btn-ghost:hover { color: var(--ih-primary); background: var(--ih-bg-mid); }

.btn-danger    { background: var(--ih-critical); color: #fff; }

.btn-sm { padding: 7px 14px; font-size: var(--fs-xs); }
.btn-lg { padding: 14px 30px; font-size: var(--fs-base); }

body.theme-forest .btn-secondary { color: var(--ih-text-on-dark); border-color: rgba(242,237,229,0.2); }
body.theme-forest .btn-secondary:hover { background: rgba(255,255,255,0.06); border-color: var(--ih-accent-light); }
body.theme-forest .btn-ghost { color: rgba(242,237,229,0.72); }
body.theme-forest .btn-ghost:hover { color: var(--ih-text-on-dark); background: rgba(255,255,255,0.06); }

/* ------------------------------------------------------------
   CARDS
   ------------------------------------------------------------ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--ih-border);
  border-radius: var(--r-card);
  padding: var(--sp-3);
}
.card-lg { padding: var(--sp-4); }
.card-hover { transition: border-color var(--dur-base) var(--ease-standard), transform var(--dur-base) var(--ease-standard), box-shadow var(--dur-base) var(--ease-standard); cursor: pointer; }
.card-hover:hover { border-color: var(--ih-primary); transform: translateY(-2px); box-shadow: var(--shadow-soft); }

.card-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: var(--sp-2); gap: var(--sp-2); }
.card-title  { font-family: var(--ih-font-display); font-size: var(--fs-lg); color: var(--ih-primary); }
.card-meta   { font-size: var(--fs-xs); color: var(--ih-text-mid); letter-spacing: var(--tracking-wide); text-transform: uppercase; }

/* ------------------------------------------------------------
   FORMS
   ------------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--ih-secondary);
}
.field input,
.field textarea,
.field select {
  font-family: var(--ih-font-body);
  font-size: var(--fs-base);
  padding: 12px 13px;
  background: #FFFFFF;
  border: 1px solid var(--ih-border);
  border-radius: var(--r-input);
  color: var(--ih-text);
  transition: border-color var(--dur-fast) var(--ease-standard), box-shadow var(--dur-fast) var(--ease-standard);
}
.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--ih-accent);
  box-shadow: 0 0 0 3px rgba(192, 122, 58, 0.15);
}
.field textarea { min-height: 120px; resize: vertical; line-height: var(--lh-body); }
.field .help    { font-size: var(--fs-xs); color: var(--ih-text-mid); }

.field-row      { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
@media (max-width: 600px) { .field-row { grid-template-columns: 1fr; } }

body.theme-forest .field label { color: var(--ih-accent-light); }
body.theme-forest .field input,
body.theme-forest .field textarea,
body.theme-forest .field select {
  background: rgba(255,255,255,0.04);
  border-color: rgba(242,237,229,0.14);
  color: var(--ih-text-on-dark);
}

/* Dropzone */
.dropzone {
  border: 1px dashed var(--ih-border);
  border-radius: var(--r-card);
  padding: var(--sp-4);
  text-align: center;
  color: var(--ih-text-mid);
  cursor: pointer;
  background: var(--ih-bg-mid);
  transition: border-color var(--dur-fast) var(--ease-standard), background var(--dur-fast) var(--ease-standard);
}
.dropzone:hover { border-color: var(--ih-accent); background: #fff; }
.dropzone .hint { font-size: var(--fs-xs); margin-top: var(--sp-1); color: var(--ih-text-soft); }

/* ------------------------------------------------------------
   PILLS — risk + status
   ------------------------------------------------------------ */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: var(--r-pill);
  font-family: var(--ih-font-body);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  line-height: 1.5;
}
.pill-critical { background: rgba(158, 43, 43, 0.12);  color: var(--ih-critical); }
.pill-high     { background: rgba(184, 88, 38, 0.14);  color: var(--ih-high); }
.pill-medium   { background: rgba(192, 122, 58, 0.18); color: #8A5425; }
.pill-low      { background: rgba(62, 115, 82, 0.15);  color: var(--ih-low); }
.pill-neutral  { background: var(--ih-bg-mid);          color: var(--ih-text-mid); }
.pill-draft    { background: rgba(192, 122, 58, 0.12); color: var(--ih-accent); }
.pill-review   { background: rgba(76, 122, 105, 0.15); color: var(--ih-secondary); }
.pill-approved { background: rgba(62, 115, 82, 0.15);  color: var(--ih-low); }

body.theme-forest .pill-neutral { background: rgba(255,255,255,0.08); color: rgba(242,237,229,0.85); }

/* ------------------------------------------------------------
   TABLES
   ------------------------------------------------------------ */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--ih-secondary);
  padding: var(--sp-2) var(--sp-2);
  border-bottom: 1px solid var(--ih-border);
  background: transparent;
}
.table td {
  padding: var(--sp-2) var(--sp-2);
  border-bottom: 1px solid var(--ih-border);
  vertical-align: top;
  color: var(--ih-text);
}
.table tbody tr { transition: background var(--dur-fast) var(--ease-standard); }
.table tbody tr:hover { background: var(--ih-bg-mid); cursor: pointer; }

/* ------------------------------------------------------------
   CALLOUTS
   ------------------------------------------------------------ */
.callout {
  border-left: 3px solid var(--ih-accent);
  padding: var(--sp-2) var(--sp-3);
  background: var(--ih-bg-mid);
  border-radius: 0 var(--r-card) var(--r-card) 0;
}
.callout-title { font-family: var(--ih-font-body); font-weight: 700; margin-bottom: 4px; color: var(--ih-primary); font-size: var(--fs-sm); letter-spacing: var(--tracking-wide); text-transform: uppercase; }
.callout p { font-size: var(--fs-sm); color: var(--ih-text); }
.callout p + p { margin-top: var(--sp-1); }

.callout-legal   { border-left-color: var(--ih-secondary); }
.callout-warning { border-left-color: var(--ih-high); }
.callout-info    { border-left-color: var(--ih-info); }

/* ------------------------------------------------------------
   TABS
   ------------------------------------------------------------ */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--ih-border); overflow-x: auto; }
.tabs button {
  font-family: var(--ih-font-body);
  font-size: var(--fs-sm);
  font-weight: 500;
  padding: 10px var(--sp-3);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ih-text-mid);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-standard), border-color var(--dur-fast) var(--ease-standard);
  white-space: nowrap;
}
.tabs button:hover  { color: var(--ih-primary); }
.tabs button.active { color: var(--ih-primary); border-bottom-color: var(--ih-accent); font-weight: 600; }

/* ------------------------------------------------------------
   PROGRESS + STEP INDICATOR
   ------------------------------------------------------------ */
.steps { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.steps .step {
  display: flex; align-items: center; gap: 6px;
  font-size: var(--fs-xs); color: var(--ih-text-mid);
  letter-spacing: var(--tracking-wide); text-transform: uppercase; font-weight: 500;
}
.steps .step .num {
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--ih-border);
  font-weight: 600;
  background: #fff;
}
.steps .step.done { color: var(--ih-accent); }
.steps .step.done .num { background: var(--ih-accent); color: #fff; border-color: var(--ih-accent); }
.steps .step.active { color: var(--ih-primary); }
.steps .step.active .num { border-color: var(--ih-accent); color: var(--ih-accent); }
.steps .divider { flex: 1; height: 1px; background: var(--ih-border); max-width: 60px; }

/* Progress bar */
.progress {
  height: 4px;
  background: var(--ih-bg-mid);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.progress > span { display: block; height: 100%; background: var(--ih-accent); transition: width var(--dur-slow) var(--ease-standard); }

/* ------------------------------------------------------------
   EMPTY STATE
   ------------------------------------------------------------ */
.empty {
  text-align: center;
  padding: var(--sp-5) var(--sp-3);
  color: var(--ih-text-mid);
  background: var(--ih-bg-mid);
  border-radius: var(--r-card);
}
.empty h3 { font-size: var(--fs-xl); color: var(--ih-primary); margin-bottom: var(--sp-1); }

/* ------------------------------------------------------------
   REPORT — shared between surveyor review + client view
   ------------------------------------------------------------ */
.report { max-width: 820px; margin: 0 auto; }
.report .cover {
  background: var(--ih-primary);
  color: var(--ih-text-on-dark);
  padding: var(--sp-5) var(--sp-4);
  border-radius: var(--r-card);
  margin-bottom: var(--sp-4);
}
.report .cover .eyebrow { color: var(--ih-accent-light); }
.report .cover h1 { color: var(--ih-text-on-dark); font-size: var(--fs-3xl); margin-top: var(--sp-2); }
.report .cover .property-meta { color: rgba(242,237,229,0.72); font-size: var(--fs-sm); margin-top: var(--sp-2); }
.report .cover .rule-brass { margin-top: var(--sp-3); }

.report h2 {
  font-family: var(--ih-font-display);
  font-size: var(--fs-xl);
  color: var(--ih-primary);
  margin-top: var(--sp-5);
  margin-bottom: var(--sp-2);
  padding-bottom: var(--sp-1);
  border-bottom: 1px solid var(--ih-border);
  position: relative;
}
.report h2::before {
  content: '';
  position: absolute;
  bottom: -1px; left: 0;
  width: 48px; height: 2px;
  background: var(--ih-accent);
}
.report h3 { font-family: var(--ih-font-display); margin-top: var(--sp-4); margin-bottom: var(--sp-2); font-size: var(--fs-lg); color: var(--ih-primary); }
.report p { margin-bottom: var(--sp-2); line-height: var(--lh-loose); color: var(--ih-text); }
.report section { scroll-margin-top: 80px; }

.report .defect-block {
  border: 1px solid var(--ih-border);
  border-radius: var(--r-card);
  padding: var(--sp-3);
  margin: var(--sp-3) 0;
  background: #fff;
}
.report .defect-block .cluster-between { margin-bottom: var(--sp-2); }
.report .defect-block h4 { font-family: var(--ih-font-body); font-size: var(--fs-md); color: var(--ih-primary); }

.defect-four-step {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}
@media (max-width: 600px) { .defect-four-step { grid-template-columns: 1fr; } }
.defect-four-step > div { background: var(--ih-bg-mid); padding: var(--sp-2); border-radius: var(--r-input); }
.defect-four-step .label {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--ih-secondary);
  margin-bottom: 4px;
}
.defect-four-step p { font-size: var(--fs-sm); margin: 0; line-height: var(--lh-body); }

.report-section-controls {
  display: flex;
  gap: var(--sp-1);
  justify-content: flex-end;
  margin-top: var(--sp-2);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-standard);
}
.report section:hover .report-section-controls,
.report section:focus-within .report-section-controls { opacity: 1; }

.report .section-header { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--sp-2); }

/* Printable variant */
@media print {
  @page { margin: 16mm 14mm; }
  body { background: #fff !important; color: #000 !important; }
  .app-shell { display: block !important; min-height: 0; }
  .app-sidebar, .app-header, .report-section-controls, .section-nav { display: none !important; }
  .app-main { padding: 0; overflow: visible; }
  .review-grid { display: block !important; }
  .report { max-width: none; }
  .report .cover { page-break-after: always; }
  .report h2 { page-break-after: avoid; color: var(--ih-primary); }
  .report section[data-section-id] { page-break-inside: avoid; }
  .report .defect-block { page-break-inside: avoid; }
  a[href]:after { content: ""; }
}

/* ------------------------------------------------------------
   MAGIC-LINK / AUTH
   ------------------------------------------------------------ */
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--sp-4);
  background: var(--ih-primary);
}
.auth-card {
  max-width: 420px;
  width: 100%;
  background: #fff;
  border-radius: var(--r-modal);
  padding: var(--sp-5) var(--sp-4);
  box-shadow: var(--shadow-forest);
}
.auth-card .ih-logo { margin: 0 auto var(--sp-4); display: block; }
.auth-card h1 { font-size: var(--fs-xl); margin-bottom: var(--sp-1); }
.auth-card p { color: var(--ih-text-mid); font-size: var(--fs-sm); margin-bottom: var(--sp-3); }

/* ------------------------------------------------------------
   TOAST
   ------------------------------------------------------------ */
.toast {
  position: fixed;
  bottom: var(--sp-3);
  right: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: var(--ih-primary);
  color: var(--ih-text-on-dark);
  border-radius: var(--r-card);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-lift);
  z-index: 100;
  animation: slideIn 280ms var(--ease-enter);
}
.toast-accent { background: var(--ih-accent); }
@keyframes slideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
