/* ===== Tokens ===== */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e3e7ee;
  --text: #1a2233;
  --text-muted: #667085;
  --primary: #3457d5;
  --primary-hover: #2941ad;
  --primary-soft: #eaefff;
  --success: #17a06a;
  --success-soft: #e4f7ee;
  --warning: #b7791f;
  --warning-soft: #fdf3dc;
  --danger: #d64545;
  --danger-soft: #fbe7e7;
  --info: #2f80c9;
  --info-soft: #e6f2fb;
  --neutral: #667085;
  --neutral-soft: #eef0f3;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
  --sidebar-w: 250px;
}

:root[data-theme="dark"] {
  --bg: #12151c;
  --surface: #1a1e28;
  --surface-2: #20242f;
  --border: #2b303c;
  --text: #e8eaf0;
  --text-muted: #9198a8;
  --primary: #6f8bff;
  --primary-hover: #8ba0ff;
  --primary-soft: #232c4d;
  --success: #34c98a;
  --success-soft: #17301f;
  --warning: #e0a83b;
  --warning-soft: #332a12;
  --danger: #f0706f;
  --danger-soft: #3a1d1d;
  --info: #5aa8e8;
  --info-soft: #172a3a;
  --neutral: #9198a8;
  --neutral-soft: #262b36;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3 { margin: 0; }
p { margin: 0; }

.muted { color: var(--text-muted); }

/* ===== Layout ===== */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.25rem 0.5rem 1.5rem;
}
.brand-mark {
  width: 26px;
  height: 26px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.brand-text strong { font-size: 0.95rem; }
.brand-text span { font-size: 0.72rem; color: var(--text-muted); }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.nav-link .icon { width: 18px; height: 18px; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

.main-content {
  flex: 1;
  min-width: 0;
  padding: 2rem 2.5rem 4rem;
}

.view-root {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ===== Page header ===== */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; }
.page-subtitle { color: var(--text-muted); margin-top: 0.2rem; font-size: 0.92rem; }
.title-row { display: flex; align-items: center; gap: 0.6rem; }
.header-actions { display: flex; gap: 0.5rem; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.section-header h2 { font-size: 1.1rem; font-weight: 700; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
  width: fit-content;
}
.back-link:hover { color: var(--primary); }
.back-link .icon { width: 16px; height: 16px; }

.drill-list { display: flex; flex-direction: column; gap: 0.4rem; }
.drill-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
  padding: 0.85rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font: inherit;
  text-align: left;
  color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.drill-row:hover { background: var(--primary-soft); border-color: var(--primary); }
.drill-row-label { font-weight: 600; }
.drill-row-value { color: var(--text-muted); font-size: 0.85rem; flex: 1; text-align: right; }
.drill-row-chevron { color: var(--text-muted); font-size: 1.1rem; }
.drill-row-static { cursor: default; }
.drill-row-static:hover { background: var(--surface-2); border-color: var(--border); }

/* ===== KPI cards ===== */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.9rem;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  box-shadow: var(--shadow);
  min-width: 0;
}
.kpi-main { min-width: 0; }
.kpi-value { overflow-wrap: break-word; }
.kpi-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.kpi-icon .icon { width: 17px; height: 17px; }
.kpi-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.kpi-value { font-size: 1.3rem; font-weight: 700; margin-top: 0.2rem; }
.kpi-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.15rem; }

/* ===== Project grid / cards ===== */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}
.project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  transition: box-shadow 0.15s, transform 0.15s;
}
.project-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.project-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.project-card-top h3 { font-size: 1.02rem; font-weight: 700; }
.project-card-meta {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem 1rem;
  font-size: 0.82rem;
}
.project-card-meta strong { display: block; font-size: 0.88rem; margin-top: 0.1rem; }
.meta-label { color: var(--text-muted); font-size: 0.75rem; }
.project-card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--border);
  padding-top: 0.7rem;
  font-size: 0.78rem;
}

.map-link {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  font-size: 0.8rem;
  margin-top: 0.5rem;
  width: fit-content;
  max-width: 100%;
  transition: background 0.15s, border-color 0.15s;
}
.map-link:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.map-link .icon { width: 15px; height: 15px; flex-shrink: 0; color: var(--danger); }
.map-link-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
  color: var(--text-muted);
}
.map-link-cta { font-weight: 700; white-space: nowrap; flex-shrink: 0; }

.budget-status { margin-top: -0.3rem; }
.profit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.profit-row strong { font-size: 1rem; }

.card-hours {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border-top: 1px solid var(--border);
  padding-top: 0.7rem;
}
.muted.small { font-size: 0.8rem; }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.6rem;
  border-radius: 99px;
  background: var(--neutral-soft);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ===== Compare percentage widget ===== */
.compare-pct { display: flex; flex-direction: column; gap: 0.4rem; }
.compare-row { display: grid; grid-template-columns: 74px 1fr 44px; align-items: center; gap: 0.6rem; }
.compare-tag { font-size: 0.72rem; font-weight: 600; color: var(--text-muted); }
.compare-val { font-size: 0.78rem; font-weight: 700; text-align: right; }
.compare-status { font-size: 0.78rem; font-weight: 600; margin-top: 0.15rem; }

/* ===== Progress bar ===== */
.progress-wrap { display: flex; align-items: center; gap: 0.5rem; }
.progress {
  flex: 1;
  height: 8px;
  background: var(--neutral-soft);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar { height: 100%; border-radius: 99px; transition: width 0.3s; }
.progress-label { font-size: 0.75rem; font-weight: 700; width: 34px; text-align: right; }

.tone-success, .tone-bg-success { background: var(--success) !important; }
.tone-warning, .tone-bg-warning { background: var(--warning) !important; }
.tone-danger, .tone-bg-danger { background: var(--danger) !important; }
.tone-info, .tone-bg-info { background: var(--info) !important; }
.tone-neutral, .tone-bg-neutral { background: var(--text-muted) !important; }

.tone-text-success { color: var(--success); }
.tone-text-warning { color: var(--warning); }
.tone-text-danger { color: var(--danger); }
.tone-text-info { color: var(--info); }
.tone-text-neutral { color: var(--text-muted); }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-neutral { background: var(--neutral-soft); color: var(--text-muted); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn .icon { width: 16px; height: 16px; }
a.btn, a.btn:hover { text-decoration: none; }
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--primary-soft); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost-danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn-ghost-danger:hover { background: var(--danger-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.35rem 0.5rem; font-size: 0.78rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); }
.icon-btn .icon { width: 16px; height: 16px; }

.icon { width: 18px; height: 18px; display: block; }
.icon-wrap { display: inline-flex; }
.icon-lg { width: 30px; height: 30px; }

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  background: none;
  border: none;
  padding: 0.65rem 0.9rem;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-body { display: flex; flex-direction: column; gap: 1.25rem; }

/* ===== Panels ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.panel h2 { font-size: 1rem; font-weight: 700; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

.bar-list { display: flex; flex-direction: column; gap: 0.6rem; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 90px; align-items: center; gap: 0.6rem; font-size: 0.8rem; }
.bar-label { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--neutral-soft); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; }
.bar-value { text-align: right; font-weight: 700; }

.chart-legend { display: flex; gap: 1.25rem; font-size: 0.8rem; color: var(--text-muted); }
.chart-legend-item { display: flex; align-items: center; gap: 0.4rem; }
.chart-legend-swatch { width: 10px; height: 10px; border-radius: 3px; }

.column-chart { display: flex; align-items: flex-end; gap: 0.9rem; height: 200px; padding-top: 1.5rem; overflow-x: auto; }
.column-chart-group { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; min-width: 46px; height: 100%; flex-shrink: 0; }
.column-chart-bars { display: flex; align-items: flex-end; gap: 3px; flex: 1; width: 100%; justify-content: center; position: relative; }
.column-chart-col { width: 14px; min-height: 2px; border-radius: 3px 3px 0 0; position: relative; }
.column-chart-col:hover::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 6px;
  background: var(--text);
  color: var(--surface);
  padding: 0.3rem 0.55rem;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  white-space: nowrap;
  z-index: 5;
  pointer-events: none;
}
.column-chart-label { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }
.column-chart-empty { color: var(--text-muted); font-size: 0.85rem; padding: 2rem 0; text-align: center; }

.invoice-number-link { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--primary); font-weight: 600; text-decoration: none; }
.invoice-number-link:hover { text-decoration: underline; }
.invoice-number-link .icon { width: 14px; height: 14px; }
.invoice-number-upload {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: none;
  border: none;
  padding: 0;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.invoice-number-upload:hover { color: var(--primary); }
.invoice-number-upload .icon { width: 12px; height: 12px; opacity: 0.6; }
.hidden-file-input { display: none; }
.invoice-number-cell { display: inline-flex; align-items: center; gap: 0.15rem; }
.invoice-pdf-remove { opacity: 0.5; }
.invoice-pdf-remove:hover { opacity: 1; }

/* ===== Table ===== */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
}
.table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-2); }
.table td select.input { min-width: 150px; }
.align-right { text-align: right; }
.row-actions { display: flex; gap: 0.25rem; justify-content: flex-end; }
.table-total {
  text-align: right;
  font-weight: 700;
  padding: 0.75rem 0.25rem;
  font-size: 0.9rem;
}

/* ===== Empty state ===== */
.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
  color: var(--text-muted);
}
.empty-state .icon-lg { color: var(--text-muted); }

/* ===== Forms ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}
.filter-row { display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filter-row .field { min-width: 200px; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field.span-2 { grid-column: 1 / -1; }
.field label { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); }
.input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.88rem;
  font-family: inherit;
}
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea.input { resize: vertical; }

.add-row { display: flex; gap: 0.5rem; }
.add-row .input { flex: 1; }
.catalog-manager { display: flex; flex-direction: column; gap: 1rem; }

.slider-row { display: flex; align-items: center; gap: 1rem; }
.slider { flex: 1; accent-color: var(--primary); height: 6px; }
.slider-value { font-weight: 700; width: 44px; text-align: right; }

.milestone-list { display: flex; flex-direction: column; gap: 0.5rem; }
.milestone-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.milestone-check { display: flex; align-items: center; gap: 0.6rem; font-size: 0.87rem; cursor: pointer; }
.milestone-check input { width: 16px; height: 16px; accent-color: var(--primary); }
.milestone-check .done { text-decoration: line-through; color: var(--text-muted); }

/* ===== Modal ===== */
.modal-root { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.modal-root.open { pointer-events: auto; }
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 25, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.15s ease-out;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.18s ease-out;
}
.modal-md { max-width: 560px; }
.modal-lg { max-width: 760px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
}
.modal-header h3 { font-size: 1.02rem; font-weight: 700; }
.modal-body { padding: 1.25rem; }
.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}
.footer-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Toasts ===== */
.toast-root {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  color: var(--text);
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: 0.85rem;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-left-color: var(--success); }
.toast-danger { border-left-color: var(--danger); }

/* ===== Banco ===== */
.setup-steps {
  margin: 0;
  padding-left: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.setup-steps strong { color: var(--text); }

.bank-account-list { display: flex; flex-direction: column; gap: 0.5rem; }
.bank-account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  gap: 0.75rem;
}

.rule-list { display: flex; flex-direction: column; gap: 0.4rem; }
.rule-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.rule-row code {
  background: var(--surface-2);
  padding: 0.15rem 0.4rem;
  border-radius: 5px;
  font-size: 0.78rem;
  flex: 1;
  overflow-x: auto;
  white-space: nowrap;
}
.rule-arrow { color: var(--text-muted); }
.rule-row .badge { flex-shrink: 0; }

/* ===== Auth (login / setup) ===== */
#auth-bg {
  display: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #06172e;
  z-index: 0;
}
.auth-bg-on #auth-bg { display: block; }
#auth-net {
  display: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  /* Arriba del velo: si queda debajo, el degradado le come el brillo a las líneas. */
  z-index: 2;
  pointer-events: none;
}
.auth-bg-on #auth-net { display: block; }
/* Velo oscuro: el video de Miami de noche ya es oscuro, pero con las luces de los edificios
   detrás de la tarjeta el texto pierde contraste. */
.auth-bg-on #auth-root::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(60% 55% at 50% 50%, rgba(6,23,46,.72), transparent 75%),
    linear-gradient(180deg, rgba(6,23,46,.45), rgba(6,23,46,.65));
  z-index: 1;
}
.auth-shell {
  position: relative;
  z-index: 3;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1.5rem;
}
.auth-bg-on .auth-shell { background: transparent; }
/* Sobre el video no va ninguna tarjeta: los campos van directo sobre la imagen. El
   contraste lo da el velo de #auth-root, no un recuadro. */
.auth-bg-on .auth-card {
  background: none;
  border: 0;
  box-shadow: none;
  padding: 1.5rem 0;
  max-width: 340px;
  color: #fff;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.5);
}
.auth-bg-on .auth-card h1 { color: #fff; }
.auth-bg-on .auth-card .muted,
.auth-bg-on .auth-card .field label { color: rgba(255, 255, 255, 0.72); }
.auth-bg-on .auth-card .input {
  background: rgba(10, 26, 48, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-color: rgba(255, 255, 255, 0.28);
  color: #fff;
  text-shadow: none;
}
.auth-bg-on .auth-card .input::placeholder { color: rgba(255, 255, 255, 0.5); }
.auth-bg-on .auth-card .input:focus {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.5);
}
.auth-bg-on .auth-card .auth-link { color: rgba(255, 255, 255, 0.85); }
.auth-bg-on .auth-card .btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  color: #fff;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.auth-brand { display: flex; align-items: center; justify-content: center; margin-bottom: 0.75rem; }
.auth-logo { width: 150px; height: auto; display: block; }
.auth-card h1 { font-size: 1.3rem; font-weight: 700; }
.auth-error { color: var(--danger); font-size: 0.85rem; }
.auth-link {
  background: none;
  border: 0;
  padding: 0.25rem;
  align-self: center;
  color: var(--primary);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.auth-link:hover { text-decoration: underline; }
.auth-link:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
.auth-fineprint { font-size: 0.82rem; }
.auth-account {
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.7rem;
  overflow-wrap: anywhere;
}
.btn-block { width: 100%; justify-content: center; margin-top: 0.4rem; }

/* ===== User menu ===== */
.user-menu-host { margin-top: auto; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin: 0.5rem 0;
}
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.3; }
.user-info strong { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-info span { font-size: 0.72rem; color: var(--text-muted); }

.lang-btn { width: auto; padding: 0 0.6rem; gap: 0.3rem; display: inline-flex; align-items: center; font-size: 0.72rem; font-weight: 700; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    position: sticky;
    top: 0;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 0.75rem 1rem;
    z-index: 10;
  }
  .brand { padding: 0; }
  .brand-text { display: none; }
  .sidebar-nav { flex-direction: row; flex: 1; justify-content: center; }
  .nav-link .nav-label { display: none; }
  .nav-link { padding: 0.5rem; }
  .sidebar-footer { border-top: none; padding-top: 0; }
  .user-chip { margin: 0; border: none; padding: 0.3rem; }
  .user-info { display: none; }
  .lang-btn .lang-text { display: none; }
  .main-content { padding: 1.25rem 1rem 3rem; }
  .two-col { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .field.span-2 { grid-column: auto; }
}

@media (max-width: 520px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .project-card-meta { grid-template-columns: 1fr; }
  .kpi-value { font-size: 1.05rem; }
  .kpi-card { padding: 0.8rem; gap: 0.5rem; }

  .sidebar { padding: 0.5rem; gap: 0.15rem; }
  .brand-mark { width: 22px; height: 22px; }
  .sidebar-nav { gap: 0; }
  .nav-link { padding: 0.35rem; }
  .icon-btn { width: 28px; height: 28px; }
  .icon-btn .icon { width: 14px; height: 14px; }
  .user-avatar { width: 26px; height: 26px; font-size: 0.7rem; }
  .sidebar-footer { gap: 0.15rem; }
  /* Con muchas secciones (el admin tiene 8) los íconos no entran en un celular y empujaban
     fuera de la pantalla los botones de usuario, idioma y tema. El menú se desliza de
     costado y esos botones quedan siempre a la vista. */
  .sidebar-nav { min-width: 0; overflow-x: auto; justify-content: flex-start; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  .nav-link { flex-shrink: 0; }
  .brand, #user-menu, .sidebar-footer { flex-shrink: 0; }
}

/* ===== Client Portal ===== */
.portal-hero {
  position: relative;
  border-radius: var(--radius);
  padding: 1.75rem 1.75rem 1.5rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  color: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.portal-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 85% -10%, rgba(255, 255, 255, 0.18), transparent 55%);
  pointer-events: none;
}
.portal-hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85);
}
.portal-hero h1 { font-size: 1.6rem; font-weight: 800; margin-top: 0.35rem; color: #fff; }
.portal-hero p { color: rgba(255, 255, 255, 0.85); margin-top: 0.25rem; font-size: 0.92rem; }

.portal-project-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.2rem 1.2rem 1.4rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.portal-project-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.9rem;
  bottom: 0.9rem;
  width: 4px;
  border-radius: 4px;
  background: var(--info);
}
.portal-project-card[data-status="Completed"]::before { background: var(--success); }
.portal-project-card[data-status="OnHold"]::before,
.portal-project-card[data-status="Planning"]::before { background: var(--warning); }
.portal-project-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.portal-progress-row {
  display: grid;
  grid-template-columns: 140px 1fr auto;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  text-align: left;
  color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease;
}
button.portal-progress-row { cursor: pointer; }
button.portal-progress-row:hover { background: var(--primary-soft); border-color: var(--primary); }
.portal-progress-label { font-weight: 600; font-size: 0.9rem; }
.portal-progress-track { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; }
.portal-progress-fill { height: 100%; border-radius: 99px; transition: width 0.3s ease; }
.portal-progress-fill.tone-done { background: var(--success); }
.portal-progress-fill.tone-mid { background: var(--info); }
.portal-progress-fill.tone-low { background: var(--warning); }
.portal-progress-fill.tone-none { background: var(--border); }
.portal-progress-value { font-size: 0.82rem; font-weight: 700; color: var(--text-muted); white-space: nowrap; text-align: right; min-width: 88px; }
.portal-progress-chevron { color: var(--text-muted); font-size: 1.1rem; }

@media (max-width: 560px) {
  .portal-progress-row { grid-template-columns: 1fr auto; grid-template-areas: "label chevron" "track track" "value value"; row-gap: 0.4rem; }
  .portal-progress-label { grid-area: label; }
  .portal-progress-chevron { grid-area: chevron; }
  .portal-progress-track { grid-area: track; }
  .portal-progress-value { grid-area: value; text-align: left; }
}

.portal-floor-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
  padding: 0.9rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.portal-floor-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.portal-stage-row { display: grid; grid-template-columns: 140px 1fr auto; align-items: center; gap: 0.75rem; }
.portal-stage-label { font-size: 0.82rem; color: var(--text-muted); }
.portal-stage-row-actions { display: flex; align-items: center; gap: 0.4rem; justify-content: flex-end; }
button.portal-floor-card-head-clickable {
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
  border: none;
  background: none;
  padding: 0.35rem 0.4rem;
  margin: -0.35rem -0.4rem 0;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease;
}
button.portal-floor-card-head-clickable:hover { background: var(--primary-soft); }
.portal-floor-card-chevron { color: var(--text-muted); font-size: 1.1rem; margin-left: auto; }
.portal-floor-card-nested { background: var(--surface); padding: 0.7rem 0.85rem; gap: 0.4rem; }
.portal-floor-card-nested .portal-progress-label { font-size: 0.85rem; }

@media (max-width: 560px) {
  .portal-stage-row { grid-template-columns: 1fr auto; grid-template-areas: "label value" "track track"; row-gap: 0.3rem; }
  .portal-stage-label { grid-area: label; }
  .portal-stage-row .portal-progress-track { grid-area: track; }
  .portal-stage-row .portal-progress-value { grid-area: value; }
}

/* ============================================================
   Carga de avance en obra (My Work) — pensada para el celular:
   objetivos de toque grandes, sin desplegables largos, sin tipear.
   ============================================================ */
.field-picker { display: flex; flex-direction: column; gap: 1rem; }

.field-picker-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  font-size: 1.02rem;
}

.field-back {
  display: inline-grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.field-back:hover { background: var(--primary-soft); border-color: var(--primary); }

/* Grilla de edificios: pocas opciones, cuadradas y grandes. */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
  gap: 0.7rem;
}

.field-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: 5rem;
  padding: 0.8rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.field-btn strong { font-size: 1.5rem; line-height: 1; }
.field-btn span { font-size: 0.7rem; color: var(--text-muted); }
.field-btn:hover, .field-btn:focus-visible { background: var(--primary-soft); border-color: var(--primary); }

/* Lista de pisos y etapas: filas altas, fáciles de acertar. */
.field-list { display: flex; flex-direction: column; gap: 0.5rem; }

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-height: 3.4rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.field-row:hover:not(:disabled), .field-row:focus-visible { background: var(--primary-soft); border-color: var(--primary); }
.field-row-meta { font-size: 0.82rem; color: var(--text-muted); white-space: nowrap; }

.field-row.is-done {
  cursor: default;
  opacity: 0.62;
  background: var(--surface-2);
}
.field-row.is-done .field-row-meta { color: var(--success); font-weight: 600; }

.field-note {
  margin: 0;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
}

.field-hint { margin: 0; font-size: 0.88rem; color: var(--text-muted); line-height: 1.5; }

.field-summary { display: flex; flex-direction: column; gap: 0.4rem; }
.field-summary > div {
  display: flex;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
}

.field-inputs { display: flex; flex-direction: column; gap: 0.6rem; }
.field-input-row { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; }
.field-input-row span { font-size: 0.92rem; }
.field-input-row .input { max-width: 6.5rem; text-align: right; font-size: 1.05rem; }

/* En pantallas chicas el modal ocupa todo y los toques crecen. */
@media (max-width: 30rem) {
  .field-grid { grid-template-columns: repeat(3, 1fr); }
  .field-btn { min-height: 4.5rem; }
  .field-row { min-height: 3.8rem; }
  .field-input-row .input { min-height: 3rem; }
}

/* ---------- Gráficos del banco ---------- */
.chart-scroll { overflow-x: auto; }
.chart-svg-wrap { min-width: 520px; }
.chart-svg-wrap svg { display: block; width: 100%; height: auto; }
.chart-axis-text { font-size: 11px; fill: var(--text-muted); font-variant-numeric: tabular-nums; }

.donut-wrap { display: flex; gap: 1.75rem; align-items: center; flex-wrap: wrap; }
.donut-svg { flex: 0 0 190px; max-width: 190px; }
.donut-svg svg { display: block; width: 100%; height: auto; }
.donut-total { font-size: 21px; font-weight: 700; fill: var(--text); font-variant-numeric: tabular-nums; }
.donut-caption { font-size: 10px; fill: var(--text-muted); letter-spacing: 0.06em; text-transform: uppercase; }

.donut-legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 15rem; display: flex; flex-direction: column; gap: 0.4rem; }
.donut-legend li { display: grid; grid-template-columns: 10px 1fr auto auto; align-items: center; gap: 0.6rem; font-size: 0.82rem; }
.donut-swatch { width: 10px; height: 10px; border-radius: 3px; }
.donut-legend-label { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.donut-legend-pct { color: var(--text-muted); font-variant-numeric: tabular-nums; min-width: 2.4rem; text-align: right; }

/* ---------- Importar extracto ---------- */
.stmt-drop {
  border: 1.5px dashed var(--border); border-radius: var(--radius);
  padding: 1.75rem 1.25rem; text-align: center; background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
}
.stmt-drop.is-over { border-color: var(--primary); background: var(--primary-soft); }
.stmt-drop p { margin: 0.4rem 0 0; color: var(--text-muted); font-size: 0.85rem; }

.stmt-verdict { display: flex; gap: 0.85rem; align-items: flex-start; padding: 0.9rem 1.1rem; border-radius: var(--radius); font-size: 0.88rem; }
.stmt-verdict.ok { background: var(--success-soft); color: var(--success); }
.stmt-verdict.bad { background: var(--danger-soft); color: var(--danger); }
.stmt-verdict strong { display: block; margin-bottom: 0.15rem; }
.stmt-verdict ul { margin: 0.4rem 0 0; padding-left: 1.1rem; }

.stmt-review { display: flex; flex-direction: column; gap: 0.4rem; max-height: 26rem; overflow-y: auto; padding-right: 0.25rem; }
.stmt-line {
  display: grid; grid-template-columns: 5.5rem 1fr 12rem 6.5rem; gap: 0.7rem;
  align-items: center; padding: 0.5rem 0.65rem; border-radius: var(--radius-sm);
  font-size: 0.83rem; border: 1px solid transparent;
}
.stmt-line:nth-child(odd) { background: var(--surface-2); }
.stmt-line.is-dupe { opacity: 0.5; border-color: var(--border); border-style: dashed; }
.stmt-line .stmt-date { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.stmt-line .stmt-merchant { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stmt-line .stmt-amount { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.stmt-line select { width: 100%; font-size: 0.8rem; padding: 0.25rem 0.4rem; }

.stmt-match { display: grid; grid-template-columns: auto 5.5rem 1fr auto; gap: 0.7rem; align-items: center; padding: 0.6rem 0.7rem; border-radius: var(--radius-sm); font-size: 0.85rem; }
.stmt-match:nth-child(odd) { background: var(--surface-2); }
.stmt-match .stmt-invoices { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.stmt-match .stmt-note { grid-column: 3 / -1; color: var(--text-muted); font-size: 0.78rem; }

@media (max-width: 720px) {
  .stmt-line { grid-template-columns: 1fr auto; grid-template-areas: "m a" "d d" "c c"; row-gap: 0.35rem; }
  .stmt-line .stmt-merchant { grid-area: m; } .stmt-line .stmt-amount { grid-area: a; }
  .stmt-line .stmt-date { grid-area: d; } .stmt-line .stmt-cat { grid-area: c; }
  .stmt-match { grid-template-columns: auto 1fr; }
}
.panel-subtitle { font-size: 0.82rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin: 1.6rem 0 0.7rem; }
.panel-inset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; background: var(--surface); margin-top: 0.9rem; }
.stmt-results { display: flex; flex-direction: column; }
.stmt-card { display: flex; flex-direction: column; }
.bulk-bar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin: 0.75rem 0 1rem; padding: 0.7rem 0.85rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.bulk-bar select { min-width: 11rem; }
.col-check { width: 2.2rem; text-align: center; }
.linkish { background: none; border: none; padding: 0; font: inherit; color: var(--primary); cursor: pointer; text-align: left; }
.linkish:hover { text-decoration: underline; }
.finance-note { margin-top: 1rem; padding: 0.8rem 1rem; border-left: 3px solid var(--warning); background: var(--warning-soft); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: 0.86rem; display: flex; flex-direction: column; gap: 0.2rem; }
.finance-note strong { color: var(--warning); }
/* Días trabajados y materiales, en la pantalla del empleado */
.day-list { display: flex; flex-direction: column; gap: 0.4rem; }
.day-row {
  display: grid; grid-template-columns: 6.5rem 1fr auto auto auto;
  align-items: center; gap: 0.7rem; padding: 0.6rem 0.8rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 0.88rem;
}
.day-row.is-unpaid { border-left: 3px solid var(--warning); }
.day-row.is-paid { border-left: 3px solid var(--success); }
.day-row.is-partial { border-left: 3px solid var(--info); }
.day-date { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.day-project { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-hours, .day-money { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
@media (max-width: 620px) {
  .day-row { grid-template-columns: 1fr auto; row-gap: 0.3rem; }
  .day-project { grid-column: 1 / -1; order: 3; color: var(--text-muted); font-size: 0.82rem; }
}
.alerta-google { border-left: 3px solid var(--danger); background: var(--danger-soft); padding: 0.85rem 1.1rem; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin-top: 0.9rem; font-size: 0.9rem; }
.alerta-google.suave { border-left-color: var(--warning); background: var(--warning-soft); }
.alerta-google strong { display: block; margin-bottom: 0.3rem; }
.alerta-google p { margin: 0.3rem 0 0; }
.alerta-google .small { font-size: 0.85rem; color: var(--text-muted); }
.alerta-google code { display: block; margin-top: 0.35rem; font-size: 0.8rem; overflow-wrap: anywhere; }
/* Estado del invoice, editable desde la lista */
.estado-invoice { font-size: 0.78rem; padding: 0.2rem 1.5rem 0.2rem 0.5rem; border-radius: 99px; font-weight: 600; border: 1px solid var(--border); cursor: pointer; }
.estado-invoice.tono-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.estado-invoice.tono-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.estado-invoice.tono-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.estado-invoice.tono-neutral { background: var(--neutral-soft); color: var(--neutral); border-color: transparent; }
/* ---------- Vista de rack ---------- */
/* 25rem es el ancho mínimo con el que 48 puertos siguen distinguiéndose uno del otro. */
.rack-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(25rem, 1fr)); gap: 1rem; }
.rack-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem; }
.rack-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.6rem; margin-bottom: 0.6rem; }
.rack-head strong { font-size: 0.98rem; }
.rack-loc { display: block; color: var(--text-muted); font-size: 0.8rem; margin-top: 0.1rem; }
.rack-free { color: var(--text-muted); font-size: 0.78rem; white-space: nowrap; }
.rack-svg { overflow-x: auto; }
.rack-svg svg { display: block; width: 100%; min-width: 22rem; height: auto; }
.rack-u { font-size: 9px; fill: var(--text-muted); font-variant-numeric: tabular-nums; }
.rack-label { font-size: 9.5px; letter-spacing: .02em; fill: #fff; font-weight: 600; }
.rack-device:hover rect { opacity: 1; }

/* ===== Contactos (seguimiento comercial) ===== */
.chip-btn { border: 1px solid transparent; cursor: pointer; font: inherit; font-size: 0.78rem; font-weight: 600; }
.chip-btn:hover { border-color: var(--border); }
.chip-btn.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.chip-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.contact-filters { display: flex; flex-direction: column; gap: 0.6rem; }
.contact-filters .input { max-width: 420px; }
.contact-list { display: flex; flex-direction: column; gap: 0.45rem; }
.contact-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  width: 100%; padding: 0.8rem 1rem; text-align: left; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.contact-row:hover { background: var(--primary-soft); border-color: var(--primary); }
.contact-row:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.contact-main { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.contact-main strong { overflow-wrap: anywhere; }
.contact-next { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; font-size: 0.84rem; margin-top: 0.2rem; }
.contact-side { display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; flex-shrink: 0; }
.contact-value { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.contact-due { font-size: 0.72rem; font-weight: 700; padding: 0.1rem 0.45rem; border-radius: 99px; white-space: nowrap; }
.due-overdue { background: var(--danger-soft); color: var(--danger); }
.due-today { background: var(--warning-soft); color: var(--warning); }
.due-upcoming { background: var(--neutral-soft); color: var(--text-muted); }
.contact-detail { display: flex; flex-direction: column; gap: 1rem; }
.contact-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.contact-head p + p { margin-top: 0.2rem; }
.contact-links a { color: var(--primary); }
.contact-stage-row { display: flex; align-items: center; gap: 0.6rem; }
.contact-stage-row .input { max-width: 240px; }
.contact-nextbox { display: flex; flex-direction: column; gap: 0.25rem; padding: 0.75rem 0.9rem; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.due-box-overdue { border-left: 3px solid var(--danger); }
.due-box-today { border-left: 3px solid var(--warning); }
.contact-log { display: flex; flex-direction: column; gap: 0.7rem; }
.contact-log h3, .contact-timeline h3, .contact-notes h3 { font-size: 0.95rem; }
.contact-timeline { display: flex; flex-direction: column; gap: 0.5rem; }
.timeline-item { display: grid; grid-template-columns: 1fr auto; gap: 0.2rem 0.6rem; padding: 0.6rem 0; border-top: 1px solid var(--border); }
.timeline-item p { grid-column: 1; white-space: pre-wrap; overflow-wrap: anywhere; }
.timeline-item .btn { grid-column: 2; grid-row: 1 / span 2; align-self: start; }
.timeline-meta { display: flex; gap: 0.5rem; align-items: baseline; }
.contact-notes p { white-space: pre-wrap; margin-top: 0.3rem; }
.contact-actions { justify-content: flex-end; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 0.8rem; }
.followup-banner { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap; padding: 0.75rem 1rem; border-radius: var(--radius-sm); background: var(--warning-soft); border-left: 3px solid var(--warning); font-size: 0.9rem; }
@media (max-width: 640px) {
  .contact-row { flex-direction: column; align-items: flex-start; }
  .contact-side { flex-direction: row; align-items: center; }
}
.contact-nextbox .contact-due { align-self: flex-start; }

.check-inline { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.82rem; color: var(--text-muted); margin-top: 0.35rem; cursor: pointer; }
.check-inline input { width: 16px; height: 16px; accent-color: var(--primary); }

/* ===== Numerito del menú ===== */
.nav-link { position: relative; }
.nav-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--danger); color: #fff; font-size: 0.72rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
@media (max-width: 900px) {
  .nav-badge { position: absolute; top: 0; right: 0; min-width: 16px; height: 16px; padding: 0 4px; font-size: 0.62rem; margin: 0; }
}

/* ===== Archivos de obra ===== */
.files-panel { display: flex; flex-direction: column; gap: 0.9rem; }
.files-body { display: flex; flex-direction: column; gap: 0.9rem; }
.files-upload { display: flex; align-items: flex-end; gap: 0.8rem; flex-wrap: wrap; padding: 0.8rem; border: 1px dashed var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.files-upload-fields { display: flex; gap: 0.8rem; flex-wrap: wrap; flex: 1; min-width: 0; }
.files-upload-fields .field { min-width: 180px; flex: 1; }
.files-empty { padding: 0.4rem 0; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.6rem; }
.photo-tile { position: relative; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; cursor: pointer; background: var(--surface-2); aspect-ratio: 4 / 3; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.photo-caption { position: absolute; left: 0; right: 0; bottom: 0; padding: 0.35rem 0.5rem; background: linear-gradient(transparent, rgba(0,0,0,0.65)); color: #fff; font-size: 0.72rem; text-align: left; display: flex; flex-direction: column; line-height: 1.25; }
.photo-caption small { opacity: 0.8; font-size: 0.66rem; }
.photo-viewer { display: flex; flex-direction: column; gap: 0.7rem; }
.photo-viewer img { width: 100%; max-height: 65vh; object-fit: contain; background: #111; border-radius: var(--radius-sm); }
.photo-meta { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.6rem; }
.file-list { display: flex; flex-direction: column; gap: 0.4rem; }
.file-row { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; padding: 0.55rem 0.7rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.file-main { display: flex; align-items: center; gap: 0.7rem; min-width: 0; flex: 1; color: var(--text); text-decoration: none; }
.file-main:hover strong { color: var(--primary); }
.file-ext { flex-shrink: 0; width: 42px; height: 42px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); font-size: 0.68rem; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.file-text { display: flex; flex-direction: column; min-width: 0; }
.file-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-actions { display: flex; align-items: center; gap: 0.25rem; flex-shrink: 0; }
.file-inline { display: block; margin-top: 0.4rem; color: var(--primary); }

/* ===== Tickets ===== */
.ticket-list { display: flex; flex-direction: column; gap: 0.45rem; }
.ticket-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.75rem 0.95rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); text-decoration: none; transition: background 0.15s, border-color 0.15s; }
.ticket-row:hover { background: var(--primary-soft); border-color: var(--primary); }
.ticket-row.ticket-new { border-left: 3px solid var(--danger); }
.ticket-main { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.ticket-title { display: flex; align-items: center; gap: 0.45rem; min-width: 0; }
.ticket-title strong { overflow-wrap: anywhere; }
.ticket-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); flex-shrink: 0; }
.ticket-num { font-size: 0.72rem; font-weight: 700; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ticket-side { display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; flex-shrink: 0; }
.ticket-visit { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.82rem; font-weight: 600; }
.ticket-visit .icon { width: 14px; height: 14px; }
.ticket-visit-box { display: flex; align-items: center; gap: 0.8rem; padding: 0.9rem 1.1rem; border-radius: var(--radius); background: var(--warning-soft); border: 1px solid var(--border); }
.ticket-visit-box.has-date { background: var(--info-soft); }
.ticket-visit-box .icon { width: 22px; height: 22px; }
.ticket-visit-box strong { font-size: 1.05rem; }
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.ticket-col { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.ticket-desc { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 0.4rem; }
.ticket-thread { display: flex; flex-direction: column; gap: 0.6rem; }
.ticket-msg { padding: 0.6rem 0.8rem; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); max-width: 90%; }
.ticket-msg.mine { align-self: flex-end; background: var(--primary-soft); }
.ticket-msg p { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 0.2rem; }
.ticket-msg-meta { display: flex; gap: 0.5rem; align-items: baseline; }
.ticket-sys { display: flex; justify-content: space-between; gap: 0.6rem; flex-wrap: wrap; font-size: 0.82rem; color: var(--text-muted); padding: 0.2rem 0.2rem; border-left: 2px solid var(--border); padding-left: 0.6rem; }
.ticket-reply { display: flex; flex-direction: column; gap: 0.5rem; border-top: 1px solid var(--border); padding-top: 0.7rem; }
.ticket-reply .btn { align-self: flex-end; }
.ticket-controls { display: flex; flex-direction: column; gap: 0.7rem; }
.ticket-banner { background: var(--danger-soft); border-left-color: var(--danger); }
@media (max-width: 900px) {
  .ticket-layout { grid-template-columns: 1fr; }
  .ticket-layout .ticket-col:last-child { order: -1; }
}
@media (max-width: 640px) {
  .ticket-row { flex-direction: column; align-items: flex-start; }
  .ticket-side { flex-direction: row; align-items: center; flex-wrap: wrap; }
  .photo-grid { grid-template-columns: repeat(2, 1fr); }
  .file-row { flex-wrap: wrap; }
}
/* En pantallas chicas el botón de subir se montaba sobre el selector: se apilan. */
.files-upload-fields .field { min-width: 0; }
.files-upload-fields .input { width: 100%; }
@media (max-width: 640px) {
  .files-upload { flex-direction: column; align-items: stretch; }
  .files-upload-fields { flex-direction: column; }
  .files-upload > .btn { justify-content: center; }
}

/* ---- Cotizaciones ---- */
.estimate-head, .estimate-line { display: grid; grid-template-columns: 1fr 86px 110px 96px 36px; gap: 0.5rem; align-items: center; }
.estimate-head { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); padding: 0 0 0.35rem; }
.estimate-head span:nth-child(2), .estimate-head span:nth-child(3), .estimate-head span:nth-child(4) { text-align: right; }
.estimate-line { padding: 0.25rem 0; }
.estimate-line .input.mini { text-align: right; }
.estimate-line .linea-total { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.estimate-actions { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.6rem; flex-wrap: wrap; }
.estimate-totals { margin-top: 0.9rem; border-top: 1px solid var(--border); padding-top: 0.6rem; display: flex; flex-direction: column; gap: 0.3rem; }
.estimate-totals .fila-total { display: flex; justify-content: space-between; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.estimate-totals .fila-total.destacada { font-size: 1.05rem; font-weight: 800; color: var(--text); }
@media (max-width: 640px) {
  .estimate-head { display: none; }
  .estimate-line { grid-template-columns: 1fr 70px 90px; grid-template-areas: "n n n" "q p t"; }
  .estimate-line .input:first-child { grid-area: n; }
}
.field-hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.25rem; line-height: 1.35; }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.small { font-size: 0.78rem; }

/* ---- Menú "Más": lo que no se usa todos los días ---- */
.nav-more { display: flex; flex-direction: column; }
.nav-more-toggle { width: 100%; background: none; border: 0; cursor: pointer; font: inherit; text-align: left; }
.nav-more-list { display: none; flex-direction: column; margin-left: 0.6rem; border-left: 1px solid var(--border); padding-left: 0.4rem; }
.nav-more.open .nav-more-list { display: flex; }
.tab-more { margin-left: auto; max-width: 150px; font-size: 0.85rem; }
@media (max-width: 860px) {
  .nav-more-list { margin-left: 0; border-left: 0; }
  .tab-more { max-width: 120px; }
}

/* ---- Plan de pagos ---- */
.draw-bar { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: var(--surface-2); }
.draw-seg { height: 100%; }
.draw-legend { display: flex; gap: 1.2rem; flex-wrap: wrap; margin-top: 0.55rem; font-size: 0.82rem; color: var(--text-muted); }
.draw-legend span { color: var(--text-muted); }
.draw-legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 0.35rem; background: currentColor; }
.draw-legend .tone-text-success::before { background: var(--success); }
.draw-legend .tone-text-info::before { background: var(--info); }
.draw-legend .tone-text-warning::before { background: var(--warning); }
.draw-hito { border-left: 3px solid transparent; padding-left: 0.55rem; }
.draw-hito.estado-paid { border-left-color: var(--success); }
.draw-hito.estado-invoiced { border-left-color: var(--info); }
.draw-hito.estado-pending { border-left-color: var(--warning); }
.kpi-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 1rem; }
.kpi-row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 1rem; }
@media (max-width: 1000px) { .kpi-row-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px) { .kpi-row-3, .kpi-row-4 { grid-template-columns: 1fr; } }
.pct-cell { display: flex; align-items: center; gap: 0.5rem; min-width: 150px; }
.pct-cell .bar-track { flex: 1; }
.pct-cell .pct-num { font-size: 0.82rem; font-weight: 700; font-variant-numeric: tabular-nums; width: 38px; text-align: right; }

/* ---- Imprimir / guardar como PDF ----
   Lo que se imprime es la tabla, no la aplicación: fuera el menú, las solapas, los
   botones y los avisos. Queda una hoja que se puede mandar por mail sin explicar nada. */
.print-head { display: none; }
@media print {
  @page { size: letter; margin: 14mm; }
  body { background: #fff; }
  .sidebar, .tabs, .followup-banner, .back-link, .page-header .btn, .row-actions,
  .section-head .btn, .table-total .btn, .no-print { display: none !important; }
  .app-shell, .main-content, .view-root, .tab-body { display: block; margin: 0; padding: 0; }
  .panel { box-shadow: none; border: 1px solid #dde4ee; break-inside: avoid; }
  .kpi-row { display: grid !important; grid-template-columns: repeat(3, 1fr) !important; }
  .kpi-card { box-shadow: none; border: 1px solid #dde4ee; }
  .print-head { display: block; margin-bottom: 10mm; border-bottom: 2px solid #1478ff; padding-bottom: 4mm; }
  .print-head img { width: 42mm; }
  .print-head .ph-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 10mm; }
  .print-head h2 { font-size: 15pt; margin-top: 3mm; }
  .print-head .ph-meta { font-size: 9pt; color: #55627a; text-align: right; line-height: 1.5; }
  table { font-size: 9.5pt; }
  a { color: inherit; text-decoration: none; }
}

/* ---- Asistente ---- */
/* ===== Ada ===== */
/* No es un chat: es un informe que se va escribiendo. La pregunta queda como título de
   sección y la respuesta abajo, a todo el ancho de la columna. Sin burbujas, sin avatar
   repetido en cada línea, sin globos de colores. Lo que se lee son cifras de una obra. */
.ada { display: flex; flex-direction: column; gap: 1rem; height: calc(100vh - 7rem); min-height: 420px; }

.ada-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.ada-id { min-width: 0; }
.ada-eyebrow {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--primary); margin-bottom: 0.3rem;
}
.ada-id h1 { font-size: 1.5rem; letter-spacing: -0.02em; line-height: 1.1; }
.ada-sub { font-size: 0.87rem; color: var(--text-muted); margin-top: 0.25rem; max-width: 46rem; }

.chat-panel { padding: 0; flex: 1; min-height: 0; display: flex; overflow: hidden; }
.chat-thread { position: relative; flex: 1; overflow-y: auto; padding: 1.6rem 1.75rem; scroll-behavior: smooth; }

/* La pregunta: título de sección, con el filete del lado izquierdo que usa el resto
   de la app para marcar de quién es una fila. */
.ada-q { margin: 2.1rem 0 1.05rem; padding-left: 0.85rem; border-left: 2px solid var(--primary); }
.ada-q:first-child { margin-top: 0; }
.ada-q h2 { font-size: 1.12rem; font-weight: 650; letter-spacing: -0.015em; line-height: 1.35; }

.ada-a { max-width: 44rem; font-size: 0.95rem; line-height: 1.65; }
.ada-a + .ada-q { border-top: 0; }

.ada-a-foot { margin-top: 0.9rem; opacity: 0; transition: opacity 0.15s; }
.ada-a:hover .ada-a-foot, .ada-a-foot:focus-within { opacity: 1; }

/* Markdown de las respuestas */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md-p { margin: 0.7rem 0; }
/* Título de la respuesta y rótulos de sección: dos escalones, no uno. */
.md-title {
  margin: 1.4rem 0 0.75rem; font-size: 1.04rem; font-weight: 650; letter-spacing: -0.015em;
  line-height: 1.35; padding-bottom: 0.55rem; border-bottom: 1px solid var(--border);
}
.md-h {
  margin: 1.5rem 0 0.5rem; font-size: 0.7rem; font-weight: 700;
  letter-spacing: 0.11em; text-transform: uppercase; color: var(--text-muted);
}
.md-title:first-child, .md-h:first-child { margin-top: 0; }
.md-list { margin: 0.6rem 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: 0.4rem; }
.md-list li { line-height: 1.6; padding-left: 0.15rem; }
.md-list li::marker { color: var(--text-muted); }
.md-code {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px;
  padding: 0.08em 0.35em; font-size: 0.85em;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.md-money { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Una viñeta "Contrato: $144,945" es en realidad una fila de un cuadro de números.
   Se arma como tal: etiqueta a la izquierda, cifra a la derecha, filete fino entre
   una y otra. Es casi toda la respuesta, y así se lee de corrido hacia abajo. */
.md-figs { margin: 0.75rem 0; display: flex; flex-direction: column; }
.md-fig {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  padding: 0.42rem 0; border-bottom: 1px solid var(--border);
}
.md-fig:last-child { border-bottom: 0; }
.md-fig-label { color: var(--text-muted); font-size: 0.9rem; min-width: 0; }
.md-fig-val { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Esperando: un filete que avanza debajo de la pregunta, no un globo con puntitos. */
.ada-a-wait { padding-top: 0.2rem; }
.ada-wait-bar { height: 2px; border-radius: 2px; background: var(--border); overflow: hidden; position: relative; }
.ada-wait-bar::after {
  content: ""; position: absolute; inset: 0; width: 38%;
  background: var(--primary); border-radius: 2px;
  animation: ada-wait 1.25s ease-in-out infinite;
}
.ada-wait-text { margin-top: 0.6rem; font-size: 0.85rem; color: var(--text-muted); }
@keyframes ada-wait { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
@media (prefers-reduced-motion: reduce) {
  .ada-wait-bar::after { animation: none; width: 100%; opacity: 0.4; }
}

/* Pantalla vacía: un índice, no cuatro tarjetas iguales. */
.ada-empty { max-width: 40rem; }
.ada-empty-hint { font-size: 1.05rem; line-height: 1.55; color: var(--text); }
.ada-empty-label {
  margin: 1.8rem 0 0.2rem; font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.13em; text-transform: uppercase; color: var(--text-muted);
}
.ada-index { list-style: none; margin: 0; padding: 0; }
.ada-index li { border-bottom: 1px solid var(--border); }
.ada-index-item {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.85rem 0.2rem; background: none; border: 0; cursor: pointer;
  font: inherit; font-size: 0.95rem; color: var(--text); text-align: left;
  transition: color 0.15s, padding-left 0.15s;
}
.ada-index-item .icon-wrap { color: var(--border); flex: none; transition: color 0.15s; }
.ada-index-item:hover { color: var(--primary); padding-left: 0.55rem; }
.ada-index-item:hover .icon-wrap { color: var(--primary); }

/* Campo para escribir */
.chat-input {
  display: flex; gap: 0.5rem; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.45rem 0.45rem 0.45rem 0.3rem;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea.ada-campo {
  flex: 1; resize: none; border: none; background: transparent; box-shadow: none;
  padding: 0.5rem 0.6rem; line-height: 1.5; overflow: hidden;
  /* Alto exacto de un renglón: el campo crece solo al escribir. Sin esto, en el teléfono
     el placeholder largo parte en dos y se ve la mitad de arriba del segundo renglón. */
  height: 2.5rem; min-height: 2.5rem; max-height: 160px;
}
textarea.ada-campo:focus { outline: none; box-shadow: none; border: none; }
.ada-send { border-radius: 9px; padding: 0.55rem 0.7rem; flex: none; }
.ada-send .icon-wrap { margin: 0; }
.ada-send span:empty { display: none; }
.chat-disclaimer { font-size: 0.76rem; color: var(--text-muted); text-align: center; }

/* Abajo de 900px la barra lateral pasa a ser una barra arriba y come más alto:
   el alto de la pantalla tiene que descontarla o aparece scroll en toda la página. */
@media (max-width: 900px) { .ada { height: calc(100vh - 11rem); } }

@media (max-width: 640px) {
  .ada { gap: 0.8rem; }
  .ada-sub { display: none; }
  .ada-id h1 { font-size: 1.3rem; }
  .chat-thread { padding: 1.1rem 1rem; }
  .ada-q { margin: 1.6rem 0 0.85rem; }
  .ada-q h2 { font-size: 1.02rem; }
  .ada-empty-hint { font-size: 0.97rem; }
  /* Sin hover no hay forma de descubrir el botón de copiar: en el teléfono va siempre visible. */
  .ada-a-foot { opacity: 1; }
  .chat-disclaimer { font-size: 0.72rem; }
}

/* ===== Desglose de un sector del draw sheet ===== */
/* Sin cajas: filetes finos entre renglones y las cifras alineadas en columna, para poder
   bajar con el ojo por una sola columna en vez de leer renglón por renglón. */
/* El nombre del sector es texto que se puede tocar. Sin flechita adelante: chocaba con
   la barrita de color del estado y partía el renglón en dos. */
.draw-abrible {
  display: block; width: 100%; padding: 0; border: 0; background: none;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.draw-abrible:hover { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }
/* El reset del botón mata todos los bordes, incluido el filete de color del estado.
   Se repone acá, que gana por especificidad. */
.draw-hito.draw-abrible { padding-left: 0.55rem; border-left: 3px solid transparent; }
.draw-hito.draw-abrible.estado-paid { border-left-color: var(--success); }
.draw-hito.draw-abrible.estado-invoiced { border-left-color: var(--info); }
.draw-hito.draw-abrible.estado-pending { border-left-color: var(--warning); }

.bd { display: flex; flex-direction: column; gap: 1.1rem; }
.bd-head h3 { font-size: 1.15rem; font-weight: 650; letter-spacing: -0.015em; margin-bottom: 0.8rem; }
.bd-datos { display: flex; flex-wrap: wrap; gap: 1.8rem; }
.bd-dato { display: flex; flex-direction: column; gap: 0.1rem; }
.bd-dato-label { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); }
.bd-dato-val { font-size: 1.1rem; font-weight: 650; font-variant-numeric: tabular-nums; }

.bd-tabla { display: flex; flex-direction: column; }
.bd-row {
  display: grid; grid-template-columns: 1fr 7rem 7rem 7rem 1.2rem;
  align-items: center; gap: 0.9rem;
  width: 100%; padding: 0.7rem 0.2rem; margin: 0;
  border: 0; border-bottom: 1px solid var(--border); background: none;
  font: inherit; color: inherit; text-align: left;
}
.bd-row:last-child { border-bottom: 0; }
.bd-row-head {
  padding: 0 0.2rem 0.4rem; border-bottom: 1px solid var(--border);
  font-size: 0.66rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-muted);
}
.bd-row-head span:not(:first-child):not(:last-child) { text-align: right; }
.bd-row-link { cursor: pointer; transition: background 0.12s; }
.bd-row-link:hover { background: var(--surface-2); }
.bd-row-link:hover .bd-chev { color: var(--primary); transform: translateX(2px); }

.bd-row-nombre { display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; font-weight: 600; }
.bd-num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
/* Un cero no es un logro: solo se pinta de verde lo que de verdad entró. */
.bd-num-cob { color: var(--success); }
.bd-num-cob.vacio { color: var(--text-muted); }
.bd-chev { color: var(--border); font-size: 1.05rem; text-align: center; transition: color 0.12s, transform 0.12s; }

/* La misma información en forma: cuánto de lo hecho está facturado, y cuánto ya se cobró.
   Un piso trabajado y sin facturar se ve de lejos, sin leer un número. */
/* Ancho acotado: a todo el ancho del renglón se lee como un subrayado del nombre,
   no como una medida. */
.bd-barra { position: relative; display: block; width: 100%; max-width: 11rem; height: 4px; border-radius: 2px; background: var(--neutral-soft); overflow: hidden; }
.bd-barra-fact, .bd-barra-cob { position: absolute; top: 0; left: 0; height: 100%; border-radius: 2px; }
.bd-barra-fact { background: var(--info); }
.bd-barra-cob { background: var(--success); }

/* Detalle de un piso: trabajo, valor y factura. */
.bd-row-item { grid-template-columns: 1fr 7rem auto; }
.bd-item-sub { font-size: 0.8rem; font-weight: 400; color: var(--text-muted); }
.bd-fact { font-size: 0.8rem; text-align: right; white-space: nowrap; }

/* Etapas dentro de un piso: cableado, terminaciones, APs. */
.bd-etapas { display: flex; flex-direction: column; gap: 1.3rem; }
.bd-etapa-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  padding-bottom: 0.4rem; border-bottom: 1px solid var(--border); margin-bottom: 0.2rem;
}
.bd-etapa-nombre { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.11em; text-transform: uppercase; color: var(--text-muted); }
.bd-etapa-val { font-weight: 650; font-variant-numeric: tabular-nums; }

.bd-aviso {
  padding: 0.7rem 0.9rem; border-radius: var(--radius-sm);
  background: var(--warning-soft); color: var(--warning); font-size: 0.87rem; font-weight: 600;
}
.bd-hint { margin-top: 0.7rem; }

@media (max-width: 760px) {
  .bd-datos { gap: 1rem 1.4rem; }
  /* Angosto: el nombre arriba a todo el ancho y las tres cifras abajo, en tres columnas. */
  .bd-row, .bd-row-item { grid-template-columns: 1fr 1fr 1fr; row-gap: 0.4rem; padding: 0.75rem 0.2rem; }
  .bd-row-nombre { grid-column: 1 / -1; }
  .bd-row-head { display: none; }
  .bd-chev { display: none; }
  /* Sin encabezado de columnas, cada cifra lleva su etiqueta encima. */
  .bd-row-link .bd-num::before,
  .bd-row-item .bd-num::before { content: attr(data-label); display: block; font-size: 0.62rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-muted); }
  .bd-row-link .bd-num, .bd-row-item .bd-num { text-align: left; }
  .bd-fact { text-align: left; grid-column: 1 / -1; }
}

/* ===== Plan de equipos ===== */
.plan-seccion { margin-bottom: 1.2rem; }
.plan-seccion h3 { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.11em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.6rem; }

/* Los avisos van arriba y en amarillo: un total que cierra mal no se nota mirando el resultado. */
.plan-avisos {
  padding: 0.8rem 1rem; margin-bottom: 1rem; border-radius: var(--radius-sm);
  background: var(--warning-soft); color: var(--warning); font-size: 0.88rem;
}
.plan-avisos ul { margin: 0.35rem 0 0; padding-left: 1.1rem; }

/* Un renglón por tipo de unidad: nombre a la izquierda y los números en fila. */
.plan-perfil {
  display: flex; align-items: flex-end; gap: 0.9rem; flex-wrap: wrap;
  padding: 0.7rem 0; border-bottom: 1px solid var(--border);
}
.plan-perfil:last-of-type { border-bottom: 0; }
.plan-perfil-nombre { flex: 1; min-width: 9rem; font-weight: 650; padding-bottom: 0.45rem; }
.plan-perfil .field { width: 6rem; margin: 0; }

.plan-edificio { margin-top: 1rem; }
.plan-edificio h4 { font-size: 0.95rem; margin-bottom: 0.4rem; }
.plan-piso { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.plan-piso:last-child { border-bottom: 0; }
.plan-piso-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.4rem; }
.plan-mix { display: flex; gap: 0.7rem; flex-wrap: wrap; }
.plan-mix .field { width: 8rem; margin: 0; }
/* La suma contra lo que dice el edificio: en rojo si no cierra, y se ve mientras se escribe. */
.plan-suma { font-variant-numeric: tabular-nums; font-size: 0.85rem; font-weight: 650; color: var(--text-muted); }
.plan-suma.bien { color: var(--success); }
.plan-suma.mal { color: var(--danger); }

.plan-closet { padding: 0.9rem 0; border-bottom: 1px solid var(--border); }
.plan-closet:last-of-type { border-bottom: 0; }
.plan-closet-top { display: flex; align-items: flex-end; gap: 0.8rem; flex-wrap: wrap; }
.plan-closet-top .field { margin: 0; }
.plan-pisos-check { display: flex; gap: 0.7rem; flex-wrap: wrap; }
.plan-extras-wrap { margin-top: 0.6rem; }
.plan-extras-label { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); }
.plan-extras { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.3rem; align-items: flex-start; }
.plan-extra { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.plan-extra .input { width: auto; min-width: 7rem; }
.plan-extra .input[type="number"] { min-width: 4.5rem; width: 4.5rem; }

@media (max-width: 760px) {
  .plan-perfil .field, .plan-mix .field { width: 100%; }
  .plan-extra .input { width: 100%; }
}
.plan-agregar { margin-top: 0.9rem; }
.plan-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.3rem; }

/* ===== Calculadora de equipos ===== */
/* Entrada a la izquierda, resultado a la derecha y pegado arriba: los números se mueven
   mientras se escribe, y eso solo sirve si se ven al mismo tiempo que lo que se cambia. */
/* Se mide contra el ancho del contenedor, no el del viewport. Adentro de un proyecto la
   pantalla es ancha pero la columna es angosta, y con media queries la fila se apilaba
   mal: el nombre del tipo se colapsaba a cero y los títulos quedaban encimados. */
.calc { display: flex; flex-wrap: wrap; gap: 1.1rem; align-items: flex-start; container-type: inline-size; }
.calc-entrada { flex: 1 1 26rem; display: flex; flex-direction: column; gap: 1.1rem; min-width: 0; }
.calc-salida { flex: 1 1 17rem; max-width: 22rem; position: sticky; top: 1rem; }

.calc-fila {
  display: grid; grid-template-columns: minmax(0, 1fr) 5.5rem 4.5rem 5.5rem 4rem 2.2rem;
  gap: 0.5rem; align-items: center; padding: 0.3rem 0;
}
.calc-fila-extra { grid-template-columns: minmax(0, 1fr) 5.5rem 9rem 7rem 2.2rem; }
.calc-head {
  font-size: 0.66rem; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 700; padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border); margin-bottom: 0.2rem;
}
/* Cada campo con su rótulo. En ancho el rótulo se esconde porque están los títulos de
   columna; en angosto los títulos desaparecen y el rótulo pasa a ser lo único que hay. */
.calc-campo { display: block; min-width: 0; }
.calc-campo-lab { display: none; }
.calc-campo .input { width: 100%; }
.calc-check { display: flex; justify-content: center; align-items: center; }
.calc-check .input { width: auto; }

.calc-panel { gap: 0; }
.calc-bigs { display: flex; flex-direction: column; gap: 0.1rem; margin-bottom: 1rem; }
.calc-big { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding: 0.35rem 0; }
.calc-big-k { font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.calc-big-v { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
/* El número que se vino a buscar: los switches. */
.calc-big.fuerte { border-bottom: 2px solid var(--primary); margin-bottom: 0.4rem; padding-bottom: 0.5rem; }
.calc-big.fuerte .calc-big-v { font-size: 2.1rem; color: var(--primary); }

.calc-detalle { display: flex; flex-direction: column; border-top: 1px solid var(--border); padding-top: 0.6rem; }
.calc-linea {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 0.28rem 0; font-size: 0.87rem; color: var(--text-muted);
}
.calc-linea b { color: var(--text); font-variant-numeric: tabular-nums; }

/* Angosto: el nombre a todo el ancho y los números abajo, cada uno con su rótulo
   encima. Sin eso son cajas con números y no se sabe cuál es la cantidad. */
@container (max-width: 640px) {
  .calc-fila { grid-template-columns: 1fr 1fr 1fr; row-gap: 0.6rem; padding: 0.7rem 0; border-bottom: 1px solid var(--border); }
  .calc-fila-extra { grid-template-columns: 1fr 1fr; }
  .calc-fila > .calc-campo:first-child { grid-column: 1 / -1; }
  .calc-head { display: none; }
  .calc-campo-lab {
    display: block; font-size: 0.64rem; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--text-muted); margin-bottom: 0.2rem;
  }
  .calc-check { justify-content: flex-start; display: block; }
}
@media (max-width: 900px) { .calc-salida { position: static; } }
/* La barra de la calculadora cuando vive adentro de un proyecto: ya hay un encabezado
   arriba, así que acá solo va la aclaración y el botón de limpiar. */
.calc-barra { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.9rem; }
/* Lo que la obra ya tiene cargado, para agregar de un toque. Va con la cantidad al lado
   porque es el dato que decide si eso es una vivienda o un renglón de logística. */
.calc-sugeridos { margin-top: 0.9rem; padding-top: 0.8rem; border-top: 1px solid var(--border); }
.calc-sugeridos-lab { font-size: 0.66rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-muted); }
.calc-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.45rem; }
.calc-nota { font-size: 0.82rem; margin: -0.4rem 0 0.9rem; line-height: 1.4; }
.calc-fila-modelo { grid-template-columns: minmax(0, 1fr) 5.5rem 6.5rem 4rem 2.2rem; }
.calc-modelos-res { margin-bottom: 0.3rem; }
