/* Configuration console (templates/console): circleback-style light shell.
   Tokens and the font live in tokens.css; the Hoje board lives in today.css. */
:root {
  --good: #1f8a3b;
  --bad: color-mix(in oklab, var(--error) 80%, #000);
  --warn: #a1740f;
  --ease-linear: cubic-bezier(0.2, 0, 0, 1);
  --side: 216px;
  --bar: 52px;
  --chat: 400px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body.console {
  background: var(--bg); color: var(--label);
  font: var(--weight-body) 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased; overflow: hidden;
  display: grid; grid-template-columns: var(--side) minmax(0, 1fr);
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
::selection { background: var(--selection); }

.c-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.c-num { font-variant-numeric: tabular-nums; }
.c-nowrap { white-space: nowrap; }
.c-dim { color: var(--label-secondary); }
.c-bad { color: var(--bad); }
.c-right { text-align: right; }
.c-strong { font-weight: 600; color: var(--label); }
.c-sub { display: block; font-size: 13px; color: var(--label-secondary); margin-top: 2px; }
.c-empty { color: var(--label-secondary); margin: 8px 0 0; }
.c-h { margin: 0 0 12px; font-size: 15px; font-weight: 700; letter-spacing: -0.015em; }
.c-panel { min-width: 0; }

/* sidebar: wordmark, pages, then assistant and sign-out at the bottom */
.c-top {
  height: 100dvh; display: flex; flex-direction: column; gap: 2px; padding: 20px 12px 16px;
  background: var(--bg-secondary); border-right: 1px solid var(--separator); min-height: 0;
}
.c-brand {
  padding: 4px 8px; margin-bottom: 20px; font-size: 16px; font-weight: 700; letter-spacing: -0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.c-tabs { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; overflow-y: auto; min-height: 0; }
.c-tab, .c-top .c-ghost {
  position: relative; display: block; padding: 6px 8px; height: auto; border-radius: var(--r-sm);
  font-size: 14px; font-weight: 500; color: var(--label-secondary); white-space: nowrap; text-align: left;
  transition: color 150ms var(--ease-linear);
}
.c-tab:hover, .c-tab.is-active, .c-top .c-ghost:hover { color: var(--label); background: none; }
.c-tab::after {
  content: ""; position: absolute; left: 8px; right: 8px; bottom: 2px; height: 2px; border-radius: 2px;
  background: var(--accent); transform: scaleX(0); transform-origin: left;
}
.c-tab.is-active::after { transform: scaleX(1); view-transition-name: tab-underline; }
.c-chat-toggle { margin-top: auto; }
body.chat-open .c-chat-toggle { color: var(--label); }
.c-tab-select { display: none; }

/* main column, and the assistant drawer over it */
.c-body { height: 100dvh; min-width: 0; }
.c-main { height: 100%; overflow: auto; padding: 40px 48px 64px; }
.c-main:not(.c-main-today) > * { max-width: 880px; }
.c-title { margin: 0 0 24px; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.c-chat {
  position: fixed; inset: 0 0 0 auto; width: min(var(--chat), 100vw); z-index: 30;
  display: flex; flex-direction: column; min-height: 0; padding: 16px 16px 12px;
  background: var(--bg); border-left: 1px solid var(--separator); box-shadow: var(--shadow-float);
  transform: translateX(100%); visibility: hidden;
  transition: transform 240ms var(--ease-linear), visibility 0s linear 240ms;
  /* the chat bundle is built dark; its palette remapped to the light tokens */
  --color-ink-950: var(--bg); --color-ink-900: var(--bg-secondary); --color-ink-800: var(--bg-tertiary);
  --color-ink-700: var(--bg-quaternary); --color-line: var(--separator); --color-paper: var(--label);
  --color-muted: var(--label-secondary); --color-dim: var(--placeholder);
  --color-sage: var(--good); --color-brick: var(--bad); --font-mono: var(--font);
}
body.chat-open .c-chat { transform: none; visibility: visible; transition: transform 240ms var(--ease-linear); }
.c-chat #chat-root { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.c-chat .chat-shell { height: 100%; flex: 1; }
/* the chat bundle ships without preflight; give its native controls a clean slate here */
:where(#chat-root) button { background-color: transparent; border: 0; padding: 0; color: inherit; cursor: pointer; }
:where(#chat-root) :is(textarea, input) { border: 0; background: transparent; outline: none; }
:where(#chat-root) img { max-width: 100%; }

/* settings: hairline rows, no boxes */
.c-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 40px 48px; }
.c-card { margin-bottom: 40px; min-width: 0; }
.c-cards .c-card { margin: 0; }
.c-card-title { margin: 0 0 8px; font-size: 15px; font-weight: 700; letter-spacing: -0.015em; }
.c-rows { margin: 0; border-bottom: 1px solid var(--separator); }
.c-row {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: center;
  min-height: 48px; padding: 6px 0; border-top: 1px solid var(--separator);
}
.c-row dd { margin: 0; }
.c-row-value { text-align: right; }
.c-label { color: var(--label-secondary); font-weight: 500; }
.c-row .c-label { color: var(--label); }
.c-value { color: var(--label); }

.c-fields { border-bottom: 1px solid var(--separator); }
.c-field-wrap, .c-fields > .c-field { border-top: 1px solid var(--separator); padding: 10px 0; }
.c-field, .c-fields > .c-field { display: grid; grid-template-columns: 260px minmax(0, 1fr) auto; gap: 16px; align-items: center; }
.c-field .c-label { color: var(--label); }
.c-control { min-width: 0; max-width: 400px; }
/* fixed width: Salvar stays put when Limpar appears */
.c-field > .c-row-actions { width: 168px; }

/* operator cells open the edit dialog */
.c-cell {
  display: inline-block; text-align: right; background: transparent; border: 0; border-radius: var(--r-sm);
  padding: 6px 8px; margin-right: -8px; cursor: pointer;
  transition: background-color 150ms var(--ease-linear), transform 140ms var(--ease-linear);
}
.c-cell:hover { background: var(--bg-tertiary); }
/* the value at the edge, where it came from just before it */
.c-row .c-cell { display: inline-flex; flex-direction: row-reverse; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
.c-cell-val { font-variant-numeric: tabular-nums; }
.c-src { font-size: 12px; color: var(--label-subtle); }
.c-cell-bad { font-size: 12px; color: var(--warn); }

/* switches */
.c-on { color: var(--label); font-weight: 600; }
.c-off { color: var(--label-subtle); }

/* controls */
.c-input {
  width: 100%; min-width: 0; height: 32px; padding: 0 10px; border-radius: var(--r-sm);
  background: var(--bg); border: 1px solid var(--separator-secondary); color-scheme: light;
  transition: border-color 150ms var(--ease-linear), box-shadow 150ms var(--ease-linear);
}
select.c-input {
  appearance: none; padding-right: 30px; cursor: pointer;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%237f7f7f' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m3 4.5 3 3 3-3'/%3E%3C/svg%3E") no-repeat right 10px center;
}
textarea.c-input { height: auto; padding: 6px 10px; resize: vertical; line-height: 1.5; }
.c-input::placeholder { color: var(--placeholder); }
.c-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.c-input-date { width: auto; height: 28px; padding: 0 8px; }
.c-btn, .c-ghost {
  height: 30px; padding: 0 12px; border: 0; border-radius: var(--r-sm); cursor: pointer; white-space: nowrap;
  font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center;
  transition: background-color 150ms var(--ease-linear), color 150ms var(--ease-linear), transform 140ms var(--ease-linear);
}
.c-btn, .c-field.is-dirty .c-save { background: var(--accent); color: #fff; }
.c-btn:hover, .c-field.is-dirty .c-save:hover { background: color-mix(in oklab, var(--accent) 94%, #000); }
.c-ghost { background: transparent; color: var(--label-secondary); font-weight: 500; }
.c-ghost:hover { color: var(--label); background: var(--bg-tertiary); }
.c-btn:active, .c-ghost:active, .c-cell:active { transform: scale(0.97); }
.c-row-actions { display: flex; gap: 4px; align-items: center; }

/* tables: drivers and decisions */
.c-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.c-table th {
  text-align: left; font-size: 12px; font-weight: 500; color: var(--label-secondary);
  padding: 0 12px 8px 0; border-bottom: 1px solid var(--separator); white-space: nowrap;
}
.c-table td { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--separator); vertical-align: top; text-align: left; }
.c-why { color: var(--label-secondary); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
tr.is-out .c-strong, tr.is-out .c-plate { color: var(--label-subtle); text-decoration: line-through; }

.c-drivers { table-layout: fixed; }
.c-drivers td:first-child { width: 36%; }
.c-drivers td:last-child { width: 96px; }
.c-drivers .c-plate { display: block; font-size: 12px; color: var(--label-secondary); font-variant-numeric: tabular-nums; margin-top: 2px; }
.c-dates { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.c-date, .c-date-add { display: flex; gap: 4px; align-items: center; margin: 0; }
.c-chip-btn {
  height: 28px; padding: 0 8px; border: 1px solid var(--separator-secondary); border-radius: var(--r-sm);
  background: var(--bg); cursor: pointer; font-size: 13px; font-variant-numeric: tabular-nums;
  transition: color 150ms var(--ease-linear), border-color 150ms var(--ease-linear);
}
.c-chip-btn:hover { color: var(--bad); border-color: currentColor; }
.c-add-driver { display: flex; gap: 8px; margin-top: 16px; max-width: 400px; }

.c-day-group { margin: 28px 0 4px; font-size: 13px; font-weight: 600; color: var(--label-secondary); }
.c-day-group:first-of-type { margin-top: 0; }
.c-log { table-layout: fixed; }
.c-log td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-log td .c-strong { font-weight: 500; }
.c-col-time { width: 56px; }
.c-col-who, .c-col-result { width: 180px; }
.c-col-revert { width: 96px; }
.c-log td:nth-child(4) { font-weight: 500; }
.c-result.is-good { color: var(--good); }
.c-result.is-bad { color: var(--bad); }
.c-result.is-warn { color: var(--warn); }

/* preview and confirm: the floating object of the page */
.c-slot:empty { display: none; }
.c-field-slot { margin-top: 10px; }
.c-preview {
  margin-top: 8px; padding: 12px 14px; border-radius: var(--r-md); background: var(--bg-elevated);
  border: 1px solid var(--separator); box-shadow: var(--shadow-float);
  display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; justify-content: space-between;
  animation: c-in 240ms var(--ease-linear) both;
}
.c-diff { font-size: 13px; display: grid; gap: 2px; min-width: 0; font-variant-numeric: tabular-nums; }
.c-diff-old { color: var(--label-secondary); }
.c-diff-old span { color: var(--bad); }
.c-diff-new span { color: var(--good); }
.c-error { color: var(--bad); margin: 8px 0 0; font-size: 13px; }

/* edit dialog */
.c-dialog {
  background: var(--bg-elevated); color: var(--label); border: 1px solid var(--separator); border-radius: var(--r-md);
  padding: 20px; width: min(440px, calc(100vw - 32px)); box-shadow: var(--shadow-float);
}
.c-dialog::backdrop { background: rgb(15 23 42 / 0.16); }
.c-dialog-form { display: grid; gap: 14px; }
.c-dialog-title { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -0.015em; }
.dlg { opacity: 0; transform: translateY(8px) scale(0.98); transition: opacity 200ms var(--ease-linear), transform 240ms var(--ease-linear), overlay 240ms allow-discrete, display 240ms allow-discrete; }
.dlg[open] { opacity: 1; transform: none; }
@starting-style { .dlg[open] { opacity: 0; transform: translateY(8px) scale(0.98); } }

.htmx-swapping { opacity: 0.5; transition: opacity 120ms; }

/* login: the one centered card */
body.c-login-page { display: grid; grid-template-columns: none; place-items: center; overflow: auto; background: var(--bg-secondary); }
.c-login {
  width: min(360px, calc(100vw - 32px)); padding: 32px; background: var(--bg); border: 1px solid var(--separator);
  border-radius: var(--r-md); box-shadow: var(--shadow-float);
}
.c-login-name { margin: 0 0 24px; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.c-login-form { display: grid; gap: 6px; }
.c-login-form .c-label { color: var(--label); font-size: 13px; }
.c-login-form .c-input { height: 36px; margin-bottom: 10px; }
.c-login-btn { height: 36px; margin-top: 6px; }

/* motion: quiet and linear; pages cross-fade and the active indicator glides */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 180ms; animation-timing-function: var(--ease-linear); }
::view-transition-group(tab-underline) { animation-duration: 240ms; animation-timing-function: var(--ease-linear); }
.c-main > * { animation: c-in 240ms var(--ease-linear) both; }
.c-main > *:nth-child(2) { animation-delay: 30ms; }
.c-main > *:nth-child(3) { animation-delay: 60ms; }
@keyframes c-in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 1100px) {
  .c-field, .c-fields > .c-field { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 8px; }
  .c-field > .c-label { grid-column: 1 / -1; }
  .c-field > .c-row-actions { width: auto; }
  .c-control { max-width: none; }
}
/* phones: the sidebar folds into a bar with the page select */
@media (max-width: 760px) {
  body.console:not(.c-login-page) { grid-template-columns: minmax(0, 1fr); grid-template-rows: var(--bar) minmax(0, 1fr); }
  .c-top {
    height: var(--bar); flex-direction: row; align-items: center; gap: 4px; padding: 0 12px 0 16px;
    border-right: 0; border-bottom: 1px solid var(--separator);
  }
  .c-brand, .c-tabs { display: none; }
  .c-tab-select {
    display: block; flex: 1; min-width: 0; height: 32px; padding: 0 8px; margin-right: 4px;
    font-size: 15px; font-weight: 700; letter-spacing: -0.015em; color: var(--label);
    background: transparent; border: 0; border-radius: var(--r-sm);
  }
  .c-chat-toggle { margin-top: 0; }
  .c-chat { top: var(--bar); box-shadow: none; }
  /* drivers: name and remove on one line, the day-off controls under them */
  .c-drivers thead { display: none; }
  .c-drivers tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; border-bottom: 1px solid var(--separator); padding: 10px 0; }
  .c-drivers td, .c-drivers td:first-child, .c-drivers td:last-child { width: auto; border: 0; padding: 0; }
  .c-drivers td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; padding-top: 8px; }
  .c-drivers td:nth-child(3) { grid-column: 2; grid-row: 1; }
  .c-body { height: calc(100dvh - var(--bar)); }
  .c-main { padding: 24px 16px 48px; }
  /* the page select already names the page */
  .c-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .c-row { grid-template-columns: 1fr; gap: 2px; padding: 10px 0; }
  .c-row-value { text-align: left; }
  .c-cell, .c-row .c-cell { margin: 0 0 0 -8px; flex-direction: row; text-align: left; }
  .c-cards { grid-template-columns: minmax(0, 1fr); }
  .c-log td:nth-child(3), .c-col-who { display: none; }
  .c-col-result { width: 112px; }
  .c-col-revert { width: 72px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  @view-transition { navigation: none; }
}
