:root {
  --bg: #f4f5f7;
  --sidebar-bg: #1c2333;
  --sidebar-text: #aab1c5;
  --sidebar-text-active: #ffffff;
  --primary: #e8912d;
  --primary-dark: #c9761a;
  --card-bg: #ffffff;
  --border: #e3e5ea;
  --text: #1f2430;
  --text-muted: #6b7280;
  --success: #1f9d55;
  --success-bg: #e6f7ec;
  --warning: #b9770e;
  --warning-bg: #fdf1dd;
  --danger: #c0392b;
  --danger-bg: #fbe9e7;
  --info: #2563eb;
  --info-bg: #e8effd;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 24, 38, 0.08), 0 1px 2px rgba(20, 24, 38, 0.06);
}

* { box-sizing: border-box; }

/* ---------- Login ---------- */
.login-screen {
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: var(--sidebar-bg);
  padding: 20px;
}
.login-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.login-logo { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 10px; overflow: hidden; }
.login-logo img { width: 100%; height: 100%; object-fit: cover; }
.login-card h1 { font-size: 18px; margin: 0 0 18px; color: var(--text); }
.login-card .field { text-align: left; margin-bottom: 12px; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

button, input, select, textarea { font-family: inherit; font-size: 14px; }

.app {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 22px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 16px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  overflow: hidden;
}

.brand-text strong {
  color: #fff;
  font-size: 14px;
  white-space: normal;
  overflow-wrap: break-word;
}

.brand-text span {
  color: var(--sidebar-text);
  font-size: 11px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-icon { font-size: 15px; width: 18px; text-align: center; }

.nav-btn:hover { background: rgba(255,255,255,0.06); color: var(--sidebar-text-active); }

.nav-btn.active {
  background: var(--primary);
  color: #1c2333;
  font-weight: 700;
}

.settings-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--sidebar-text);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}

.settings-btn:hover { color: #fff; border-color: rgba(255,255,255,0.3); }

/* ---------- Main ---------- */
.main {
  flex: 1;
  min-width: 0;
  padding: 28px 34px 60px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 22px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 { margin: 0 0 4px; font-size: 22px; }
.page-header p { margin: 0; color: var(--text-muted); font-size: 13.5px; }

.header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: filter 0.1s, background 0.1s;
  white-space: nowrap;
}

.btn:hover { filter: brightness(0.97); }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #1c2333;
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.btn-danger { color: var(--danger); border-color: #f0c4bd; background: var(--danger-bg); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 6px 9px; }

/* ---------- Cards / grid ---------- */
.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.stat-card .label { font-size: 12.5px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 24px; font-weight: 800; margin-top: 8px; }
.stat-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.card h3 { margin: 0 0 14px; font-size: 15px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-bg); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  padding: 12px 14px;
  background: #f8f9fb;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
td.actions { text-align: right; white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 30px; margin-bottom: 10px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted { background: #eef0f3; color: var(--text-muted); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(232,145,45,0.15);
}
.field textarea { resize: vertical; min-height: 64px; }
.hint { font-size: 11.5px; color: var(--text-muted); }

.alert-list { list-style: none; padding: 0; margin: 6px 0 0; }
.alert-list li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.alert-list li:last-child { border-bottom: none; }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 220px;
}
.search-box input { border: none; outline: none; width: 100%; background: transparent; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.filters select { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: #fff; }

/* ---------- Tabs (sub) ---------- */
.subtabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.subtab-btn {
  padding: 9px 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.subtab-btn.active { color: var(--primary-dark); border-bottom-color: var(--primary); }

/* ---------- Modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20,24,38,0.45);
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}
.modal-overlay.active { display: flex; }
.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 620px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal.modal-wide { max-width: 1160px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Proposal items ---------- */
.items-table th, .items-table td { padding: 8px; }
.items-table input { padding: 7px 8px; }
.items-total-row td { font-weight: 700; }
.remove-item-btn { color: var(--danger); background: none; border: none; cursor: pointer; font-size: 16px; }

/* ---------- Quote matrix ---------- */
.quote-matrix { border-collapse: collapse; white-space: nowrap; }
.quote-matrix th, .quote-matrix td { border: 1px solid var(--border); padding: 6px 8px; font-size: 13px; }
.quote-matrix thead th { background: var(--bg); font-weight: 700; }
.quote-matrix th select { max-width: 150px; }
.quote-matrix input { width: 90px; padding: 6px 7px; }
.quote-matrix th select, .quote-matrix th .remove-item-btn { vertical-align: middle; }
.quote-matrix tfoot td { font-weight: 700; background: var(--bg); }
.quote-matrix tfoot input { font-weight: 400; }
.quote-matrix td.num { text-align: right; }

/* ---------- Progress bar ---------- */
.progress-bar { background: #eef0f3; border-radius: 999px; height: 8px; overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--primary); }

/* ---------- Obra detail ---------- */
.obra-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color .1s;
}
.obra-list-item:hover { border-color: var(--primary); }
.obra-list-item .title { font-weight: 700; }
.obra-list-item .meta { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }

.back-link { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 13px; margin-bottom: 10px; padding: 0; }
.back-link:hover { color: var(--text); }

.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; align-items: center; overflow-x: auto; }
  .nav { flex-direction: row; }
  .brand { border: none; margin: 0; padding: 0 10px 0 0; }
  .settings-btn { white-space: nowrap; }
  .main { padding: 20px; }
  .form-grid, .two-col { grid-template-columns: 1fr; }
}

/* ---------- Print ---------- */
.print-area { display: none; }
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area {
    display: block; position: absolute; top: 0; left: 0; width: 100%; padding: 28px 32px;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: #2a2a2a;
  }

  .print-header { display: flex; align-items: center; justify-content: space-between; border-bottom: 2px solid #4a4643; padding-bottom: 12px; margin-bottom: 18px; }
  .print-logo { height: 46px; width: auto; display: block; }
  .print-header-info { text-align: right; font-size: 11px; color: #55524f; line-height: 1.5; }
  .print-role { font-weight: 700; }

  .print-section { margin-bottom: 18px; }
  .print-section-bar {
    background: #4a4643; color: #fff; font-weight: 700; font-size: 12.5px; letter-spacing: 0.3px;
    padding: 8px 14px; border-left: 5px solid var(--primary); margin-bottom: 10px;
  }

  .print-id-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; font-size: 13px; }
  .print-id-grid .label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--primary-dark); font-weight: 700; margin-bottom: 2px; }

  .print-text { font-size: 13px; line-height: 1.6; white-space: pre-wrap; margin: 0; }

  .print-table { width: 100%; border-collapse: collapse; }
  .print-table th { background: #eeeeee; color: var(--primary-dark); text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.3px; text-align: left; padding: 8px 10px; }
  .print-table td { border-bottom: 1px solid #e2e2e2; padding: 8px 10px; font-size: 12.5px; }

  .print-total-bar {
    display: flex; justify-content: space-between; align-items: center; margin-top: 10px;
    background: var(--primary); color: #fff; font-weight: 700; font-size: 14px; padding: 10px 14px; border-radius: 4px;
  }

  .print-matrix, .print-matrix th, .print-matrix td { border: 1px solid #ccc; }
  .print-matrix th, .print-matrix td { text-align: center; padding: 6px 8px; }
  .print-matrix td:first-child { text-align: left; }
  .print-matrix tfoot td { font-weight: 700; background: #f5f5f5; }

  .print-note-box { background: #f0f0ef; border-radius: 4px; padding: 12px 14px; }
  .print-note-label { color: var(--primary-dark); font-weight: 700; font-size: 10.5px; letter-spacing: 0.3px; margin-bottom: 6px; }

  .print-accept { page-break-inside: avoid; }
  .print-signatures { display: flex; gap: 40px; margin-top: 34px; }
  .print-sign { flex: 1; font-size: 12.5px; }
  .print-sign-line { border-top: 1px solid #888; margin-bottom: 6px; }
  .print-sign strong { display: block; font-size: 13px; }
  .print-sign span { color: #6b6b6b; }

  .print-footer { margin-top: 26px; padding-top: 10px; border-top: 1px solid #e2e2e2; font-size: 10px; color: #8a8a8a; }

  /* ---------- Contrato ---------- */
  .contract { font-size: 12.5px; line-height: 1.55; }
  .contract-mainheader { text-align: center; margin-bottom: 18px; }
  .contract-logo { height: 70px; width: auto; margin-bottom: 10px; }
  .contract-mainheader h1 { margin: 0; font-size: 16px; letter-spacing: 0.2px; }
  .contract-subtitle { color: var(--primary-dark); font-weight: 700; font-size: 12px; margin-top: 4px; letter-spacing: 0.2px; }
  .contract-subline { font-style: italic; color: #6b6b6b; font-size: 10.5px; margin-top: 4px; }

  .contract-h2 {
    font-weight: 700; font-size: 12.5px; letter-spacing: 0.2px; color: #2a2a2a;
    border-bottom: 2px solid var(--primary); padding-bottom: 4px; margin: 18px 0 8px;
  }

  .contract-p { text-align: justify; margin: 0 0 8px; }
  .contract-list { margin: 0 0 8px; padding-left: 20px; }
  .contract-list li { text-align: justify; margin-bottom: 4px; }

  .contract-place-date { margin-top: 22px; }

  .contract-signatures { display: flex; gap: 40px; margin-top: 40px; page-break-inside: avoid; }
  .contract-sign { flex: 1; font-size: 12px; text-align: center; }
  .contract-sign-line { border-top: 1px solid #888; margin-bottom: 6px; }
  .contract-sign strong { display: block; font-size: 12px; }
  .contract-sign span { color: #444; }

  .contract-witnesses { display: flex; gap: 40px; margin-top: 34px; font-size: 11.5px; color: #333; }
  .contract-witnesses > div { flex: 1; }
  .contract-witnesses .contract-sign-line { margin-bottom: 6px; }

  .contract-footer { margin-top: 26px; padding-top: 10px; border-top: 1px solid #e2e2e2; font-size: 9.5px; color: #8a8a8a; text-align: center; }
}
