/* ═══════════════════════════════════════════════════════════════════
   CARGA DISTRIB v2 — Design System
   Industrial / Utilitarian + Modern finesse
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg: #0e1117;
  --bg-surface: #161b22;
  --bg-card: #1c2128;
  --bg-card-hover: #21262d;
  --bg-input: #0d1117;
  --border: #30363d;
  --border-focus: #58a6ff;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #6e7681;
  --accent: #58a6ff;
  --accent-soft: rgba(88,166,255,0.15);
  --green: #3fb950;
  --green-soft: rgba(63,185,80,0.15);
  --yellow: #d29922;
  --yellow-soft: rgba(210,153,34,0.15);
  --red: #f85149;
  --red-soft: rgba(248,81,73,0.15);
  --purple: #bc8cff;
  --purple-soft: rgba(188,140,255,0.15);
  --orange: #f0883e;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --font: 'DM Sans', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --topbar-h: 56px;
  --tabs-h: 44px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ═══ VIEWS ═══ */
.view { display: none; }
.view.active { display: block; }

/* ═══ LOGIN ═══ */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, rgba(88,166,255,0.08) 0%, transparent 60%),
              radial-gradient(ellipse at 70% 80%, rgba(63,185,80,0.06) 0%, transparent 50%),
              var(--bg);
  padding: 20px;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.login-header { text-align: center; margin-bottom: 32px; }
.login-logo { font-size: 40px; margin-bottom: 12px; }
.login-header h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.login-sub { color: var(--text-muted); font-size: 0.9rem; margin-top: 6px; }
.login-card label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 16px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.login-card input[type="text"],
.login-card input[type="password"] {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
.login-card input:focus { border-color: var(--border-focus); }

.msg-error {
  background: var(--red-soft);
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-top: 12px;
}
.msg-info {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-top: 12px;
}
.msg-success {
  background: var(--green-soft);
  color: var(--green);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-top: 12px;
}

/* ═══ BUTTONS ═══ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #79b8ff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-card-hover); color: var(--text); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-full { width: 100%; margin-top: 24px; padding: 12px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ═══ TOPBAR ═══ */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-logo { font-size: 24px; }
.topbar-title { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.01em; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-user { color: var(--text-muted); font-size: 0.85rem; }

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
}

/* ═══ TABS ═══ */
.tabs-nav {
  height: var(--tabs-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  padding: 0 24px;
  gap: 4px;
  overflow-x: auto;
}
.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0 16px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ═══ TAB PANELS ═══ */
.tab-panel { display: none; padding: 24px; }
.tab-panel.active { display: block; }

/* ═══ CARDS / PANEL ═══ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card h3 { font-size: 1rem; font-weight: 700; margin-bottom: 8px; }
.card-desc { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 16px; }

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: -0.02em;
}
.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}
.stat-accent .stat-value { color: var(--accent); }
.stat-green .stat-value { color: var(--green); }
.stat-yellow .stat-value { color: var(--yellow); }
.stat-red .stat-value { color: var(--red); }

.panel-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ═══ CHARTS (simple CSS bars) ═══ */
.chart-area { margin-top: 12px; }
.chart-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.chart-bar-label {
  width: 120px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart-bar-track {
  flex: 1;
  height: 22px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.chart-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
  min-width: 2px;
}
.chart-bar-value {
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--text-muted);
  width: 48px;
  text-align: right;
  flex-shrink: 0;
}

/* ═══ TOOLBAR ═══ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.input-search {
  flex: 1;
  min-width: 200px;
  padding: 8px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  outline: none;
}
.input-search:focus { border-color: var(--border-focus); }
.input-sm {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  outline: none;
  width: 100px;
}
.input-sm:focus { border-color: var(--border-focus); }
.select-filter {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  outline: none;
}

/* ═══ DATA TABLE ═══ */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.data-table th {
  background: var(--bg-surface);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:hover td { background: var(--bg-card-hover); }
.data-table .mono { font-family: var(--mono); font-size: 0.8rem; }

.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.table-footer .coord-only { display: flex; gap: 8px; align-items: center; }

/* Status badges */
.status-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.status-disponivel { background: var(--purple-soft); color: var(--purple); }
.status-aberto { background: var(--accent-soft); color: var(--accent); }
.status-correcao { background: var(--yellow-soft); color: var(--yellow); }
.status-pendente { background: var(--orange); color: #fff; background: rgba(240,136,62,0.2); color: var(--orange); }
.status-concluido { background: var(--green-soft); color: var(--green); }
.status-cancelado { background: var(--red-soft); color: var(--red); }

.area-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.area-u { background: var(--accent-soft); color: var(--accent); }
.area-r { background: var(--green-soft); color: var(--green); }

/* ═══ DISTRIBUTION GRID ═══ */
.dist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.form-row { display: flex; gap: 10px; margin-bottom: 10px; }
.form-row .select-filter,
.form-row .input-sm { flex: 1; }

#fileInput {
  width: 100%;
  padding: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  margin-bottom: 12px;
}

/* ═══ MODAL ═══ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; }
.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}
.btn-close:hover { color: var(--text); }
.modal-body { padding: 20px 24px; }
.modal-body label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.modal-body label:first-child { margin-top: 0; }
.modal-body input,
.modal-body select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  outline: none;
}
.modal-body input:focus,
.modal-body select:focus { border-color: var(--border-focus); }
.modal-footer {
  padding: 16px 24px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
  .panel-row { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .input-search { min-width: 100%; }
  .topbar-title { display: none; }
}

/* Hide coord-only elements for technicians (toggled by JS) */
body.perfil-tecnico .coord-only { display: none !important; }
