/* ================================================================
   Sistema de Licitaciones — ConectaSPA
   Estilos base
   ================================================================ */

/* ── Variables ─────────────────────────────────────────────────── */
:root {
    --sidebar-w:      240px;
    --sidebar-bg:     #0f172a;
    --sidebar-text:   #94a3b8;
    --sidebar-active: #3b82f6;
    --sidebar-hover:  #1e293b;

    --topbar-h:       56px;
    --topbar-bg:      #ffffff;
    --topbar-border:  #e2e8f0;

    --bg-page:        #f1f5f9;
    --bg-card:        #ffffff;
    --border:         #e2e8f0;
    --radius:         8px;

    --text-primary:   #0f172a;
    --text-secondary: #64748b;
    --text-muted:     #94a3b8;

    --blue:           #3b82f6;
    --blue-dark:      #2563eb;
    --green:          #22c55e;
    --orange:         #f97316;
    --red:            #ef4444;
    --yellow:         #eab308;

    --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
    --shadow:    0 4px 12px rgba(0,0,0,.10);
}

/* ── Reset mínimo ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; color: var(--text-primary); background: var(--bg-page); }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ── Layout ────────────────────────────────────────────────────── */
/*
 * El sidebar usa position:fixed → está fuera del flujo normal.
 * .main-wrapper compensa con margin-left: var(--sidebar-w).
 * NO usar display:grid aquí — causaría doble compensación horizontal
 * (grid reserva 240px + margin-left suma otros 240px = 480px perdidos).
 */
.layout {
    display: block;
    min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: var(--sidebar-w);
    overflow-y: auto;
    transition: width .2s ease;
    z-index: 100;
}
.sidebar.collapsed { width: 56px; }
.sidebar.collapsed .brand-name,
.sidebar.collapsed .nav-section,
.sidebar.collapsed .user-details,
.sidebar.collapsed .nav-item span { display: none; }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid #1e293b;
    flex-shrink: 0;
}
.brand-icon { font-size: 1.4rem; color: var(--blue); }
.brand-name  { font-size: 1rem; font-weight: 700; color: #fff; white-space: nowrap; }

.sidebar-nav {
    flex: 1;
    padding: .75rem 0;
    overflow-y: auto;
}
.nav-section {
    display: block;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #475569;
    padding: .75rem 1rem .25rem;
}
.nav-item {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .55rem 1rem;
    color: var(--sidebar-text);
    border-radius: 6px;
    margin: 1px .5rem;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.nav-item i { width: 18px; text-align: center; font-size: .95rem; flex-shrink: 0; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--blue); color: #fff; }

.sidebar-footer {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .75rem 1rem;
    border-top: 1px solid #1e293b;
    flex-shrink: 0;
}
.user-avatar { font-size: 1.6rem; color: #475569; flex-shrink: 0; }
.user-details { flex: 1; overflow: hidden; }
.user-name  { display: block; font-size: .8rem; font-weight: 600; color: #e2e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role  { display: block; font-size: .7rem; color: #475569; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-logout { color: #475569; font-size: 1rem; flex-shrink: 0; padding: .25rem; transition: color .15s; }
.btn-logout:hover { color: var(--red); text-decoration: none; }

/* ── Main wrapper ──────────────────────────────────────────────── */
.main-wrapper {
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Topbar ────────────────────────────────────────────────────── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem;
    box-shadow: var(--shadow-sm);
}
.sidebar-toggle { background: none; border: none; cursor: pointer; font-size: 1.1rem; color: var(--text-secondary); padding: .25rem .5rem; border-radius: 4px; }
.sidebar-toggle:hover { background: var(--bg-page); color: var(--text-primary); }
.topbar-title { font-size: 1rem; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.topbar-icon { font-size: 1.1rem; color: var(--text-secondary); padding: .35rem .5rem; border-radius: 6px; }
.topbar-icon:hover { background: var(--bg-page); color: var(--text-primary); text-decoration: none; }

/* ── Main content ──────────────────────────────────────────────── */
.main-content {
    flex: 1;
    padding: 1.5rem;
    max-width: 1400px;
    width: 100%;
}

/* ── Page header ───────────────────────────────────────────────── */
.page-header { margin-bottom: 1.5rem; }
.page-header h2 { font-size: 1.25rem; font-weight: 700; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }

/* ── Alerts / Flash ────────────────────────────────────────────── */
.alert {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: .875rem;
}
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── KPI Grid ──────────────────────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
}
.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-blue   { background: #eff6ff; color: var(--blue); }
.kpi-green  { background: #f0fdf4; color: var(--green); }
.kpi-orange { background: #fff7ed; color: var(--orange); }
.kpi-red    { background: #fef2f2; color: var(--red); }
.kpi-body { display: flex; flex-direction: column; }
.kpi-value { font-size: 1.6rem; font-weight: 700; line-height: 1; }
.kpi-label { font-size: .75rem; color: var(--text-secondary); margin-top: .2rem; }

/* ── Panel / Card ──────────────────────────────────────────────── */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}
.panel-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.panel-header h3 { font-size: .95rem; font-weight: 600; display: flex; align-items: center; gap: .5rem; }
.panel-body { padding: 1.25rem; }

/* ── Tabla ─────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { background: #f8fafc; font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-secondary); padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--border); }
td { padding: .7rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

/* ── Badges ────────────────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center;
    padding: .2rem .55rem;
    border-radius: 9999px;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-yellow { background: #fef9c3; color: #854d0e; }

/* Scoring badges */
.badge-atacar   { background: #dcfce7; color: #166534; }
.badge-revisar  { background: #dbeafe; color: #1e40af; }
.badge-opcional { background: #fef9c3; color: #854d0e; }
.badge-descartar{ background: #fee2e2; color: #991b1b; }

/* ── Botones ───────────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .5rem 1rem;
    border-radius: 6px;
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background .15s, border-color .15s, box-shadow .15s;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary   { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn-secondary { background: #fff; color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-page); }
.btn-danger    { background: var(--red); color: #fff; border-color: var(--red); }
.btn-sm        { padding: .3rem .65rem; font-size: .8rem; }
.btn-full      { width: 100%; justify-content: center; }

/* ── Formularios ───────────────────────────────────────────────── */
.form-group { margin-bottom: 1.1rem; }
.form-group label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: .35rem; color: var(--text-secondary); }
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], select, textarea {
    width: 100%;
    padding: .55rem .75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .875rem;
    background: #fff;
    color: var(--text-primary);
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.input-icon { position: relative; }
.input-icon > i { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: .85rem; }
.input-icon > input { padding-left: 2.25rem; }

/* ── Login page ────────────────────────────────────────────────── */
.login-page {
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-container { width: 100%; max-width: 400px; padding: 1rem; }
.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 2rem; }
.login-brand-icon { font-size: 2.5rem; color: var(--blue); display: block; margin-bottom: .5rem; }
.login-brand h1 { font-size: 1.4rem; font-weight: 700; }
.login-brand p { color: var(--text-muted); font-size: .85rem; margin-top: .25rem; }
.login-form { display: flex; flex-direction: column; gap: .1rem; }
.login-form .btn { margin-top: .75rem; padding: .7rem 1rem; font-size: .95rem; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-wrapper { margin-left: 0; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .main-content { padding: 1rem; }
}
