/* ========== RESET & BASE ========== */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #F3F4F6;
    color: #1F2937;
    font-size: 14px;
}
h1, h2, h3 { margin: 0; }
a { text-decoration: none; color: inherit; }

/* ========== LOGIN ========== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #EFF6FF 0%, #DBEAFE 100%);
    padding: 20px;
}
.login-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 400px;
    padding: 36px 36px 24px;
}
.login-header { text-align: center; margin-bottom: 28px; }
.login-logo {
    width: 64px;
    height: 64px;
    margin: 0 auto 14px;
    background: #EFF6FF;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-header h1 {
    font-size: 24px;
    color: #2563EB;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.login-sub { color: #6B7280; font-size: 13px; margin: 6px 0 0; }

.login-form { display: flex; flex-direction: column; }
.login-form label {
    font-size: 12px;
    color: #4B5563;
    margin-bottom: 4px;
    margin-top: 12px;
    font-weight: 600;
}
.login-form input,
.login-form select {
    height: 38px;
    border: 1px solid #D1D5DB;
    border-radius: 6px;
    padding: 0 10px;
    font-size: 14px;
    background: #fff;
    color: #111827;
    transition: border 0.15s;
}
.login-form input:focus,
.login-form select:focus {
    outline: none;
    border-color: #2563EB;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.login-error {
    background: #FEF2F2;
    color: #B91C1C;
    border: 1px solid #FECACA;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    margin-top: 14px;
}
.login-btn {
    margin-top: 22px;
    height: 42px;
    background: #2563EB;
    color: #fff;
    border: 0;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.login-btn:hover { background: #1D4ED8; }
.login-footer {
    text-align: center;
    color: #9CA3AF;
    font-size: 11px;
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid #F3F4F6;
}

/* ========== LAYOUT ========== */
.layout { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    background: #fff;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid #E5E7EB;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.topbar-left { display: flex; align-items: baseline; gap: 10px; }
.brand { font-size: 17px; font-weight: 700; color: #2563EB; }
.brand-sub { font-size: 12px; color: #6B7280; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #F3F4F6;
    color: #4B5563;
    padding: 5px 10px;
    border-radius: 14px;
    font-size: 13px;
}
.btn-logout {
    background: #FEF2F2;
    color: #DC2626;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid #FEE2E2;
    transition: background 0.15s;
}
.btn-logout:hover { background: #FEE2E2; }

.content { flex: 1; padding: 18px 24px; }

/* ========== DASHBOARD ========== */
.dash-header { text-align: center; margin-bottom: 14px; }
.dash-header h1 {
    color: #2563EB;
    font-size: 22px;
    letter-spacing: 1px;
    font-weight: 700;
}
.dash-header p { color: #6B7280; font-size: 12px; margin: 2px 0 0; }

.filters {
    background: #fff;
    border-radius: 8px;
    border: 1px solid #E5E7EB;
    padding: 14px 18px;
    display: flex;
    align-items: flex-end;
    gap: 22px;
    margin-bottom: 16px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 11px; color: #4B5563; font-weight: 600; }
.filter-group select,
.filter-group input[type=date] {
    height: 32px;
    border: 1px solid #D1D5DB;
    border-radius: 5px;
    padding: 0 8px;
    font-size: 13px;
    background: #fff;
    min-width: 160px;
}
.dates { display: flex; align-items: center; gap: 6px; }
.dates span { color: #9CA3AF; }
.btn-refresh {
    margin-left: auto;
    background: #EFF6FF;
    color: #2563EB;
    border: 1px solid #BFDBFE;
    height: 36px;
    padding: 0 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
}
.btn-refresh:hover { background: #DBEAFE; }
.btn-refresh:disabled { opacity: 0.5; cursor: not-allowed; }

.loading-msg {
    text-align: center;
    padding: 40px;
    color: #6B7280;
    background: #fff;
    border-radius: 8px;
    border: 1px solid #E5E7EB;
}

/* ========== KPI CARDS ========== */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 14px;
    margin-bottom: 16px;
}
.kpi-card {
    background: #fff;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    padding: 14px 16px 12px;
    min-height: 134px;
    position: relative;
}
.kpi-title { font-size: 12px; font-weight: 700; }
.kpi-body { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.kpi-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.kpi-icon svg { width: 36px; height: 36px; }
.kpi-value {
    font-size: 30px;
    font-weight: 700;
    color: #111827;
    line-height: 1;
}
.kpi-sub { color: #6B7280; font-size: 11px; margin-top: 4px; padding-left: 64px; }
.kpi-delta {
    font-size: 11px;
    font-weight: 700;
    margin-top: 8px;
}
.kpi-delta.pos { color: #16A34A; }
.kpi-delta.neg { color: #DC2626; }

/* ========== CHARTS ========== */
.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 16px;
}
.card {
    background: #fff;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    padding: 14px 16px;
    overflow: hidden;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.card-header h3 { font-size: 13px; font-weight: 700; color: #1F2937; }
.chart-card canvas { max-height: 200px; }
.chart-foot { font-size: 11px; color: #6B7280; margin-top: 8px; }
.donut-wrapper { height: 200px; }
.total-tag { font-size: 11px; color: #6B7280; }
.total-tag b { color: #111827; font-size: 13px; }

/* ========== TABLES ========== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
    table-layout: fixed;        /* respeta los anchos por columna */
}
.data-table th {
    text-align: left;
    color: #6B7280;
    font-weight: 600;
    font-size: 11px;
    padding: 6px 8px;
    border-bottom: 1px solid #E5E7EB;
    white-space: nowrap;
}
.data-table td {
    padding: 7px 8px;
    border-bottom: 1px solid #F3F4F6;
    color: #1F2937;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.data-table td.muted { color: #6B7280; }
.data-table td.empty {
    text-align: center;
    color: #9CA3AF;
    padding: 18px;
    font-style: italic;
    white-space: normal;
}

/* Anchos específicos de la tabla de Últimos Movimientos (5 columnas) */
.card > .data-table:first-of-type th:nth-child(1),
.card > .data-table:first-of-type td:nth-child(1) { width: 70px; }   /* Fecha */
.card > .data-table:first-of-type th:nth-child(2),
.card > .data-table:first-of-type td:nth-child(2) { width: 50px; }   /* Hora */
.card > .data-table:first-of-type th:nth-child(4),
.card > .data-table:first-of-type td:nth-child(4) { width: 100px; }  /* Origen */

/* Pill para Entrada / Salida */
.th-mov { text-align: center; width: 80px; }
.td-mov {
    text-align: center;
    font-weight: 700;
    font-size: 11.5px;
}
.td-mov.entrada { color: #16A34A; }
.td-mov.salida  { color: #DC2626; }

/* ========== BARS (empresas) ========== */
.bars { padding: 4px 0; }
.bar-row {
    display: grid;
    grid-template-columns: 110px 1fr 36px;
    gap: 8px;
    align-items: center;
    margin-bottom: 10px;
}
.bar-label {
    font-size: 12.5px;
    color: #1F2937;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bar-track {
    background: #F3F4F6;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
}
.bar-fill {
    background: #2563EB;
    height: 100%;
    border-radius: 4px;
}
.bar-value {
    font-size: 12.5px;
    font-weight: 700;
    color: #111827;
    text-align: right;
}

/* ========== BOTTOM ROW (proporciones espejando WinForms) ==========
   WinForms: Movimientos 560 | Empresas 260 | NoAutorizadas 400
   En CSS usamos las mismas proporciones con fr.                       */
.bottom-row {
    display: grid;
    grid-template-columns: 56fr 26fr 40fr;
    gap: 12px;
}

/* ========== BADGE NO AUTORIZADOS ========== */
.badge-na {
    font-size: 12px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 12px;
    white-space: nowrap;
}
.badge-na.danger { background: #FEF2F2; color: #DC2626; }
.badge-na.ok { background: #F0FDF4; color: #16A34A; }

.empty { color: #9CA3AF; padding: 14px; text-align: center; font-style: italic; }

/* ========== RESPONSIVE ========== */
@media (max-width: 1200px) {
    .kpi-row { grid-template-columns: repeat(2, 1fr); }
    .charts-row { grid-template-columns: 1fr; }
    .bottom-row { grid-template-columns: 1fr; }
}
