* {
    box-sizing: border-box;
}

:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --text: #101828;
    --muted: #475467;
    --line: #d0d5dd;
    --primary: #0b63ce;
    --danger: #b42318;
    --success: #067647;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Noto Sans", sans-serif;
    background: linear-gradient(145deg, #eef2f8 0%, #f8fafc 100%);
    color: var(--text);
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: #0f172a;
    color: #e2e8f0;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.brand {
    font-size: 18px;
    font-weight: 700;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar nav a {
    color: #e2e8f0;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar nav a.active,
.sidebar nav a:hover {
    background: rgba(226, 232, 240, 0.14);
}

.nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    text-align: center;
    font-size: 14px;
}

.sidebar-user {
    margin-top: auto;
    font-size: 13px;
    display: grid;
    gap: 8px;
}

.sidebar-user button {
    border: none;
    background: #ef4444;
    color: #fff;
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
}

.content {
    flex: 1;
    padding: 24px;
    display: block;
}

.login-main {
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    width: min(100%, 420px);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 26px;
    box-shadow: 0 16px 32px rgba(16, 24, 40, 0.08);
    display: grid;
    gap: 14px;
}

.login-alert {
    margin: 0;
}

.page-header h1 {
    margin: 0 0 8px;
}

.page-header p {
    margin: 0;
    color: var(--muted);
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.kpi-grid.small {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.kpi-card {
    background: var(--surface-alt);
    border: 1px solid #e4e7ec;
    border-radius: 10px;
    padding: 14px;
}

.kpi-card h3 {
    margin: 0 0 10px;
    font-size: 13px;
    color: var(--muted);
}

.kpi-value {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.two-cols {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th,
td {
    border-bottom: 1px solid #eaecf0;
    padding: 10px 8px;
    text-align: left;
    vertical-align: top;
}

th {
    font-weight: 600;
    background: #f8fafc;
}

.form-grid {
    display: grid;
    gap: 10px;
}

label {
    font-size: 13px;
    color: var(--muted);
    display: grid;
    gap: 6px;
}

input,
select,
textarea,
button {
    font: inherit;
}

input,
select,
textarea {
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    padding: 10px;
    background: #fff;
}

button {
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    padding: 10px 12px;
    cursor: pointer;
}

.inline-form {
    display: inline-flex;
    gap: 6px;
    margin-right: 6px;
    margin-bottom: 6px;
}

.inline-form input[type='password'] {
    width: 140px;
}

/* Toast Notifications - Flotantes */
.toast {
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    max-width: 400px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast-error {
    background: #ef4444;
    color: #fff;
    border-left: 4px solid #dc2626;
}

.toast-success {
    background: #22c55e;
    color: #fff;
    border-left: 4px solid #16a34a;
}

.field-list {
    margin-top: 10px;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    padding: 10px;
    max-height: 280px;
    overflow: auto;
}

.field-list ul {
    margin: 0;
    padding-left: 18px;
}

/* ===== NAV SECTIONS ===== */
.nav-section {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #64748b;
    padding: 20px 12px 8px;
    font-weight: 700;
    border-top: 1px solid rgba(100, 116, 139, 0.2);
    margin-top: 8px;
}

.nav-section:first-of-type {
    border-top: none;
    margin-top: 0;
    padding-top: 12px;
}

/* ===== KPI VARIANTS ===== */
.kpi-card.kpi-primary {
    border-left: 3px solid var(--primary);
}

.kpi-card.kpi-danger {
    border-left: 3px solid var(--danger);
}

.kpi-card.kpi-success {
    border-left: 3px solid var(--success);
}

.kpi-sub {
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
}

/* ===== TABLE ACTIONS BAR ===== */
.table-actions-bar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.table-actions-bar h2 {
    margin: 0;
    align-self: center;
}

.bar-right {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

/* ===== FILTER ROW ===== */
.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.filter-row input[type="text"],
.filter-row input[type="date"],
.filter-row select {
    padding: 6px 10px;
    font-size: 13px;
    height: 34px;
    border-radius: 6px;
    max-width: 160px;
}

.filter-row button {
    height: 34px;
    padding: 0 14px;
    font-size: 13px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    white-space: nowrap;
}

.btn-outline {
    display: inline-flex;
    align-items: center;
    height: 34px;
    padding: 0 14px;
    font-size: 13px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.btn-outline:hover {
    background: var(--surface-alt);
}

/* ===== BADGES ===== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-success,
.badge-ok {
    background: #dcfae6;
    color: var(--success);
}

.badge-error {
    background: #fee4e2;
    color: var(--danger);
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-idle,
.badge-failed {
    background: #f1f5f9;
    color: #475467;
}

/* ===== PAGINATION ===== */
.pagination {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #eaecf0;
}

.pag-info {
    font-size: 12px;
    color: var(--muted);
    margin-right: 8px;
}

.pag-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}

.pag-btn:hover {
    background: var(--surface-alt);
}

.pag-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ===== CELL HELPERS ===== */
.cell-error {
    max-width: 260px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--muted);
    font-size: 12px;
}

.text-muted {
    color: var(--muted);
    font-size: 13px;
    padding: 14px 8px;
}

/* ===== ANALYTICS ===== */
.analytics-period-bar {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
}

.analytics-period-bar .period-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.analytics-period-bar .period-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.analytics-period-bar .preset-btn {
    padding: 8px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    text-decoration: none;
    color: var(--muted);
    font-size: 13px;
    background: var(--surface);
    transition: all 0.2s;
}

.analytics-period-bar .preset-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.analytics-period-bar .preset-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.analytics-period-bar .period-custom {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.analytics-period-bar .period-custom label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
}

.analytics-period-bar .period-custom input[type="date"] {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 13px;
}

.analytics-period-bar .period-custom button {
    padding: 8px 16px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}

.btn-secondary {
    background: #64748b;
    color: #ffffff;
    border: 1px solid #475569;
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.btn-secondary:hover {
    background: #475569;
}

.chart-panel {
    display: flex;
    flex-direction: column;
    min-height: 320px;
    padding: 16px;
}

.chart-panel canvas {
    max-height: 260px;
    width: 100% !important;
}

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

.chart-header h2 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}
.btn-icon {
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
}

.btn-icon:hover {
    background: var(--surface-alt);
}

.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    margin: 0 0 8px 0;
    font-size: 24px;
    font-weight: 600;
}

.page-header p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
    }

    .table-actions-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .filter-row input[type="text"],
    .filter-row input[type="date"],
    .filter-row select {
        max-width: 100%;
        flex: 1;
    }
}
