:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --ink: #152033;
    --muted: #6b778c;
    --line: #dbe3ef;
    --primary: #204b8f;
    --primary-dark: #173763;
    --danger: #b42318;
    --success: #067647;
    --radius: 16px;
    --shadow: 0 14px 40px rgba(21, 32, 51, 0.08);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg); }
a { color: inherit; text-decoration: none; }
.app-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar { background: #0f1d33; color: #fff; padding: 24px; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 28px; }
.brand.center { justify-content: center; }
.brand-mark { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(135deg, #35a3ff, #2350a0); color: #fff; font-weight: 800; }
.brand small { display: block; color: #9fb0c8; font-size: 12px; margin-top: 2px; }
.sidebar nav { display: grid; gap: 6px; }
.sidebar nav a { color: #d6e3f5; padding: 12px 14px; border-radius: 12px; }
.sidebar nav a:hover { background: rgba(255,255,255,0.09); color: #fff; }
.main { padding: 28px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.topbar h1 { margin: 0; font-size: 28px; }
.topbar p, .muted { color: var(--muted); margin: 6px 0 0; }
.content { display: grid; gap: 20px; }
.card, .login-card, .qr-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.login-card { width: min(420px, calc(100% - 32px)); margin: 8vh auto; }
.guest-body { display: grid; min-height: 100vh; place-items: start center; }
.grid.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.metric span { color: var(--muted); display: block; margin-bottom: 10px; }
.metric strong { font-size: 34px; }
.module-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.module-grid div { background: #f7f9fd; border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; }
h2 { margin: 0 0 8px; }
label { display: block; margin-top: 14px; margin-bottom: 6px; color: var(--muted); font-weight: 700; font-size: 14px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 15px; }
.btn { border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 700; cursor: pointer; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.secondary { background: #edf2f8; color: var(--ink); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.full { width: 100%; margin-top: 18px; }
.alert { padding: 12px 14px; border-radius: 12px; margin: 12px 0; }
.alert.danger { background: #fef3f2; color: var(--danger); border: 1px solid #fecdca; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-flex; align-items: center; padding: 4px 9px; border-radius: 999px; background: #e9f1ff; color: var(--primary); font-size: 12px; font-weight: 700; }
.public-page { max-width: 760px; margin: 24px auto; padding: 0 16px; }
.qr-card h1 { margin-top: 10px; }
@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; }
    .grid.cards, .module-grid { grid-template-columns: 1fr; }
    .topbar { align-items: flex-start; gap: 12px; flex-direction: column; }
}

/* v0.2 Mantención */
.detail-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: 16px; }
.detail-grid div { background: #f7f9fd; border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.detail-grid span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.detail-grid strong { display: block; font-size: 15px; }
.inline-form { margin-top: 18px; }
.form-section { border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin: 16px 0; background: #fbfcff; }
.form-section h3 { margin: 0 0 10px; }
.actions-row { display: flex; justify-content: flex-end; margin-top: 18px; }
.small { font-size: 12px; }
.alert.success { background: #ecfdf3; color: var(--success); border: 1px solid #abefc6; }
.compact-card { box-shadow: none; }
.timeline-item { border-left: 4px solid var(--primary); padding: 10px 0 12px 14px; margin: 10px 0; }
.timeline-item p { margin: 6px 0; color: var(--muted); }
.signature-box { border: 1px dashed var(--line); background: #fff; border-radius: 14px; padding: 12px; }
.signature-box canvas { width: 100%; height: 180px; background: #fff; border: 1px solid var(--line); border-radius: 10px; touch-action: none; }
.signature-box .btn { margin-top: 8px; }
.status-closed, .status-closed_with_observation { background: #ecfdf3; color: var(--success); }
.status-closed_with_critical_observation, .status-expired { background: #fef3f2; color: var(--danger); }
.status-in_progress { background: #fff8db; color: #8a6100; }
@media (max-width: 1100px) { .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .detail-grid { grid-template-columns: 1fr; } }

/* v0.3 Españolización base */
.status-active, .status-submitted, .status-approved, .status-closed { background: #ecfdf3; color: var(--success); }
.status-inactive, .status-suspended, .status-cancelled, .status-rejected { background: #f2f4f7; color: #475467; }
.status-draft, .status-programmed, .status-scheduled, .status-assigned, .status-pending, .status-open { background: #e9f1ff; color: var(--primary); }
.status-sent, .status-follow_up, .status-in_progress, .status-pending_sync { background: #fff8db; color: #8a6100; }
.status-closed_with_observation { background: #fff8db; color: #8a6100; }
.status-closed_with_critical_observation, .status-expired, .status-critical, .priority-high, .priority-critical, .priority-urgent, .risk-high, .risk-critical { background: #fef3f2; color: var(--danger); }
.risk-low, .priority-low { background: #ecfdf3; color: var(--success); }
.risk-medium, .priority-medium, .priority-normal { background: #fff8db; color: #8a6100; }
.risk-none { background: #f2f4f7; color: #475467; }

.table-input {
    width: 100%;
    min-width: 82px;
    padding: 8px 10px;
    border: 1px solid #d7dde8;
    border-radius: 8px;
    font-size: 13px;
}

.small-number { max-width: 90px; }
.small-unit { max-width: 70px; }
.money-input { max-width: 110px; }
.mt-2 { margin-top: 12px; }
.totals-card strong { font-size: 18px; }

/* v0.4.1 Presupuesto editable */
.quote-description-cell { min-width: 320px; }
.item-description-input {
    min-width: 300px;
    width: 100%;
    resize: vertical;
    line-height: 1.35;
}
.manual-item-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
    margin-top: 10px;
}
@media (max-width: 1100px) {
    .manual-item-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .quote-items-table { display: block; overflow-x: auto; }
}
@media (max-width: 700px) {
    .manual-item-grid { grid-template-columns: 1fr; }
}
