:root {
  --bg: #f7f4f4;
  --ink: #172026;
  --muted: #60717c;
  --line: #eadcdd;
  --panel: #ffffff;
  --brand: #e9282f;
  --brand-2: #b91f29;
  --warn: #b85c00;
  --bad: #a73535;
  --good: #b91f29;
  --shadow: 0 10px 30px rgba(18, 38, 48, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
body.auth-locked .app-shell { display: none; }
button, input, select { font: inherit; }
button { border: 0; border-radius: 7px; background: var(--brand); color: #fff; padding: 10px 14px; cursor: pointer; }
button.secondary, .file-button { background: #e7eef0; color: var(--ink); }
button.icon-button { width: 28px; height: 28px; padding: 0; background: #edf2f3; color: var(--muted); }
button.save-late-row { padding: 7px 10px; }
button:hover { filter: brightness(.96); }
.app-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: #2b1719; color: #fff7f7; padding: 22px; display: flex; flex-direction: column; gap: 24px; }
.brand { display: grid; gap: 10px; align-items: start; }
.brand-mark { width: 46px; height: 46px; border-radius: 8px; background: #fff0f1; color: #7f1720; display: grid; place-items: center; font-weight: 800; }
.brand-logo { width: 96px; max-width: 100%; height: auto; display: block; background: #fff; border-radius: 8px; padding: 4px; }
.brand small, .sync-box span { color: #adc1c6; display: block; margin-top: 3px; }
.nav { display: grid; gap: 8px; }
.nav-link { background: transparent; text-align: left; color: #f5d9dc; padding: 12px; }
.nav-link.active { background: rgba(255,255,255,.12); color: #fff; }
.sync-box { margin-top: auto; border: 1px solid rgba(255,255,255,.12); border-radius: 8px; padding: 14px; }
.sync-box + .sync-box { margin-top: 0; }
.logout-button { margin-top: 10px; width: 100%; padding: 8px 10px; }
main { min-width: 0; padding: 24px; }
.topbar { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.eyebrow { margin: 0 0 5px; color: var(--brand); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 32px; }
h2 { font-size: 18px; }
.toolbar, .filters-row, .data-actions, .form-actions { display: flex; align-items: end; flex-wrap: wrap; gap: 12px; }
label { color: var(--muted); font-size: 13px; display: grid; gap: 5px; }
input, select { border: 1px solid var(--line); border-radius: 7px; padding: 9px 10px; background: #fff; color: var(--ink); min-height: 39px; }
.view { display: none; }
.view.active { display: block; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
.daily-dashboard { margin-bottom: 14px; }
.daily-kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
.mini-kpi { border: 1px solid var(--line); background: #fff8f8; border-radius: 8px; padding: 12px; min-width: 0; }
.mini-kpi span { color: var(--muted); font-size: 12px; }
.mini-kpi strong { display: block; font-size: 22px; margin-top: 6px; }
.mini-kpi small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.chart-grid.dense { grid-template-columns: repeat(2, minmax(360px, 1fr)); }
.chart-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fff; min-width: 0; }
.chart-card h3 { margin: 0 0 8px; font-size: 14px; letter-spacing: 0; }
.chart-card canvas { height: 340px; max-height: 360px; cursor: zoom-in; }
.rank-list.compact { max-height: 250px; overflow: auto; }
.kpi, .panel, .entry-form { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); }
.kpi { padding: 16px; }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi strong { display: block; font-size: 27px; margin-top: 8px; }
.kpi small { color: var(--muted); }
.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.panel { padding: 16px; min-width: 0; }
.panel.wide { grid-column: 1 / -1; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
canvas { width: 100%; max-height: 360px; }
.badge { background: #fff0f1; color: var(--brand); border-radius: 999px; padding: 5px 9px; font-weight: 700; }
.alert-list, .rank-list, .chat-log { display: grid; gap: 9px; margin-top: 12px; }
.alert-item { border-left: 4px solid var(--warn); background: #fff8ed; padding: 10px; border-radius: 6px; }
.alert-item.bad { border-color: var(--bad); background: #fff1f1; }
.rank-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.entry-form { padding: 18px; display: grid; gap: 18px; }
.form-section { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.checkbox { display: flex; align-items: center; color: var(--ink); }
.checkbox input { min-height: 0; }
.stats-table { display: grid; gap: 9px; margin-top: 12px; }
.stat-row { display: grid; grid-template-columns: 1.2fr repeat(5, 1fr); gap: 8px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.stat-row.header { color: var(--muted); font-weight: 700; }
.table-wrap { overflow: auto; max-height: 460px; margin-top: 12px; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; min-width: 920px; background: #fff; }
th, td { border-bottom: 1px solid var(--line); padding: 9px 10px; text-align: left; font-size: 13px; white-space: nowrap; }
th { position: sticky; top: 0; background: #fff0f1; z-index: 1; }
.sheet-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; max-height: 540px; background: #fff; }
.sheet-table { min-width: 2600px; table-layout: fixed; }
.sheet-table th { top: 0; font-size: 12px; color: #3b4d56; padding: 8px 6px; vertical-align: bottom; white-space: normal; }
.sheet-table td { padding: 0; background: #fff; }
.sheet-table input, .sheet-table select, .late-table input, .late-table select { width: 100%; min-height: 34px; border: 0; border-radius: 0; padding: 6px 7px; background: transparent; }
.sheet-table input:focus, .sheet-table select:focus, .late-table input:focus, .late-table select:focus { outline: 2px solid rgba(233, 40, 47, .28); outline-offset: -2px; background: #fff8f8; }
.sheet-table input[readonly], .late-table input[readonly] { background: #f7f1f1; color: #675b5d; }
.sheet-table input[data-status], .late-table input[data-status] { font-weight: 800; }
.sheet-table input[data-status="status-liberado"], .late-table input[data-status="status-liberado"] { background: #fff3f3; color: #8f1822; }
.sheet-table input[data-status="status-condicional"], .late-table input[data-status="status-condicional"] { background: #fff5cd; color: #7a5600; }
.sheet-table input[data-status="status-retenido"], .late-table input[data-status="status-retenido"] { background: #ffe4e6; color: #a81f2a; }
.sheet-table .row-num, .sheet-table .row-actions { width: 42px; text-align: center; background: #f6fafb; color: var(--muted); }
.sheet-table .xs { width: 74px; }
.sheet-table .sm { width: 112px; }
.sheet-table .md { width: 150px; }
.sheet-table .lg { width: 185px; }
.load-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; }
.flowmeter-grid { display: grid; grid-template-columns: repeat(2, minmax(170px, 1fr)) repeat(2, minmax(150px, .65fr)); gap: 12px; align-items: end; margin: 12px 0; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff8f8; }
.flowmeter-result { min-height: 58px; display: grid; align-content: center; gap: 4px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.flowmeter-result span { color: var(--muted); font-size: 12px; }
.flowmeter-result strong { font-size: 18px; }
.late-panel { margin-top: 14px; }
.late-table { min-width: 1240px; }
.late-table td { padding: 0 8px; }
.late-table td:nth-child(-n+5) { padding: 8px 10px; }
.pad { padding: 14px; }
.settings-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 14px; margin-top: 12px; }
.import-grid { display: grid; grid-template-columns: minmax(280px, 1.5fr) minmax(160px, .5fr) minmax(280px, 1fr); gap: 14px; align-items: end; margin-top: 12px; }
.import-status { margin-top: 12px; }
.settings-panel { margin-top: 14px; }
.settings-table-wrap { max-height: none; }
.settings-table { min-width: 720px; }
.family-settings-table { min-width: 760px; }
.family-settings-table th span { color: var(--muted); font-weight: 500; font-size: 11px; }
.settings-table td { vertical-align: middle; }
.settings-table input[type="number"] { width: 120px; min-height: 34px; }
.settings-tabs { display: inline-flex; gap: 6px; padding: 4px; margin: 12px 0; border: 1px solid var(--line); border-radius: 8px; background: #fff7f8; }
.settings-tab { background: transparent; color: var(--muted); box-shadow: none; padding: 8px 12px; }
.settings-tab.active { background: var(--brand); color: #fff; }
.master-settings { display: grid; gap: 12px; }
.master-add-row { display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: 10px; max-width: 640px; }
.master-table-wrap { max-height: 430px; }
.master-table { min-width: 640px; }
.master-table input[type="text"], .master-table select { min-height: 36px; }
.master-table input[type="text"] { width: 100%; }
.master-table select { width: 210px; }
.icon-action { width: 38px; height: 34px; padding: 0; font-size: 18px; }
.cheese-family-settings { max-height: 430px; }
.cheese-family-table { min-width: 560px; }
.cheese-family-table select { width: 210px; min-height: 36px; }
.inline-check { display: inline-flex; grid-template-columns: none; align-items: center; gap: 8px; color: var(--ink); }
.inline-check input { min-height: 0; }
.threshold-preview { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.status-chip { display: inline-block; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 800; background: #eef4f5; color: var(--muted); }
.status-liberado { background: #fff3f3; color: #8f1822; }
.status-condicional { background: #fff1b8; color: #745100; }
.status-retenido { background: #ffe0e3; color: #a51e2a; }
.assistant-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(280px, .5fr); gap: 14px; }
.chat-log { min-height: 430px; align-content: start; }
.message { padding: 12px; border-radius: 8px; background: #eef4f5; }
.message.user { background: #fff0f1; justify-self: end; max-width: 80%; }
.message.bot { background: #fff; border: 1px solid var(--line); }
.ask-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 12px; }
.quick-prompts { display: grid; gap: 10px; margin-top: 12px; }
.file-button { border-radius: 7px; padding: 10px 14px; cursor: pointer; display: inline-flex; color: var(--ink); }
.file-button input { display: none; }
.muted { color: var(--muted); }
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: #2b1719; }
.login-screen[hidden] { display: none; }
.login-card { width: min(420px, 100%); display: grid; gap: 14px; padding: 24px; border-radius: 10px; background: #fff; border: 1px solid var(--line); box-shadow: 0 24px 80px rgba(0,0,0,.28); }
.login-card h1 { font-size: 26px; }
.login-logo { width: 140px; background: #fff; border-radius: 8px; }
.user-admin-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(300px, .8fr); gap: 14px; }
.user-admin-grid h3 { margin: 8px 0; font-size: 15px; }
.user-add-row { grid-template-columns: 1fr 1fr 180px auto; margin-top: 12px; max-width: none; }
.pill { display: inline-block; border-radius: 999px; padding: 3px 8px; font-size: 12px; background: #eef4f5; }
.pill.bad { background: #ffe4e4; color: var(--bad); }
.chart-tooltip { position: fixed; z-index: 30; max-width: 280px; background: #221719; color: #fff; border-radius: 8px; padding: 9px 10px; font-size: 12px; line-height: 1.45; box-shadow: 0 14px 35px rgba(0,0,0,.2); pointer-events: none; }
.chart-modal { position: fixed; inset: 0; z-index: 25; background: rgba(23, 32, 38, .64); padding: 28px; display: grid; place-items: center; }
.chart-modal[hidden], .chart-tooltip[hidden] { display: none; }
.chart-modal-panel { width: min(1240px, 96vw); max-height: 92vh; overflow: auto; background: #fff; border-radius: 8px; padding: 18px; box-shadow: 0 24px 70px rgba(0,0,0,.28); }
.chart-modal canvas { width: 100%; height: min(650px, 70vh); max-height: none; }
@media (max-width: 1000px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .nav { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .topbar, .assistant-layout { display: grid; }
  .kpi-grid, .report-grid, .form-grid, .daily-kpi-grid, .chart-grid.dense, .user-admin-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 680px) {
  main { padding: 16px; }
  .nav { grid-template-columns: 1fr 1fr; }
  .kpi-grid, .report-grid, .form-grid, .daily-kpi-grid, .chart-grid, .chart-grid.dense, .user-admin-grid, .user-add-row { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .ask-form { grid-template-columns: 1fr; }
}
