:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #171918;
  background: #f2f3f1;
  letter-spacing: 0;
  --ink: #171918;
  --muted: #666c68;
  --line: #d7dad7;
  --surface: #ffffff;
  --red: #c83232;
  --red-dark: #9e2525;
  --green: #17805d;
  --amber: #a76008;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: #f2f3f1; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(100%, 380px); background: var(--surface); border: 1px solid var(--line); padding: 32px; }
.brand { margin: 0 0 5px; color: var(--red); font-weight: 800; font-size: 14px; }
h1, h2, p { margin-top: 0; }
.login-panel h1 { margin-bottom: 30px; font-size: 26px; }
label { display: block; color: #3e433f; font-size: 14px; font-weight: 650; margin: 16px 0 7px; }
input, textarea, select { width: 100%; border: 1px solid #b8bdb9; background: #fff; color: var(--ink); padding: 11px 12px; border-radius: 4px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(200, 50, 50, .12); }
textarea { min-height: 92px; resize: vertical; }
.form-error { min-height: 20px; color: var(--red-dark); font-size: 13px; margin: 9px 0; }

.primary, .secondary, .quiet, .icon-button { border-radius: 4px; min-height: 40px; border: 1px solid transparent; padding: 9px 14px; font-weight: 700; }
.primary { width: 100%; background: var(--red); color: white; }
.primary:hover { background: var(--red-dark); }
.primary.compact { width: auto; }
.secondary { background: var(--ink); color: white; }
.quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.icon-button { width: 40px; padding: 0; background: #fff; border-color: var(--line); font-size: 20px; }

.app-view { min-height: 100vh; }
.topbar { min-height: 76px; background: var(--surface); border-bottom: 1px solid var(--line); padding: 14px 28px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar h1 { margin: 0; font-size: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.user-label { color: var(--muted); font-size: 14px; }
.status { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.status span { width: 9px; height: 9px; border-radius: 50%; background: var(--red); }
.status.online span { background: var(--green); }
.status.waiting span { background: var(--amber); }

.view-tabs { height: 46px; padding: 0 28px; display: flex; align-items: end; gap: 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.view-tab { height: 46px; padding: 0 2px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); font-weight: 700; }
.view-tab.active { color: var(--ink); border-bottom-color: var(--red); }

.session-strip { padding: 14px 28px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 36px; background: #f8f9f7; border-bottom: 1px solid var(--line); }
.session-strip div { min-width: 0; }
.session-strip strong, .session-strip span:last-child { display: block; overflow-wrap: anywhere; }
.session-strip strong { font-size: 15px; }
.session-strip span:last-child { margin-top: 3px; color: var(--muted); font-size: 13px; }

.summary-band { background: var(--surface); border-bottom: 1px solid var(--line); padding: 24px 28px; display: grid; grid-template-columns: minmax(220px, 1fr) minmax(330px, 1.6fr) auto; align-items: end; gap: 32px; }
.metric-label { color: var(--muted); display: block; font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.occupancy { display: block; font-size: 72px; line-height: .95; }
.capacity { color: var(--muted); display: block; font-size: 14px; margin-top: 9px; }
.summary-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.summary-metrics div { background: #fff; min-height: 76px; padding: 15px 18px; }
.summary-metrics strong { font-size: 24px; }
.summary-actions { display: flex; flex-direction: column; gap: 8px; min-width: 155px; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 0; max-width: 1600px; margin: 0 auto; }
.video-section { min-width: 0; padding: 24px 28px 32px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-heading h2, .operations h2 { font-size: 17px; margin-bottom: 3px; }
.section-heading p { color: var(--muted); font-size: 13px; margin: 0; }
.video-wrap { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #151716; overflow: hidden; }
.video-wrap video, .video-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.video-wrap video { object-fit: contain; }
.video-wrap canvas { pointer-events: none; }
.video-failure { position: absolute; inset: 0; display: grid; place-items: center; color: #f1f2f1; background: #262927; font-weight: 700; }
.video-failure.hidden { display: none; }
.operations { border-left: 1px solid var(--line); padding: 28px 24px; background: #f8f9f7; }
.operations dl { margin: 18px 0 0; }
.operations dl div { border-top: 1px solid var(--line); padding: 13px 0; display: flex; justify-content: space-between; gap: 16px; }
.operations dt { color: var(--muted); font-size: 13px; }
.operations dd { margin: 0; font-size: 13px; font-weight: 700; text-align: right; }
.state-value.good { color: var(--green); }
.state-value.bad { color: var(--red-dark); }
.role-note { border-top: 3px solid var(--amber); margin-top: 28px; padding-top: 12px; }
.role-note strong, .role-note span { display: block; font-size: 13px; }
.role-note span { color: var(--muted); margin-top: 5px; line-height: 1.45; }

dialog { width: min(92vw, 440px); border: 1px solid var(--line); border-radius: 6px; padding: 0; box-shadow: 0 20px 60px rgba(0, 0, 0, .2); }
dialog::backdrop { background: rgba(20, 22, 21, .55); }
dialog form { padding: 24px; }
dialog h2 { font-size: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.dialog-actions .primary { width: auto; }
.reception-only { display: none; }

.sessions-view, .users-view { max-width: 1440px; margin: 0 auto; padding: 28px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.page-heading h2 { margin-bottom: 4px; font-size: 22px; }
.page-heading p { margin: 0; color: var(--muted); font-size: 14px; }
.data-section { margin-top: 28px; border-top: 1px solid var(--line); }
.data-heading { min-height: 52px; display: flex; align-items: center; gap: 10px; }
.data-heading h3 { margin: 0; font-size: 16px; }
.subtle-count { min-width: 24px; padding: 2px 6px; border-radius: 3px; background: #e4e7e4; color: var(--muted); font-size: 12px; text-align: center; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { color: var(--muted); background: #f8f9f7; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
td:first-child { white-space: normal; min-width: 160px; font-weight: 650; }
.empty-row { height: 74px; color: var(--muted); text-align: center; font-weight: 400 !important; }
.table-action { min-height: 32px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 4px; background: #fff; font-weight: 700; }
.table-action.danger { color: var(--red-dark); }
.row-actions { display: flex; gap: 6px; }
.current-user { display: inline-block; margin-left: 6px; padding: 2px 5px; border-radius: 3px; background: #e4e7e4; color: var(--muted); font-size: 10px; font-weight: 750; vertical-align: 1px; }
.state-tag { display: inline-block; padding: 3px 7px; border-radius: 3px; background: #e4e7e4; color: #424744; font-size: 11px; font-weight: 750; }
.state-tag.active { background: #dcefe8; color: #126447; }
.state-tag.missed { background: #fff0ce; color: #744304; }
.state-tag.disabled, .state-tag.cancelled { color: var(--muted); }
.source-tag { display: inline-block; margin-left: 6px; padding: 2px 5px; border: 1px solid #9bb9ad; border-radius: 3px; color: #126447; font-size: 10px; font-weight: 750; vertical-align: 1px; }
.odoo-sync { display: grid; grid-template-columns: minmax(260px, 1.3fr) minmax(330px, 1fr) auto; align-items: center; gap: 24px; padding: 18px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.odoo-sync h3 { margin: 0 0 4px; font-size: 16px; }
.odoo-sync p { margin: 0; color: var(--muted); font-size: 13px; }
.odoo-sync dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin: 0; }
.odoo-sync dt { color: var(--muted); font-size: 12px; }
.odoo-sync dd { margin: 4px 0 0; font-size: 13px; font-weight: 700; }
.odoo-sync .form-error { grid-column: 1 / -1; min-height: 0; color: var(--red-dark); }

.wide-dialog { width: min(92vw, 680px); }
.dialog-subtitle { margin: -10px 0 18px; color: var(--muted); font-size: 14px; }
.field-hint { margin: 9px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.check-control { display: flex; align-items: center; gap: 9px; margin-top: 20px; }
.check-control input { width: 18px; height: 18px; margin: 0; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
#weeklyFields { grid-template-columns: 1.4fr 1fr 1fr; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 0; padding: 0; margin: 18px 0; }
.mode-switch legend { margin-bottom: 7px; color: #3e433f; font-size: 14px; font-weight: 650; }
.mode-switch label { margin: 0; }
.mode-switch input { position: absolute; opacity: 0; pointer-events: none; }
.mode-switch span { display: block; padding: 10px 12px; border: 1px solid #b8bdb9; text-align: center; cursor: pointer; }
.mode-switch label:first-of-type span { border-radius: 4px 0 0 4px; }
.mode-switch label:last-of-type span { border-left: 0; border-radius: 0 4px 4px 0; }
.mode-switch input:checked + span { background: var(--ink); border-color: var(--ink); color: #fff; }
.dialog-content { padding: 24px; }
.detail-heading { display: flex; justify-content: space-between; align-items: start; gap: 16px; }
.detail-heading h2 { margin: 0; }
.detail-summary { display: grid; grid-template-columns: repeat(3, 1fr); margin: 22px 0; border: 1px solid var(--line); }
.detail-summary div { padding: 12px; border-right: 1px solid var(--line); }
.detail-summary div:last-child { border-right: 0; }
.detail-summary dt { color: var(--muted); font-size: 12px; }
.detail-summary dd { margin: 4px 0 0; font-size: 18px; font-weight: 750; }
.timeline { max-height: 280px; overflow-y: auto; border-top: 1px solid var(--line); }
.timeline-row { display: grid; grid-template-columns: 90px 100px 1fr; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line); font-size: 13px; }
.timeline-row span:first-child { color: var(--muted); }
.timeline-empty { padding: 24px 0; color: var(--muted); font-size: 13px; }

.statistics-view { max-width: 1440px; margin: 0 auto; padding: 28px; }
.statistics-heading { margin-bottom: 18px; }
.range-presets { display: flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.range-presets button { min-height: 36px; padding: 7px 11px; border: 0; border-right: 1px solid var(--line); background: #fff; color: var(--muted); font-size: 13px; font-weight: 700; }
.range-presets button:last-child { border-right: 0; }
.range-presets button.active { background: var(--ink); color: #fff; }
.filter-bar { display: grid; grid-template-columns: 180px 180px 150px minmax(250px, 1fr) 100px; align-items: end; gap: 10px; padding: 16px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.filter-bar label { margin-top: 0; }
.filter-bar button { min-width: 90px; }
.stats-kpis { display: grid; grid-template-columns: repeat(6, 1fr); margin: 24px 0 8px; border: 1px solid var(--line); background: var(--surface); }
.stats-kpis div { min-width: 0; padding: 15px 16px; border-right: 1px solid var(--line); }
.stats-kpis div:last-child { border-right: 0; }
.stats-kpis strong { display: block; font-size: 26px; overflow-wrap: anywhere; }
.statistics-empty { margin-top: 24px; padding: 46px 20px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); text-align: center; }
.statistics-content { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px; margin-top: 28px; }
.occupancy-section { grid-column: 1 / -1; }
.chart-section { min-width: 0; border-top: 1px solid var(--line); padding-top: 14px; }
.chart-heading { min-height: 48px; display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.chart-heading h3 { margin: 0 0 3px; font-size: 16px; }
.chart-heading p { margin: 0; color: var(--muted); font-size: 12px; }
.chart-legend { display: flex; gap: 14px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.chart-legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 5px; border-radius: 2px; }
.chart-legend .entries::before { background: var(--red); }
.chart-legend .exits::before { background: var(--green); }
.chart-legend .occupancy-series::before { background: #315f9f; }
.chart-frame { position: relative; width: 100%; aspect-ratio: 2.25 / 1; min-height: 220px; border: 1px solid var(--line); background: var(--surface); }
.occupancy-chart-frame { aspect-ratio: 4.7 / 1; }
.chart-frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.ranked-bars, .weekday-bars { min-height: 220px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; }
.ranked-row { display: grid; grid-template-columns: minmax(110px, 1fr) minmax(120px, 2fr) 44px; align-items: center; gap: 12px; min-height: 41px; border-bottom: 1px solid #eceeec; font-size: 12px; }
.ranked-row:last-child { border-bottom: 0; }
.ranked-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.bar-track { height: 8px; background: #e6e8e6; overflow: hidden; }
.bar-fill { display: block; height: 100%; min-width: 0; background: var(--red); }
.weekday-bars .bar-fill { background: var(--green); }
.ranked-value { text-align: right; font-weight: 750; }
.ranked-empty { display: grid; min-height: 200px; place-items: center; color: var(--muted); font-size: 13px; }

@media (max-width: 900px) {
  .summary-band { grid-template-columns: 1fr 1fr; }
  .summary-metrics { grid-column: 1 / -1; grid-row: 2; }
  .summary-actions { align-self: center; }
  .workspace { grid-template-columns: 1fr; }
  .operations { border-left: 0; border-top: 1px solid var(--line); }
  .statistics-heading { align-items: flex-start; flex-direction: column; }
  .stats-kpis { grid-template-columns: repeat(3, 1fr); }
  .stats-kpis div:nth-child(3) { border-right: 0; }
  .stats-kpis div:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
  .statistics-content { grid-template-columns: 1fr; }
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar button { width: 100%; }
  .odoo-sync { grid-template-columns: 1fr auto; }
  .odoo-sync dl { grid-column: 1 / -1; grid-row: 2; }
}

@media (max-width: 600px) {
  .topbar { align-items: flex-start; padding: 14px 16px; }
  .topbar-actions { align-items: flex-end; flex-direction: column; gap: 6px; }
  .user-label { display: none; }
  .summary-band { padding: 20px 16px; grid-template-columns: 1fr; gap: 20px; }
  .occupancy { font-size: 64px; }
  .summary-metrics { grid-column: auto; grid-row: auto; }
  .summary-metrics div { padding: 12px 10px; min-width: 0; }
  .summary-metrics strong { font-size: 19px; overflow-wrap: anywhere; }
  .summary-actions { width: 100%; }
  .video-section { padding: 20px 16px 24px; }
  .operations { padding: 24px 16px; }
  .view-tabs { padding: 0 16px; overflow-x: auto; }
  .view-tab { flex: 0 0 auto; }
  .session-strip { padding: 14px 16px; grid-template-columns: 1fr; gap: 14px; }
  .sessions-view { padding: 22px 16px; }
  .users-view { padding: 22px 16px; }
  .odoo-sync { grid-template-columns: 1fr; gap: 16px; }
  .odoo-sync dl { grid-column: auto; grid-row: auto; }
  .odoo-sync button { width: 100%; }
  .page-heading { align-items: flex-start; }
  .field-grid, #weeklyFields { grid-template-columns: 1fr; gap: 0; }
  .detail-summary { grid-template-columns: 1fr; }
  .detail-summary div { border-right: 0; border-bottom: 1px solid var(--line); }
  .detail-summary div:last-child { border-bottom: 0; }
  .timeline-row { grid-template-columns: 70px 82px minmax(0, 1fr); gap: 8px; }
  .statistics-view { padding: 22px 16px; }
  .range-presets { width: 100%; }
  .range-presets button { flex: 1; min-width: 0; padding: 7px 5px; }
  .filter-bar { grid-template-columns: 1fr 1fr; }
  .filter-bar div:nth-child(3), .filter-bar button { grid-column: 1 / -1; }
  .stats-kpis { grid-template-columns: repeat(2, 1fr); }
  .stats-kpis div, .stats-kpis div:nth-child(3) { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .stats-kpis div:nth-child(even) { border-right: 0; }
  .stats-kpis div:nth-last-child(-n+2) { border-bottom: 0; }
  .stats-kpis strong { font-size: 22px; }
  .filter-bar { grid-template-columns: 1fr; }
  .chart-frame { min-height: 210px; aspect-ratio: 1.55 / 1; }
  .occupancy-chart-frame { aspect-ratio: 1.7 / 1; }
  .chart-heading { min-height: 58px; }
  .ranked-row { grid-template-columns: minmax(90px, 1fr) minmax(80px, 1.3fr) 38px; gap: 8px; }
}
