/* ============================================================
   Mercado Público — Diseño CRM (ABC Chile Ingeniería style)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

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

:root {
    --azul:       #2563eb;
    --azul-dark:  #1d4ed8;
    --azul-light: #eff6ff;
    --verde:      #0D9488;
    --verde-dark: #0f766e;
    --verde-light:#ccfbf1;
    --gris-bg:    #f1f5f9;
    --gris-borde: #e2e8f0;
    --gris-texto: #64748b;
    --negro:      #0f172a;
    --blanco:     #ffffff;

    /* sidebar — color exacto del inspector */
    --sb-bg:      #1E3A5F;
    --sb-item-hover: rgba(255,255,255,0.08);
    --sb-width:   210px;
    --sb-col:     56px;
    --topbar-h:   60px;
}

html, body { height: 100%; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    color: var(--negro);
    background: var(--gris-bg);
}

body.has-sidebar {
    display: flex;
    min-height: 100vh;
}

a { color: var(--azul); text-decoration: none; }
a:hover { color: var(--verde); }

/* ══════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════ */
.sidebar {
    width: var(--sb-width);
    min-height: 100vh;
    background: var(--sb-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 300;
    transition: width 0.22s ease;
    flex-shrink: 0;
}

.sidebar.collapsed { width: var(--sb-col); }

/* ── Brand ── */
.sb-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 10px 14px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    min-height: 62px;
    flex-shrink: 0;
    overflow: hidden;
}
.sb-brand-left {
    display: flex; align-items: center; gap: 10px;
    min-width: 0; overflow: hidden;
}
.sb-brand-icon {
    width: 32px; height: 32px; flex-shrink: 0;
    background: var(--verde);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px;
}
.sb-brand-text { overflow: hidden; transition: opacity 0.15s, width 0.22s; white-space: nowrap; }
.sidebar.collapsed .sb-brand-text { opacity: 0; width: 0; pointer-events: none; }
.sb-brand-name { font-size: 12.5px; font-weight: 800; color: white; line-height: 1.2; }
.sb-brand-sub  { font-size: 10px; color: var(--verde); font-weight: 600; }

.sb-toggle {
    background: rgba(255,255,255,0.06);
    border: none; cursor: pointer;
    width: 22px; height: 22px;
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    color: rgba(255,255,255,0.35);
    font-size: 14px; font-weight: 700;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, transform 0.22s;
    line-height: 1;
}
.sb-toggle:hover { background: rgba(255,255,255,0.12); color: white; }
.sidebar.collapsed .sb-toggle { transform: rotate(180deg); }

/* ── Nav ── */
.sb-nav {
    flex: 1;
    padding: 8px 8px;
    overflow-y: auto;
    overflow-x: hidden;
}
.sb-nav::-webkit-scrollbar { width: 3px; }
.sb-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.07); border-radius: 3px; }

.sb-group-label {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 1px; color: rgba(255,255,255,0.22);
    padding: 10px 10px 4px 10px;
    white-space: nowrap; overflow: hidden;
    transition: opacity 0.15s;
}
.sidebar.collapsed .sb-group-label { opacity: 0; }

.sb-sep { height: 1px; background: rgba(255,255,255,0.05); margin: 4px 0; }

/* ── Items ── */
.sb-item {
    display: flex; align-items: center; gap: 10px;
    padding: 0 10px; height: 40px;
    color: #BFDBF4;
    text-decoration: none;
    border-radius: 8px;
    transition: background 0.13s, color 0.13s;
    white-space: nowrap;
    position: relative;
    margin-bottom: 2px;
    overflow: hidden;
}
.sb-item:hover {
    background: rgba(255,255,255,0.09);
    color: white;
    text-decoration: none;
}
.sb-item.active {
    background: var(--verde);
    color: white;
    font-weight: 600;
}
.sb-item.active:hover { background: var(--verde-dark); color: white; }

.sb-icon {
    font-size: 16px; flex-shrink: 0;
    width: 20px; text-align: center;
}
.sb-label {
    font-size: 13px; font-weight: 500;
    overflow: hidden; white-space: nowrap;
    transition: opacity 0.15s;
}
.sidebar.collapsed .sb-label { opacity: 0; }

/* Tooltip cuando colapsado */
.sb-item[data-tooltip]::after {
    content: attr(data-tooltip);
    position: fixed;
    left: calc(var(--sb-col) + 10px);
    background: #1E3A5F;
    color: white;
    padding: 5px 10px;
    border-radius: 7px;
    font-size: 12px; font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    box-shadow: 0 4px 14px rgba(0,0,0,0.3);
    z-index: 999;
    transition: opacity 0.12s;
}
.sidebar.collapsed .sb-item:hover::after { opacity: 1; }

/* ── Footer sidebar ── */
.sb-footer {
    flex-shrink: 0;
    border-top: 1px solid rgba(255,255,255,0.06);
    padding: 8px 8px;
    overflow: hidden;
}
.sb-user-row {
    display: flex; align-items: center; gap: 9px;
    padding: 6px 10px 4px;
    overflow: hidden;
}
.sb-avatar {
    width: 30px; height: 30px; flex-shrink: 0;
    background: #1E3A5F;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 800; color: white;
    border: 2px solid rgba(255,255,255,0.15);
}
.sb-user-info { overflow: hidden; transition: opacity 0.15s; min-width: 0; }
.sidebar.collapsed .sb-user-info { opacity: 0; }
.sb-user-label    { font-size: 9px; font-weight: 600; color: var(--verde); text-transform: uppercase; letter-spacing: 0.6px; }
.sb-user-name     { font-size: 12px; font-weight: 700; color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-role-txt { font-size: 10px; color: rgba(255,255,255,0.35); }

.sb-logout {
    display: flex; align-items: center; gap: 10px;
    padding: 0 10px; height: 36px;
    color: #BFDBF4;
    text-decoration: none; border-radius: 8px;
    transition: background 0.13s, color 0.13s;
    position: relative; overflow: hidden;
    margin-top: 2px;
}
.sb-logout:hover { background: rgba(239,68,68,0.1); color: #f87171; text-decoration: none; }
.sb-logout .sb-label { font-size: 12px; }

/* ══════════════════════════════════════════
   MAIN WRAP
══════════════════════════════════════════ */
.main-wrap {
    margin-left: var(--sb-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.22s ease;
}
.main-wrap.collapsed { margin-left: var(--sb-col); }

/* ── Topbar ── */
.topbar {
    height: var(--topbar-h);
    background: white;
    border-bottom: 1px solid var(--gris-borde);
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky; top: 0; z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    flex-shrink: 0;
}
.topbar-left  { display: flex; align-items: center; gap: 14px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }

.topbar-title-wrap {}
.topbar-title { font-size: 18px; font-weight: 800; color: var(--negro); line-height: 1.2; }
.topbar-date  { font-size: 12px; color: var(--gris-texto); margin-top: 1px; }

.user-chip {
    display: flex; align-items: center; gap: 10px;
    background: var(--gris-bg);
    border: 1px solid var(--gris-borde);
    border-radius: 10px;
    padding: 6px 12px 6px 8px;
}
.user-avatar {
    width: 32px; height: 32px;
    background: var(--sb-bg);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 800; color: white;
}
.user-info-top { line-height: 1.25; }
.user-info-top .u-name { font-size: 13px; font-weight: 700; color: var(--negro); }
.user-info-top .u-role { font-size: 11px; color: var(--gris-texto); }

/* ── Container ── */
.container {
    flex: 1; padding: 24px 28px; max-width: 100%;
}

/* ══════════════════════════════════════════
   COMPONENTES
══════════════════════════════════════════ */

/* Alertas */
.alert {
    padding: 11px 16px; border-radius: 8px;
    margin-bottom: 12px; display: flex;
    justify-content: space-between; align-items: center;
    font-size: 13px; border-left: 4px solid transparent;
}
.alert-success { background: #f0fdf4; color: #166534; border-color: var(--verde); }
.alert-error   { background: #fef2f2; color: #991b1b; border-color: #ef4444; }
.alert-info    { background: #eff6ff; color: #1e40af; border-color: var(--azul); }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #f59e0b; }
.alert-close { background: none; border: none; font-size: 18px; cursor: pointer; opacity: 0.4; }
.alert-close:hover { opacity: 1; }

/* Page header */
.page-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 22px; flex-wrap: wrap; gap: 12px;
}
.page-header h1 { font-size: 20px; font-weight: 800; color: var(--negro); }
.breadcrumb { font-size: 12px; color: var(--gris-texto); margin-bottom: 3px; }
.breadcrumb a { color: var(--azul); }

/* Botones */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: 8px; font-size: 13px;
    font-weight: 600; cursor: pointer; border: none;
    text-decoration: none; transition: all 0.13s;
    white-space: nowrap; font-family: inherit;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--azul); color: white; }
.btn-primary:hover { background: var(--azul-dark); color: white; }
.btn-teal { background: var(--verde); color: white; }
.btn-teal:hover { background: var(--verde-dark); color: white; }
.btn-outline { background: white; color: var(--azul); border: 1.5px solid var(--gris-borde); }
.btn-outline:hover { border-color: var(--azul); background: var(--azul-light); color: var(--azul); }
.btn-block { display: flex; width: 100%; justify-content: center; }
.btn-sm {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 600;
    background: var(--gris-bg); color: var(--negro);
    border: 1px solid var(--gris-borde); cursor: pointer;
    text-decoration: none; transition: all 0.12s; font-family: inherit;
}
.btn-sm:hover { background: var(--azul-light); color: var(--azul); border-color: var(--azul); text-decoration: none; }
.btn-edit   { background: var(--verde-light); color: var(--verde-dark); border-color: #bbf7d0; }
.btn-edit:hover  { background: var(--verde); color: white; }
.btn-danger { background: #fff5f5; color: #c53030; border-color: #feb2b2; }
.btn-danger:hover { background: #c53030; color: white; }
.req { color: #ef4444; }

/* Tablas */
.table {
    width: 100%; border-collapse: collapse; background: white;
    border-radius: 10px; overflow: hidden;
    border: 1px solid var(--gris-borde);
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.table th {
    background: var(--sb-bg); color: white;
    padding: 11px 14px; text-align: left;
    font-size: 12px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap;
}
.table td {
    padding: 11px 14px; border-bottom: 1px solid var(--gris-bg);
    font-size: 13px; vertical-align: middle; color: var(--negro);
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fafc; }
.acciones { display: flex; gap: 5px; flex-wrap: wrap; }
.filename { font-size: 11px; color: var(--gris-texto); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.total-info { margin-top: 10px; font-size: 12px; color: var(--gris-texto); }

/* Formularios */
.form-card {
    background: white; border: 1px solid var(--gris-borde);
    border-radius: 12px; padding: 28px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04); max-width: 860px;
}
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.4px;
    color: var(--gris-texto); margin-bottom: 6px;
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 9px 13px;
    border: 1.5px solid var(--gris-borde); border-radius: 8px;
    font-size: 14px; color: var(--negro); background: white;
    transition: border-color 0.15s, box-shadow 0.15s; font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--verde);
    box-shadow: 0 0 0 3px rgba(34,197,94,0.1);
}
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.form-check { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.doc-filename {
    font-size: 13px; color: var(--gris-texto); background: var(--gris-bg);
    padding: 8px 13px; border-radius: 8px; margin-bottom: 16px;
    border: 1px solid var(--gris-borde);
}

/* Filtros */
.filtros-form { margin-bottom: 18px; }
.filtros-row {
    display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end;
    background: white; padding: 14px; border-radius: 10px;
    border: 1px solid var(--gris-borde); box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.filtros-row input, .filtros-row select {
    padding: 8px 12px; border: 1.5px solid var(--gris-borde);
    border-radius: 7px; font-size: 13px; flex: 1; min-width: 120px;
    color: var(--negro); font-family: inherit; background: white;
}
.filtros-row input:focus, .filtros-row select:focus { outline: none; border-color: var(--verde); }

/* Stats */
.stats-row { display: flex; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.stat-card {
    background: white; border: 1px solid var(--gris-borde);
    border-radius: 12px; padding: 18px 24px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04); text-align: center;
    min-width: 120px; border-top: 3px solid var(--verde);
    flex: 1;
}
.stat-num   { font-size: 30px; font-weight: 800; color: var(--sb-bg); }
.stat-label { font-size: 11px; color: var(--gris-texto); margin-top: 3px; text-transform: uppercase; letter-spacing: 0.3px; }
.section-title {
    font-size: 14px; font-weight: 700; color: var(--negro);
    margin-bottom: 12px; padding-bottom: 7px;
    border-bottom: 2px solid var(--verde); display: inline-block;
}

/* Home */
.home-hero {
    background: linear-gradient(135deg, var(--sb-bg) 0%, #162d4a 100%);
    border-radius: 14px; padding: 36px 32px; margin-bottom: 24px;
    position: relative; overflow: hidden;
}
.home-hero::after {
    content: ''; position: absolute; right: -50px; top: -50px;
    width: 250px; height: 250px; border-radius: 50%;
    background: rgba(255,255,255,0.03);
}
.home-hero h1 { font-size: 24px; font-weight: 800; color: white; margin-bottom: 5px; }
.home-hero p  { color: rgba(255,255,255,0.55); font-size: 13px; }
.teal-bar { display: inline-block; width: 32px; height: 3px; background: var(--verde); border-radius: 2px; margin-bottom: 10px; }
.modulos-grid { display: flex; flex-direction: column; gap: 10px; max-width: 340px; }
.modulo-card {
    background: white; border: 1px solid var(--gris-borde);
    border-radius: 10px; padding: 16px 20px; display: flex;
    flex-direction: column; gap: 8px;
    transition: box-shadow 0.18s, transform 0.18s;
    border-left: 4px solid var(--azul);
}
.modulo-card:hover { box-shadow: 0 6px 24px rgba(30,58,95,0.1); transform: translateY(-2px); }
.modulo-card.teal { border-left-color: var(--verde); }
.modulo-icon { width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; background: var(--azul-light); }
.modulo-card.teal .modulo-icon { background: var(--verde-light); }
.modulo-card h2 { font-size: 16px; font-weight: 700; color: var(--negro); }
.modulo-card p  { color: var(--gris-texto); font-size: 13px; line-height: 1.6; flex: 1; }
.modulo-acciones { display: flex; gap: 8px; margin-top: 4px; }

/* Combinar */
.combinar-lista { max-height: 480px; overflow-y: auto; border: 1.5px solid var(--gris-borde); border-radius: 8px; }
.combinar-item { display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px; cursor: pointer; border-bottom: 1px solid var(--gris-bg); }
.combinar-item:last-child { border-bottom: none; }
.combinar-item:hover { background: var(--azul-light); }
.combinar-item small { display: block; color: var(--gris-texto); font-size: 11px; }

/* Badge */
.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-admin { background: #eff6ff; color: var(--azul); border: 1px solid #bfdbfe; }
.badge-user  { background: var(--verde-light); color: var(--verde-dark); border: 1px solid #bbf7d0; }

/* Error pages */
.error-page { text-align: center; padding: 80px 0; }
.error-page h1 { font-size: 80px; font-weight: 900; color: var(--gris-borde); }
.error-page p  { font-size: 17px; color: var(--gris-texto); margin-bottom: 24px; }
.empty-msg { color: var(--gris-texto); font-size: 13px; padding: 24px 0; text-align: center; }

/* Footer */
.footer {
    background: white; border-top: 1px solid var(--gris-borde);
    color: var(--gris-texto); text-align: center;
    padding: 12px; font-size: 12px;
}

/* ══════════════════════════════════════════
   HOME LAYOUT
══════════════════════════════════════════ */
.home-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.home-panel {
    background: white;
    border: 1px solid var(--gris-borde);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    width: 320px;
    flex-shrink: 0;
}

.panel-title {
    font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.8px;
    color: var(--gris-texto);
    padding: 14px 18px 10px;
    border-bottom: 1px solid var(--gris-borde);
}

.panel-item {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--gris-borde);
    text-decoration: none;
    transition: background 0.13s;
    color: var(--negro);
}
.panel-item:last-child { border-bottom: none; }
.panel-item:hover { background: var(--gris-bg); text-decoration: none; color: var(--negro); }

.panel-item-icon {
    width: 38px; height: 38px; flex-shrink: 0;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
}
.panel-item-icon.azul { background: var(--azul-light); }
.panel-item-icon.teal { background: var(--verde-light); }
.panel-item-icon.gris { background: var(--gris-bg); }

.panel-item-body { flex: 1; min-width: 0; }
.panel-item-name { font-size: 13px; font-weight: 600; color: var(--negro); }
.panel-item-desc { font-size: 11px; color: var(--gris-texto); margin-top: 2px; }

.panel-arrow {
    font-size: 18px; color: var(--gris-borde);
    font-weight: 300; flex-shrink: 0;
}
.panel-item:hover .panel-arrow { color: var(--verde); }

/* ══════════════════════════════════════════
   LOGIN / REGISTRO
══════════════════════════════════════════ */
.page-title-small { font-size: 15px; font-weight: 700; color: var(--negro); }
