/* Tahliliy app pages — page-level layout on top of app.css utilities */

.page-head { margin-bottom: var(--space-6); }
.page-title {
  margin: 0 0 var(--space-2);
  font-family: var(--font-heading);
  font-size: var(--fs-2xl);
  letter-spacing: var(--tracking-tight);
  line-height: var(--lh-tight);
}
.page-sub { margin: 0; color: var(--muted); font-size: var(--fs-sm); }
.section { margin-bottom: var(--space-8); }
.section-title { margin: 0 0 var(--space-4); font-family: var(--font-heading); font-size: var(--fs-lg); }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.row-between { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }

.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-4); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-5); }
.stat-sub { font-size: var(--fs-sm); color: var(--muted); }
.stat-positive .stat-value { color: var(--positive); }
.stat-neutral .stat-value { color: var(--muted); }
.stat-negative .stat-value { color: var(--negative); }

/* Form controls */
.input, .select {
  min-height: var(--tap);
  padding: 0 var(--space-4);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  min-width: 0;
}
.input { flex: 1 1 260px; }
.select { max-width: 100%; }
.input:focus, .select:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px var(--glow-blue); }
.input.invalid { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: var(--fs-sm); margin: var(--space-2) 0 0; min-height: 1.2em; }
.btn-sm { min-height: 36px; padding: 0 var(--space-3); font-size: var(--fs-sm); }
.btn-danger { background: var(--danger); }
.btn-link {
  background: none; border: 0; padding: 0; font: inherit; color: var(--primary);
  cursor: pointer; text-decoration: underline;
}

/* Tabs */
.tabs { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.tab {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: 40px; padding: 0 var(--space-4);
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px;
  font: inherit; font-size: var(--fs-sm); font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab[aria-selected="true"], .tab.active {
  background: var(--primary-soft); color: var(--text); border-color: var(--primary);
}
.tab .count { font-weight: 500; color: var(--muted); }

/* Stepper */
.stepper { list-style: none; margin: var(--space-5) 0 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-3); }
.stepper li { display: flex; align-items: center; gap: var(--space-2); color: var(--muted); font-size: var(--fs-sm); }
.stepper .dot {
  flex: 0 0 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); font-weight: 700; font-size: var(--fs-xs);
}
.stepper li.active { color: var(--text); }
.stepper li.active .dot { border-color: var(--primary); background: var(--primary-soft); }
.stepper li.done { color: var(--text); }
.stepper li.done .dot { background: var(--positive); border-color: var(--positive); color: #fff; }
.stepper li.failed .dot { background: var(--danger); border-color: var(--danger); color: #fff; }
.progress { height: 6px; background: var(--surface-elevated); border-radius: 999px; overflow: hidden; margin-top: var(--space-4); }
.progress > span { display: block; height: 100%; width: 0; background: var(--primary); transition: width var(--transition); }

/* Charts */
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 300px; }
.legend { display: flex; flex-wrap: wrap; gap: var(--space-4); margin-top: var(--space-3); font-size: var(--fs-sm); color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }

/* Comments table */
.comments-table { min-width: 720px; }
.comments-table td { vertical-align: middle; }
.col-num { width: 48px; color: var(--muted); }
.col-text { min-width: 240px; max-width: 460px; overflow-wrap: anywhere; }
.col-actions { min-width: 190px; }
.user-cell { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.avatar {
  flex: 0 0 32px; width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--violet-soft); color: var(--violet); font-weight: 700; font-size: var(--fs-xs);
}
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
.actions { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.fb-group { display: inline-flex; gap: 4px; }
.fb-btn {
  min-height: 30px; padding: 0 10px; border-radius: 999px; font: inherit; font-size: var(--fs-xs); font-weight: 600;
  background: transparent; color: var(--muted); border: 1px solid var(--border); cursor: pointer;
}
.fb-btn:hover:not(:disabled) { background: var(--surface-elevated); color: var(--text); }
.fb-btn:disabled { opacity: .5; cursor: default; }
.fb-btn.chosen { border-color: var(--primary); color: var(--text); background: var(--primary-soft); opacity: 1; }
.corrected-note { font-size: var(--fs-xs); color: var(--muted); margin-top: 4px; }
.check-result { display: inline-flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; font-size: var(--fs-xs); }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin-top: var(--space-4); }
.pager-info { color: var(--muted); font-size: var(--fs-sm); }
.empty { text-align: center; color: var(--muted); padding: var(--space-8) var(--space-4); }
.note { margin: var(--space-3) 0 0; color: var(--muted); font-size: var(--fs-sm); }
tr.is-clickable { cursor: pointer; }
tr.is-clickable:hover td { background: var(--surface); }
.mobile-card-head { display: flex; justify-content: space-between; gap: var(--space-3); align-items: center; margin-bottom: var(--space-2); }
.mobile-card-meta { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin-top: var(--space-3); }

/* Home */
.hero { margin-bottom: var(--space-6); }
.guide { margin-bottom: var(--space-6); }
.guide summary { cursor: pointer; font-family: var(--font-heading); font-size: var(--fs-lg); font-weight: 700; list-style: none; display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.guide summary::-webkit-details-marker { display: none; }
.guide summary::after { content: "▾"; color: var(--muted); transition: transform var(--transition-fast); }
.guide[open] summary::after { transform: rotate(180deg); }
.guide-steps { list-style: none; margin: var(--space-5) 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--space-4); counter-reset: step; }
.guide-steps li { counter-increment: step; display: flex; flex-direction: column; gap: var(--space-2); }
.guide-steps li::before {
  content: counter(step); width: 32px; height: 32px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--text); font-weight: 700;
}
.guide-steps strong { font-size: var(--fs-base); }
.guide-steps span { color: var(--muted); font-size: var(--fs-sm); }
.example-card { border-style: dashed; margin-bottom: var(--space-6); }
.example-tag { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--neutral-soft); color: var(--muted); font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: var(--tracking-label); }
.platform-card { display: flex; flex-direction: column; gap: var(--space-4); }
.platform-card h2 { margin: 0; font-family: var(--font-heading); font-size: var(--fs-xl); }
.platform-total { font-family: var(--font-heading); font-size: var(--fs-stat); font-weight: 800; line-height: var(--lh-tight); }
.mini-split { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.recent-list li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-3); align-items: center; padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
.recent-list li:last-child { border-bottom: 0; }
.recent-title { font-weight: 600; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.recent-title:hover { color: var(--primary); }

/* Info box */
.info-box { background: var(--primary-soft); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-5); }
.info-box h3 { margin: 0 0 var(--space-2); font-family: var(--font-heading); font-size: var(--fs-md); }
.info-box p, .info-box li { color: var(--muted); font-size: var(--fs-sm); margin: 0 0 var(--space-2); }
.info-box ul { margin: 0; padding-left: 1.2em; }

/* Risk bars / tier counts */
.bar-row { display: grid; grid-template-columns: 90px 1fr 48px; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); font-size: var(--fs-sm); }
.bar-track { height: 10px; background: var(--surface-elevated); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 999px; }
.bar-fill.high { background: var(--risk-high); }
.bar-fill.medium { background: var(--risk-medium); }
.bar-fill.low { background: var(--risk-low); }

/* Drawer */
.drawer-backdrop { position: fixed; inset: 0; background: var(--overlay); z-index: 190; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw);
  background: var(--bg); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  z-index: 200; display: flex; flex-direction: column; transform: translateX(100%);
  transition: transform var(--transition-slow);
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); padding: var(--space-5); border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-family: var(--font-heading); font-size: var(--fs-lg); }
.drawer-body { flex: 1 1 auto; overflow-y: auto; padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); }
.drawer-foot { display: flex; flex-wrap: wrap; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-value { overflow-wrap: anywhere; }
details.collapsible { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3) var(--space-4); }
details.collapsible summary { cursor: pointer; font-weight: 600; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: var(--space-2) var(--space-4); margin: var(--space-3) 0 0; font-size: var(--fs-sm); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; }
.toast {
  position: fixed; left: 50%; bottom: var(--space-6); transform: translateX(-50%);
  background: var(--surface-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--space-3) var(--space-5); z-index: 300; box-shadow: var(--shadow-lg); font-size: var(--fs-sm);
}
.toast.error { border-color: var(--danger); }

.empty-state { text-align: center; padding: var(--space-10) var(--space-4); }
.empty-state h2 { margin: 0 0 var(--space-2); font-family: var(--font-heading); }
.empty-state .row { justify-content: center; margin-top: var(--space-5); }

@media (max-width: 1023px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
  .stepper { grid-template-columns: 1fr 1fr; }
  .bar-row { grid-template-columns: 70px 1fr 40px; }
}
@media (prefers-reduced-motion: reduce) {
  .drawer, .progress > span { transition: none; }
}
@media print {
  .no-print, .tabs, .pager, .toast, .drawer, .drawer-backdrop { display: none !important; }
  .page-head .row { display: none; }
  .chart-box { height: 220px; }
}
