/* AMC — paleta profesional inmobiliaria */
:root {
  --primary: #1e3a5f;
  --primary-dark: #0f2640;
  --accent: #c8a04b;
  --accent-dark: #9d7b2f;
  --green: #2d8659;
  --green-light: #d4f0e0;
  --red: #b03a2e;
  --bg: #f5f6f8;
  --white: #fff;
  --border: #e1e4e8;
  --text: #1a2332;
  --muted: #6c757d;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
  --radius: 8px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
h1,h2,h3,h4 { margin: 0; }
a { color: var(--primary); }

/* ─── LOGIN ─────────────────────────── */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); }
.login-card { background: white; padding: 2.5rem; border-radius: 12px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.login-title { font-size: 2.5rem; font-weight: 700; color: var(--primary); letter-spacing: 0.05em; }
.login-sub { color: var(--muted); margin: 0.25rem 0 1.5rem; }
.login-form label { display: block; margin-bottom: 1rem; }
.login-form span { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 0.4rem; color: var(--primary-dark); }
.login-form input { width: 100%; padding: 0.7rem 0.9rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.95rem; }
.login-form input:focus { outline: none; border-color: var(--primary); }
.login-form button { width: 100%; padding: 0.85rem; background: var(--primary); color: white; border: none; border-radius: 6px; font-weight: 700; font-size: 1rem; cursor: pointer; transition: background 0.2s; }
.login-form button:hover { background: var(--primary-dark); }
.login-error { color: var(--red); font-size: 0.85rem; margin-top: 0.75rem; min-height: 1.2em; }

/* ─── TOPBAR ────────────────────────── */
.topbar { background: var(--primary); color: white; padding: 0.75rem 1.5rem; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 2px 4px rgba(0,0,0,0.08); }
.brand { font-size: 1.2rem; font-weight: 700; letter-spacing: 0.05em; }
.brand .muted { color: rgba(255,255,255,0.7); font-size: 0.85rem; font-weight: 400; margin-left: 0.5rem; }
.topbar-actions { display: flex; align-items: center; gap: 1rem; }
.topbar-actions .muted { color: rgba(255,255,255,0.85); }
.btn-ghost { background: transparent; border: 1px solid rgba(255,255,255,0.3); color: white; padding: 0.4rem 1rem; border-radius: 6px; cursor: pointer; }
.btn-ghost:hover { background: rgba(255,255,255,0.1); }

/* ─── LAYOUT ────────────────────────── */
.layout { display: grid; grid-template-columns: 280px 1fr; min-height: calc(100vh - 56px); }
.sidebar { background: white; border-right: 1px solid var(--border); padding: 1.25rem; overflow-y: auto; }
.sidebar h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 1.25rem 0 0.5rem; }
.amc-list { list-style: none; padding: 0; margin: 0; }
.amc-list li { padding: 0.6rem 0.75rem; border-radius: 6px; cursor: pointer; margin-bottom: 0.25rem; }
.amc-list li:hover { background: var(--bg); }
.amc-list li.active { background: var(--primary); color: white; }
.amc-list li .meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }
.amc-list li.active .meta { color: rgba(255,255,255,0.7); }
.amc-list li.empty { color: var(--muted); font-style: italic; cursor: default; }
.amc-list li.empty:hover { background: transparent; }

.main { padding: 1.5rem; max-width: 1500px; }

/* ─── BLOCKS ────────────────────────── */
.block { background: white; border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.25rem; box-shadow: var(--shadow); }
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; gap: 1rem; }
.block h2 { font-size: 1.1rem; font-weight: 700; color: var(--primary-dark); }
.block h2 small { font-weight: 400; color: var(--muted); }
.badge { padding: 0.2rem 0.7rem; background: var(--bg); color: var(--muted); border-radius: 100px; font-size: 0.75rem; font-weight: 600; }

/* ─── FORM ──────────────────────────── */
.grid { display: grid; gap: 0.85rem; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.col-2 { grid-column: span 2; }
label { display: block; }
label > span { display: block; font-size: 0.78rem; font-weight: 600; color: var(--primary-dark); margin-bottom: 0.3rem; text-transform: uppercase; letter-spacing: 0.04em; }
label > span small { font-weight: 400; text-transform: none; }
input, select, textarea { width: 100%; padding: 0.55rem 0.7rem; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; font-size: 0.9rem; background: white; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,58,95,0.1); }
textarea { resize: vertical; }
.checks { display: flex; gap: 1.5rem; margin: 1rem 0 0.75rem; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.check input { width: auto; }
.check span { display: inline; font-size: 0.85rem; text-transform: none; letter-spacing: normal; }

/* ─── TABLA COMPARATIVOS ────────────── */
.table-wrap { overflow-x: auto; }
.comp-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.comp-table th { text-align: left; padding: 0.5rem 0.4rem; background: var(--bg); border-bottom: 2px solid var(--border); font-weight: 700; color: var(--primary-dark); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.comp-table th small { font-weight: 400; text-transform: none; }
.comp-table td { padding: 0.4rem 0.4rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.comp-table tbody tr:hover { background: #fafbfc; }
.comp-table input, .comp-table select { padding: 0.3rem 0.4rem; font-size: 0.82rem; }
.comp-table input[type="number"] { text-align: right; min-width: 90px; }
.comp-table .num-readonly { background: #f9fafb; text-align: right; padding: 0.4rem 0.5rem; border-radius: 4px; font-weight: 600; color: var(--primary-dark); }
.btn-row-del { background: transparent; border: none; color: var(--red); cursor: pointer; font-size: 1.1rem; padding: 0.2rem 0.4rem; border-radius: 4px; }
.btn-row-del:hover { background: #fee; }
.tipo-cell select { min-width: 100px; }

/* ─── ANÁLISIS ──────────────────────── */
.calc-grid { margin-bottom: 1.5rem; }
.stat-card { background: var(--bg); padding: 1rem; border-radius: 8px; border: 1px solid var(--border); }
.stat-card.highlight { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); color: white; border-color: var(--primary); }
.stat-card.highlight .muted { color: rgba(255,255,255,0.8); }
.stat-card h4 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 0.5rem; }
.stat-card.highlight h4 { color: var(--accent); }
.stat-card .big { font-size: 1.6rem; font-weight: 700; color: var(--primary-dark); margin: 0.25rem 0; }
.stat-card.highlight .big { color: white; }
.stat-card .mini { font-size: 0.75rem; color: var(--muted); margin-top: 0.4rem; }
.stat-card.highlight .mini { color: rgba(255,255,255,0.7); }

.result-grid { background: var(--bg); border-radius: 8px; padding: 1rem 1.25rem; }
.result-row { display: flex; justify-content: space-between; padding: 0.4rem 0; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
.result-row:last-child { border-bottom: none; }
.result-row b { color: var(--primary-dark); }
.result-row.total { font-size: 1.1rem; font-weight: 700; padding: 0.6rem 0; }
.result-row.total b { color: var(--primary); }
.result-row.total.green b { color: var(--green); font-size: 1.3rem; }

/* ─── WARNINGS ──────────────────────── */
.warnings { margin-bottom: 1rem; }
.warnings:empty { display: none; }
.warning { background: #fff8e1; border-left: 4px solid var(--accent); padding: 0.6rem 0.9rem; border-radius: 0 6px 6px 0; margin-bottom: 0.4rem; font-size: 0.85rem; }

/* ─── ACTION BAR ────────────────────── */
.action-bar { display: flex; align-items: center; gap: 0.75rem; padding: 1rem 0; }
.btn-primary, .btn-secondary, .btn-danger { padding: 0.6rem 1.4rem; border: none; border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 0.9rem; transition: all 0.15s; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary.block { width: 100%; }
.btn-secondary { background: var(--accent); color: white; }
.btn-secondary:hover { background: var(--accent-dark); }
.btn-secondary:disabled { background: #ccc; cursor: not-allowed; }
.btn-danger { background: white; color: var(--red); border: 1px solid var(--red); }
.btn-danger:hover { background: var(--red); color: white; }
.btn-danger:disabled { opacity: 0.4; cursor: not-allowed; }
.save-status { color: var(--muted); font-size: 0.85rem; margin-left: auto; }
.save-status.ok { color: var(--green); }
.save-status.err { color: var(--red); }

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

/* ─── MODALES ───────────────────────── */
.modal { display: none; position: fixed; inset: 0; background: rgba(15, 38, 64, 0.6); z-index: 100; align-items: center; justify-content: center; padding: 1rem; backdrop-filter: blur(3px); }
.modal.open { display: flex; }
.modal-inner { background: white; border-radius: 12px; width: 100%; max-width: 720px; max-height: 90vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-inner.small { max-width: 420px; }
.modal-head { padding: 1.1rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { color: var(--primary-dark); font-size: 1.1rem; }
.modal-close { background: none; border: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 0.3rem; }
.modal-close:hover { color: var(--red); }
.modal-body { padding: 1.5rem; overflow-y: auto; }
.modal-body label { margin-bottom: 0.85rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }
.modal-error { color: var(--red); font-size: 0.85rem; min-height: 1.2em; margin: 0.4rem 0; }
.users-table { width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: 0.9rem; }
.users-table th { text-align: left; padding: 0.5rem 0.75rem; background: var(--bg); border-bottom: 1px solid var(--border); font-size: 0.75rem; text-transform: uppercase; color: var(--primary-dark); }
.users-table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
.users-table .role { padding: 0.15rem 0.55rem; border-radius: 100px; font-size: 0.7rem; font-weight: 700; }
.users-table .role-admin { background: var(--accent); color: white; }
.users-table .role-user { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.users-table button { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.users-table .btn-row-action { background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: 4px; cursor: pointer; margin-right: 0.25rem; }
.users-table .btn-row-action:hover { border-color: var(--primary); color: var(--primary); }
.users-table .btn-row-del { color: var(--red); border-color: #fee; }
.users-table .btn-row-del:hover { background: var(--red); color: white; border-color: var(--red); }

/* ─── MODO TERRENO vs CONSTRUCCIÓN ───── */
body.mode-construccion [data-mode="terreno"] { display: none !important; }

/* ─── HINT BOX (sugerencia desde matriz) ─── */
.hint-box { margin-top: 1rem; padding: 0.7rem 1rem; background: #fff8e1; border-left: 4px solid var(--accent); border-radius: 0 6px 6px 0; display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.hint-label { font-size: 0.78rem; font-weight: 700; color: var(--accent-dark); text-transform: uppercase; letter-spacing: 0.04em; }
.hint-value { font-weight: 600; color: var(--text); }
.btn-link { background: none; border: none; color: var(--primary); font-weight: 600; cursor: pointer; padding: 0.2rem 0.5rem; font-size: 0.85rem; text-decoration: underline; margin-left: auto; }
.btn-link:hover { color: var(--primary-dark); }
body.mode-construccion .btn-link { display: none; }

/* ─── MOBILE / TABLET ───────────────── */
@media (max-width: 900px) {
  body { font-size: 15px; }
  .topbar { padding: 0.6rem 1rem; flex-wrap: wrap; gap: 0.5rem; }
  .brand { font-size: 1rem; }
  .brand .muted { display: none; }
  .topbar-actions { gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }
  .btn-ghost { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
  #user-name { display: none; }

  .layout { grid-template-columns: 1fr; min-height: auto; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); padding: 1rem; max-height: 50vh; }
  .main { padding: 1rem; }
  .block { padding: 1rem; }
  .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; gap: 0.6rem; }
  .col-2 { grid-column: span 2; }

  /* Tabla → cards verticales */
  .table-wrap { overflow: visible; }
  .comp-table, .comp-table thead, .comp-table tbody, .comp-table tr, .comp-table td, .comp-table th { display: block; }
  .comp-table thead { display: none; }
  .comp-table tr { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; margin-bottom: 0.6rem; }
  .comp-table td { border-bottom: none; padding: 0.4rem 0; position: relative; padding-left: 0; }
  .comp-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--primary-dark);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.15rem;
  }
  .comp-table td:first-child { display: none; }
  .comp-table input, .comp-table select { font-size: 0.95rem; padding: 0.55rem 0.6rem; }
  .comp-table input[type="number"] { text-align: left; min-width: 0; width: 100%; }
  .comp-table .num-readonly { text-align: left; }
  .comp-table .btn-row-del { position: absolute; top: 0.5rem; right: 0.5rem; font-size: 1.4rem; }

  /* Stats grid: cards apiladas */
  .grid-3.calc-grid { grid-template-columns: 1fr; }

  /* Action bar sticky en bottom */
  .action-bar {
    position: sticky;
    bottom: 0;
    background: white;
    margin: 1rem -1rem -1rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.05);
    flex-wrap: wrap;
  }
  .action-bar button { flex: 1; min-width: 100px; }
  .save-status { width: 100%; text-align: center; margin: 0; }

  /* Modales pantalla completa en mobile */
  .modal { padding: 0; }
  .modal-inner { max-height: 100vh; height: 100vh; max-width: 100vw; border-radius: 0; }
  .users-table { font-size: 0.85rem; }
  .users-table th, .users-table td { padding: 0.4rem 0.5rem; }
}

@media (max-width: 480px) {
  .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .col-2 { grid-column: span 1; }
  .checks { flex-direction: column; gap: 0.5rem; }
}
