:root {
    --navy-950: #071726;
    --navy-900: #0b2034;
    --navy-800: #12324f;
    --navy-700: #1a496f;
    --blue-600: #1473e6;
    --blue-100: #eaf3ff;
    --surface: #ffffff;
    --surface-soft: #f5f7fa;
    --surface-muted: #edf1f5;
    --border: #dce3ea;
    --text: #18212b;
    --text-muted: #687582;
    --success: #15805c;
    --success-bg: #e7f7f1;
    --warning: #a56500;
    --warning-bg: #fff4d6;
    --danger: #b3261e;
    --danger-bg: #fdebea;
    --critical: #d34824;
    --shadow: 0 10px 30px rgba(15, 35, 55, .08);
    --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: Inter, "Segoe UI", Arial, sans-serif; color: var(--text); background: var(--surface-soft); }
a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 270px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: linear-gradient(180deg, var(--navy-950), var(--navy-900)); color: #fff; display: flex; flex-direction: column; z-index: 30; }
.brand-panel { display: flex; align-items: center; gap: 12px; padding: 24px 20px; border-bottom: 1px solid rgba(255,255,255,.09); }
.brand-panel strong, .brand-inline strong { display: block; font-size: 1.02rem; letter-spacing: .01em; }
.brand-panel small, .brand-inline small { display: block; margin-top: 3px; color: rgba(255,255,255,.58); font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; }
.brand-mark { width: 42px; height: 42px; flex: 0 0 42px; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; background: linear-gradient(135deg, #2f8cff, #0c5fc5); color: #fff; font-weight: 800; box-shadow: 0 8px 20px rgba(20,115,230,.3); }
.brand-mark.large { width: 58px; height: 58px; flex-basis: 58px; border-radius: 17px; font-size: 1.25rem; }
.nav-menu { padding: 16px 12px; overflow-y: auto; flex: 1; }
.nav-section { padding: 18px 12px 8px; color: rgba(255,255,255,.38); font-size: .65rem; font-weight: 800; letter-spacing: .14em; }
.nav-menu a { display: flex; align-items: center; gap: 12px; padding: 11px 12px; margin: 3px 0; color: rgba(255,255,255,.74); border-radius: 10px; font-weight: 600; transition: .18s ease; }
.nav-menu a:hover { color: #fff; background: rgba(255,255,255,.07); }
.nav-menu a.active { color: #fff; background: linear-gradient(90deg, rgba(20,115,230,.92), rgba(20,115,230,.46)); box-shadow: 0 8px 18px rgba(0,0,0,.15); }
.nav-icon { width: 24px; text-align: center; font-size: 1.1rem; }
.sidebar-footer { padding: 18px 20px; border-top: 1px solid rgba(255,255,255,.09); color: rgba(255,255,255,.75); }
.sidebar-footer span, .sidebar-footer small { display: block; }
.sidebar-footer small { margin-top: 3px; color: rgba(255,255,255,.42); }

.main-area { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { height: 72px; display: flex; align-items: center; gap: 16px; padding: 0 28px; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(10px); }
.menu-button { display: none; border: 0; background: var(--surface-muted); width: 42px; height: 42px; border-radius: 11px; font-size: 1.25rem; }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title strong, .topbar-title span { display: block; }
.topbar-title strong { font-size: .95rem; }
.topbar-title span { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }
.user-menu { display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--navy-800); color: #fff; font-weight: 800; font-size: .75rem; }
.user-menu strong, .user-menu a { display: block; max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu strong { font-size: .82rem; }
.user-menu a { font-size: .72rem; color: var(--text-muted); margin-top: 2px; }
.content-area { flex: 1; width: 100%; max-width: 1720px; margin: 0 auto; padding: 30px; }
.app-footer { padding: 20px 30px; text-align: center; font-size: .75rem; color: var(--text-muted); border-top: 1px solid var(--border); background: #fff; }
.sidebar-overlay { display: none; }

.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 24px; }
.page-heading h1 { margin: 4px 0 5px; font-size: clamp(1.55rem, 2vw, 2.2rem); line-height: 1.12; color: var(--navy-900); }
.page-heading p { margin: 0; color: var(--text-muted); }
.eyebrow { display: block; color: var(--blue-600); font-size: .67rem; letter-spacing: .14em; font-weight: 850; }
.heading-actions { display: flex; flex-wrap: wrap; gap: 9px; }

.btn { border: 1px solid transparent; border-radius: 10px; padding: 10px 15px; display: inline-flex; justify-content: center; align-items: center; gap: 7px; font-weight: 700; line-height: 1.2; transition: .15s ease; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 5px 13px rgba(15,35,55,.12); }
.btn-primary { background: var(--blue-600); color: #fff; }
.btn-secondary { background: #fff; color: var(--navy-800); border-color: var(--border); }
.btn-warning { background: #ed9c13; color: #261600; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-small { padding: 6px 9px; border-radius: 8px; font-size: .73rem; }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 15px; margin-bottom: 22px; }
.metric-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric-card { padding: 19px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.metric-card::after { content: ""; position: absolute; width: 82px; height: 82px; border-radius: 50%; right: -30px; top: -35px; background: var(--blue-100); }
.metric-card span, .metric-card strong, .metric-card small { display: block; position: relative; z-index: 1; }
.metric-card span { color: var(--text-muted); font-size: .76rem; font-weight: 700; }
.metric-card strong { margin-top: 9px; font-size: clamp(1.45rem, 2.4vw, 2.15rem); color: var(--navy-900); }
.metric-card small { margin-top: 7px; color: var(--text-muted); }
.metric-card.danger::after { background: var(--danger-bg); }
.metric-card.critical::after { background: #fff0e9; }
.metric-card.warning::after { background: var(--warning-bg); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(380px, .8fr); gap: 20px; }
.panel-card, .simple-card, .filter-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-card { padding: 20px; }
.simple-card { padding: 24px; margin-bottom: 22px; }
.panel-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 17px; }
.panel-header h2, .simple-card h2 { margin: 4px 0 0; font-size: 1.05rem; color: var(--navy-900); }
.panel-header > small, .panel-header > span { color: var(--text-muted); font-size: .75rem; }
.table-card { padding: 0; overflow: hidden; }
.table-card .panel-header, .table-card .table-toolbar { padding: 19px 20px 0; }
.table-responsive { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .79rem; }
.data-table thead th { text-align: left; padding: 12px 13px; color: #536270; background: #f6f8fa; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); text-transform: uppercase; font-size: .62rem; letter-spacing: .065em; white-space: nowrap; }
.data-table tbody td { padding: 12px 13px; border-bottom: 1px solid #edf0f3; vertical-align: middle; }
.data-table tbody tr:hover { background: #f9fbfd; }
.data-table .number { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.compact-table tbody td { padding-top: 10px; padding-bottom: 10px; }
.row-note { display: block; color: var(--text-muted); margin-top: 3px; max-width: 330px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.positive { color: var(--success); }
.negative { color: var(--danger); }
.status-pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; font-size: .67rem; font-weight: 800; white-space: nowrap; }
.status-pill.normal { background: var(--success-bg); color: var(--success); }
.status-pill.warning { background: var(--warning-bg); color: var(--warning); }
.status-pill.low { background: #ffe8ca; color: #9e4e00; }
.status-pill.critical { background: #ffe4dc; color: var(--critical); }
.status-pill.depleted { background: var(--danger-bg); color: var(--danger); }
.table-toolbar { display: flex; justify-content: space-between; align-items: center; padding-bottom: 15px !important; color: var(--text-muted); font-size: .78rem; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 15px; padding: 18px; }
.history-table-wrap { max-height: 620px; overflow: auto; }
.history-table-wrap thead { position: sticky; top: 0; z-index: 2; }

.activity-list { display: grid; gap: 7px; }
.activity-item { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 11px; border-radius: 11px; color: var(--text); }
.activity-item:hover { background: var(--surface-soft); }
.activity-item div strong, .activity-item div span { display: block; }
.activity-item div strong { font-size: .78rem; }
.activity-item div span { margin-top: 3px; color: var(--text-muted); font-size: .7rem; }
.activity-item b { font-size: .77rem; font-variant-numeric: tabular-nums; }
.activity-sign { width: 30px; height: 30px; display: inline-flex; justify-content: center; align-items: center; border-radius: 9px; font-size: 1.15rem; font-weight: 800; }
.activity-sign.in { background: var(--success-bg); color: var(--success); }
.activity-sign.out { background: var(--danger-bg); color: var(--danger); }

.filter-card { padding: 17px; margin-bottom: 20px; }
.filter-grid { display: grid; grid-template-columns: minmax(280px, 1.8fr) minmax(150px, .7fr) minmax(190px, .9fr) auto; gap: 12px; align-items: end; }
.filter-grid label, .form-grid label, .settings-section > label, .simple-card label, .login-card label { display: block; margin: 0 0 6px; color: #44515d; font-size: .73rem; font-weight: 750; }
.filter-actions { display: flex; gap: 8px; }
.form-control { width: 100%; border: 1px solid #ccd5de; border-radius: 9px; padding: 10px 11px; min-height: 40px; background: #fff; color: var(--text); outline: none; transition: .15s ease; }
.form-control:focus { border-color: var(--blue-600); box-shadow: 0 0 0 3px rgba(20,115,230,.12); }
textarea.form-control { min-height: 82px; resize: vertical; }
.form-control.compact { min-height: 32px; padding: 6px 8px; font-size: .75rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid-5 { grid-template-columns: 1.1fr 1.3fr 1.1fr .8fr auto; align-items: end; }
.field-wide { grid-column: span 2; }
.form-action { display: flex; align-items: end; }
.form-grid small, .settings-section small { display: block; color: var(--text-muted); margin-top: 5px; font-size: .67rem; }
.check-line { display: flex !important; align-items: center; gap: 9px; margin: 12px 0 !important; }
.check-line input { width: 17px; height: 17px; }

.chart-panel { margin-bottom: 20px; }
.bar-chart { display: flex; align-items: end; gap: 6px; height: 250px; overflow-x: auto; padding: 25px 5px 0; border-bottom: 1px solid var(--border); }
.bar-column { min-width: 48px; height: 100%; display: flex; flex-direction: column; justify-content: end; align-items: center; position: relative; }
.bar { width: 26px; min-height: 3px; background: linear-gradient(180deg, #2f8cff, #0d5fbf); border-radius: 6px 6px 0 0; transition: .2s ease; }
.bar-column:hover .bar { filter: brightness(1.08); width: 31px; }
.bar-value { font-size: .61rem; color: var(--text-muted); margin-bottom: 4px; }
.bar-column small { margin-top: 7px; font-size: .6rem; white-space: nowrap; transform: rotate(-35deg); transform-origin: center; height: 35px; }

.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.report-card { display: flex; flex-direction: column; gap: 17px; }
.report-card h2 { margin: 4px 0 8px; font-size: 1.2rem; }
.report-card p { margin: 0; color: var(--text-muted); line-height: 1.55; }
.report-icon { width: 48px; height: 48px; display: inline-flex; align-items: center; justify-content: center; border-radius: 14px; background: var(--blue-100); color: var(--blue-600); font-weight: 900; }
.report-card .btn { align-self: flex-start; }
.information-panel h2 { margin-top: 0; }
.feature-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; }
.feature-grid div { padding: 15px; border-radius: 12px; background: var(--surface-soft); }
.feature-grid strong, .feature-grid span { display: block; }
.feature-grid span { color: var(--text-muted); margin-top: 5px; font-size: .75rem; line-height: 1.4; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.settings-section { min-width: 0; }
.settings-section .form-grid { margin-top: 12px; }
.settings-section textarea { margin-bottom: 11px; }
.body-editor { min-height: 145px !important; font-family: Consolas, monospace; font-size: .78rem; }
.security-note { padding: 10px 12px; background: var(--blue-100); color: #24537f; border-radius: 10px; font-size: .72rem; }
.switch { display: inline-block; position: relative; width: 48px; height: 27px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #bdc7d0; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 21px; height: 21px; left: 3px; top: 3px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0,0,0,.2); transition: .2s; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(21px); }
.sticky-actions { position: sticky; bottom: 12px; z-index: 15; display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin-top: 20px; padding: 13px; border: 1px solid var(--border); border-radius: 14px; background: rgba(255,255,255,.96); box-shadow: 0 12px 30px rgba(15,35,55,.16); backdrop-filter: blur(8px); }
.inline-loading { display: inline-flex; align-items: center; gap: 8px; color: var(--text-muted); }

.alert { border-radius: 11px; padding: 13px 15px; margin-bottom: 18px; border: 1px solid transparent; line-height: 1.45; }
.alert.success { color: var(--success); background: var(--success-bg); border-color: #bde8d8; }
.alert.warning { color: var(--warning); background: var(--warning-bg); border-color: #f3d98a; }
.alert.danger { color: var(--danger); background: var(--danger-bg); border-color: #f2c4c1; }
.validation-summary, .field-error { color: var(--danger); font-size: .75rem; }
.validation-summary ul { margin: 4px 0 12px; padding-left: 20px; }

.loading-panel, .empty-state { min-height: 260px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); text-align: center; }
.spinner { width: 34px; height: 34px; border: 3px solid #dce8f4; border-top-color: var(--blue-600); border-radius: 50%; animation: spin .7s linear infinite; }
.spinner.small { width: 19px; height: 19px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-icon { min-width: 58px; height: 58px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; border-radius: 17px; background: var(--surface-muted); color: var(--navy-800); font-weight: 900; font-size: 1.25rem; }
.empty-state h1, .empty-state h2 { color: var(--navy-900); margin-bottom: 7px; }

.inline-form { display: flex; gap: 6px; align-items: center; }
.stack-actions { display: grid; gap: 7px; min-width: 235px; }
.error-cell { max-width: 300px; color: var(--danger); font-size: .7rem; }

/* Identity / Razor Pages */
.account-body { background: linear-gradient(135deg, #eef4fa 0%, #f8fafc 55%, #e8f1fb 100%); min-height: 100vh; }
.account-topbar { min-height: 70px; padding: 12px clamp(18px, 4vw, 56px); display: flex; align-items: center; justify-content: space-between; background: rgba(7,23,38,.97); color: #fff; }
.brand-inline { display: flex; align-items: center; gap: 11px; color: #fff; }
.account-nav { display: flex; gap: 15px; }
.account-nav a { color: rgba(255,255,255,.75); font-size: .8rem; }
.account-shell { width: min(1420px, calc(100% - 30px)); margin: 0 auto; padding: 38px 0; }
.login-grid { min-height: calc(100vh - 150px); display: grid; grid-template-columns: 1.15fr .85fr; gap: clamp(30px, 7vw, 100px); align-items: center; }
.login-hero { max-width: 650px; }
.login-hero h1 { font-size: clamp(2.4rem, 5vw, 5.2rem); line-height: .98; letter-spacing: -.055em; color: var(--navy-950); margin: 13px 0 23px; }
.login-hero p { color: #506071; font-size: clamp(1rem, 1.4vw, 1.18rem); line-height: 1.65; max-width: 580px; }
.hero-stat { margin-top: 35px; display: inline-flex; align-items: center; gap: 15px; padding: 14px 18px; background: rgba(255,255,255,.72); border: 1px solid rgba(255,255,255,.9); border-radius: 14px; box-shadow: var(--shadow); }
.hero-stat strong, .hero-stat span { display: block; }
.hero-stat strong { color: var(--blue-600); }
.hero-stat span { color: var(--text-muted); font-size: .77rem; }
.login-card { background: rgba(255,255,255,.96); padding: clamp(25px, 4vw, 42px); border-radius: 24px; box-shadow: 0 30px 70px rgba(15,35,55,.17); border: 1px solid rgba(255,255,255,.9); }
.login-card-header { display: flex; align-items: center; gap: 16px; margin-bottom: 25px; }
.login-card-header h2 { margin: 0; font-size: 1.65rem; }
.login-card-header p { margin: 4px 0 0; color: var(--text-muted); }
.login-card .form-control { margin-bottom: 4px; }
.login-card label { margin-top: 14px; }
.login-note { margin: 20px 0 0; color: var(--text-muted); font-size: .7rem; line-height: 1.5; text-align: center; }
.narrow-card { width: min(580px, 100%); margin: 30px auto; }
.narrow-card h1 { margin-top: 5px; }
.narrow-card .form-control { margin-bottom: 5px; }
.narrow-card label { margin-top: 14px; }
.account-page-heading { margin-top: 8px; }

@media (max-width: 1250px) {
    .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .settings-grid { grid-template-columns: 1fr; }
    .form-grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid-5 .form-action { grid-column: span 2; }
    .feature-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 980px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: 0; transform: translateX(-100%); width: 270px; transition: .2s ease; }
    .sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-overlay { position: fixed; inset: 0; border: 0; background: rgba(3,12,21,.55); z-index: 25; }
    .sidebar-open .sidebar-overlay { display: block; }
    .menu-button { display: inline-flex; align-items: center; justify-content: center; }
    .dashboard-grid, .report-grid { grid-template-columns: 1fr; }
    .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-actions { grid-column: span 2; }
    .login-grid { grid-template-columns: 1fr; min-height: auto; }
    .login-hero { display: none; }
    .login-card { max-width: 560px; margin: 20px auto; width: 100%; }
}

@media (max-width: 700px) {
    .content-area { padding: 20px 14px; }
    .topbar { padding: 0 14px; }
    .topbar-title span { display: none; }
    .user-menu div { display: none; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .heading-actions { width: 100%; }
    .heading-actions .btn { flex: 1; }
    .metric-grid, .metric-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metric-card { padding: 15px; }
    .filter-grid, .form-grid, .form-grid-3, .form-grid-5, .feature-grid { grid-template-columns: 1fr; }
    .field-wide, .filter-actions, .form-grid-5 .form-action { grid-column: span 1; }
    .filter-actions .btn { flex: 1; }
    .panel-card { padding: 15px; }
    .table-card { padding: 0; }
    .settings-section { padding: 17px; }
    .sticky-actions { position: static; }
    .sticky-actions .btn { width: 100%; }
    .account-topbar { padding: 12px 15px; }
    .account-nav { display: none; }
    .account-shell { padding: 20px 0; }
    .bar-column { min-width: 42px; }
}

@media (max-width: 430px) {
    .metric-grid, .metric-grid-4 { grid-template-columns: 1fr; }
    .brand-panel { padding: 18px; }
    .login-card { padding: 23px 18px; }
}

/* Dashboard de pedaceras */
.pedacera-summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.threshold-card {
    position: relative;
    overflow: hidden;
    min-width: 0;
    padding: 21px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow);
}

.threshold-card::after {
    content: "";
    position: absolute;
    right: -42px;
    top: -48px;
    width: 145px;
    height: 145px;
    border-radius: 50%;
    opacity: .11;
    background: currentColor;
}

.threshold-100 { color: #2368c4; }
.threshold-50 { color: #6a5db5; }
.threshold-20 { color: #cf4f2d; }

.threshold-card-title {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 11px;
}

.threshold-card-title h2 {
    margin: 2px 0 0;
    font-size: 1rem;
    color: var(--navy-900);
}

.threshold-card-title small {
    display: block;
    font-size: .62rem;
    font-weight: 850;
    letter-spacing: .11em;
    color: var(--text-muted);
}

.threshold-dot {
    width: 12px;
    height: 12px;
    flex: 0 0 12px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 6px color-mix(in srgb, currentColor 12%, transparent);
}

.threshold-main {
    position: relative;
    z-index: 1;
    display: block;
    margin-top: 18px;
    color: var(--navy-900);
    font-size: clamp(1.8rem, 3vw, 2.6rem);
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.threshold-caption {
    position: relative;
    z-index: 1;
    display: block;
    margin-top: 5px;
    color: var(--text-muted);
    font-size: .72rem;
}

.threshold-stats {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 18px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
}

.threshold-stats div {
    min-width: 0;
}

.threshold-stats span,
.threshold-stats b {
    display: block;
}

.threshold-stats span {
    color: var(--text-muted);
    font-size: .67rem;
}

.threshold-stats b {
    margin-top: 5px;
    color: var(--text);
    font-size: .87rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pedacera-trend-panel {
    margin-bottom: 20px;
}

.trend-header {
    align-items: center;
}

.panel-description {
    margin: 7px 0 0;
    color: var(--text-muted);
    font-size: .75rem;
    line-height: 1.45;
}

.trend-toggle {
    display: inline-flex;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface-soft);
}

.trend-toggle button {
    border: 0;
    padding: 8px 12px;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: .73rem;
    font-weight: 800;
}

.trend-toggle button.active {
    background: #fff;
    color: var(--navy-900);
    box-shadow: 0 3px 9px rgba(15,35,55,.11);
}

.trend-chart-wrap {
    width: 100%;
    overflow-x: auto;
    padding: 4px 0 0;
}

.trend-chart {
    display: block;
    width: 100%;
    min-width: 780px;
    height: auto;
    overflow: visible;
}

.trend-grid-line {
    stroke: #e6ebf0;
    stroke-width: 1;
}

.trend-axis-value,
.trend-axis-month {
    fill: #71808e;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    font-size: 11px;
}

.trend-axis-month {
    font-size: 10.5px;
    text-transform: uppercase;
}

.trend-line {
    fill: none;
    stroke-width: 3.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 3px 4px rgba(15,35,55,.08));
}

.line-100 { stroke: #276fc8; }
.line-50 { stroke: #6a5db5; }
.line-20 { stroke: #cf4f2d; }

.trend-point {
    stroke: #fff;
    stroke-width: 2;
}

.point-100 { fill: #276fc8; }
.point-50 { fill: #6a5db5; }
.point-20 { fill: #cf4f2d; }

.trend-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 18px;
    margin: 2px 0 18px 72px;
    color: var(--text-muted);
    font-size: .73rem;
}

.trend-legend span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.trend-legend i {
    width: 23px;
    height: 3px;
    border-radius: 999px;
}

.legend-100 { background: #276fc8; }
.legend-50 { background: #6a5db5; }
.legend-20 { background: #cf4f2d; }
.trend-legend small { margin-left: auto; }

.trend-table-wrap {
    max-height: 370px;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.trend-data-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

.trend-data-table td,
.trend-data-table th {
    white-space: nowrap;
}

.current-month-row {
    background: #eef6ff;
}

.dashboard-note {
    margin-top: 14px;
    padding: 11px 13px;
    border-radius: 10px;
    background: var(--surface-soft);
    color: var(--text-muted);
    font-size: .7rem;
    line-height: 1.5;
}

@media (max-width: 1050px) {
    .pedacera-summary-grid {
        grid-template-columns: 1fr;
    }

    .trend-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .trend-toggle {
        width: 100%;
    }

    .trend-toggle button {
        flex: 1;
    }
}

@media (max-width: 700px) {
    .threshold-stats {
        grid-template-columns: 1fr;
    }

    .trend-legend {
        margin-left: 0;
        gap: 10px 15px;
    }

    .trend-legend small {
        width: 100%;
        margin-left: 0;
    }
}

/* ================================================================
   Control de Tramos - pantalla única basada en el tablero de Excel
   ================================================================ */
.single-app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: #eef1f4;
}

.control-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    min-height: 72px;
    height: auto;
    padding: 12px clamp(18px, 4vw, 52px);
}

.control-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.control-brand strong,
.control-brand span {
    display: block;
}

.control-brand strong {
    color: var(--navy-900);
    font-size: .96rem;
}

.control-brand div > span {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: .73rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 18px;
}

.control-admin-menu {
    position: relative;
}

.control-admin-menu summary {
    list-style: none;
    padding: 8px 11px;
    border: 1px solid #d8e0e8;
    border-radius: 8px;
    background: #fff;
    color: #526170;
    cursor: pointer;
    font-size: .75rem;
    font-weight: 700;
    user-select: none;
}

.control-admin-menu summary::-webkit-details-marker {
    display: none;
}

.control-admin-menu[open] summary {
    border-color: #b7c9dc;
    background: #edf3f9;
    color: var(--blue-600);
}

.control-admin-menu nav {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 60;
    width: 220px;
    display: grid;
    gap: 4px;
    padding: 8px;
    border: 1px solid #d8e0e8;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 12px 30px rgba(21, 39, 58, .16);
}

.control-admin-menu nav a {
    padding: 10px 11px;
    border-radius: 7px;
    color: #526170;
    font-size: .76rem;
    font-weight: 700;
}

.control-admin-menu nav a:hover {
    background: #edf3f9;
    color: var(--blue-600);
}

.control-content-area {
    flex: 1;
    width: 100%;
    max-width: 1540px;
    margin: 0 auto;
    padding: 26px clamp(14px, 3vw, 42px) 38px;
}

.control-tramos-page {
    min-height: 760px;
    padding: clamp(22px, 3vw, 44px);
    border: 1px solid #d8dde3;
    border-radius: 2px;
    background: #fff;
    box-shadow: 0 4px 14px rgba(25, 36, 48, .10);
}

.control-tramos-header {
    display: grid;
    grid-template-columns: minmax(210px, 1fr) auto minmax(240px, 1fr);
    align-items: start;
    gap: 24px;
    min-height: 150px;
}

.control-title h1,
.control-title span {
    display: block;
    margin: 0;
    color: #222;
    font-weight: 400;
}

.control-title h1 {
    font-size: clamp(1.3rem, 2vw, 1.75rem);
    letter-spacing: -.02em;
}

.control-title span {
    margin-top: 2px;
    font-size: clamp(1rem, 1.45vw, 1.35rem);
}

.control-download {
    min-width: 180px;
    padding: 16px 24px;
    border: 1px solid #c9cdd2;
    border-radius: 4px;
    background: linear-gradient(#fff, #f1f1f1);
    box-shadow: 0 2px 4px rgba(0, 0, 0, .18);
    color: #171717;
    text-align: center;
    font-size: clamp(1.15rem, 2vw, 1.65rem);
    font-weight: 400;
}

.control-download:hover {
    color: #111;
    transform: translateY(-1px);
    box-shadow: 0 4px 9px rgba(0, 0, 0, .16);
}

.control-selector {
    justify-self: end;
    width: min(320px, 100%);
    position: relative;
}

.control-selector > span {
    position: absolute;
    left: 18px;
    top: 50%;
    z-index: 1;
    transform: translateY(-50%);
    color: #333;
    font-size: .9rem;
    pointer-events: none;
}

.control-selector select {
    width: 100%;
    min-height: 54px;
    padding: 0 42px 0 94px;
    border: 1px solid #c9cdd2;
    border-radius: 4px;
    background: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .14);
    color: #333;
}

.control-table-caption {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    min-height: 29px;
    padding: 5px 9px;
    background: #eaf2ff;
    color: #111;
    font-size: .78rem;
    font-weight: 750;
}

.control-summary-table-wrap {
    overflow-x: auto;
    margin-bottom: 44px;
}

.control-summary-table {
    width: 100%;
    border-collapse: collapse;
    color: #3d444b;
    font-size: .78rem;
}

.control-summary-table th,
.control-summary-table td {
    min-width: 115px;
    padding: 10px 9px;
    text-align: right;
    border-bottom: 1px solid #e8ebee;
    font-variant-numeric: tabular-nums;
}

.control-summary-table th:first-child,
.control-summary-table td:first-child {
    min-width: 170px;
    text-align: left;
}

.control-summary-table th {
    color: #525b63;
    font-weight: 500;
    white-space: nowrap;
}

.control-summary-table tbody tr:nth-child(even) {
    background: #f4f5f6;
}

.control-summary-table .total-row {
    background: #fff !important;
    color: #2d3338;
    font-weight: 750;
}

.control-charts-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(420px, .92fr);
    gap: clamp(28px, 5vw, 72px);
    align-items: start;
}

.control-chart-card {
    min-width: 0;
}

.control-chart-card h2 {
    margin: 0 0 20px;
    color: #171717;
    font-size: clamp(1.05rem, 1.7vw, 1.38rem);
    font-weight: 400;
}

.control-line-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    margin: 0 0 4px;
    color: #515960;
    font-size: .73rem;
}

.control-line-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.range-color {
    display: inline-block;
    width: 20px;
    height: 2px;
}

.range-1,
.series-1,
.point-1 { color: #4f7fea; stroke: #4f7fea; background: #4f7fea; fill: #4f7fea; }
.range-2,
.series-2,
.point-2 { color: #f5a052; stroke: #f5a052; background: #f5a052; fill: #f5a052; }
.range-3,
.series-3,
.point-3 { color: #a875df; stroke: #a875df; background: #a875df; fill: #a875df; }

.control-line-chart-wrap {
    width: 100%;
    overflow: hidden;
}

.control-line-chart {
    display: block;
    width: 100%;
    min-width: 520px;
    height: auto;
}

.control-grid-line {
    stroke: #dfe3e7;
    stroke-width: 1;
}

.control-axis-label,
.control-month-label {
    fill: #59636c;
    font-size: 12px;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
}

.control-month-label {
    font-size: 11px;
}

.control-series {
    fill: none;
    stroke-width: 2.3;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.control-chart-point {
    stroke: #fff;
    stroke-width: 1.5;
}

.warehouse-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.warehouse-heading h2 {
    margin-bottom: 0;
}

.warehouse-heading select {
    max-width: 145px;
    padding: 7px 9px;
    border: 1px solid #d6dce2;
    border-radius: 6px;
    background: #fff;
    color: #59636c;
    font-size: .72rem;
}

.warehouse-donut-area {
    display: grid;
    grid-template-columns: minmax(230px, 1fr) minmax(180px, .75fr);
    align-items: center;
    gap: 22px;
}

.warehouse-donut {
    width: min(100%, 360px);
    aspect-ratio: 1;
    margin: 0 auto;
    border-radius: 50%;
    position: relative;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .8);
}

.warehouse-donut::after {
    content: "";
    position: absolute;
    inset: 26%;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(255,255,255,.95);
}

.warehouse-donut-hole {
    position: absolute;
    inset: 31%;
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.warehouse-donut-hole strong {
    color: #26313b;
    font-size: clamp(.9rem, 1.6vw, 1.25rem);
    font-variant-numeric: tabular-nums;
}

.warehouse-donut-hole span {
    margin-top: 3px;
    color: #7a858f;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.warehouse-legend {
    display: grid;
    gap: 9px;
}

.warehouse-legend-row {
    display: grid;
    grid-template-columns: 11px minmax(0, 1fr) auto;
    gap: 7px 9px;
    align-items: center;
    padding-bottom: 8px;
    border-bottom: 1px solid #edf0f2;
    font-size: .72rem;
}

.warehouse-legend-row i {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    grid-row: span 2;
}

.warehouse-legend-row span {
    color: #47525b;
}

.warehouse-legend-row strong {
    color: #252d34;
}

.warehouse-legend-row small {
    grid-column: 2 / 4;
    color: #7b858e;
    font-variant-numeric: tabular-nums;
}

.control-audit-note {
    display: grid;
    gap: 5px;
    margin-top: 30px;
    padding: 12px 14px;
    border: 1px solid #e1e6eb;
    border-radius: 8px;
    background: #f7f9fb;
    color: #65717c;
    font-size: .7rem;
    line-height: 1.45;
}

.control-audit-note strong {
    color: #34414d;
}

.control-admin-panel {
    margin-top: 18px;
    padding: 0;
    border: 1px dashed #b8c4cf;
    border-radius: 10px;
    background: #fbfcfd;
}

.control-admin-panel > summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    padding: 13px 15px;
    cursor: pointer;
    list-style: none;
}

.control-admin-panel > summary::-webkit-details-marker {
    display: none;
}

.control-admin-panel > summary::after {
    content: "▾";
    color: #75808a;
    font-size: .9rem;
}

.control-admin-panel[open] > summary::after {
    content: "▴";
}

.control-admin-panel > summary strong,
.control-admin-panel > summary span,
.control-admin-panel label span {
    display: block;
}

.control-admin-panel > summary strong {
    color: #2e3943;
    font-size: .82rem;
}

.control-admin-panel > summary span,
.control-admin-panel label span,
.control-admin-panel > small {
    margin-top: 4px;
    color: #75808a;
    font-size: .68rem;
}

.control-admin-fields {
    display: grid;
    grid-template-columns: minmax(180px, 220px) auto auto;
    align-items: end;
    gap: 12px;
    padding: 2px 15px 12px;
    border-top: 1px solid #edf0f2;
}

.control-admin-panel > small {
    display: block;
    padding: 0 15px 14px;
    line-height: 1.45;
}

.control-admin-panel input[type="month"] {
    width: 100%;
    margin-top: 5px;
    padding: 9px 10px;
    border: 1px solid #ccd4dc;
    border-radius: 7px;
    background: #fff;
}

.control-empty,
.control-loading {
    min-height: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-align: center;
    color: #6b7782;
}

.control-empty h2 {
    margin: 0;
    color: #263542;
}

.control-empty p {
    max-width: 620px;
    margin: 0 0 8px;
    line-height: 1.55;
}

.control-empty.compact {
    min-height: 280px;
}

@media (max-width: 1050px) {
    .control-tramos-header {
        grid-template-columns: 1fr auto;
        min-height: 175px;
    }

    .control-selector {
        grid-column: 1 / -1;
        justify-self: end;
    }

    .control-charts-grid {
        grid-template-columns: 1fr;
    }

    .warehouse-donut-area {
        grid-template-columns: minmax(230px, 360px) minmax(200px, 1fr);
        justify-content: center;
    }

    .control-admin-fields {
        grid-template-columns: minmax(180px, 220px) 1fr 1fr;
    }

    .control-admin-panel .btn {
        width: 100%;
    }
}

@media (max-width: 720px) {
    .control-topbar {
        padding: 10px 14px;
    }

    .control-brand div > span,
    .user-menu div {
        display: none;
    }

    .topbar-actions {
        gap: 8px;
    }

    .control-admin-menu summary {
        font-size: 0;
    }

    .control-admin-menu summary::first-letter {
        font-size: 1rem;
    }

    .control-content-area {
        padding: 12px;
    }

    .control-tramos-page {
        padding: 20px 14px;
    }

    .control-tramos-header {
        grid-template-columns: 1fr;
        min-height: 0;
        gap: 16px;
        margin-bottom: 35px;
    }

    .control-download,
    .control-selector {
        justify-self: stretch;
        width: 100%;
    }

    .control-summary-table th,
    .control-summary-table td {
        min-width: 100px;
    }

    .control-charts-grid {
        gap: 36px;
    }

    .warehouse-donut-area {
        grid-template-columns: 1fr;
    }

    .warehouse-donut {
        max-width: 300px;
    }

    .control-admin-panel > summary {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .control-admin-fields {
        grid-template-columns: 1fr;
        align-items: stretch;
    }
}

/* ================================================================
   PORTAL INNOVADOR - CONTROL DE TRAMOS HISTORICO
   ================================================================ */
.portal-sidebar {
    background:
        radial-gradient(circle at 20% 0%, rgba(47,128,237,.24), transparent 34%),
        linear-gradient(180deg, #071725 0%, #091f32 58%, #071725 100%);
}
.portal-brand-panel { min-height: 92px; }
.portal-brand-panel .brand-mark { background: linear-gradient(135deg, #23a6ff, #4f46e5); box-shadow: 0 10px 25px rgba(35,166,255,.32); }
.portal-nav-menu a { min-height: 46px; }
.portal-nav-menu a.active { background: linear-gradient(90deg, rgba(47,128,237,.95), rgba(79,70,229,.55)); }
.portal-sidebar-footer { display: grid; gap: 4px; }
.source-status { display: flex !important; align-items: center; gap: 8px; font-weight: 700; }
.source-status i { width: 8px; height: 8px; border-radius: 50%; background: #42d392; box-shadow: 0 0 0 5px rgba(66,211,146,.12); }
.portal-topbar { box-shadow: 0 8px 28px rgba(7,23,37,.04); }
.portal-content-area { max-width: 1760px; }
.control-page-heading { margin-bottom: 20px; }
.control-page-heading h1, .history-page-heading h1 { letter-spacing: -.025em; }
.panel-description { margin: 5px 0 0; color: var(--text-muted); font-size: .78rem; line-height: 1.5; }

.snapshot-hero {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(250px, 330px);
    align-items: center;
    gap: 28px;
    overflow: hidden;
    min-height: 190px;
    margin-bottom: 20px;
    padding: 30px 34px;
    color: #fff;
    border-radius: 22px;
    background:
        radial-gradient(circle at 88% 10%, rgba(88,182,255,.38), transparent 31%),
        radial-gradient(circle at 60% 130%, rgba(132,92,246,.33), transparent 40%),
        linear-gradient(125deg, #071d31 0%, #0d3c66 47%, #205c9d 100%);
    box-shadow: 0 20px 50px rgba(10,49,83,.23);
}
.snapshot-hero-main { position: relative; z-index: 2; }
.snapshot-status-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 22px; color: rgba(255,255,255,.75); font-size: .72rem; }
.snapshot-status { display: inline-flex; align-items: center; gap: 8px; padding: 7px 11px; border: 1px solid rgba(255,255,255,.18); border-radius: 999px; background: rgba(255,255,255,.09); color: #fff; font-weight: 750; backdrop-filter: blur(8px); }
.snapshot-status i { width: 7px; height: 7px; border-radius: 50%; background: #55e3a6; box-shadow: 0 0 0 5px rgba(85,227,166,.13); }
.snapshot-period-caption { color: #8fd0ff; font-size: .66rem; letter-spacing: .16em; font-weight: 850; }
.snapshot-hero h2 { margin: 7px 0 5px; font-size: clamp(2rem, 4vw, 3.25rem); line-height: 1; text-transform: capitalize; letter-spacing: -.045em; }
.snapshot-hero p { margin: 0; color: rgba(255,255,255,.68); font-size: .82rem; }
.snapshot-month-selector { position: relative; z-index: 2; display: grid; gap: 8px; }
.snapshot-month-selector span { color: rgba(255,255,255,.68); font-size: .7rem; font-weight: 700; }
.snapshot-month-selector select { width: 100%; padding: 13px 14px; border: 1px solid rgba(255,255,255,.22); border-radius: 12px; outline: none; background: rgba(255,255,255,.95); color: #102b45; font-weight: 750; box-shadow: 0 12px 25px rgba(0,0,0,.14); }
.snapshot-hero-glow { position: absolute; right: -80px; bottom: -120px; width: 380px; height: 380px; border: 1px solid rgba(255,255,255,.1); border-radius: 50%; box-shadow: 0 0 0 45px rgba(255,255,255,.035), 0 0 0 90px rgba(255,255,255,.025); }

.snapshot-kpis { margin-bottom: 20px; }
.snapshot-kpis .metric-card { min-height: 128px; border: 0; }
.snapshot-kpis .metric-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; border-radius: 4px; background: #2f80ed; }
.snapshot-kpis .kpi-meters::before { background: #14b8a6; }
.snapshot-kpis .kpi-amount::before { background: #8b5cf6; }
.snapshot-kpis .kpi-audit::before { background: #f2994a; }
.snapshot-kpis .metric-card strong { font-size: clamp(1.55rem, 2.3vw, 2.25rem); letter-spacing: -.035em; }

.range-insight-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.range-insight-card { position: relative; overflow: hidden; padding: 21px; border: 1px solid var(--border); border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.range-insight-card::after { content: ""; position: absolute; right: -32px; top: -32px; width: 105px; height: 105px; border-radius: 50%; background: rgba(239,83,80,.08); }
.range-insight-card.range-warning::after { background: rgba(242,153,74,.1); }
.range-insight-card.range-monitor::after { background: rgba(47,128,237,.1); }
.range-insight-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.range-badge { position: relative; z-index: 1; padding: 6px 10px; border-radius: 999px; background: #fff0ef; color: #c9453f; font-size: .68rem; font-weight: 800; }
.range-warning .range-badge { background: #fff5e8; color: #ad690d; }
.range-monitor .range-badge { background: #eaf3ff; color: #2365b4; }
.range-share { color: var(--text-muted); font-size: .74rem; font-weight: 700; }
.range-insight-card > strong { display: inline-block; margin-top: 19px; font-size: 2.25rem; letter-spacing: -.05em; color: var(--navy-900); }
.range-unit { margin-left: 6px; color: var(--text-muted); font-size: .76rem; }
.range-insight-values { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.range-insight-values div { padding: 10px 11px; border-radius: 10px; background: #f7f9fb; }
.range-insight-values small, .range-insight-values b { display: block; }
.range-insight-values small { color: var(--text-muted); font-size: .65rem; }
.range-insight-values b { margin-top: 4px; color: #293847; font-size: .82rem; }
.range-progress { height: 5px; overflow: hidden; margin-top: 15px; border-radius: 999px; background: #eef1f4; }
.range-progress i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #ef5350, #ff8a65); }
.range-warning .range-progress i { background: linear-gradient(90deg, #f2994a, #f7c15f); }
.range-monitor .range-progress i { background: linear-gradient(90deg, #2f80ed, #56b4fc); }

.history-ribbon-panel { margin-bottom: 20px; padding: 20px; border: 1px solid var(--border); border-radius: 18px; background: #fff; box-shadow: var(--shadow); }
.history-ribbon-header { margin-bottom: 15px; }
.history-ribbon-header > a { font-size: .76rem; font-weight: 750; }
.history-ribbon { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(105px, 1fr); gap: 10px; overflow-x: auto; padding: 3px 2px 8px; scrollbar-width: thin; }
.history-month-chip { position: relative; min-height: 100px; padding: 13px; text-align: left; border: 1px solid #e3e9ef; border-radius: 13px; background: #f8fafc; color: #314153; transition: .18s ease; }
.history-month-chip:hover { transform: translateY(-2px); border-color: #90bff4; box-shadow: 0 10px 20px rgba(47,128,237,.1); }
.history-month-chip.active { color: #fff; border-color: transparent; background: linear-gradient(145deg, #1768bd, #5145d7); box-shadow: 0 12px 26px rgba(41,94,180,.25); }
.history-month-chip span, .history-month-chip strong, .history-month-chip small { display: block; }
.history-month-chip span { font-size: .72rem; text-transform: uppercase; font-weight: 850; }
.history-month-chip strong { margin-top: 1px; font-size: 1.05rem; }
.history-month-chip small { margin-top: 15px; color: #758494; font-size: .66rem; }
.history-month-chip.active small { color: rgba(255,255,255,.7); }
.history-month-chip i { position: absolute; right: 10px; top: 11px; width: 7px; height: 7px; border-radius: 50%; background: #49d79b; box-shadow: 0 0 0 4px rgba(73,215,155,.12); }

.executive-dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(350px, .75fr); gap: 20px; margin-bottom: 20px; }
.trend-innovation-panel, .warehouse-innovation-panel { min-height: 470px; }
.innovative-chart-wrap { min-height: 330px; }
.innovative-chart { width: 100%; height: auto; min-width: 690px; }
.modern-legend { margin-top: 5px; }
.warehouse-innovation-body { display: grid; gap: 23px; align-items: center; justify-items: center; }
.innovative-donut { width: min(280px, 90%); }
.innovation-warehouse-legend { width: 100%; }
.innovation-warehouse-legend .warehouse-legend-row { grid-template-columns: 12px minmax(0,1fr) auto; padding: 9px 2px; }

.monthly-matrix-panel { margin-bottom: 20px; padding: 0; overflow: hidden; }
.monthly-matrix-panel .panel-header { padding: 20px 20px 0; }
.monthly-matrix-table tbody tr { cursor: pointer; transition: background .14s ease; }
.monthly-matrix-table tbody tr:hover { background: #f5f9ff; }
.selected-history-row { background: #edf5ff !important; box-shadow: inset 3px 0 0 #2f80ed; }
.frozen-pill { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 999px; background: #e8f8f1; color: #147a55; font-size: .62rem; font-weight: 800; }
.frozen-pill.large { padding: 7px 10px; font-size: .7rem; }
.audit-warning { margin: 15px 0; padding: 13px 15px; border: 1px solid #f0d9a7; border-radius: 11px; background: #fff8e9; color: #795619; font-size: .75rem; line-height: 1.55; }
.empty-history-state { display: flex; min-height: 420px; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 30px; text-align: center; border: 1px solid var(--border); border-radius: 20px; background: #fff; box-shadow: var(--shadow); }
.empty-history-state h2 { margin: 0; color: var(--navy-900); }
.empty-history-state p { max-width: 620px; margin: 0 0 8px; color: var(--text-muted); }
.empty-history-icon { display: grid; place-items: center; width: 72px; height: 72px; margin-bottom: 6px; border-radius: 21px; background: linear-gradient(145deg, #eaf4ff, #f0edff); color: #376fbe; font-size: 2rem; }

/* Historical archive */
.history-command-center { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 24px; overflow: hidden; margin-bottom: 18px; padding: 24px 26px; border-radius: 19px; color: #fff; background: linear-gradient(120deg, #0a263e, #154f7d 58%, #5848cf); box-shadow: 0 18px 42px rgba(12,54,91,.2); }
.history-command-copy h2 { margin: 5px 0; font-size: clamp(1.65rem, 3vw, 2.45rem); text-transform: capitalize; letter-spacing: -.04em; }
.history-command-copy p { margin: 0; color: rgba(255,255,255,.68); font-size: .78rem; }
.history-command-center .eyebrow { color: #8fd0ff; }
.history-status-card { display: grid; gap: 7px; justify-items: end; min-width: 190px; }
.history-status-card small { color: rgba(255,255,255,.62); font-size: .67rem; }
.history-month-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 12px; margin-bottom: 19px; }
.history-snapshot-card { min-height: 140px; padding: 16px; text-align: left; border: 1px solid var(--border); border-radius: 16px; background: #fff; color: #26384a; box-shadow: 0 8px 24px rgba(15,35,55,.06); transition: .18s ease; }
.history-snapshot-card:hover { transform: translateY(-3px); border-color: #92bff0; box-shadow: 0 14px 28px rgba(24,94,167,.13); }
.history-snapshot-card.active { color: #fff; border-color: transparent; background: linear-gradient(145deg, #1369bf, #5547d2); box-shadow: 0 16px 32px rgba(36,78,170,.25); }
.history-snapshot-top { position: relative; }
.history-snapshot-top span, .history-snapshot-top strong { display: block; }
.history-snapshot-top span { font-size: .7rem; text-transform: uppercase; font-weight: 850; }
.history-snapshot-top strong { margin-top: 1px; font-size: 1.12rem; }
.history-snapshot-top i { position: absolute; right: 0; top: 2px; width: 8px; height: 8px; border-radius: 50%; background: #42d392; box-shadow: 0 0 0 5px rgba(66,211,146,.13); }
.history-snapshot-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.history-snapshot-metrics small, .history-snapshot-metrics b { display: block; }
.history-snapshot-metrics small { color: #8090a0; font-size: .6rem; }
.history-snapshot-metrics b { margin-top: 2px; font-size: .77rem; }
.history-snapshot-card.active .history-snapshot-metrics small { color: rgba(255,255,255,.62); }
.history-version { display: block; margin-top: 12px; color: #8090a0; font-size: .61rem; }
.history-snapshot-card.active .history-version { color: rgba(255,255,255,.65); }
.history-detail-kpis { margin-bottom: 18px; }
.history-range-summary { display: grid; gap: 9px; margin-bottom: 18px; }
.history-range-row { display: grid; grid-template-columns: minmax(220px, 1fr) 120px 145px 155px; align-items: center; gap: 18px; padding: 14px 17px; border: 1px solid var(--border); border-left: 4px solid #ef5350; border-radius: 12px; background: #fff; box-shadow: 0 6px 17px rgba(15,35,55,.045); }
.history-range-row.range-warning { border-left-color: #f2994a; }
.history-range-row.range-monitor { border-left-color: #2f80ed; }
.history-range-row div span, .history-range-row div small { display: block; }
.history-range-row div span { color: #26384a; font-weight: 800; }
.history-range-row div small { margin-top: 3px; color: var(--text-muted); font-size: .66rem; }
.history-range-row > strong { font-size: 1.35rem; color: var(--navy-900); }
.history-range-row > b, .history-range-row > em { text-align: right; font-style: normal; font-size: .78rem; }
.history-range-row > em { color: #4c5e70; }
.history-detail-panel { margin-bottom: 18px; padding: 0; overflow: hidden; }
.history-detail-header { padding: 20px 20px 0; }
.history-filter-bar { display: grid; grid-template-columns: minmax(280px, 1fr) 170px 180px; gap: 12px; padding: 16px 20px; border-top: 1px solid #edf1f4; background: #fafbfd; }
.history-filter-bar label { display: grid; gap: 5px; }
.history-filter-bar label > span { color: #637383; font-size: .65rem; font-weight: 700; }
.history-filter-bar input, .history-filter-bar select { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid #d6dfe7; border-radius: 9px; background: #fff; outline: none; }
.history-filter-bar input:focus, .history-filter-bar select:focus { border-color: #6da7e7; box-shadow: 0 0 0 3px rgba(47,128,237,.1); }
.history-detail-table-wrap { max-height: 570px; overflow: auto; }
.history-detail-table thead { position: sticky; top: 0; z-index: 2; }
.warehouse-code-pill { display: inline-flex; justify-content: center; min-width: 42px; padding: 4px 7px; border-radius: 7px; background: #eef3f8; color: #40566c; font-size: .67rem; font-weight: 800; }
.range-table-pill { display: inline-flex; padding: 5px 7px; border-radius: 999px; background: #fff0ef; color: #bd403a; font-size: .61rem; font-weight: 800; }
.range-table-pill.range-warning { background: #fff5e8; color: #a8650d; }
.range-table-pill.range-monitor { background: #eaf3ff; color: #2768b6; }
.history-audit-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, .75fr); gap: 18px; margin-bottom: 18px; }
.audit-record-card h2, .rebuild-control-card h2 { margin: 5px 0 14px; color: var(--navy-900); font-size: 1.05rem; }
.audit-record-card dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; }
.audit-record-card dl div { padding: 10px 11px; border-radius: 9px; background: #f7f9fb; }
.audit-record-card dt { color: var(--text-muted); font-size: .62rem; }
.audit-record-card dd { margin: 4px 0 0; color: #2b3b4b; font-size: .75rem; font-weight: 750; }
.rebuild-control-card { border-color: #ead7a8; background: linear-gradient(180deg, #fffefa, #fffaf0); }
.rebuild-control-card p { margin: 0 0 14px; color: #6f6551; font-size: .72rem; line-height: 1.55; }
.rebuild-control-card label { display: grid; gap: 5px; }
.rebuild-control-card label span { color: #6f6551; font-size: .65rem; font-weight: 700; }
.rebuild-control-card input { width: 100%; padding: 10px; border: 1px solid #ddc993; border-radius: 9px; background: #fff; }
.rebuild-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.history-operation-message { position: sticky; bottom: 15px; z-index: 8; box-shadow: 0 12px 35px rgba(15,35,55,.2); }

@media (max-width: 1250px) {
    .executive-dashboard-grid { grid-template-columns: 1fr; }
    .warehouse-innovation-body { grid-template-columns: minmax(240px, 330px) minmax(260px, 1fr); justify-items: stretch; }
    .trend-innovation-panel, .warehouse-innovation-panel { min-height: auto; }
}

@media (max-width: 1000px) {
    .snapshot-hero { grid-template-columns: 1fr; }
    .snapshot-month-selector { max-width: 420px; }
    .range-insight-grid { grid-template-columns: 1fr; }
    .history-range-row { grid-template-columns: minmax(180px, 1fr) 100px 125px 135px; }
    .history-filter-bar { grid-template-columns: 1fr 1fr; }
    .history-search { grid-column: 1 / -1; }
    .history-audit-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .portal-content-area { padding: 18px 13px; }
    .snapshot-hero { padding: 24px 20px; border-radius: 17px; }
    .snapshot-hero h2 { font-size: 2rem; }
    .range-insight-values { grid-template-columns: 1fr; }
    .history-command-center { align-items: flex-start; flex-direction: column; }
    .history-status-card { justify-items: start; }
    .history-range-row { grid-template-columns: 1fr 1fr; gap: 10px; }
    .history-range-row > b, .history-range-row > em { text-align: left; }
    .history-filter-bar { grid-template-columns: 1fr; }
    .history-search { grid-column: auto; }
    .warehouse-innovation-body { grid-template-columns: 1fr; }
    .audit-record-card dl { grid-template-columns: 1fr; }
}
