/* Functional glass shell: glass for navigation, opaque surfaces for operations. */
:root {
  color-scheme: light;
  --bg: #edf2f7;
  --panel: #fff;
  --panel-2: #f6f8fb;
  --line: rgba(16, 43, 76, .14);
  --line-strong: rgba(16, 43, 76, .25);
  --text: #102b4c;
  --muted: #607187;
  --brand: #102b4c;
  --brand-2: #f97316;
  --ok: #087a5b;
  --warn: #7b5b00;
  --danger: #b4232f;
  --focus: #1769c2;
  --glass: rgba(255, 255, 255, .79);
  --glass-strong: rgba(255, 255, 255, .92);
  --shadow: 0 14px 36px rgba(16, 43, 76, .12);
  --shadow-soft: 0 4px 14px rgba(16, 43, 76, .08);
  --radius: 8px;
}
html { background: var(--bg); scroll-behavior: smooth; }
body { background: var(--bg); color: var(--text); letter-spacing: 0; }
body::before, body::after { content: none; }
button, input, select, textarea { letter-spacing: 0; }
button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: var(--brand-2);
  color: #fff;
  padding: 8px 12px;
  box-shadow: none;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease,
    transform 160ms ease, box-shadow 160ms ease;
}
button:hover:not(:disabled) { box-shadow: 0 5px 14px rgba(249, 115, 22, .2); transform: translateY(-1px); }
button:active:not(:disabled) { transform: translateY(0); }
button.secondary { background: #eaf0f7; color: var(--brand); border-color: var(--line); }
button.secondary:hover:not(:disabled) { background: #dde7f2; border-color: var(--line-strong); box-shadow: none; }
button.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
button.ghost:hover:not(:disabled) { background: rgba(16, 43, 76, .06); color: var(--brand); box-shadow: none; }
button.danger { background: #c62d38; color: #fff; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
summary:focus-visible, [role='button']:focus-visible { outline: 3px solid rgba(23, 105, 194, .28); outline-offset: 2px; }
input, select, textarea {
  min-height: 40px;
  background: #fff;
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: 7px;
  padding: 9px 10px;
  box-shadow: inset 0 1px 2px rgba(16, 43, 76, .03);
}
input::placeholder, textarea::placeholder { color: #8997a8; }
input:hover, select:hover, textarea:hover { border-color: rgba(16, 43, 76, .34); }
input[type='file'] { padding: 6px; background: var(--panel-2); }
input[type='checkbox'] { min-height: auto; accent-color: var(--brand-2); }
textarea { min-height: 92px; }
label { gap: 5px; color: #52647b; font-size: 12px; font-weight: 700; }
.shell { grid-template-rows: 68px minmax(0, 1fr); min-height: 100vh; }
.topbar {
  min-height: 68px;
  padding: 8px 14px;
  gap: 12px;
  border-bottom: 1px solid rgba(16, 43, 76, .12);
  background: var(--glass);
  -webkit-backdrop-filter: saturate(160%) blur(22px);
  backdrop-filter: saturate(160%) blur(22px);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .72), 0 8px 24px rgba(16, 43, 76, .08);
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand { min-width: 220px; gap: 10px; }
.brand img { width: 104px; height: 46px; object-fit: contain; border-radius: 7px; padding: 3px; box-shadow: 0 2px 8px rgba(16, 43, 76, .08); }
.brand h1 { color: var(--brand); font-size: 17px; line-height: 1.15; }
.brand p { color: var(--muted); font-size: 11px; }
.tabs { padding: 3px; gap: 3px; flex-wrap: nowrap; border: 1px solid var(--line); border-radius: 8px; background: rgba(227, 234, 243, .76); }
.tab { min-height: 34px; padding: 7px 11px; background: transparent; border: 0; color: var(--muted); }
.tab:hover:not(:disabled) { box-shadow: none; }
.tab.active { background: #fff; color: var(--brand); box-shadow: 0 2px 7px rgba(16, 43, 76, .11); }
.toolbar { gap: 6px; flex-wrap: nowrap; }
.toolbar button { min-height: 36px; padding: 7px 10px; }
.toolbar a { color: inherit; text-decoration: none; }
.toolbar svg, button svg { width: 17px; height: 17px; flex: 0 0 auto; stroke-width: 2; }
.layout {
  grid-template-columns: minmax(390px, 460px) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  min-height: 0;
  height: calc(100vh - 68px);
}
.sidebar {
  display: block;
  max-height: none;
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-right: 2px;
}
.panel { background: var(--panel); border-color: var(--line); border-radius: var(--radius); box-shadow: var(--shadow-soft); }
.sidebar > .panel { min-height: 100%; }
.panel-inner { padding: 13px; border-bottom: 1px solid rgba(16, 43, 76, .1); }
.panel-inner:last-child { border-bottom: 0; }
.panel h2, .panel h3 { color: var(--brand); letter-spacing: 0; }
.panel h2 { font-size: 17px; }
.panel h3 { font-size: 14px; }
#adminPanel .panel-inner > h2, #adminPanel .panel-inner > h3 { min-height: 28px; margin: 0; padding: 2px 0; cursor: pointer; }
#adminPanel .panel-inner > h2::after, #adminPanel .panel-inner > h3::after {
  content: 'Ocultar';
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 3px 7px;
  font-size: 10px;
}
#adminPanel .panel-inner.collapsed { padding-top: 9px; padding-bottom: 9px; }
#adminPanel .panel-inner.collapsed > h2::after, #adminPanel .panel-inner.collapsed > h3::after { content: 'Mostrar'; }
.muted { color: var(--muted); }
.small { font-size: 12px; line-height: 1.45; }
.grid-2, .grid-3 { gap: 9px; }
.stat { min-height: 66px; background: var(--panel-2); border-color: var(--line); padding: 10px; }
.stat span { color: var(--muted); font-size: 10px; letter-spacing: 0; }
.stat strong { margin-top: 4px; color: var(--brand); font-size: 19px; }
.stat.danger { border-color: rgba(180, 35, 47, .35); background: #fff7f7; }
.stat.warn { border-color: rgba(138, 100, 0, .35); background: #fffbeb; }
.stat.ok { border-color: rgba(8, 122, 91, .3); background: #f2fbf7; }
.row-card { background: var(--panel-2); border-color: var(--line); padding: 11px; }
.row-card:hover { border-color: var(--line-strong); }
.row-card.selected { border-color: rgba(23, 105, 194, .65); box-shadow: inset 3px 0 0 var(--focus); }
.row-title { color: var(--brand); }
.badge { background: #edf3f8; color: var(--brand); border-color: var(--line); }
.badge.ok { color: #087a5b; border-color: rgba(8, 122, 91, .3); background: #effaf5; }
.badge.warn { color: #765600; border-color: rgba(138, 100, 0, .3); background: #fff9e6; }
.badge.danger { color: #a11f2a; border-color: rgba(180, 35, 47, .3); background: #fff2f3; }
.badge.info { color: #b64d06; border-color: rgba(249, 115, 22, .32); background: #fff6ef; }
.linked-trip-summary, .account-compact { background: var(--panel-2); border-color: var(--line); }
.linked-trip-summary { padding: 10px; }
.meter { height: 6px; background: #dfe7ef; border: 0; }
.meter > span { background: var(--ok); }
.source-chip { color: var(--muted); letter-spacing: 0; }
.actions { gap: 7px; margin-top: 9px; }
.intel-strip { align-items: center; }
.table-wrap { overflow-x: auto; }
.expense-table { color: var(--text); }
.expense-table th { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.expense-table th, .expense-table td { padding: 8px 6px; border-color: var(--line); }
details { margin-top: 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-2); padding: 8px 10px; }
summary { color: var(--brand); cursor: pointer; font-size: 12px; font-weight: 800; }
dialog {
  color: var(--text);
  background: var(--glass-strong);
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: saturate(150%) blur(24px);
  backdrop-filter: saturate(150%) blur(24px);
}
dialog::backdrop { background: rgba(16, 43, 76, .32); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
#map { min-height: 100%; height: 100%; border-radius: 7px; background: #dbe5ee; }
.layout > .panel:last-child { min-width: 0; overflow: hidden; box-shadow: var(--shadow-soft); }
.maplibregl-ctrl-group { overflow: hidden; border: 1px solid rgba(16, 43, 76, .16); border-radius: 7px; box-shadow: var(--shadow-soft); }
.maplibregl-popup-content { color: var(--brand); border-radius: 7px; box-shadow: var(--shadow); }
.map-expanded .layout { grid-template-columns: 1fr; }
.login { background: var(--bg); }
.login-card {
  width: min(420px, 100%);
  background: var(--glass-strong);
  border-color: var(--line-strong);
  color: var(--text);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: saturate(155%) blur(24px);
  backdrop-filter: saturate(155%) blur(24px);
}
.feedback-success { color: var(--ok) !important; }
.feedback-error { color: var(--danger) !important; }
.production-host #btnSeed { display: none !important; }

@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(360px, 420px) minmax(0, 1fr); }
  .brand { min-width: 190px; }
  .brand img { width: 92px; }
  .toolbar button { padding-inline: 8px; }
}

@media (max-width: 980px) {
  .shell { display: block; }
  .topbar {
    min-height: 58px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    padding: 7px 9px;
    gap: 7px;
  }
  .brand { min-width: 0; gap: 8px; }
  .brand img { width: 82px; height: 38px; }
  .brand h1 { font-size: 15px; }
  .brand p { max-width: 155px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabs { justify-self: end; }
  .tab { min-height: 32px; padding: 6px 9px; font-size: 12px; }
  .toolbar {
    grid-column: 1 / -1;
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 1px;
    scrollbar-width: none;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar button { min-width: 38px; min-height: 36px; flex: 0 0 auto; }
  #btnRefreshData, #btnMapMode, #btnMailbox, #btnLogout { font-size: 0; }
  #btnRefreshData svg, #btnMapMode svg, #btnMailbox svg, #btnLogout svg { margin: 0; }
  #mailboxCount { font-size: 10px; position: absolute; transform: translate(12px, -11px); }
  #controlHomeLink button { font-size: 12px; }
  .layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100svh - 96px);
    padding: 8px;
    gap: 8px;
  }
  .sidebar { height: auto; overflow: visible; padding: 0; }
  .sidebar > .panel { min-height: 0; }
  .panel { box-shadow: none; }
  .panel-inner { padding: 12px; }
  #map { height: 42svh; min-height: 300px; }
  .layout > .panel:last-child { min-height: 300px; order: 2; }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat { min-height: 58px; padding: 8px; }
  .stat strong { font-size: 17px; }
  .row-head { align-items: flex-start; }
  .actions button { flex: 1 1 auto; }
  .expense-table { min-width: 520px; }
  #operatorPanel .expense-table { min-width: 470px; }
}

@media (max-width: 620px) {
  .brand img { width: 76px; }
  .brand h1 { font-size: 14px; }
  .brand p { font-size: 10px; max-width: 128px; }
  .tabs { padding: 2px; }
  .tab { padding-inline: 7px; }
  .layout { padding: 6px; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  #operatorTripActions .grid-2, #operatorExpensePanel .grid-2, #clientPanel .grid-2 { grid-template-columns: 1fr; }
  .panel-inner { padding: 11px; }
  .row-card { padding: 10px; }
  .mini-grid { grid-template-columns: 1fr 1fr; }
  .account-compact { grid-template-columns: 1fr; }
  dialog { width: calc(100vw - 12px); max-height: calc(100svh - 24px); }
  .dialog-inner { padding: 14px; }
}

@media (prefers-reduced-transparency: reduce) {
  .topbar, dialog, .login-card { background: #fff; -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  :root { --line: rgba(16, 43, 76, .35); --line-strong: rgba(16, 43, 76, .58); }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Local UX review: calmer surfaces and readable controls at every size. */
:root { --radius: 14px; }
.topbar { border-bottom-color: rgba(16,43,76,.09); }
.panel { border-radius: 16px; }
.row-card { border-radius: 12px; }
.row-card.selected { border-color: #1769c2; background: #f0f6ff; }
.stat { border-radius: 12px; }
#adminPanel > .panel-inner + .panel-inner { border-top: 1px solid var(--line); }
#adminPanel .panel-inner > h2, #adminPanel .panel-inner > h3 { min-height: 40px; margin-bottom: 8px; }
#adminPanel .panel-inner.collapsed > h2, #adminPanel .panel-inner.collapsed > h3 { margin-bottom: 0; }
#tripSearch { background: #f6f8fb; }
@media (max-width:980px) {
  #btnRefreshData, #btnMapMode, #btnMailbox, #btnLogout { font-size: 12px; }
  .toolbar { flex-wrap: wrap; overflow: visible; }
  .toolbar button { min-height: 44px; }
  #mailboxCount { position: static; transform: none; }
}
