:root {
  color-scheme: light;
  --bg: #eef3f9;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --surface-strong: #edf3fb;
  --line: #d4dfed;
  --line-strong: #bdcce0;
  --text: #111827;
  --muted: #66758d;
  --primary: #2f67e8;
  --primary-dark: #1e50c9;
  --primary-soft: #e8f0ff;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --purple: #7c3aed;
  --shadow: 0 16px 38px rgba(15, 23, 42, .08);
  --shadow-menu: 0 24px 70px rgba(15, 23, 42, .22);
  --focus: rgba(47, 103, 232, .5);
  --focus-ring: 0 0 0 3px var(--focus);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

body.dark {
  color-scheme: dark;
  --bg: #0b1020;
  --surface: #121a2a;
  --surface-soft: #0f172a;
  --surface-strong: #1a2437;
  --line: #2d3b52;
  --line-strong: #3b4e69;
  --text: #f8fafc;
  --muted: #a8b6ca;
  --primary: #6c8dff;
  --primary-dark: #5276ea;
  --primary-soft: #101d3a;
  --shadow: 0 18px 46px rgba(0, 0, 0, .34);
  --shadow-menu: 0 30px 90px rgba(0, 0, 0, .55);
  --focus: rgba(108, 141, 255, .55);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background:
    radial-gradient(circle at top left, rgba(47, 103, 232, .13), transparent 28rem),
    linear-gradient(180deg, rgba(255,255,255,.55), transparent 16rem),
    var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: -.01em;
}

body.dark {
  background:
    radial-gradient(circle at top left, rgba(108, 141, 255, .14), transparent 28rem),
    var(--bg);
}

button,
input,
select,
textarea { font-family: var(--font); }

button { user-select: none; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: 14px 0;
  background: rgba(255, 255, 255, .82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

body.dark .app-header { background: rgba(7, 11, 24, .86); }

/* Mesma largura e alinhamento do conteúdo (app-shell), tudo centralizado */
.app-header-inner {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 0 24px;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-text { min-width: 0; }

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: .01em;
  background: linear-gradient(135deg, #265ee9, #7c3aed);
  box-shadow: 0 10px 22px rgba(49, 104, 229, .22);
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-name { color: var(--text); font-weight: 800; }
.brand-sep { color: var(--muted); margin: 0 5px; font-weight: 400; }
.brand-title { color: var(--muted); font-weight: 600; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.35; }

.header-actions { display: flex; gap: 12px; align-items: center; }

/* Alternador de tema segmentado */
.theme-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.theme-opt {
  height: 34px;
  padding: 0 16px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: background .13s ease, color .13s ease, box-shadow .13s ease;
}
.theme-opt:hover { color: var(--text); }
.theme-opt.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .16);
}
body.dark .theme-opt.active {
  background: var(--surface-strong);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
}
.theme-opt:focus-visible { box-shadow: var(--focus-ring); }

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px 24px 32px;
  display: grid;
  gap: 16px;
}

.btn {
  border: 0;
  border-radius: 13px;
  height: 44px;
  padding: 0 16px;
  color: white;
  font-weight: 700;
  font-size: 13.5px;
  letter-spacing: -.005em;
  cursor: pointer;
  background: var(--primary);
  transition: transform .13s ease, box-shadow .13s ease, opacity .13s ease, background .13s ease;
  box-shadow: 0 8px 18px rgba(47, 103, 232, .2);
  white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); opacity: .97; }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); }
.btn-secondary { background: var(--primary); }
.btn-ghost {
  color: var(--text);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  box-shadow: none;
}
.btn-danger { background: #fee2e2; color: #991b1b; box-shadow: none; }
body.dark .btn-danger { background: #46191d; color: #fecaca; }
.btn:disabled { cursor: default; opacity: .8; transform: none; }

/* Foco acessível por teclado */
:focus-visible { outline: none; }
.btn:focus-visible,
.multi-actions button:focus-visible,
.lote-details summary:focus-visible,
.multi-item:focus-within {
  box-shadow: var(--focus-ring);
}
.btn-ghost:focus-visible,
.btn-danger:focus-visible { box-shadow: var(--focus-ring); }
select:focus-visible,
input[type="text"]:focus-visible,
textarea:focus-visible,
.multi-trigger:focus-visible,
.multi-search:focus-visible {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
.file-box:focus-within {
  border-style: solid;
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: var(--focus-ring);
}

/* Botão em processamento */
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: calc(50% - 8px);
  left: calc(50% - 8px);
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.command-center,
.stats-grid,
.quick-summary,
.side-card,
.result-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.command-center {
  padding: 16px;
  display: grid;
  grid-template-columns: 440px minmax(0, 1fr);
  gap: 16px;
  align-items: end;
  position: relative;
  overflow: visible;
}

.upload-area {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.field-title,
.filter-field label {
  display: block;
  grid-column: 1 / -1;
  color: var(--muted);
  font-weight: 700;
  font-size: 11.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-bottom: -2px;
}

.file-box {
  position: relative;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border: 1px dashed var(--line-strong);
  background: var(--surface-soft);
  border-radius: var(--radius-md);
  cursor: pointer;
  min-width: 0;
  transition: border-color .13s ease, background .13s ease, box-shadow .13s ease;
}
.file-box:hover { border-color: var(--primary); background: var(--primary-soft); }

/* Estado de arraste sobre a área de upload */
.file-box.dragover {
  border-style: solid;
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: var(--focus-ring);
}
.file-box.dragover::after {
  content: "Solte o arquivo CSV aqui";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: inherit;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: -.005em;
  pointer-events: none;
}
.file-box.processing { opacity: .7; cursor: progress; }
.file-box input { display: none; }
.file-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 950;
}
.file-text { min-width: 0; }
.file-box strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.file-box small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }

.filters-area {
  display: grid;
  grid-template-columns: minmax(260px, 1.1fr) minmax(220px, .85fr) minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: end;
  min-width: 0;
}

.filter-field { min-width: 0; }

select,
input[type="text"] {
  width: 100%;
  height: 52px;
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0 14px;
  outline: none;
  font-size: 14px;
  transition: border .13s ease, box-shadow .13s ease, background .13s ease;
}
select:hover,
input[type="text"]:hover { border-color: var(--line-strong); }
select:focus,
input[type="text"]:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(47, 103, 232, .12);
}
select:focus-visible,
input[type="text"]:focus-visible,
textarea:focus-visible {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

.notice {
  grid-column: 1 / -1;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.35;
}
.notice-ok { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.notice-warn { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }
body.dark .notice-ok { background: #052e24; color: #c9ffeb; border-color: #0f7b5d; }
body.dark .notice-warn { background: #3a2a05; color: #ffe9b0; border-color: #9f6b00; }

.stats-grid {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.stat-card {
  min-height: 92px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-soft);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.stat-card span { color: var(--muted); font-weight: 700; font-size: 11.5px; letter-spacing: .03em; text-transform: uppercase; }
.stat-card strong { margin-top: 6px; font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.stat-primary { background: var(--primary-soft); }
.stat-soft { background: #fff7ed; }
body.dark .stat-soft { background: #2b2115; }

.quick-summary {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
.mini-card {
  min-height: 72px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-soft);
}
.mini-card strong { display: block; font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.mini-card span { display: block; color: var(--muted); font-weight: 700; font-size: 11.5px; letter-spacing: .02em; margin-top: 3px; }
.mini-card.red strong { color: var(--danger); }
.mini-card.blue strong { color: var(--primary); }
.mini-card.purple strong { color: var(--purple); }
.mini-card.amber strong { color: var(--warning); }

.multi-dropdown { position: relative; width: 100%; }
.multi-trigger {
  width: 100%;
  height: 52px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  text-align: left;
  transition: border .13s ease, box-shadow .13s ease, background .13s ease;
}
.multi-trigger:hover { border-color: var(--primary); background: var(--primary-soft); }
.multi-trigger small { display: block; color: var(--muted); font-size: 11px; font-weight: 850; margin-bottom: 2px; }
.multi-trigger strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chevron { color: var(--muted); font-size: 14px; }

.multi-menu {
  display: none;
  position: absolute;
  z-index: 120;
  top: calc(100% + 8px);
  left: 0;
  width: 390px;
  max-width: calc(100vw - 48px);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-menu);
  padding: 12px;
}
.multi-menu.open { display: block; animation: menuIn .12s ease-out; }
@keyframes menuIn { from { transform: translateY(-4px); opacity: .7; } to { transform: translateY(0); opacity: 1; } }
.multi-menu-header {
  padding: 2px 2px 10px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.multi-menu-header strong { font-size: 14px; }
.multi-menu-header span { color: var(--muted); font-size: 12px; }
.multi-search {
  width: 100%;
  height: 42px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 0 12px;
  outline: none;
}
.multi-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.multi-actions button {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-strong);
  color: var(--text);
  font-weight: 850;
  cursor: pointer;
}
.multi-actions button:hover { border-color: var(--primary); }
.multi-list {
  max-height: 292px;
  overflow-y: auto;
  display: grid;
  gap: 4px;
  padding-right: 4px;
}
.multi-list::-webkit-scrollbar,
.summary-table-wrap::-webkit-scrollbar { width: 9px; }
.multi-list::-webkit-scrollbar-thumb,
.summary-table-wrap::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }
.multi-item {
  min-height: 38px;
  padding: 8px 9px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  transition: background .12s ease;
}
.multi-item:hover { background: rgba(47, 103, 232, .1); }
.multi-item-left { display: flex; align-items: center; gap: 9px; font-weight: 780; min-width: 0; }
.multi-item-left span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.multi-item input { width: 16px; height: 16px; accent-color: var(--primary); }
.multi-count { color: var(--muted); font-size: 12px; font-weight: 900; }

.workspace { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; align-items: start; }
.side-card,
.result-card { padding: 18px; }
.card-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.card-title.compact { margin-bottom: 12px; }
.section-kicker { color: var(--primary); font-size: 10.5px; font-weight: 800; letter-spacing: .1em; }
.card-title h2 { margin: 4px 0 0; font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.hint { color: var(--muted); font-size: 12px; white-space: nowrap; }
.summary-table-wrap { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 14px; }
.summary-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.summary-table th,
.summary-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.summary-table th { position: sticky; top: 0; background: var(--surface-strong); z-index: 1; }
.lote-details { margin-top: 14px; }
.lote-details summary { cursor: pointer; color: var(--muted); font-weight: 850; }
textarea {
  width: 100%;
  height: 150px;
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  resize: vertical;
  outline: none;
  line-height: 1.45;
  margin-top: 10px;
}
.os-list { display: grid; gap: 10px; }
.os-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 15px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--primary);
  border-radius: 18px;
  background: var(--surface-soft);
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.os-card:hover { transform: translateY(-1px); border-color: rgba(47, 103, 232, .55); box-shadow: 0 10px 26px rgba(15, 23, 42, .08); }
.os-title { font-size: 15.5px; font-weight: 750; letter-spacing: -.015em; margin-bottom: 7px; }
.os-sub { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { padding: 4px 9px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 11.5px; font-weight: 650; }
.badge.red { color: #b91c1c; background: #fee2e2; }
.badge.amber { color: #92400e; background: #fef3c7; }
.badge.green { color: #166534; background: #dcfce7; }
.badge.purple { color: #6d28d9; background: #ede9fe; }
body.dark .badge.red { background: #411b22; color: #fecaca; }
body.dark .badge.amber { background: #3a2a05; color: #fde68a; }
body.dark .badge.green { background: #052e24; color: #bbf7d0; }
body.dark .badge.purple { background: #27164a; color: #ddd6fe; }

.badge.badge-equipe { background: #eef2ff; color: #4338ca; }
body.dark .badge.badge-equipe { background: #1e1b4b; color: #c7d2fe; }

.os-info { min-width: 0; }

.os-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 7px;
}
.os-title-row .os-title { margin-bottom: 0; }

.badge-atraso {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 900;
  letter-spacing: -.01em;
  color: #fff;
  background: var(--danger);
  box-shadow: 0 3px 10px rgba(220, 38, 38, .28);
}
body.dark .badge-atraso { background: #ef4444; box-shadow: 0 3px 12px rgba(239, 68, 68, .35); }

.os-rodape {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px dashed var(--line);
}
.rodape-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
}
.rodape-alerta {
  color: var(--danger);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .02em;
}
body.dark .rodape-alerta { color: #fca5a5; }

.os-card.card-atrasada { border-left-color: var(--danger); }
.empty-state {
  min-height: 260px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 6px;
  padding: 32px 24px;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 18px;
  background: var(--surface-soft);
  text-align: center;
}
.empty-icon {
  font-size: 26px;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  margin-bottom: 6px;
}
.empty-state strong { color: var(--text); font-size: 15px; font-weight: 700; }
.empty-state span { max-width: 340px; font-size: 13px; line-height: 1.4; }

@media (max-width: 1180px) {
  .command-center { grid-template-columns: 1fr; }
  .filters-area { grid-template-columns: 1fr 1fr; }
  .stats-grid,
  .quick-summary { grid-template-columns: repeat(2, 1fr); }
  .workspace { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .app-header { position: static; }
  .app-header-inner { flex-direction: column; align-items: stretch; gap: 12px; }
  .header-actions { width: 100%; }
  .theme-toggle { flex: 1; }
  .theme-opt { flex: 1; }
  .app-shell { padding: 14px; }
  .upload-area,
  .filters-area,
  .stats-grid,
  .quick-summary { grid-template-columns: 1fr; }
  .multi-menu { width: 100%; max-width: 100%; }
  .os-card { grid-template-columns: 1fr; }
  .os-card .btn { width: 100%; }
}

@media (max-width: 480px) {
  .stats-grid,
  .quick-summary { grid-template-columns: 1fr; }
  .brand h1 { font-size: 16px; white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  html { scroll-behavior: auto; }
}
