/* assets/css/app.css — Cotizador Kuai v1.0 */
/* Fondo blanco, diseño limpio, listo para APK */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --brand:    #0077B6;
    --brand2:   #023E8A;
    --success:  #2D9D3A;
    --danger:   #C1121F;
    --warning:  #E05C00;
    --bg:       #F8F9FA;
    --white:    #FFFFFF;
    --border:   #DEE2E6;
    --text:     #212529;
    --muted:    #6C757D;
    --radius:   8px;
    --radius-lg:12px;
    --shadow:   0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg:0 4px 12px rgba(0,0,0,0.12);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
}

/* ── NAV ──────────────────────────────────────────────────── */
.topnav {
    background: var(--white);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}
.topnav-brand {
    font-weight: 700;
    font-size: 16px;
    color: var(--brand);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}
.topnav-actions { display: flex; align-items: center; gap: 8px; }

/* ── LAYOUT ───────────────────────────────────────────────── */
.container { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.page { padding: 24px 16px; max-width: 1100px; margin: 0 auto; }
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header p  { color: var(--muted); margin-top: 4px; font-size: 13px; }

/* ── CARDS ────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}
.card-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── BUTTONS ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand2); border-color: var(--brand2); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-danger  { background: var(--danger);  color: #fff; border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── FORMS ────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.3px; }
.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--white);
    color: var(--text);
    transition: border-color 0.15s;
}
.form-control:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(0,119,182,0.1); }
.form-control[readonly] { background: var(--bg); }
select.form-control { cursor: pointer; }

/* ── GRID ─────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

/* ── TABLES ───────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border); font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #F8F9FA; }

/* ── BADGES ───────────────────────────────────────────────── */
.badge { display: inline-block; padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-borrador  { background: #E9ECEF; color: #495057; }
.badge-enviada   { background: #CCE5FF; color: #004085; }
.badge-aprobada  { background: #D4EDDA; color: #155724; }
.badge-rechazada { background: #F8D7DA; color: #721C24; }
.badge-ejecutada { background: #D1ECF1; color: #0C5460; }

/* ── ALERTS ───────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.alert-success { background: #D4EDDA; color: #155724; border: 1px solid #C3E6CB; }
.alert-danger   { background: #F8D7DA; color: #721C24; border: 1px solid #F5C6CB; }
.alert-warning  { background: #FFF3CD; color: #856404; border: 1px solid #FFEEBA; }
.alert-info     { background: #D1ECF1; color: #0C5460; border: 1px solid #BEE5EB; }

/* ── COTIZADOR — SECCIONES ────────────────────────────────── */
.seccion-block {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
    overflow: hidden;
    background: var(--white);
}
.seccion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: move;
    user-select: none;
}
.seccion-header-left { display: flex; align-items: center; gap: 10px; }
.seccion-color-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.seccion-nombre { font-weight: 600; font-size: 14px; }
.seccion-body { padding: 0 16px 12px; }

.item-row {
    display: grid;
    grid-template-columns: 24px 1fr 80px 110px 100px 70px 28px;
    gap: 6px;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid #F0F0F0;
}
.item-row:last-child { border-bottom: none; }
.item-drag-handle { cursor: grab; color: var(--muted); font-size: 16px; }
.item-desc-toggle { font-size: 11px; color: var(--brand); cursor: pointer; margin-top: 3px; }
.item-desc-text { margin-top: 6px; padding: 8px 12px; background: #F8F9FA; border-radius: 6px; font-size: 12px; color: var(--muted); border-left: 3px solid var(--brand); display: none; }
.item-desc-text.visible { display: block; }

.add-item-row { padding: 8px 0 4px; }

/* ── PRECIO INPUT CON FORMULA ─────────────────────────────── */
.precio-input {
    position: relative;
}
.precio-input input {
    padding-right: 28px;
}
.precio-input .formula-icon {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    color: var(--success);
    font-weight: 700;
    display: none;
}
.precio-input input.has-formula ~ .formula-icon { display: block; }

/* ── RESUMEN FINANCIERO ────────────────────────────────────── */
.resumen-financiero {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    position: sticky;
    top: 72px;
}
.resumen-linea {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #F0F0F0;
    font-size: 13px;
}
.resumen-linea:last-child { border-bottom: none; }
.resumen-linea.total {
    font-weight: 700;
    font-size: 16px;
    padding-top: 12px;
    margin-top: 4px;
    border-top: 2px solid var(--border);
}
.resumen-linea label { color: var(--muted); }
.precio-venta-input {
    border: none;
    border-bottom: 2px solid var(--brand);
    border-radius: 0;
    padding: 4px 8px;
    font-size: 18px;
    font-weight: 700;
    color: var(--brand);
    width: 130px;
    text-align: right;
    background: transparent;
}
.precio-venta-input:focus { outline: none; }

.margen-bar { height: 6px; background: #E9ECEF; border-radius: 3px; margin-top: 6px; overflow: hidden; }
.margen-fill { height: 100%; border-radius: 3px; transition: width 0.3s, background 0.3s; }

/* ── MARCAS GRID ──────────────────────────────────────────── */
.marca-card {
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
    background: var(--white);
}
.marca-card:hover { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(0,119,182,0.1); }
.marca-card.selected { border-color: var(--brand); background: rgba(0,119,182,0.04); }
.marca-dot { width: 36px; height: 36px; border-radius: 50%; margin: 0 auto 8px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 13px; }

/* ── BIBLIOTECA ITEMS ─────────────────────────────────────── */
.biblioteca-item {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 6px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.12s;
    background: var(--white);
}
.biblioteca-item:hover { border-color: var(--brand); background: rgba(0,119,182,0.03); }
.biblioteca-item-name { font-weight: 500; font-size: 13px; }
.biblioteca-item-precio { font-size: 12px; color: var(--muted); }

/* ── MODAL ────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 500;
    overflow-y: auto;
    padding: 20px;
}
.modal-overlay.open { display: flex; align-items: flex-start; justify-content: center; }
.modal-box {
    background: var(--white);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 600px;
    margin: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity:0; transform:translateY(-20px); } to { opacity:1; transform:translateY(0); } }
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* ── LOGIN ────────────────────────────────────────────────── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #0077B6 0%, #023E8A 100%);
}
.login-box {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 28px; font-weight: 800; color: var(--brand); }
.login-logo p { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ── HISTORIAL / LISTA ────────────────────────────────────── */
.cotizacion-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.12s;
    text-decoration: none;
    color: var(--text);
}
.cotizacion-row:hover { background: #F8F9FA; }
.cotizacion-row:last-child { border-bottom: none; }
.cot-marca-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.cot-info { flex: 1; min-width: 0; }
.cot-numero { font-size: 11px; color: var(--muted); }
.cot-cliente { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cot-tipo { font-size: 12px; color: var(--muted); }
.cot-precio { font-weight: 700; font-size: 14px; color: var(--brand); white-space: nowrap; }

/* ── RESPONSIVE ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .item-row { grid-template-columns: 24px 1fr 70px 80px 70px 50px 24px; gap: 4px; }
    .cotizador-layout { display: block; }
    .resumen-financiero { position: static; margin-top: 16px; }
}
@media (max-width: 480px) {
    .item-row { grid-template-columns: 1fr; }
    .item-row > *:not(.item-desc-col) { display: none; }
    .item-desc-col { display: block; }
}

/* ── UTILS ────────────────────────────────────────────────── */
.text-muted  { color: var(--muted); }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.fw-bold     { font-weight: 700; }
.d-flex      { display: flex; }
.align-center { align-items: center; }
.gap-8       { gap: 8px; }
.gap-12      { gap: 12px; }
.mt-8        { margin-top: 8px; }
.mt-16       { margin-top: 16px; }
.mb-0        { margin-bottom: 0; }
.w-100       { width: 100%; }
.flex-1      { flex: 1; }
