:root, html[data-theme='light'] {
  color-scheme: light;
  --bg: #f8f6f1;
  --bg-accent: rgba(27, 107, 74, 0.1);
  --surface: #ffffff;
  --border: #ddd6c8;
  --border-soft: #ebe4d6;
  --text: #1f2421;
  --muted: #6b7280;
  --primary: #1b6b4a;
  --primary-hover: #145a3e;
  --primary-soft: rgba(27, 107, 74, 0.14);
  --accent-warm: #c9a227;
  --sidebar-bg: #f3efe6;
  --shadow: 0 2px 12px rgba(31, 36, 33, 0.07);
  --card-shadow: 0 4px 20px rgba(31, 36, 33, 0.09);
  --input-bg: #ffffff;
  --error-bg: #fef2f2;
  --error-text: #dc2626;
  --warn-bg: #fffbeb;
  --radius: 10px;
}

html[data-theme='dark'] {
  color-scheme: dark;
  --bg: #121614;
  --bg-accent: rgba(61, 153, 112, 0.12);
  --surface: #1a1f1c;
  --border: #2f3832;
  --border-soft: #252b27;
  --text: #eef2ef;
  --muted: #9ca89f;
  --primary: #3d9970;
  --primary-hover: #52b388;
  --primary-soft: rgba(61, 153, 112, 0.18);
  --accent-warm: #d4b84a;
  --sidebar-bg: #0f1210;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --card-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --input-bg: #141816;
  --error-bg: rgba(248, 81, 73, 0.12);
  --error-text: #ff8a84;
  --warn-bg: rgba(201, 162, 39, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

.app-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(ellipse 100% 80% at 50% -30%, var(--bg-accent), transparent 55%), var(--bg);
}

.toolbar-import { margin-bottom: 0; }
.panel-import { margin-bottom: 1rem; }
.panel-import h3 { margin: 0 0 0.5rem; }
.import-status { margin: 0.75rem 0 0; padding: 0.6rem 0.75rem; background: var(--primary-soft); border-radius: 8px; }
.file-label { cursor: pointer; margin: 0; }
.file-label input { display: none; }

.hidden { display: none !important; }

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--card-shadow);
}

.auth-card h1 { margin: 0 0 0.25rem; font-size: 1.5rem; color: var(--primary); }
.auth-topbar { display: flex; justify-content: flex-end; margin-bottom: 0.75rem; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.9rem; margin-bottom: 0.35rem; color: var(--muted); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: var(--input-bg);
  color: var(--text);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

.form-inline { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.form-inline .form-group { flex: 1; min-width: 140px; margin-bottom: 0; }

.hint { color: var(--muted); font-size: 0.85rem; margin: 0.5rem 0 0; }
.hint code { font-size: 0.8rem; }

.error-msg {
  margin-top: 0.75rem;
  padding: 0.6rem 0.8rem;
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: 8px;
  font-size: 0.9rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

.theme-picker { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.theme-picker-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.35rem 0.55rem;
  font-size: 0.75rem;
  cursor: pointer;
}
.theme-picker-btn.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.theme-picker-wrap { margin-bottom: 0.75rem; }
.theme-picker-label { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.35rem; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.75rem;
}

.brand { padding: 0 0.5rem 1rem; border-bottom: 1px solid var(--border-soft); margin-bottom: 0.75rem; }
.brand-logo-wrap { display: flex; justify-content: center; margin-bottom: 0.65rem; }
.brand-logo {
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
  padding: 4px;
  box-shadow: var(--shadow);
}
.brand-logo--full {
  width: 100%;
  max-width: 240px;
  height: auto;
}
.brand-logo--crest {
  width: 72px;
  height: 72px;
}
.page-header-logo.brand-logo--crest {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
}
.brand-title { margin: 0; font-size: 1.05rem; color: var(--primary); text-align: center; }
.brand-tagline { margin: 0.25rem 0 0; font-size: 0.8rem; color: var(--muted); text-align: center; }

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 0.25rem; }

.nav-btn {
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.75rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.nav-btn:hover { background: var(--primary-soft); }
.nav-btn.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-btn-link {
  display: block;
  text-decoration: none;
  box-sizing: border-box;
}

.user-box {
  padding: 0.75rem 0.5rem 0;
  border-top: 1px solid var(--border-soft);
  font-size: 0.9rem;
}
.user-role { display: block; color: var(--muted); font-size: 0.8rem; margin: 0.15rem 0 0.5rem; }

.main { flex: 1; min-width: 0; padding: 1rem 1.25rem 2rem; }

.page-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.page-header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}
.page-header-logo {
  flex-shrink: 0;
}
html[data-theme='dark'] .brand-logo { background: #fff; }
.page-header h2 { margin: 0; font-size: 1.35rem; }

.btn-mobile-menu {
  display: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font-size: 1.1rem;
  cursor: pointer;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.input-search {
  flex: 1;
  min-width: 180px;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.panel h3 { margin: 0 0 0.75rem; font-size: 1rem; }

.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 800px) { .panel-grid { grid-template-columns: 1fr; } }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.stat-label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.35rem; }
.stat-value { font-size: 1.4rem; color: var(--primary); }
.stat-card strong.stat-value { color: var(--primary); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border-soft); border-radius: var(--radius); background: var(--surface); }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { padding: 0.65rem 0.85rem; text-align: left; border-bottom: 1px solid var(--border-soft); }
.data-table th { background: var(--bg); color: var(--muted); font-weight: 600; font-size: 0.8rem; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table .empty { text-align: center; color: var(--muted); padding: 2rem; }
.data-table .actions { white-space: nowrap; }
.data-table .cell-itens { max-width: 220px; }

.row-muted { opacity: 0.55; }
.row-warn { background: var(--warn-bg); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-ok { background: #dcfce7; color: #166534; }
.badge-off { background: var(--border-soft); color: var(--muted); }
.badge-warn { background: #fef3c7; color: #92400e; }
html[data-theme='dark'] .badge-ok { background: rgba(34, 197, 94, 0.2); color: #86efac; }
html[data-theme='dark'] .badge-warn { background: rgba(251, 191, 36, 0.2); color: #fcd34d; }

.simple-list { margin: 0; padding-left: 1.2rem; }
.simple-list li { margin-bottom: 0.35rem; }

.turnos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.turno-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
}

.turno-card--fechado { border-color: rgba(27, 107, 74, 0.35); }

.turno-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.turno-card-header h3 { margin: 0; font-size: 1.05rem; color: var(--primary); }
.turno-janela { font-size: 0.75rem; color: var(--muted); }
.turno-meta { margin: 0.5rem 0; font-size: 0.9rem; }
.turno-pagamentos { margin: 0.5rem 0 0; padding-left: 1.1rem; font-size: 0.85rem; color: var(--muted); }
.turno-fechamento-resumo { margin-top: 0.75rem; }

.turno-relatorio { margin: 0.75rem 0; }
.turno-relatorio h4 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 600;
}
.turno-relatorio-vazio { margin: 0.5rem 0; }
.turno-relatorio-table { font-size: 0.88rem; }
.turno-relatorio-table tfoot td { border-top: 2px solid var(--border); background: var(--primary-soft); }
.turno-relatorio--modal { max-height: 200px; overflow: auto; margin-bottom: 0.75rem; }
.table-wrap--compact { margin: 0; }
.data-table .num { text-align: right; white-space: nowrap; }
.fechamento-diff.ok { color: var(--primary); }
.fechamento-diff.warn { color: var(--error-text); font-weight: 600; }

.modal.hidden { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

body.modal-open { overflow: hidden; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }
.modal-card {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--card-shadow);
}
.modal-card h3 { margin: 0 0 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

.app-toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: #1a1d26;
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 200;
  transition: transform 0.25s ease;
  max-width: min(90vw, 420px);
  text-align: center;
}
.app-toast.visible { transform: translateX(-50%) translateY(0); }
.app-toast[data-type='error'] { background: #dc2626; }
.app-toast[data-type='success'] { background: #16a34a; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
}

@media (max-width: 900px) {
  .btn-mobile-menu { display: inline-flex; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--card-shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop:not(.hidden) { display: block; }
}
