:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --border: #e1dfdd;
    --border-soft: #f3f2f1;
    --text: #201f1e;
    --text-muted: #605e5c;
    --text-faint: #a19f9d;
    --accent: #315f72;
    --accent-dark: #244b5d;
    --accent-soft: #eaf3f6;
    --blue: #2868b2;
    --green: #107c10;
    --green-dark: #0b6a0b;
    --red: #d13438;
    --red-dark: #a4262c;
    --red-bg: #fde7e9;
    --red-border: #f4b8be;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}
a { color: inherit; }

/* Header */
.header {
    background: #13252d;
    color: white;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    height: 48px;
}
.header-logo {
    display: flex; align-items: center; gap: 8px;
    font-size: 15px; font-weight: 600; color: #e8e6e3; text-decoration: none;
}
.brand-icon {
    width: 20px; height: 20px;
    background: linear-gradient(135deg, #38a169 0%, #2868b2 100%);
    border-radius: 4px; display: inline-block;
}
.header-sep { color: #605e5c; margin: 0 4px; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-faint); }
.header-right strong { color: white; }
.role-badge {
    font-size: 11px; font-weight: 700; text-transform: uppercase;
    padding: 2px 8px; border-radius: 10px; letter-spacing: 0.4px;
}
.role-badge.admin { background: #442a66; color: #d9c7f5; }
.role-badge.user { background: #2c3e50; color: #cfd8dc; }
.header-right a { color: var(--text-faint); text-decoration: none; }
.header-right a:hover { color: white; }

/* Nav */
.nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex; align-items: center; gap: 4px; height: 40px;
}
.nav a {
    color: var(--text-muted); text-decoration: none; font-size: 13px;
    padding: 4px 8px; border-radius: 4px;
}
.nav a:hover { background: var(--border-soft); color: var(--text); }
.nav a.active { color: var(--accent); font-weight: 600; }
.nav .nav-admin { margin-left: auto; color: var(--accent); font-weight: 600; }

/* Content */
.content { max-width: 1180px; margin: 32px auto; padding: 0 24px; }
.content-wide { max-width: 100%; margin: 24px 32px; }

.page-title { font-size: 22px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 24px; }

.breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb span { margin: 0 6px; }

/* Grid / cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card {
    background: var(--surface); border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    padding: 24px; border: 1px solid var(--border); transition: box-shadow 0.15s;
    position: relative;
}
.card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.12); }
.card-icon {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--blue) 100%);
    border-radius: 8px; margin-bottom: 16px; display: flex; align-items: center; justify-content: center;
}
.card-icon svg { fill: white; }
.card-name { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.card-meta { font-size: 12px; color: var(--text-muted); line-height: 1.6; }
.card-meta span { display: block; }
.card-footer { margin-top: 20px; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: 4px; font-size: 13px; font-weight: 500;
    text-decoration: none; cursor: pointer; border: none;
}
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; border: 1px solid var(--accent); color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-green { background: var(--green); color: white; }
.btn-green:hover { background: var(--green-dark); }
.btn-neutral { background: var(--border-soft); color: var(--text); border: 1px solid var(--border); }
.btn-neutral:hover { background: #edebe9; }
.btn-danger { background: transparent; border: 1px solid var(--red); color: var(--red-dark); }
.btn-danger:hover { background: var(--red-bg); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* Forms */
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.form-row label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; }
.form-row input, .form-row select, .form-row textarea {
    padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; font-family: inherit;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { outline: none; border-color: var(--accent); }
.form-inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.form-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-bottom: 20px; }
.form-panel h3 { font-size: 14px; margin-bottom: 14px; }
.admin-hero { display: grid; grid-template-columns: minmax(220px, .8fr) 2fr; gap: 18px; align-items: start; }
.section-admin-list { display: grid; gap: 16px; }
.section-admin-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    padding: 18px; box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.section-admin-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.section-title-input {
    flex: 1; border: 0; border-bottom: 1px solid var(--border);
    font-size: 18px; font-weight: 650; padding: 6px 0; outline: 0;
}
.section-title-input:focus { border-color: var(--accent); }
.access-panel { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border-soft); }
.access-title { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; margin-bottom: 8px; }
.access-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; margin-bottom: 8px; }
.check-row, .check-inline {
    display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text);
}
.check-row {
    border: 1px solid var(--border-soft); border-radius: 6px; padding: 8px 10px; background: #fbfbfc;
}
.check-row small { margin-left: auto; color: var(--text-muted); }
.access-note { color: var(--text-muted); font-size: 12px; margin: 2px 0 10px; }
.view-icon { background: linear-gradient(135deg, #315f72 0%, #38a169 100%); }

/* Toolbar / search */
.toolbar {
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px 8px 0 0;
    padding: 12px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.search-box { padding: 6px 12px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; max-width: 300px; flex: 1; }
.search-box:focus { outline: none; border-color: var(--accent); }
.count-badge { background: var(--border-soft); color: var(--text-muted); font-size: 12px; padding: 3px 10px; border-radius: 12px; margin-left: auto; }

/* Table */
.table-wrapper { background: var(--surface); border: 1px solid var(--border); border-top: none; border-radius: 0 0 8px 8px; overflow: hidden; }
.table-scroll-wrapper { overflow: auto; max-height: 70vh; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th {
    background: #f8f7f6; text-align: left; padding: 10px 16px; font-size: 12px; font-weight: 600;
    color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
td { padding: 10px 16px; font-size: 13px; color: var(--text); border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8f7f6; }
.null-value { color: #bbb; font-style: italic; }
.cell-diff { background: #fff4ce; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-green { background: #dff6dd; color: #107c10; }
.badge-blue { background: #eff6fc; color: #0078d4; }
.badge-amber { background: #fff4ce; color: #835b00; }
.badge-gray { background: var(--border-soft); color: var(--text-muted); }
.badge-red { background: var(--red-bg); color: var(--red-dark); }

.env-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 44px; height: 22px; padding: 0 9px; border-radius: 999px;
    font-size: 11px; font-weight: 800; letter-spacing: .4px;
    border: 1px solid transparent; margin: 6px 0;
}
.env-dev { background: #eef2ff; color: #33459f; border-color: #c7d2fe; }
.env-test { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.env-prod { background: #ecfdf3; color: #166534; border-color: #bbf7d0; }
.data-card::before,
.card:has(.env-badge)::before {
    content: ""; position: absolute; inset: 0 auto 0 0; width: 5px;
    border-radius: 8px 0 0 8px; background: var(--accent);
}
.card:has(.env-dev)::before { background: #667eea; }
.card:has(.env-test)::before { background: #f97316; }
.card:has(.env-prod)::before { background: #16a34a; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 38px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; cursor: pointer; inset: 0; background: #c8c6c4; border-radius: 20px; transition: .15s;
}
.switch .slider::before {
    content: ""; position: absolute; height: 14px; width: 14px; left: 3px; bottom: 3px;
    background: white; border-radius: 50%; transition: .15s;
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab { padding: 8px 16px; font-size: 13px; font-weight: 500; color: var(--text-muted); text-decoration: none; border-bottom: 2px solid transparent; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Modal / progress */
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1000; align-items: center; justify-content: center; }
.overlay.active { display: flex; }
.dl-card { background: var(--surface); border-radius: 10px; padding: 32px 36px; width: 420px; max-width: 90vw; box-shadow: 0 8px 32px rgba(0,0,0,0.2); }
.dl-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.dl-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.dl-track { background: var(--border-soft); border-radius: 99px; height: 8px; overflow: hidden; margin-bottom: 10px; }
.dl-bar { height: 8px; border-radius: 99px; background: var(--green); width: 30%; animation: dl-pulse 1.4s ease-in-out infinite; transition: width 0.6s ease; }
.dl-bar.measured { animation: none; }
.dl-bar.done { animation: none; width: 100% !important; background: var(--green); }
.dl-bar.error { animation: none; width: 100% !important; background: var(--red); }
@keyframes dl-pulse { 0% { margin-left: 0%; width: 30%; } 50% { margin-left: 60%; width: 30%; } 100% { margin-left: 0%; width: 30%; } }
.dl-pct { font-size: 22px; font-weight: 700; margin: 12px 0 4px; min-height: 30px; }
.dl-info { font-size: 12px; color: var(--text-muted); min-height: 18px; }
.dl-cancel { margin-top: 20px; background: none; border: 1px solid var(--border); border-radius: 4px; padding: 7px 18px; font-size: 13px; color: var(--text-muted); cursor: pointer; }
.dl-cancel:hover { background: var(--border-soft); }

.error-box { background: var(--red-bg); border: 1px solid var(--red-border); border-radius: 8px; padding: 16px 20px; color: var(--red-dark); font-size: 13px; margin-bottom: 16px; }
.info-box { background: var(--accent-soft); border: 1px solid #e3d6f5; border-radius: 8px; padding: 14px 18px; color: #4a2f78; font-size: 13px; margin-bottom: 16px; }
.empty { text-align: center; padding: 48px 20px; color: var(--text-muted); font-size: 14px; }

.section-block { margin-bottom: 32px; }
.section-heading { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.section-heading h2 { font-size: 16px; font-weight: 600; }
.section-heading .section-desc { font-size: 12px; color: var(--text-muted); }

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - 88px); }
.login-card { background: var(--surface); padding: 40px; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); text-align: center; max-width: 380px; }
.login-card h1 { margin-bottom: 6px; font-size: 20px; }
.login-card p { color: var(--text-muted); margin-bottom: 20px; font-size: 13px; }
.login-actions { display: flex; flex-direction: column; gap: 10px; }

/* --- Widget global de descargas (flotante, presente en toda la app) --- */
.dlw { position: fixed; right: 18px; bottom: 18px; z-index: 900; width: 340px; max-width: calc(100vw - 36px);
       display: flex; flex-direction: column; gap: 10px; }
.dlw-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
            box-shadow: 0 6px 24px rgba(0,0,0,0.18); padding: 14px 16px; font-size: 13px; }
.dlw-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.dlw-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlw-fmt { font-size: 11px; color: var(--text-muted); text-transform: uppercase; flex-shrink: 0; }
.dlw-track { background: var(--border-soft); border-radius: 99px; height: 7px; overflow: hidden; margin-bottom: 7px; }
.dlw-bar { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--blue)); transition: width 0.5s ease; }
.dlw-bar.indeterminate { width: 30% !important; animation: dl-pulse 1.6s infinite ease-in-out; }
.dlw-bar.done { background: var(--green); }
.dlw-bar.error { background: var(--red-dark); }
.dlw-info { color: var(--text-muted); font-size: 12px; min-height: 16px; display: flex; justify-content: space-between; gap: 8px; }
.dlw-actions { display: flex; gap: 8px; margin-top: 9px; }
.dlw-btn { border: 1px solid var(--border); background: none; border-radius: 4px; padding: 5px 12px;
           font-size: 12px; color: var(--text-muted); cursor: pointer; }
.dlw-btn:hover { background: var(--border-soft); }
.dlw-btn.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.dlw-btn.primary:hover { background: var(--green-dark); }

@media (max-width: 760px) {
    .admin-hero { grid-template-columns: 1fr; }
    .header { height: auto; min-height: 54px; padding: 10px 14px; flex-wrap: wrap; }
    .nav { height: auto; padding: 8px 14px; flex-wrap: wrap; }
    .content, .content-wide { margin: 18px auto; padding: 0 14px; }
}
