:root {
  --bg: #f1f0ec;
  --panel: #ffffff;
  --ink: #1e2124;
  --ink-soft: #5b6167;
  --line: #dedad2;
  --blue-100: #2f5d8a;
  --blue-soft: #e7edf3;
  --yellow: #f2a93b;
  --yellow-soft: #fdf1de;
  --guarapuava: #2f5d8a;
  --cascavel: #f2a93b;
  --radius: 10px;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  background: var(--ink);
  color: #f1f0ec;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 40px;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.5px;
}

.brand-sub {
  font-size: 11px;
  color: #a9adb1;
  letter-spacing: 0.3px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: #cfd2d5;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  padding: 11px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }

.nav-item.active {
  background: var(--yellow);
  color: #1e2124;
  font-weight: 600;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: currentColor;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 12px;
  color: #a9adb1;
}

.foot-label {
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-size: 10px;
  margin-bottom: 8px;
  color: #7d8186;
}

.foot-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.tag {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  display: inline-block;
}
.tag-guarapuava { background: var(--guarapuava); }
.tag-cascavel { background: var(--cascavel); }

/* MAIN */
.main {
  padding: 32px 40px 60px;
  max-width: 1280px;
  min-width: 0;
}

.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 28px;
}

h1 {
  font-family: var(--font-display);
  font-size: 26px;
  margin: 0 0 4px;
  letter-spacing: -0.2px;
}

.subtitle {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

select, input[type=date], input[type=text], input[type=number] {
  font-family: var(--font-body);
  font-size: 13px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  box-sizing: border-box;
}

textarea {
  font-family: var(--font-body);
  font-size: 13px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235b6167' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

select:focus, input:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--blue-100);
  outline-offset: 1px;
}

.btn {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
}

.btn-primary {
  background: var(--ink);
  color: #fff;
}
.btn-primary:hover { background: #34383c; }

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: #fff; }

/* KPIs */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  min-width: 0;
}

.kpi-label {
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.kpi-value {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  overflow-wrap: break-word;
}

.mono { font-family: var(--font-mono); }

/* hitch divider - signature element */
.hitch-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 28px 0;
}
.hitch-divider span {
  flex: 1;
  height: 1px;
  background: var(--line);
}
.hitch-divider i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--yellow);
  background: var(--bg);
}

/* Charts */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.panel-wide { grid-column: span 2; }

.panel-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 14px;
  color: var(--ink);
}

.panel canvas { max-height: 280px; }

/* Skeleton de carregamento */
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton {
  display: inline-block;
  background: linear-gradient(90deg, var(--line) 25%, #efece4 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: 4px;
}
.skeleton-text { width: 90px; height: 1em; vertical-align: middle; }

.chart-wrap { position: relative; min-height: 200px; }
.chart-skeleton {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  gap: 10px;
  padding: 10px 16px;
  background: #fff;
}
.chart-skeleton span {
  flex: 1;
  background: linear-gradient(90deg, var(--line) 25%, #efece4 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: 4px 4px 0 0;
}
.chart-skeleton span:nth-child(1) { height: 40%; }
.chart-skeleton span:nth-child(2) { height: 70%; }
.chart-skeleton span:nth-child(3) { height: 55%; }
.chart-skeleton span:nth-child(4) { height: 85%; }
.chart-skeleton span:nth-child(5) { height: 30%; }

.chart-skeleton-round {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: linear-gradient(90deg, var(--line) 25%, #efece4 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}

.chart-wrap.loaded .chart-skeleton,
.chart-wrap.loaded .chart-skeleton-round {
  display: none;
}

.chart-error {
  font-size: 13px;
  color: var(--ink-soft);
  padding: 40px 0;
  text-align: center;
}

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--ink-soft); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
td.mono-cell { font-family: var(--font-mono); }
tbody tr:nth-child(even) { background: #fbfaf8; }
tbody tr:hover { background: var(--yellow-soft); }
td.cell-truncate {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
td.empty-state {
  text-align: center;
  color: var(--ink-soft);
  padding: 28px 0;
  white-space: normal;
}

.panel-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.panel-title-row .panel-title { margin-bottom: 0; }
.panel-caption {
  font-size: 12px;
  color: var(--ink-soft);
}

.table-header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.page-size-field {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-soft);
}
.page-size-field select {
  padding: 4px 24px 4px 8px;
  font-size: 12px;
  background-position: right 6px center;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.pagination-pages {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 6px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}
.page-btn:hover { background: var(--yellow-soft); }
.page-btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
  font-weight: 600;
}

.page-ellipsis {
  color: var(--ink-soft);
  padding: 0 2px;
  font-size: 12px;
}

.pagination .btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-width: 760px;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 500;
  min-width: 0;
}
.span-2 { grid-column: span 2; }

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}

.insert-status { font-size: 13px; color: var(--ink-soft); }
.insert-status.ok { color: #1a7f4b; }
.insert-status.err { color: #b3261e; }

/* Ações da tabela */
.actions-cell { white-space: nowrap; }
.row-action {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  margin-right: 4px;
  color: var(--ink-soft);
  padding: 0;
}
.row-action:hover { background: var(--yellow-soft); color: var(--ink); }
.delete-action:hover { background: #fbe7e5; color: #b3261e; border-color: #f0c4bf; }

/* Campo de vendedor com botão de gerenciar */
.seller-field {
  display: flex;
  align-items: stretch;
  gap: 6px;
  min-width: 0;
}
.seller-field select { flex: 1; height: 38px; min-width: 0; }
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  color: var(--ink-soft);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--yellow-soft); color: var(--ink); }

/* Modais */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 33, 36, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: #fff;
  border-radius: 12px;
  max-width: 760px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px 28px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal-sm { max-width: 420px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-header h2 {
  font-family: var(--font-display);
  font-size: 19px;
  margin: 0;
}
.modal-close {
  background: transparent;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 2px 6px;
}
.modal-close:hover { color: var(--ink); }

#form-edit.form-grid { max-width: none; }

/* CRUD de vendedores */
.seller-add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.seller-add-row input { flex: 1; }

.seller-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}
.seller-item, .seller-empty {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
}
.seller-empty { color: var(--ink-soft); justify-content: center; }
.seller-name { font-weight: 600; flex: 1; }
.seller-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
  background: var(--bg);
  padding: 2px 7px;
  border-radius: 20px;
}
.seller-rename-input {
  flex: 1;
  font-size: 13px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
}

/* Meta do mês */
.goal-panel { margin-bottom: 0; }
.goal-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.goal-item { min-width: 0; }
.goal-item-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.goal-value {
  margin-left: auto;
  font-family: var(--font-mono);
  font-weight: 600;
}
.goal-bar {
  width: 100%;
  height: 10px;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--line);
  overflow: hidden;
}
.goal-bar-fill {
  height: 100%;
  background: var(--guarapuava);
  border-radius: 20px;
  transition: width 0.4s ease;
}
.goal-bar-fill.cascavel { background: var(--cascavel); }
.goal-bar-fill.goal-hit { background: #1a7f4b; }
.goal-sub {
  margin-top: 6px;
  font-size: 12px;
  color: var(--ink-soft);
}
.goal-sub.goal-hit-text { color: #1a7f4b; font-weight: 600; }

.field-error {
  display: block;
  font-size: 12px;
  color: #b3261e;
  margin-top: 4px;
}
.field-error:empty { display: none; }
.uf-input { text-transform: uppercase; }
.money-input { text-align: right; font-family: var(--font-mono); }

/* Tela de bloqueio (PIN local) */
.lock-screen {
  position: fixed;
  inset: 0;
  background: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 20px;
}
.lock-screen.hidden { display: none; }

.lock-card {
  background: #fff;
  border-radius: 14px;
  padding: 32px 28px;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
}
.lock-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 26px;
}
.lock-mode.hidden { display: none; }
.lock-mode h2 {
  font-family: var(--font-display);
  font-size: 18px;
  margin: 0 0 6px;
}
.lock-sub {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 18px;
  line-height: 1.4;
}
.lock-mode input {
  width: 100%;
  margin-bottom: 10px;
  text-align: center;
  letter-spacing: 4px;
  font-family: var(--font-mono);
  font-size: 16px;
}
.lock-mode input::placeholder {
  letter-spacing: normal;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--ink-soft);
}
.lock-error {
  color: #b3261e;
  font-size: 12px;
  min-height: 16px;
  margin-bottom: 6px;
}
.lock-mode .btn { width: 100%; justify-content: center; }
.lock-link {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  margin-top: 12px;
  text-align: center;
}
.lock-link:hover { color: var(--ink); }

.logout-btn {
  margin-top: 12px;
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.15);
  color: #cfd2d5;
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  cursor: pointer;
}
.logout-btn:hover { background: rgba(255,255,255,0.06); color: #fff; }

/* Botão hamburguer, só aparece no mobile */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 210;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--ink);
  border: none;
  cursor: pointer;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.sidebar-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  background: #f1f0ec;
  border-radius: 2px;
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar-toggle { display: flex; }
  .sidebar {
    display: none;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 240px;
    z-index: 150;
    overflow-y: auto;
    flex-shrink: 0;
  }
  .sidebar.open { display: flex; }
  .chart-grid { grid-template-columns: 1fr; }
  .panel-wide { grid-column: span 1; }
  .main { padding: 20px; padding-top: 68px; }
  .goal-row { grid-template-columns: 1fr; }
  .kpi-row { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr !important; }
  .form-grid .span-2 { grid-column: span 1 !important; }
}

/* Mesmas regras acima, mas disparadas por uma classe que o JS aplica medindo
   window.innerWidth direto — reforço independente do @media, caso o media
   query do CSS não esteja sendo avaliado corretamente em algum aparelho. */
html.js-mobile .app { grid-template-columns: 1fr !important; }
html.js-mobile .sidebar-toggle { display: flex !important; }
html.js-mobile .sidebar {
  display: none;
  position: fixed !important;
  top: 0;
  bottom: 0;
  left: 0;
  width: 240px !important;
  z-index: 150;
  overflow-y: auto;
  flex-shrink: 0;
}
html.js-mobile .sidebar.open { display: flex !important; }
html.js-mobile .chart-grid { grid-template-columns: 1fr !important; }
html.js-mobile .panel-wide { grid-column: span 1 !important; }
html.js-mobile .main { padding: 20px !important; padding-top: 68px !important; }
html.js-mobile .goal-row { grid-template-columns: 1fr !important; }
html.js-mobile .kpi-row { grid-template-columns: 1fr !important; }
html.js-mobile .form-grid { grid-template-columns: 1fr !important; }
