/* ===== 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; }
.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-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1.5rem;
}
.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; }
.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; }
}

/* ===== 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; }
}
