/* ==========================================================================
   Presupuestos — hoja de estilos
   Diseño sobrio: azul marino + grises azulados, tarjetas blancas, tipografía del sistema.
   ========================================================================== */

:root {
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --text: #0f1b2d;
    --muted: #5d6b82;
    --border: #e1e6ee;
    --border-strong: #cbd3df;

    --primary: #14213d;
    --primary-hover: #0c1630;
    --accent: #2457d6;
    --accent-soft: #e8eefc;

    --ok: #146c43;
    --ok-bg: #e3f4ea;
    --error: #b42318;
    --error-bg: #fdecea;
    --warn-bg: #fff4e0;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(15, 27, 45, .05), 0 4px 14px rgba(15, 27, 45, .05);
    --focus: 0 0 0 3px rgba(36, 87, 214, .25);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Cabecera y navegación ---------- */

.top {
    background: var(--primary);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 1px 0 rgba(255, 255, 255, .06), 0 2px 8px rgba(15, 27, 45, .18);
}

.top-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 20px;
    min-height: 56px;
    display: flex;
    align-items: center;
    gap: 24px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: .01em;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: #9db7ff; }

.main-nav {
    display: flex;
    gap: 4px;
    flex: 1;
    min-width: 0;
}
.main-nav a {
    color: #cfd8ea;
    padding: 8px 12px;
    border-radius: 8px;
    font-weight: 500;
    font-size: .93rem;
    white-space: nowrap;
}
.main-nav a:hover { color: #fff; background: rgba(255, 255, 255, .08); text-decoration: none; }
.main-nav a.active { color: #fff; background: rgba(255, 255, 255, .14); }

.user-menu { position: relative; margin-left: auto; }
.user-menu summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 999px;
    color: #e6ecf8;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: rgba(255, 255, 255, .08); }
.avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #3a5ba8;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: .85rem;
}
.user-name { font-size: .85rem; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-body {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 190px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(15, 27, 45, .18);
    padding: 6px;
    display: flex;
    flex-direction: column;
}
.user-menu-body a,
.user-menu-body button.link {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 12px;
    border-radius: 6px;
    color: var(--text);
    text-decoration: none;
    font-size: .93rem;
}
.user-menu-body a:hover,
.user-menu-body button.link:hover { background: var(--surface-2); text-decoration: none; }
.user-menu-body form { margin: 0; }

main { max-width: 1120px; margin: 0 auto; padding: 24px 20px 56px; }

/* ---------- Tarjetas y encabezados ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 24px;
    box-shadow: var(--shadow);
}
main > .card, main > section.card { margin-bottom: 18px; }
.card.narrow { max-width: 440px; margin: 56px auto; }

h1 { margin: 0 0 4px; font-size: 1.25rem; font-weight: 650; letter-spacing: -.005em; }
h2 { margin: 0 0 4px; font-size: 1.02rem; font-weight: 650; }
.muted { color: var(--muted); margin: 2px 0 14px; font-size: .92rem; }
.head .muted { margin-bottom: 0; }

.head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 14px;
}
.head h1 { margin: 0; }
.head form { margin: 0; }

hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

/* ---------- Formularios ---------- */

label {
    display: block;
    margin-bottom: 14px;
    font-size: .82rem;
    font-weight: 600;
    color: var(--muted);
}

input, select, textarea {
    display: block;
    width: 100%;
    margin-top: 5px;
    padding: 9px 12px;
    font: inherit;
    font-size: .95rem;
    font-weight: 400;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    transition: border-color .12s, box-shadow .12s;
}
input:hover, select:hover, textarea:hover { border-color: #aeb9ca; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus);
}
textarea { resize: vertical; }

label.check {
    display: flex;
    gap: 8px;
    align-items: center;
    font-weight: 500;
    color: var(--text);
}
label.check input { width: auto; margin: 0; }
input[type="checkbox"] { accent-color: var(--accent); }

.row  { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 16px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.inline-form { display: flex; gap: 8px; align-items: center; margin: 0 0 10px; }
.inline-form input, .inline-form select { margin-top: 0; }

/* ---------- Botones ---------- */

button, a.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    font: inherit;
    font-size: .93rem;
    font-weight: 600;
    line-height: 1.3;
    color: #fff;
    background: var(--primary);
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s, border-color .12s, box-shadow .12s;
}
button:hover, a.button:hover { background: var(--primary-hover); border-color: var(--primary-hover); text-decoration: none; }
button:focus-visible, a.button:focus-visible { outline: none; box-shadow: var(--focus); }

button.secondary, a.button.secondary {
    color: var(--text);
    background: #fff;
    border-color: var(--border-strong);
}
button.secondary:hover, a.button.secondary:hover { background: var(--surface-2); border-color: #aeb9ca; }

button.danger { background: var(--error); border-color: var(--error); }
button.danger:hover { background: #8f1d14; border-color: #8f1d14; }

button.link {
    padding: 0;
    color: var(--accent);
    background: none;
    border: 0;
    font-weight: 500;
    text-decoration: none;
}
button.link:hover { background: none; text-decoration: underline; }

form > button[type="submit"]:last-child { margin-top: 4px; }

/* ---------- Avisos ---------- */

.alert {
    margin: 0 0 16px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    font-size: .93rem;
    border: 1px solid transparent;
}
.alert-ok { background: var(--ok-bg); color: var(--ok); border-color: #bfe3cd; }
.alert-error { background: var(--error-bg); color: var(--error); border-color: #f4bcb6; }

/* Compatibilidad con páginas que usan .error / .ok sueltos */
p.error, div.error, span.error { color: var(--error); font-size: .9rem; }
p.error { background: var(--error-bg); border: 1px solid #f4bcb6; border-radius: var(--radius-sm); padding: 11px 14px; }
p.ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #bfe3cd; border-radius: var(--radius-sm); padding: 11px 14px; font-size: .93rem; }

.errores { background: var(--error-bg); border: 1px solid #f4bcb6; border-radius: var(--radius-sm); padding: 10px 14px; margin: 12px 0; color: var(--error); }
.errores ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Tablas ---------- */

.filters { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; margin-bottom: 14px; }
.filters.filters-simple { grid-template-columns: 1fr auto; }
.filters input, .filters select { margin-top: 0; }

.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
.table-wrap table { min-width: 560px; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th {
    font-size: .74rem;
    font-weight: 650;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
}
th:first-child { border-top-left-radius: 8px; }
th:last-child { border-top-right-radius: 8px; }
tbody tr:hover { background: #fafbfd; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td form { margin: 0; }
td a { font-weight: 600; }

.tarifa td, .tarifa th { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tarifa th:first-child, .tarifa td:first-child { text-align: left; font-weight: 600; }

/* ---------- Estados ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: .76rem;
    font-weight: 600;
    background: #eceff5;
    color: #3b4960;
    white-space: nowrap;
}
.badge[class*="estado-"]::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}
.badge.estado-borrador { background: #eceff5; color: #54617a; }
.badge.estado-enviado { background: var(--accent-soft); color: #1e47ad; }
.badge.estado-aceptado { background: var(--ok-bg); color: var(--ok); }
.badge.estado-rechazado { background: var(--error-bg); color: var(--error); }

/* ---------- Totales y calculadora ---------- */

.totales { margin: 18px 0 0 auto; max-width: 340px; font-variant-numeric: tabular-nums; }
.totales div { display: flex; justify-content: space-between; padding: 4px 0; color: var(--muted); }
.totales .total {
    border-top: 2px solid var(--text);
    margin-top: 6px;
    padding-top: 9px;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text);
}

.result {
    font-size: 1.7rem;
    font-weight: 700;
    letter-spacing: -.01em;
    min-height: 2.4rem;
    margin: 14px 0 16px;
    padding: 12px 16px;
    background: var(--surface-2);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    font-variant-numeric: tabular-nums;
}
.result small { font-size: .85rem; font-weight: 500; color: var(--muted); }
.error { color: var(--error); font-size: .9rem; }

.extra-linea { font-size: .8rem; color: var(--muted); }
.extra-fila { padding: 12px 0; border-bottom: 1px solid var(--border); }
.extra-fila:last-child { border-bottom: 0; }

fieldset.extras {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin: 0 0 14px;
    padding: 8px 14px;
    background: var(--surface-2);
}
fieldset.extras legend { font-size: .82rem; font-weight: 600; color: var(--muted); padding: 0 6px; }

/* ---------- Resumen del cliente ---------- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 4px 0 20px; }
.stat {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.stat-label { font-size: .74rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Ajustes ---------- */

.subnav { display: flex; gap: 4px; margin: 0 0 18px; border-bottom: 1px solid var(--border-strong); }
.subnav a {
    padding: 9px 14px;
    margin-bottom: -1px;
    color: var(--muted);
    font-weight: 600;
    font-size: .93rem;
    border-bottom: 2px solid transparent;
}
.subnav a:hover { color: var(--text); text-decoration: none; }
.subnav a.active { color: var(--accent); border-bottom-color: var(--accent); }

.logo-preview {
    display: block;
    max-width: 180px;
    max-height: 90px;
    margin-bottom: 10px;
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

details.ayuda { margin: 8px 0 14px; font-size: .9rem; color: var(--muted); }
details.ayuda summary { cursor: pointer; font-weight: 600; }
details.ayuda pre { background: var(--surface-2); border: 1px solid var(--border); padding: 10px; border-radius: 8px; overflow-x: auto; }

.menu { position: relative; display: inline-block; text-align: left; }
.menu summary {
    list-style: none;
    cursor: pointer;
    color: var(--accent);
    font-weight: 600;
    font-size: .9rem;
    padding: 4px 8px;
    border-radius: 6px;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover { background: var(--accent-soft); }
.menu[open] > .menu-body {
    min-width: 300px;
    margin-top: 8px;
    padding: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.export-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 8px; }
.export-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    background: var(--surface-2);
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-start;
}
.export-item .muted { margin-bottom: 10px; }

/* ---------- Agenda ---------- */

.alert-warn { background: var(--warn-bg); color: #8a5300; border-color: #f2d49b; }

.agenda-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.seg a { padding: 7px 14px; font-size: .9rem; color: var(--muted); text-decoration: none; border-left: 1px solid var(--border); }
.seg a:first-child { border-left: 0; }
.seg a.active { background: var(--primary); color: #fff; }
.agenda-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.agenda-filters select { width: auto; min-width: 180px; }

.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; font-size: .78rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.cal-head span { padding: 0 6px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-day { min-height: 110px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-grid.semana .cal-day { min-height: 220px; }
.cal-day.fuera { opacity: .5; }
.cal-day.hoy { background: var(--accent-soft); border-color: var(--accent); }
.cal-num { display: flex; justify-content: space-between; font-size: .85rem; font-weight: 600; color: var(--text); text-decoration: none; }
.cal-dow { display: none; text-transform: capitalize; font-weight: 500; color: var(--muted); }
.cita-mas { font-size: .78rem; color: var(--accent); text-decoration: none; }

.cita-chip { display: flex; gap: 5px; align-items: baseline; padding: 3px 6px; border-radius: 6px; font-size: .78rem; line-height: 1.25; text-decoration: none; color: var(--text); border-left: 3px solid var(--tipo, var(--accent)); background: var(--tipo-bg, var(--accent-soft)); overflow: hidden; }
.cita-hora { font-weight: 700; flex: none; }
.cita-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tipo-1 { --tipo: #2457d6; --tipo-bg: #e8eefc; }
.tipo-2 { --tipo: #b45309; --tipo-bg: #fdf0dc; }
.tipo-3 { --tipo: #146c43; --tipo-bg: #e3f4ea; }
.tipo-4 { --tipo: #7c3aed; --tipo-bg: #f1e9fd; }
.tipo-5 { --tipo: #5d6b82; --tipo-bg: #eceff5; }
.estado-cita-3 { opacity: .55; }
.estado-cita-3 .cita-txt, .estado-cita-3 .cita-fila-cuerpo { text-decoration: line-through; }
.estado-cita-2 .cita-hora::after { content: " ✓"; }

.dia-titulo { margin: 18px 0 8px; font-size: 1rem; }
.dia-titulo::first-letter { text-transform: uppercase; }
.dia-titulo.hoy { color: var(--accent); }
.cita-lista { display: flex; flex-direction: column; gap: 8px; }
.cita-fila { display: flex; gap: 14px; align-items: center; padding: 10px 14px; border: 1px solid var(--border); border-left: 4px solid var(--tipo, var(--accent)); border-radius: var(--radius-sm); background: var(--surface); text-decoration: none; color: var(--text); }
.cita-fila:hover { background: var(--surface-2); }
.cita-fila-hora { display: flex; flex-direction: column; min-width: 70px; font-size: .9rem; }
.cita-fila-cuerpo { flex: 1; min-width: 0; }
.cita-badge-0 { background: #eceff5; color: #54617a; }
.cita-badge-1 { background: var(--accent-soft); color: #1e47ad; }
.cita-badge-2 { background: var(--ok-bg); color: var(--ok); }
.cita-badge-3 { background: var(--error-bg); color: var(--error); }
.ayuda summary { cursor: pointer; font-weight: 600; }

/* ---------- Responsive ---------- */

@media (max-width: 760px) {
    .top-inner { flex-wrap: wrap; gap: 6px 12px; padding: 8px 14px; }
    .main-nav { order: 3; flex-basis: 100%; overflow-x: auto; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
    .user-name { display: none; }
    main { padding: 16px 14px 44px; }
    .card { padding: 18px 16px; }
    .card.narrow { margin: 24px auto; }
    .row, .row3, .row4 { grid-template-columns: 1fr; }
    .filters, .filters.filters-simple { grid-template-columns: 1fr; }
    .head { flex-direction: column; align-items: stretch; }
    .stats { grid-template-columns: 1fr; }
    .export-grid { grid-template-columns: 1fr; }
    .menu[open] > .menu-body { min-width: 0; }
    .inline-form { flex-wrap: wrap; }
    .cal-head { display: none; }
    .cal-grid { grid-template-columns: 1fr; }
    .cal-day { min-height: 0; }
    .cal-day.vacio:not(.hoy) { display: none; }
    .cal-dow { display: inline; }
    .cal-day.fuera { display: none; }
    .agenda-filters select { width: 100%; }
    .cita-fila { flex-wrap: wrap; }
}

@media print {
    .top, .subnav, button, a.button { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; border: 0; }
}

/* Buscador de clientes */
.resultados { list-style: none; margin: 4px 0 12px; padding: 4px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); box-shadow: var(--shadow); }
.resultados button { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 9px 10px; border-radius: 6px; font: inherit; cursor: pointer; }
.resultados button:hover, .resultados button:focus { background: var(--accent-soft); }
.resultados button.nuevo { color: var(--accent); font-weight: 600; }
