:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --text: #17202a;
  --muted: #667085;
  --line: #e4e7ec;
  --primary: #0f8a5f;
  --primary-dark: #096847;
  --dark: #101828;
  --warn: #b42318;
  --blue: #155eef;
  --yellow: #b7791f;
  --radius: 16px;
  --shadow: 0 14px 40px rgba(16, 24, 40, .10);
}

body.dark-theme {
  --bg: #0f172a;
  --surface: #111c2f;
  --surface-2: #0b1220;
  --surface-3: #1f2a3d;
  --text: #f8fafc;
  --muted: #a8b3c7;
  --line: #273449;
  --dark: #020617;
  --shadow: 0 14px 40px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, Segoe UI, Arial, sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
input, select, textarea { color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
textarea { resize: vertical; min-height: 76px; }

.app-shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
.sidebar { background: #0b1220; color: #fff; padding: 20px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 28px; }
.brand-icon { width: 44px; height: 44px; display: grid; place-items: center; background: rgba(255,255,255,.12); border-radius: 14px; }
.brand strong { display: block; font-size: 16px; }
.brand span { display: block; color: #b6c2d1; font-size: 13px; margin-top: 2px; }
.nav-btn { width: 100%; text-align: left; border: 0; background: transparent; color: #d0d5dd; padding: 12px 14px; border-radius: 12px; margin-bottom: 6px; }
.nav-btn:hover, .nav-btn.active { background: rgba(255,255,255,.12); color: #fff; }
.sidebar-note { margin-top: 28px; padding: 14px; border-radius: 14px; background: rgba(255,255,255,.08); }
.sidebar-note strong, .sidebar-note span { display: block; }
.sidebar-note span { color: #b6c2d1; font-size: 12px; margin-top: 6px; line-height: 1.35; }

.main { padding: 22px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 20px; }
.title-block { min-width: 220px; }
h1 { margin: 0; font-size: 28px; letter-spacing: -.03em; }
h2 { margin: 0; font-size: 18px; }
p { margin: 6px 0 0; color: var(--muted); }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; }
.date-filter { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); font-weight: 700; }
.date-filter input { width: 150px; }
.btn { border: 0; border-radius: 12px; padding: 11px 14px; font-weight: 800; color: #fff; background: var(--primary); transition: transform .15s ease, opacity .15s ease; white-space: nowrap; }
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--primary); }
.btn.dark { background: var(--dark); }
.btn.secondary { background: var(--surface-3); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: #fee4e2; color: #b42318; border: 1px solid #fecdca; }
.btn.small { padding: 8px 10px; border-radius: 10px; font-size: 13px; }
.file-label { display: inline-block; }
.icon-btn { width: 36px; height: 36px; border: 0; border-radius: 10px; background: var(--surface-3); color: var(--text); font-size: 22px; }
.view { display: none; }
.view.active { display: block; }
.hint-box { background: color-mix(in srgb, var(--primary) 8%, var(--surface)); border: 1px solid color-mix(in srgb, var(--primary) 28%, var(--line)); color: var(--text); padding: 12px 14px; border-radius: 14px; margin-bottom: 14px; }

.kpi-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: 0 6px 18px rgba(16,24,40,.04); }
.kpi-card span { color: var(--muted); font-size: 13px; }
.kpi-card strong { display: block; font-size: 28px; margin-top: 8px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 18px rgba(16,24,40,.04); margin-bottom: 18px; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 18px; border-bottom: 1px solid var(--line); }
.compact-head { padding-bottom: 10px; }
.inline-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.table-wrap { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 980px; }
.data-table th { background: var(--surface-2); color: var(--muted); text-transform: uppercase; font-size: 12px; letter-spacing: .04em; text-align: left; padding: 12px; border-bottom: 1px solid var(--line); }
.data-table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 14px; }
.data-table tr:last-child td { border-bottom: 0; }
.actions-cell { display: flex; flex-wrap: wrap; gap: 6px; }
.empty { padding: 20px; color: var(--muted); }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 900; white-space: nowrap; }
.badge.sep { color: #7a2e0e; background: #fef0c7; }
.badge.wait { color: #1849a9; background: #d1e9ff; }
.badge.route { color: #5925dc; background: #ebe9fe; }
.badge.done, .badge.ready { color: #027a48; background: #d1fadf; }
.badge.cancel { color: #b42318; background: #fee4e2; }
.badge.neutral { color: var(--muted); background: var(--surface-3); }

.kanban { display: grid; grid-template-columns: repeat(5, minmax(260px, 1fr)); gap: 14px; overflow-x: auto; padding-bottom: 10px; }
.kanban-col { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-height: 420px; overflow: hidden; }
.kanban-head { display: flex; justify-content: space-between; align-items: center; padding: 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); font-weight: 900; text-transform: uppercase; }
.kanban-drop { min-height: 340px; padding: 12px; transition: background .12s ease; }
.kanban-drop.drag-over { background: color-mix(in srgb, var(--primary) 9%, transparent); outline: 2px dashed var(--primary); outline-offset: -7px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 10px; box-shadow: 0 8px 20px rgba(16,24,40,.06); }
.card[draggable="true"] { cursor: grab; }
.card.dragging { opacity: .55; transform: rotate(1deg); }
.card-title { font-weight: 900; margin-bottom: 6px; }
.card-meta { color: var(--muted); font-size: 12px; line-height: 1.55; }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.report-panel { padding: 18px; min-height: 230px; }
.report-row { display: flex; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.report-row:last-child { border-bottom: 0; }
.report-row b { text-align: right; }
.filters-grid, .settings-grid { padding: 18px; display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 14px; }
.filters-grid label, .settings-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 800; }
.full { grid-column: 1 / -1; }
.filter-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }

.modal-root { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 18px; background: rgba(2, 6, 23, .55); z-index: 50; }
.modal-root.active { display: flex; }
.modal { background: var(--surface); color: var(--text); border-radius: 18px; width: min(880px, 96vw); max-height: 92vh; overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--line); }
.modal.small { width: min(560px, 96vw); }
.modal-head { padding: 18px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; overflow: auto; max-height: calc(92vh - 132px); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--line); background: var(--surface-2); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 800; }
.form-grid .full { grid-column: 1 / -1; }
.check-row { display: flex !important; grid-template-columns: none !important; align-items: center; gap: 8px !important; }
.check-row input { width: auto; }
.preview-ticket { width: 320px; background: #fff; color: #000; font-family: monospace; border: 1px dashed #333; padding: 12px; margin: 0 auto; }
.preview-ticket .center { text-align: center; font-weight: 900; }
.preview-ticket .line { border-top: 1px dashed #000; margin: 8px 0; }

.toast { position: fixed; right: 20px; bottom: 20px; background: var(--dark); color: #fff; padding: 12px 14px; border-radius: 12px; box-shadow: var(--shadow); transform: translateY(24px); opacity: 0; transition: .2s ease; z-index: 60; max-width: 360px; }
.toast.show { opacity: 1; transform: translateY(0); }

@media print {
  body * { visibility: hidden !important; }
  .print-area, .print-area * { visibility: visible !important; }
  .print-area { position: absolute; left: 0; top: 0; width: 100%; }
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .topbar { flex-direction: column; align-items: stretch; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .report-grid, .filters-grid, .settings-grid { grid-template-columns: 1fr; }
  .kanban { grid-template-columns: repeat(5, 280px); }
}

.import-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0 18px;
}
.step-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  background: var(--surface-soft);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.step-card strong {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  flex: 0 0 auto;
}
.import-preview { margin-top: 18px; }
.code-block {
  white-space: pre-wrap;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  overflow: auto;
  max-height: 440px;
  font-size: 12px;
}
@media (max-width: 980px) {
  .import-steps { grid-template-columns: 1fr; }
}

/* ===== V4: Login, administradores e recuperação de senha ===== */
body:not(.authenticated) .app-shell { display: none; }
body.authenticated .auth-screen { display: none; }
.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at top left, color-mix(in srgb, var(--primary) 18%, transparent), transparent 32%),
    linear-gradient(135deg, #0b1220, #111827 52%, #0f172a);
}
.auth-card {
  width: min(520px, 96vw);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 26px;
}
.auth-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 20px; }
.auth-logo { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--primary); color: #fff; font-size: 24px; }
.auth-brand h1 { font-size: 24px; }
.auth-pane { display: grid; gap: 12px; }
.auth-pane h2 { font-size: 20px; }
.auth-pane label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 800; }
.auth-alert { border-radius: 14px; padding: 12px; margin-bottom: 14px; border: 1px solid #fecdca; background: #fee4e2; color: #b42318; font-weight: 800; }
.auth-alert.ok { border-color: #abefc6; background: #d1fadf; color: #027a48; }
.auth-note { background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.link-btn { border: 0; background: transparent; color: var(--primary); font-weight: 900; padding: 8px; justify-self: center; }
.recovery-code { border: 1px dashed var(--primary); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); border-radius: 14px; padding: 12px; font-weight: 900; }
.user-chip { display: inline-flex; align-items: center; gap: 7px; padding: 10px 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); color: var(--text); font-weight: 900; }
.status-dot { display: inline-flex; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 900; }
.status-dot.active { color: #027a48; background: #d1fadf; }
.status-dot.inactive { color: #b42318; background: #fee4e2; }
.admin-help { font-size: 12px; color: var(--muted); margin-top: 4px; }
