/* ============================================================
   KTR Cotizaciones v2 — Corporate UI
   Palette: #1e3c72 (primary) / #2a5298 (secondary) / #f4f6f9 (bg)
============================================================ */

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary:      #1e3c72;
    --primary-dark: #152d57;
    --secondary:    #2a5298;
    --accent:       #667eea;
    --success:      #10b981;
    --danger:       #ef4444;
    --warning:      #f59e0b;
    --info:         #3b82f6;
    --bg:           #f4f6f9;
    --surface:      #ffffff;
    --border:       #e5e7eb;
    --text:         #111827;
    --text-muted:   #6b7280;
    --sidebar-w:    260px;
    --topbar-h:     60px;
    --radius:       10px;
    --shadow:       0 1px 6px rgba(0,0,0,.08);
    --shadow-md:    0 4px 20px rgba(0,0,0,.12);
}

html { font-size: 14px; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--secondary); text-decoration: none; }
a:hover { color: var(--primary); }

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--primary);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform .25s ease;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,.1);
}

.sidebar-logo-img {
    max-width: 192px;
    max-height: 58px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 6px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
}

.sidebar-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: rgba(255,255,255,.4);
    padding: 12px 20px 4px;
    text-transform: uppercase;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: rgba(255,255,255,.75);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 0;
    transition: background .15s, color .15s;
    position: relative;
}

.sidebar-link i { font-size: 1.1rem; flex-shrink: 0; }

.sidebar-link:hover {
    background: rgba(255,255,255,.08);
    color: #fff;
}

.sidebar-link.active {
    background: rgba(255,255,255,.15);
    color: #fff;
    font-weight: 700;
}

.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0; top: 4px; bottom: 4px;
    width: 3px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

/* Sidebar footer */
.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid rgba(255,255,255,.1);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-user { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }

.sidebar-user-avatar {
    width: 32px; height: 32px;
    background: rgba(255,255,255,.2);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; color: #fff; font-size: 0.85rem;
    flex-shrink: 0;
}

.sidebar-user-info { min-width: 0; }
.sidebar-user-name { font-size: 0.82rem; font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 0.7rem; color: rgba(255,255,255,.5); }

.sidebar-logout {
    color: rgba(255,255,255,.5);
    font-size: 1.1rem;
    padding: 6px;
    border-radius: 6px;
    transition: color .15s, background .15s;
}
.sidebar-logout:hover { color: #fff; background: rgba(255,255,255,.1); }

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
    position: fixed;
    top: 0; left: var(--sidebar-w); right: 0;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    z-index: 900;
    transition: left .25s ease;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
}
.sidebar-toggle:hover { background: var(--bg); }

.topbar-breadcrumb {
    display: flex; align-items: center; gap: 8px;
    flex: 1;
    font-size: 0.9rem;
}
.breadcrumb-link { color: var(--text-muted); }
.breadcrumb-link:hover { color: var(--primary); }
.breadcrumb-current { color: var(--text); font-weight: 600; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.topbar-btn {
    width: 36px; height: 36px;
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
    transition: background .15s, color .15s;
}
.topbar-btn:hover { background: var(--border); color: var(--primary); }

.topbar-user-chip {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px;
    background: var(--bg);
    border-radius: 20px;
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 600;
}
.topbar-user-chip:hover { background: var(--border); color: var(--primary); }

.topbar-avatar {
    width: 26px; height: 26px;
    background: var(--primary);
    border-radius: 50%;
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem;
    font-weight: 800;
}
.topbar-username { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Main Content ──────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    margin-top: var(--topbar-h);
    padding: 28px 28px;
    min-height: calc(100vh - var(--topbar-h));
    transition: margin-left .25s ease;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.card-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.card-body { padding: 20px; }
.card-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: #fafbfc;
    border-radius: 0 0 var(--radius) var(--radius);
}

/* ── Page Header ───────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
}

.page-title {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary);
    display: flex; align-items: center; gap: 10px;
    margin: 0;
}

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

.kpi-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow);
    transition: box-shadow .2s, transform .2s;
}
.kpi-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.kpi-icon {
    width: 46px; height: 46px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.kpi-card.kpi-total      .kpi-icon { background: #ede9fe; color: #7c3aed; }
.kpi-card.kpi-ganada     .kpi-icon { background: #d1fae5; color: #059669; }
.kpi-card.kpi-conversion .kpi-icon { background: #dbeafe; color: #2563eb; }
.kpi-card.kpi-cop        .kpi-icon { background: #fef9c3; color: #b45309; }
.kpi-card.kpi-usd        .kpi-icon { background: #dcfce7; color: #16a34a; }
.kpi-card.kpi-negociacion .kpi-icon { background: #fef3c7; color: #d97706; }

.kpi-value {
    font-size: 1.5rem;
    font-weight: 900;
    color: var(--text);
    line-height: 1.1;
}
.kpi-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
    font-weight: 500;
}

/* ── Dashboard Grid ─────────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* ── Tables ────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.table thead th {
    background: #f8f9fc;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    padding: 11px 16px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f2f5;
    vertical-align: middle;
}

.table.table-hover tbody tr:hover { background: #f5f7ff; }

.table-footer {
    padding: 10px 16px;
    background: #fafbfc;
    border-top: 1px solid var(--border);
    font-size: 0.82rem;
}

.text-right { text-align: right; }
.text-muted  { color: var(--text-muted); }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.4;
}
.badge-usd      { background: #d1fae5; color: #065f46; }
.badge-cop      { background: #dbeafe; color: #1e40af; }
.badge-success  { background: #d1fae5; color: #065f46; }
.badge-danger   { background: #fee2e2; color: #991b1b; }
.badge-neutral  { background: #f3f4f6; color: #4b5563; }
.badge-admin    { background: #e0e7ff; color: #3730a3; }
.badge-user     { background: #f3f4f6; color: #374151; }

.badge-estado { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 700; }
.badge-prospecto   { background: #f3f4f6; color: #4b5563; }
.badge-enviada     { background: #dbeafe; color: #1e40af; }
.badge-negociacion { background: #fef3c7; color: #92400e; }
.badge-ganada      { background: #d1fae5; color: #065f46; }
.badge-perdida     { background: #fee2e2; color: #991b1b; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px;
    border-radius: 8px;
    border: none;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }

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

.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { background: #1e3c72; color: #fff; }

.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; color: #fff; }

.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }

.btn-outline   {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--border);
}
.btn-outline:hover { border-color: var(--primary); background: #f0f4ff; color: var(--primary); }

.btn-sm { padding: 6px 14px; font-size: 0.82rem; }
.btn-block { display: flex; width: 100%; justify-content: center; }

/* ── Action Buttons (tabla) ─────────────────────────────────── */
.action-group { display: flex; gap: 6px; flex-wrap: wrap; }

.btn-action {
    width: 32px; height: 32px;
    border-radius: 7px;
    border: none;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background .15s;
    text-decoration: none;
}
.btn-action-view   { background: #dbeafe; color: #2563eb; }
.btn-action-view:hover { background: #bfdbfe; }
.btn-action-edit   { background: #fef3c7; color: #d97706; }
.btn-action-edit:hover { background: #fde68a; }
.btn-action-print  { background: #e0e7ff; color: #4338ca; }
.btn-action-print:hover { background: #c7d2fe; }
.btn-action-delete { background: #fee2e2; color: #dc2626; }
.btn-action-delete:hover { background: #fecaca; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.required { color: var(--danger); }

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    color: var(--text);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}
.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(102,126,234,.15);
}
.form-control[readonly] { background: #f9fafb; color: var(--text-muted); }

.form-control-sm { padding: 6px 10px; font-size: 0.83rem; }

textarea.form-control { resize: vertical; }

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
}

.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    flex-wrap: wrap;
    padding: 20px 0;
    border-top: 1px solid var(--border);
}

/* Password toggle */
.input-password-wrapper { position: relative; }
.input-password-wrapper .form-control { padding-right: 42px; }
.btn-toggle-password {
    position: absolute;
    right: 10px; top: 50%;
    transform: translateY(-50%);
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); font-size: 1rem; padding: 4px;
}
.btn-toggle-password:hover { color: var(--primary); }

.password-requirements { margin-top: 6px; }

/* Filters */
.filters-form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
}
.filter-group { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-group .form-control { min-width: 150px; }

.date-filter-form {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.date-filter-form .form-control { width: 140px; }

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef9c3; color: #854d0e; border: 1px solid #fde68a; }

.alert-dismissible { justify-content: space-between; }
.alert-dismissible button {
    background: none; border: none; cursor: pointer; font-size: 0.9rem;
    color: inherit; opacity: .7; padding: 2px 4px; border-radius: 4px;
}
.alert-dismissible button:hover { opacity: 1; background: rgba(0,0,0,.08); }

/* ── Seguimientos ───────────────────────────────────────────── */
.seguimiento-list { list-style: none; }
.seguimiento-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid #f0f2f5;
    font-size: 0.88rem;
}
.seguimiento-item:last-child { border-bottom: none; }
.seguimiento-item.vencido .seguimiento-fecha { color: var(--danger); font-weight: 700; }
.seguimiento-info { min-width: 0; }
.seguimiento-info strong { display: block; }
.seguimiento-fecha { white-space: nowrap; color: var(--text-muted); font-size: 0.82rem; display: flex; align-items: center; gap: 4px; }
.badge-num { background: var(--bg); color: var(--text-muted); padding: 1px 6px; border-radius: 4px; font-size: 0.75rem; margin-left: 6px; }

/* ── Items Table ─────────────────────────────────────────────── */
.items-table .form-control { min-width: 0; }

/* ── Totales ────────────────────────────────────────────────── */
.totales-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 16px;
}
.totales-box {
    min-width: 280px;
    background: #f8f9fc;
    border-radius: 8px;
    padding: 12px 16px;
    border: 1px solid var(--border);
}
.totales-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
}
.totales-row:last-child { border-bottom: none; }
.totales-total {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--primary);
    padding-top: 8px;
    margin-top: 4px;
}

/* ── Detail List ──────────────────────────────────────────── */
.detail-list {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 6px 12px;
    font-size: 0.9rem;
}
.detail-list dt { color: var(--text-muted); font-weight: 600; }
.detail-list dd { color: var(--text); }

/* ── Empty State ─────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-muted);
}
.empty-state h3 { font-size: 1rem; color: var(--text); margin: 12px 0 6px; }
.empty-state p  { font-size: 0.88rem; margin-bottom: 20px; }

/* ── Auth Layout ──────────────────────────────────────────── */
.auth-body {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #667eea 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-wrapper {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.auth-card {
    background: #fff;
    border-radius: 16px;
    padding: 36px 36px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.auth-brand { text-align: center; margin-bottom: 28px; }

.auth-logo-img {
    max-width: 200px;
    max-height: 70px;
    width: auto;
    height: auto;
    object-fit: contain;
    margin: 0 auto 16px;
    display: block;
}

.auth-form { display: flex; flex-direction: column; gap: 0; }

.auth-alert {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.88rem;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.auth-alert-error   { background: #fee2e2; color: #991b1b; }
.auth-alert-success { background: #d1fae5; color: #065f46; }

.auth-footer { font-size: 0.78rem; color: rgba(255,255,255,.5); text-align: center; }

/* TOTP code input */
.totp-input {
    font-size: 1.8rem !important;
    letter-spacing: 0.4em !important;
    text-align: center !important;
    font-weight: 800 !important;
}

/* ── Sidebar Overlay (mobile) ────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 999;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 900px) {
    /* Sidebar oculto por defecto en móvil */
    .sidebar {
        transform: translateX(calc(-1 * var(--sidebar-w)));
    }
    .sidebar.open { transform: translateX(0); }
    .topbar { left: 0; }
    .main-content { margin-left: 0; padding: 20px 16px; }
    .sidebar-toggle { display: block; }
    .sidebar-overlay.open { display: block; }

    /* Logo sidebar más pequeño */
    .sidebar-logo-img {
        max-width: 150px;
        max-height: 48px;
    }

    /* Grids a una columna */
    .form-grid-2,
    .form-row-2,
    .form-row-3,
    .dashboard-grid { grid-template-columns: 1fr !important; }

    .kpi-grid { grid-template-columns: 1fr 1fr; }

    /* Page header apila título y acciones */
    .page-header { flex-direction: column; align-items: flex-start; }

    /* Botones de acción ocupan todo el ancho */
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; text-align: center; justify-content: center; }

    /* Filtros en columna */
    .filters-form { flex-direction: column; }
    .filter-group { flex-direction: column; }
    .filter-group .form-control,
    .date-filter-form .form-control { min-width: unset; width: 100%; }
    .date-filter-form { flex-direction: column; align-items: stretch; }

    /* Tabla de acciones en lista: ocultar columnas menos importantes */
    .col-hide-mobile { display: none; }
}

@media (max-width: 500px) {
    .main-content { padding: 14px 12px; }

    /* Auth card */
    .auth-body { padding: 12px; }
    .auth-card { padding: 24px 18px; }
    .auth-logo-img {
        max-width: 150px;
        max-height: 52px;
    }

    /* KPI una columna */
    .kpi-grid { grid-template-columns: 1fr; }

    /* Topbar compacto */
    .topbar-username { display: none; }
    .topbar-breadcrumb { font-size: 0.8rem; }

    /* Page title más pequeño */
    .page-title { font-size: 1.15rem; }

    /* Card padding reducido */
    .card-body { padding: 14px; }
    .card-header { padding: 12px 14px; }

    /* Sidebar logo aún más pequeño */
    .sidebar-logo-img {
        max-width: 130px;
        max-height: 42px;
    }
}
