/* MartinsConnect ERP — App-level overrides and global rules */
/* Kit-level additions on top of components.css. Keep thin. */

/* Loading / auth-redirect state */
.mc-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  gap: var(--space-3);
}

.mc-spinner {
  width: var(--space-5);
  height: var(--space-5);
  border: 2px solid var(--color-border);
  border-top-color: var(--color-brand);
  border-radius: var(--radius-full);
  animation: mc-spin 0.7s linear infinite;
  animation-play-state: running;
}
.mc-loading[hidden] .mc-spinner,
.mc-loading[aria-hidden="true"] .mc-spinner {
  animation-play-state: paused;
}

@keyframes mc-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .mc-spinner { animation: none; opacity: 0.6; }
}

/* Health check result inline block */
.mc-health-result {
  margin-top: var(--space-3);
  padding: var(--space-2-5) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  border: var(--border-width) solid var(--color-border);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  min-height: 36px;
}

/* Placeholder cards ("em construção") */
.card-placeholder {
  opacity: 0.5;
  pointer-events: none;
  user-select: none;
  position: relative;
}
.card-placeholder[aria-disabled="true"]::after {
  content: 'Em breve';
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: inline-flex;
  align-items: center;
  padding: var(--space-0-5) var(--space-2);
  border-radius: var(--radius-full);
  background: var(--slate-100);
  color: var(--slate-700);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold, 600);
  letter-spacing: var(--tracking-wide, 0.025em);
}

/* Form-level error message (a11y: anúncio via role=alert) */
.form-error {
  font-size: var(--text-xs);
  color: var(--color-danger-text);
  display: none;
  margin-top: var(--space-1);
}
.form-error.is-active { display: block; }

/* Visually hidden (a11y) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ---------- Phase 4b screens: chat, branding, metrics, hoshin ---------- */

/* Chat */
.chat-shell {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 220px);
  height: calc(100dvh - 220px);
  min-height: 360px;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-bg-card);
}
.chat-transcript {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.chat-msg {
  max-width: 80%;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  border: var(--border-width) solid var(--color-border);
  background: var(--color-bg);
}
.chat-msg.chat-user      { align-self: flex-end; background: var(--color-brand-soft, var(--navy-50)); }
.chat-msg.chat-assistant { align-self: flex-start; }
.chat-msg-header {
  display: flex; justify-content: space-between; gap: var(--space-2);
  font-size: var(--text-xs); color: var(--color-text-muted); margin-bottom: var(--space-1);
}
.chat-msg-body { white-space: pre-wrap; word-wrap: break-word; line-height: 1.5; }
.chat-status {
  padding: var(--space-1) var(--space-3);
  border-top: var(--border-width) solid var(--color-border);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
.chat-status-ok   { color: var(--color-success-text-strong); }
.chat-status-warn { color: var(--color-warning-text-strong); }
.chat-status-err  { color: var(--color-danger-text); }
.chat-composer {
  display: flex; gap: var(--space-2);
  padding: var(--space-3);
  border-top: var(--border-width) solid var(--color-border);
  background: var(--color-bg);
}
.chat-composer textarea {
  flex: 1 1 auto; resize: none;
  padding: var(--space-2);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-sm);
  font: inherit;
}

/* Branding form-grid + form-row + form-field */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-3);
}
.form-row {
  display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap;
  margin-bottom: var(--space-3);
}
.form-row > select, .form-row > input {
  flex: 1 1 200px;
}
.form-field { display: flex; flex-direction: column; gap: var(--space-1); }
.form-label { font-size: var(--text-xs); color: var(--color-text-muted); }
.form-field input,
.form-row input,
.form-row select {
  padding: var(--space-2);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-sm);
  font: inherit;
}
.card { padding: var(--space-4); border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md); background: var(--color-bg-card); margin-bottom: var(--space-4); }
.card-title { font-size: var(--text-md); margin: 0 0 var(--space-3); }
.card-actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); }
.page-banner { padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm);
  margin-bottom: var(--space-3); border: var(--border-width) solid var(--color-border); background: var(--color-bg-card); }
.page-banner-ok  { border-color: var(--success-400); background: var(--success-100); color: var(--color-success-text-strong); }
.page-banner-warn { border-color: var(--warning-400); background: var(--warning-100); color: var(--color-warning-text-strong); }
.page-banner-err { border-color: var(--danger-400); background: var(--danger-100); color: var(--color-danger-text-strong); }

/* Metrics chart */
.chart-host { padding: var(--space-3); }
.chart { width: 100%; height: auto; max-height: 300px; }

/* Hoshin matrix */
.hoshin-host { margin-top: var(--space-4); }
.hoshin-grid {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  grid-template-rows: 1fr 2fr 1fr;
  gap: var(--space-2);
  min-height: 480px;
}
.hoshin-cell {
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  background: var(--color-bg-card);
  overflow: auto;
}
.hoshin-north  { grid-column: 2; grid-row: 1; }
.hoshin-west   { grid-column: 1; grid-row: 2; }
.hoshin-center { grid-column: 2; grid-row: 2; display: flex; align-items: center;
                 justify-content: center; text-align: center;
                 background: var(--color-brand-soft); }
.hoshin-east   { grid-column: 3; grid-row: 2; }
.hoshin-south  { grid-column: 2; grid-row: 3; }
.hoshin-side-title { font-size: var(--text-sm); color: var(--color-text-muted); margin: 0 0 var(--space-2); }
.hoshin-title { margin: 0; font-size: var(--text-lg); }
.hoshin-cells { list-style: disc; padding-left: 1.4em; margin: 0; }
.hoshin-cells li { padding: 2px 0; }
.empty-cell { color: var(--color-text-muted); font-style: italic; list-style: none; }

/* Notification bell + toast host */
.navbar-bell { position: relative; }
.navbar-bell-badge {
  position: absolute;
  top: 2px; right: 2px;
  min-width: var(--space-4); height: var(--space-4);
  border-radius: var(--radius-full);
  background: var(--color-danger); color: #fff;
  font-size: var(--text-2xs); line-height: var(--space-4);
  padding: 0 var(--space-1); text-align: center;
  pointer-events: none;
}

.toast-host {
  position: fixed;
  right: var(--space-4); bottom: var(--space-4);
  display: flex; flex-direction: column; gap: var(--space-2);
  z-index: var(--z-toast);
}
.toast {
  background: var(--color-bg-card, var(--color-surface));
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2-5) var(--space-3-5);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-md);
  min-width: 220px;
  transition: opacity var(--duration-300) var(--ease-out),
              transform var(--duration-300) var(--ease-out);
}
.toast-ok  { border-color: var(--success-400); }
.toast-err { border-color: var(--danger-400); }
.toast-out { opacity: 0; transform: translateX(20px); }

/* Signup page — pre-auth, no shell */
.signup-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--color-bg);
  padding: var(--space-4);
}
.signup-card {
  background: var(--color-bg-card, var(--color-surface));
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-8) var(--space-7);
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.signup-brand { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-6); }
.signup-wordmark { font-size: var(--text-base); font-weight: 600; color: var(--color-text-strong); }
.signup-title { margin: 0 0 var(--space-1-5); font-size: var(--text-xl); }
.signup-subtitle { margin: 0 0 var(--space-5); color: var(--color-text-muted); font-size: var(--text-sm); line-height: 1.4; }
.signup-actions { margin-top: var(--space-4); }
.signup-actions .btn { width: 100%; }
.signup-login { margin: var(--space-4) 0 0; font-size: var(--text-xs); color: var(--color-text-muted); text-align: center; }
.signup-login a { color: var(--color-brand); text-decoration: none; }
.signup-login a:hover { text-decoration: underline; }

/* ---------- Phase 6 admin screens: tenants, users, settings ---------- */

/* Status badges */
.tenant-badge { display: inline-block; padding: 2px var(--space-2); border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: 600; }
.badge-active       { background: var(--success-100); color: var(--color-success-text-strong); }
.badge-provisioning { background: var(--warning-100); color: var(--color-warning-text-strong); }
.badge-suspended    { background: var(--danger-100);  color: var(--color-danger-text-strong); }

/* Tenant card grid */
.tenant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4); margin-bottom: var(--space-4); }
.tenant-card-top  { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-2); }
.tenant-card-name { margin: 0; font-size: var(--text-md); }
.tenant-card-slug { margin: 0; font-size: var(--text-sm); color: var(--color-text-muted); font-family: var(--font-mono); }
.tenant-card-meta { margin: 0 0 var(--space-2); font-size: var(--text-xs); color: var(--color-text-muted); }

/* Users two-column layout */
.users-layout { display: grid; grid-template-columns: 280px 1fr; gap: var(--space-4); align-items: start; }
@media (max-width: 700px) { .users-layout { grid-template-columns: 1fr; } }
.users-left  { border: var(--border-width) solid var(--color-border); border-radius: var(--radius-md);
  overflow: hidden; background: var(--color-bg-card); }
.users-right { min-height: 200px; }
.users-list  { list-style: none; margin: 0; padding: 0; }
.users-list-item { padding: var(--space-2-5) var(--space-3); cursor: pointer;
  border-bottom: var(--border-width) solid var(--color-border); display: flex; justify-content: space-between; align-items: center; }
.users-list-item:last-child { border-bottom: none; }
.users-list-item:hover  { background: var(--color-bg); }
.users-list-item.active { background: var(--color-brand-soft, var(--navy-50)); }
.users-list-email  { font-size: var(--text-sm); word-break: break-all; }
.users-list-status { font-size: var(--text-xs); color: var(--color-text-muted); margin-left: var(--space-2); flex-shrink: 0; }
.users-list-item.active .users-list-status { color: var(--navy-600); }
[data-theme="dark"] .users-list-item.active .users-list-status { color: var(--navy-200); }
.users-list-empty  { padding: var(--space-4); color: var(--color-text-muted); font-size: var(--text-sm); text-align: center; }
.users-left .card-title { padding: var(--space-3); margin: 0; border-bottom: var(--border-width) solid var(--color-border); font-size: var(--text-sm); }
.detail-title-row { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-3); }
.memberships-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.memberships-item { display: flex; justify-content: space-between; align-items: center;
  padding: var(--space-2) var(--space-3); background: var(--color-bg);
  border: var(--border-width) solid var(--color-border); border-radius: var(--radius-sm); }
.memberships-empty { color: var(--color-text-muted); font-size: var(--text-sm); font-style: italic; }

/* Settings tabs */
.settings-tabs { display: flex; border-bottom: var(--border-width) solid var(--color-border); margin-bottom: var(--space-4); }
.settings-tab-btn { padding: var(--space-2-5) var(--space-4); border: none; background: none; cursor: pointer;
  font: inherit; font-size: var(--text-sm); color: var(--color-text-secondary);
  border-bottom: var(--border-width-2) solid transparent; margin-bottom: -1px;
  transition: color var(--duration-150) var(--ease-out), border-color var(--duration-150) var(--ease-out); }
.settings-tab-btn:hover  { color: var(--color-text-strong); }
.settings-tab-btn.active { color: var(--color-brand); border-bottom-color: var(--color-brand); font-weight: 600; }
.settings-readonly { font-size: var(--text-sm); color: var(--color-text-secondary); padding: var(--space-1) 0; }
.pref-row { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3);
  padding: var(--space-2-5) 0; border-bottom: var(--border-width) solid var(--color-border); }
.pref-row:last-child { border-bottom: none; }
.pref-info    { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.pref-type    { font-size: var(--text-xs); color: var(--color-text-muted); font-family: var(--font-mono); }
.pref-val-wrap { display: flex; gap: var(--space-2); align-items: center; flex-shrink: 0; }
.pref-input   { width: 180px; padding: var(--space-1-5) var(--space-2);
  border: var(--border-width) solid var(--color-border); border-radius: var(--radius-sm); font: inherit; }

/* ---------- Phase 6 polish: chat tool-call cards ---------- */
.chat-tool-card {
  align-self: flex-start;
  max-width: 90%;
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
}
.chat-tool-header {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap;
}
.chat-tool-badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  background: var(--slate-100); border: var(--border-width) solid var(--slate-300);
  border-radius: var(--radius-full); padding: 2px var(--space-2);
  font-size: var(--text-xs); font-weight: 600; color: var(--slate-700);
}
.chat-tool-toggle {
  background: none; border: none; cursor: pointer;
  font: inherit; font-size: var(--text-xs);
  color: var(--color-brand); text-decoration: underline;
  padding: 0;
}
.chat-tool-toggle:hover { opacity: 0.75; }
.chat-tool-body, .chat-tool-pre {
  margin: var(--space-1) 0 0;
}
.chat-tool-pre {
  background: var(--slate-50); border: var(--border-width) solid var(--slate-200);
  border-radius: var(--radius-sm);
  padding: var(--space-2); font-family: var(--font-mono);
  font-size: var(--text-xs); white-space: pre-wrap; word-break: break-all;
  max-height: 200px; overflow-y: auto;
}
.chat-tool-result-row {
  display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-1);
}
.chat-tool-success {
  display: inline-block; padding: 1px 7px;
  border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: 600;
  background: var(--success-100); color: var(--color-success-text-strong); border: var(--border-width) solid var(--success-400);
}
.chat-tool-fail {
  display: inline-block; padding: 1px 7px;
  border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: 600;
  background: var(--danger-100); color: var(--color-danger-text-strong); border: var(--border-width) solid var(--danger-400);
}

/* ---------- Phase 6 polish: branding live preview ---------- */
.brand-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  align-items: start;
}
@media (max-width: 760px) { .brand-layout { grid-template-columns: 1fr; } }
.brand-preview-wrap { min-height: 240px; }
.brand-preview {
  display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-3);
  border: var(--border-width) solid var(--color-border); border-radius: var(--radius-md);
  background: var(--slate-50); min-height: 180px;
}
.brand-preview-logo-row { min-height: 40px; display: flex; align-items: center; }
.brand-preview-logo-placeholder {
  height: 40px; width: 80px;
  background: var(--slate-200); border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs); color: var(--slate-400); font-weight: 600; letter-spacing: 1px;
}
.brand-preview-heading {
  margin: 0; font-size: var(--text-md); font-weight: 600;
  color: var(--color-text-strong);
}
.brand-preview-cta {
  align-self: flex-start;
  padding: var(--space-1-5) var(--space-3);
  border: var(--border-width-2) solid var(--slate-400); border-radius: var(--radius-sm);
  background: var(--slate-400); color: #fff; cursor: default;
  font: inherit; font-size: var(--text-sm); font-weight: 600;
}
.brand-preview-secondary {
  margin: 0; font-size: var(--text-sm); color: var(--color-text-muted);
}
.brand-preview-accent {
  display: inline-block; padding: 2px var(--space-2-5);
  border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: 600;
  background: var(--slate-400); color: #fff;
}
.brand-preview-hint {
  margin: 0; font-size: var(--text-xs); color: var(--color-danger-text);
  font-style: italic;
}

/* ---------- Financial Dashboard hero (fd-*) ---------- */

.fd-hero {
  position: relative;
  padding: var(--space-5) var(--space-5) var(--space-5) var(--space-6);
  margin-bottom: var(--space-6);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: var(--space-6);
  align-items: start;
}
.fd-hero::before {
  content: "";
  position: absolute;
  left: 0;
  top: var(--space-5);
  bottom: var(--space-5);
  width: 3px;
  background: var(--navy-700);
  border-radius: 0 2px 2px 0;
}
[data-theme="dark"] .fd-hero::before { background: var(--gold-400); }

.fd-hero-head { display: flex; flex-direction: column; gap: var(--space-2); }
.fd-hero-title {
  font-size: var(--h3-size);
  font-weight: var(--h3-weight);
  line-height: var(--h3-leading);
  letter-spacing: var(--h3-tracking);
  color: var(--color-text-primary);
  margin: 0;
}
.fd-hero-loading {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin: var(--space-2) 0 0;
}
.fd-hero--clear {
  grid-template-columns: 1fr;
}
.fd-hero-clear-text {
  font-size: var(--h4-size);
  font-weight: var(--h4-weight);
  color: var(--color-text-primary);
  margin: var(--space-2) 0 0;
  line-height: var(--h4-leading);
}

.fd-hero-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  border-left: var(--border-width) solid var(--color-border-subtle);
  padding-left: var(--space-5);
}
.fd-hero-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: baseline;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-2) 0;
  border-bottom: var(--border-width) solid var(--color-border-subtle);
  text-decoration: none;
  color: var(--color-text-primary);
  font-size: var(--text-sm);
  transition: color var(--duration-150) var(--ease-out);
}
.fd-hero-rows .fd-hero-row:last-child { border-bottom: none; }
.fd-hero-row:hover { color: var(--navy-700); }
[data-theme="dark"] .fd-hero-row:hover { color: var(--gold-400); }
.fd-hero-row:focus-visible {
  outline: var(--ring-width) solid var(--ring-color);
  outline-offset: var(--ring-offset);
  border-radius: var(--radius-sm);
}
.fd-hero-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  align-self: center;
  flex-shrink: 0;
}
.fd-hero-text {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
}
.fd-hero-link {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.fd-hero-row:hover .fd-hero-link { color: inherit; }

@media (max-width: 900px) {
  .fd-hero { grid-template-columns: 1fr; }
  .fd-hero-rows { border-left: 0; padding-left: 0; }
}

/* Editorial summary block (replaces stat-grid template) */
.fd-summary {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: var(--space-8);
  align-items: end;
  padding: var(--space-2) 0 var(--space-5);
}
.fd-figure { display: flex; flex-direction: column; gap: var(--space-1-5); margin: 0; min-width: 0; }
.fd-figure .caption { margin: 0; }
.fd-figure-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  margin: 0;
}
.fd-figure-value.income { color: var(--success-600); }
.fd-figure-value.expense { color: var(--danger-600); }
[data-theme="dark"] .fd-figure-value.income { color: var(--color-success-text); }
[data-theme="dark"] .fd-figure-value.expense { color: var(--color-danger-text); }
.fd-figure-context {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin: 0;
  max-width: 48ch;
  line-height: 1.5;
}
.fd-figure--primary .fd-figure-value {
  font-size: var(--text-4xl);
  letter-spacing: -0.025em;
  line-height: 1;
}
.fd-figure-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-5) var(--space-6);
  margin: 0;
  padding: 0;
  border-left: var(--border-width) solid var(--color-border-subtle);
  padding-left: var(--space-6);
}
.fd-figure-strip .fd-figure-value { font-size: var(--text-xl); }

@media (max-width: 900px) {
  .fd-summary { grid-template-columns: 1fr; gap: var(--space-5); }
  .fd-figure-strip { border-left: 0; padding-left: 0; padding-top: var(--space-4); border-top: var(--border-width) solid var(--color-border-subtle); }
}

.fd-divider {
  border: 0;
  border-top: var(--border-width) solid var(--color-border);
  margin: 0 0 var(--space-6);
}

/* ---------- Select chevron (Task D) ---------- */
/* Static slate-500 stroke is the only acceptable hex literal here —
   inline SVG can't read CSS custom properties. Dark variant uses slate-400. */
select.input,
select.form-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding-right: var(--space-9);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 16px 16px;
}
[data-theme="dark"] select.input,
[data-theme="dark"] select.form-input {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
}
select.input::-ms-expand { display: none; }

/* date inputs already inherit .input focus ring; ensure consistent indicator color in dark mode */
[data-theme="dark"] input[type="date"].input::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="datetime-local"].input::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="time"].input::-webkit-calendar-picker-indicator {
  filter: invert(0.85);
}

/* ========== Finanças Dashboard — widget grid (fd-grid / fd-widget) ========== */

.fd-range {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky, 10);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.fd-range-quick { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.fd-range-quick .btn.is-active {
  background: var(--navy-700);
  color: var(--color-text-inverse);
  border-color: var(--navy-700);
}
[data-theme="dark"] .fd-range-quick .btn.is-active {
  background: var(--gold-400);
  color: var(--slate-900);
  border-color: var(--gold-400);
}
.fd-range-custom { display: flex; flex-wrap: wrap; align-items: end; gap: var(--space-3); }
.fd-range-field { display: flex; flex-direction: column; gap: var(--space-1); }
.fd-range-field .caption { margin: 0; }

.fd-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--space-6);
}
.fd-grid-actions  { grid-column: span 8; }
.fd-grid-saldo    { grid-column: span 4; }
.fd-grid-result   { grid-column: span 8; }
.fd-grid-fluxo    { grid-column: span 4; }
.fd-grid-vencidos { grid-column: span 8; }
.fd-grid-hist     { grid-column: span 4; }
.fd-grid-rent     { grid-column: span 12; }

.fd-widget {
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0;
}
.fd-widget--span-4  { grid-column: span 4; }
.fd-widget--span-6  { grid-column: span 6; }
.fd-widget--span-8  { grid-column: span 8; }
.fd-widget--span-12 { grid-column: span 12; }

.fd-widget-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: var(--space-2) var(--space-3);
}
.fd-widget-eyebrow {
  grid-column: 1 / -1;
  margin: 0;
}
.fd-widget-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text-primary);
  margin: 0;
}
.fd-widget-drill {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: color var(--duration-150) var(--ease-out);
}
.fd-widget-drill:hover { color: var(--navy-700); }
[data-theme="dark"] .fd-widget-drill:hover { color: var(--gold-400); }
.fd-widget-drill:focus-visible {
  outline: var(--ring-width) solid var(--ring-color);
  outline-offset: var(--ring-offset);
  border-radius: var(--radius-sm);
}

.fd-widget-body { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.fd-widget-foot { display: flex; justify-content: flex-end; }

.fd-stat {
  font-family: var(--font-mono, "Fira Code"), ui-monospace, monospace;
  font-size: var(--text-3xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin: 0;
  color: var(--navy-700);
}
[data-theme="dark"] .fd-stat { color: var(--gold-400); }
.fd-stat.income { color: var(--success-600); }
.fd-stat.expense { color: var(--danger-600); }
[data-theme="dark"] .fd-stat.income { color: var(--color-success-text); }
[data-theme="dark"] .fd-stat.expense { color: var(--color-danger-text); }

.fd-prose {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin: 0;
  line-height: 1.5;
}
.fd-prose--muted { color: var(--color-text-muted); }

.fd-hero-actions { margin-top: var(--space-3); display: flex; gap: var(--space-2); }
.fd-hero-rows--bare { border-left: 0; padding-left: 0; }

/* Skeleton classes moved to components.css; only the error helper remains. */
.fd-widget-error { width: 100%; justify-content: space-between; }

/* Stale-while-revalidate dimming applied to fd-widget during refetch. */
.fd-stale {
  opacity: 0.6;
  pointer-events: none;
  transition: opacity var(--duration-200) var(--ease-out);
}
@media (prefers-reduced-motion: reduce) {
  .fd-stale { transition: none; }
}

/* ── Histórico strip ── */
.fd-hist-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--space-2);
}
.fd-hist-cell {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  border: var(--border-width) solid var(--color-border-subtle);
  text-align: center;
  min-width: 0;
}
.fd-hist-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: lowercase;
  margin: 0;
}
.fd-hist-value {
  font-family: var(--font-mono, "Fira Code"), ui-monospace, monospace;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fd-hist-value.income { color: var(--success-600); }
.fd-hist-value.expense { color: var(--danger-600); }
[data-theme="dark"] .fd-hist-value.income { color: var(--color-success-text); }
[data-theme="dark"] .fd-hist-value.expense { color: var(--color-danger-text); }

/* ── Rentabilidade table ── */
.fd-rent-table .income { color: var(--success-600); }
.fd-rent-table .expense { color: var(--danger-600); }
[data-theme="dark"] .fd-rent-table .income { color: var(--color-success-text); }
[data-theme="dark"] .fd-rent-table .expense { color: var(--color-danger-text); }

/* ── Fluxo chart ── */
.fd-chart { width: 100%; height: auto; max-height: 180px; display: block; }
.fd-chart-line { stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.fd-chart-line--in  { stroke: var(--navy-700); }
.fd-chart-line--out { stroke: var(--slate-500); }
[data-theme="dark"] .fd-chart-line--in  { stroke: var(--gold-400); }
[data-theme="dark"] .fd-chart-line--out { stroke: var(--slate-400); }
.fd-chart-legend {
  display: flex; gap: var(--space-4);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  align-items: center;
  margin-top: var(--space-2);
}
.fd-chart-swatch {
  display: inline-block; width: 14px; height: 2px;
  background: var(--navy-700);
  margin-right: var(--space-1-5);
  vertical-align: middle;
}
.fd-chart-swatch--out { background: var(--slate-500); }
[data-theme="dark"] .fd-chart-swatch { background: var(--gold-400); }
[data-theme="dark"] .fd-chart-swatch--out { background: var(--slate-400); }

/* ── Breadcrumb spacing for drill sub-routes ── */
.fd-breadcrumb { margin-bottom: var(--space-4); }

/* ── Tablet: 2-col layout ── */
@media (max-width: 1024px) {
  .fd-grid { grid-template-columns: repeat(12, 1fr); }
  .fd-grid-actions  { grid-column: span 8; }
  .fd-grid-saldo    { grid-column: span 4; }
  .fd-grid-result   { grid-column: span 8; }
  .fd-grid-fluxo    { grid-column: span 4; }
  .fd-grid-vencidos { grid-column: span 12; }
  .fd-grid-hist     { grid-column: span 12; }
  .fd-grid-rent     { grid-column: span 12; }
}

/* ── Mobile: single column, priority-ordered ── */
@media (max-width: 768px) {
  .fd-grid { grid-template-columns: 1fr; gap: var(--space-4); }
  .fd-grid > * { grid-column: 1 / -1; }
  .fd-grid-actions  { order: 1; }
  .fd-grid-saldo    { order: 2; }
  .fd-grid-result   { order: 3; }
  .fd-grid-vencidos { order: 4; }
  .fd-grid-fluxo    { order: 5; }
  .fd-grid-hist     { order: 6; }
  .fd-grid-rent     { order: 7; }
  .fd-range { flex-direction: column; align-items: stretch; }
  .fd-range-custom { flex-wrap: wrap; }
  .fd-hist-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Reduced-motion rules for skeleton primitives live in components.css. */

/* ========== CMD+K COMMAND PALETTE ========== */

.cmd-k-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal-backdrop);
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh var(--space-4) var(--space-4);
  animation: cmd-k-fade var(--duration-150) var(--ease-out);
}
.cmd-k-backdrop.reduce-motion { animation: none; }

@keyframes cmd-k-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.cmd-k-modal {
  width: 100%;
  max-width: 600px;
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2xl);
  display: flex;
  flex-direction: column;
  max-height: 70vh;
  overflow: hidden;
  z-index: var(--z-modal);
}
[data-theme="dark"] .cmd-k-modal {
  background: var(--slate-900);
  border-color: var(--slate-800);
}

.cmd-k-input-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-width) solid var(--color-border);
  flex-shrink: 0;
}
.cmd-k-input-wrap svg { color: var(--color-text-muted); flex-shrink: 0; }

.cmd-k-input {
  flex: 1 1 auto;
  border: 0;
  outline: 0;
  background: transparent;
  font-family: inherit;
  font-size: var(--text-md);
  color: var(--color-text-primary);
}
.cmd-k-input::placeholder { color: var(--color-text-muted); }

.cmd-k-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 80px;
}

.cmd-k-empty {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.cmd-k-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-primary);
  font-family: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--duration-150) var(--ease-out);
}
.cmd-k-item svg { color: var(--color-text-muted); flex-shrink: 0; }
.cmd-k-item-label { flex: 1 1 auto; }
.cmd-k-item-section {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}
.cmd-k-item[aria-selected="true"] {
  background: var(--navy-50);
  color: var(--navy-700);
}
.cmd-k-item[aria-selected="true"] svg { color: var(--navy-700); }
.cmd-k-item[aria-selected="true"] .cmd-k-item-section { color: var(--navy-700); }
[data-theme="dark"] .cmd-k-item[aria-selected="true"] {
  background: rgba(245, 204, 0, 0.10);
  color: var(--gold-400);
}
[data-theme="dark"] .cmd-k-item[aria-selected="true"] svg { color: var(--gold-400); }
[data-theme="dark"] .cmd-k-item[aria-selected="true"] .cmd-k-item-section { color: var(--gold-400); }

.cmd-k-footer {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-4);
  padding: var(--space-2-5) var(--space-4);
  border-top: var(--border-width) solid var(--color-border);
  font-size: var(--text-2xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  flex-shrink: 0;
}
.cmd-k-footer .kbd-hint {
  background: var(--slate-100);
  color: var(--color-text-secondary);
  border-color: var(--color-border);
}
[data-theme="dark"] .cmd-k-footer .kbd-hint {
  background: var(--slate-800);
  border-color: var(--slate-700);
  color: var(--slate-400);
}

@media (max-width: 540px) {
  .cmd-k-backdrop { padding: var(--space-4) var(--space-2); align-items: flex-start; }
  .cmd-k-modal { max-height: 90vh; }
}

@media (prefers-reduced-motion: reduce) {
  .cmd-k-backdrop { animation: none; }
}

/* ── Financial history drawer (Despesas/Receitas v3) ───────────────────── */
.mc-drawer-backdrop {
  position: fixed; inset: 0; z-index: var(--z-modal-backdrop, 900);
  background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(4px);
}
.mc-drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: var(--z-modal, 1000);
  width: 480px; max-width: 100vw;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transform: translateX(0);
  transition: transform var(--duration-200, 200ms) var(--ease-out, ease-out);
}
.mc-drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
}
.mc-drawer-title {
  font-size: var(--text-lg); font-weight: 600;
  color: var(--color-text); margin: 0;
  letter-spacing: var(--tracking-tight);
}
.mc-drawer-close {
  background: none; border: none; cursor: pointer;
  font-size: var(--text-2xl); line-height: 1;
  color: var(--color-text-muted);
  padding: var(--space-1) var(--space-2); border-radius: var(--radius-md);
}
.mc-drawer-close:hover { color: var(--color-text); background: var(--color-surface-hover); }
.mc-drawer-close:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.mc-drawer-body { flex: 1 1 auto; overflow-y: auto; padding: var(--space-5) var(--space-6); }
.mc-drawer-footer {
  display: flex; justify-content: flex-end; gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
}
.mc-drawer-loading, .mc-drawer-error { color: var(--color-text-muted); font-size: var(--text-sm); }

.fp-history-revision {
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--color-border);
}
.fp-history-revision:last-child { border-bottom: none; }
.fp-history-header {
  display: flex; align-items: baseline; gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.fp-history-version {
  font-family: var(--font-mono, "Fira Code", monospace);
  font-weight: 600; color: var(--color-text);
  background: var(--color-surface-hover); padding: 2px var(--space-2);
  border-radius: var(--radius-md); font-size: var(--text-xs);
}
.fp-history-meta { color: var(--color-text-muted); font-size: var(--text-sm); }
.fp-history-meta code {
  font-family: var(--font-mono, "Fira Code", monospace);
  font-size: var(--text-xs);
}
.fp-history-reason { font-style: italic; color: var(--color-text-muted); margin: var(--space-2) 0; font-size: var(--text-sm); }
.fp-history-creation, .fp-history-nochange {
  color: var(--color-text-muted); font-size: var(--text-sm); margin: var(--space-2) 0 0 0;
}
.fp-history-diff {
  list-style: none; padding: 0; margin: var(--space-2) 0 0 0;
  display: flex; flex-direction: column; gap: var(--space-2);
}
.fp-history-diff li {
  font-size: var(--text-sm);
  display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: baseline;
}
.fp-history-field { color: var(--color-text-muted); }
.fp-history-old   { color: var(--color-text-muted); text-decoration: line-through; font-variant-numeric: tabular-nums; }
.fp-history-new   { color: var(--color-text); font-weight: 500; font-variant-numeric: tabular-nums; }
.fp-history-arrow { color: var(--color-text-muted); }

@media (max-width: 640px) {
  .mc-drawer { width: 100vw; }
}
@media (prefers-reduced-motion: reduce) {
  .mc-drawer { transition: none; }
}

/* ── Mensal | Anual pill tabs ───────────────────────────────────────────── */
.fp-tabs {
  display: inline-flex; gap: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-surface);
  padding: 2px;
  margin: var(--space-3) 0;
}
.fp-tabs button {
  background: transparent; border: none; cursor: pointer;
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm); color: var(--color-text-muted);
  border-radius: var(--radius-full);
  font-weight: 500;
  transition: background var(--duration-150, 150ms) var(--ease-out, ease-out),
              color var(--duration-150, 150ms) var(--ease-out, ease-out);
}
.fp-tabs button[aria-pressed="true"] {
  background: var(--color-primary, var(--navy-700, #003566));
  color: var(--color-on-primary, #fff);
}
.fp-tabs button:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

.fp-history-badge {
  display: inline-block; margin-left: var(--space-2);
  font-family: var(--font-mono, "Fira Code", monospace);
  font-size: var(--text-xs); padding: 1px var(--space-2);
  border-radius: var(--radius-md);
  background: var(--color-surface-hover); color: var(--color-text);
  border: 1px solid var(--color-border);
  cursor: pointer;
}
.fp-history-badge:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
