:root {
  /* Superfícies */
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e5e8ee;
  --border-strong: #d5d9e1;

  /* Texto */
  --text: #171a21;
  --text-muted: #5c6371;
  --text-subtle: #8b91a0;

  /* Marca / ação */
  --accent: #2f5fdb;
  --accent-hover: #274fc0;
  --accent-weak: #eaf0fd;

  /* Status */
  --pending: #a86412;
  --pending-strong: #d98a1f;
  --pending-bg: #fdf1de;
  --accepted: #2f5fdb;
  --accepted-strong: #3f6cf0;
  --accepted-bg: #e8eefc;
  --done: #147a42;
  --done-strong: #1c9a53;
  --done-bg: #e2f5ea;
  --danger: #c0392f;
  --danger-bg: #fbeae8;

  /* Elevação */
  --shadow-sm: 0 1px 2px rgba(19, 24, 33, 0.05);
  --shadow-card: 0 1px 3px rgba(19, 24, 33, 0.06), 0 6px 20px rgba(19, 24, 33, 0.05);

  --radius: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101318;
    --surface: #1a1e25;
    --surface-2: #21262f;
    --border: #2b303a;
    --border-strong: #39404c;

    --text: #eef0f4;
    --text-muted: #9aa1ae;
    --text-subtle: #737b8a;

    --accent: #6d93ff;
    --accent-hover: #83a3ff;
    --accent-weak: #1c2540;

    --pending: #f0b155;
    --pending-strong: #f5bf6d;
    --pending-bg: #382a13;
    --accepted: #7ea1ff;
    --accepted-strong: #9ab5ff;
    --accepted-bg: #1c2540;
    --done: #4fd684;
    --done-strong: #6ee29c;
    --done-bg: #123021;
    --danger: #f0796d;
    --danger-bg: #3a1d1a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

.icon {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px 32px;
  max-width: 1180px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  box-shadow: var(--shadow-sm);
}

.brand-text h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}

.brand-text p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--done-strong);
  box-shadow: 0 0 0 0 rgba(28, 154, 83, 0.5);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(28, 154, 83, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(28, 154, 83, 0); }
  100% { box-shadow: 0 0 0 0 rgba(28, 154, 83, 0); }
}

/* ---------- Layout ---------- */
main {
  padding: 4px 32px 56px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  max-width: 1180px;
  margin: 0 auto;
}

/* ---------- Resumo operacional ---------- */
.overview {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--text-subtle);
}

.stat-device::before { background: var(--accent); }
.stat-pending::before { background: var(--pending-strong); }
.stat-progress::before { background: var(--accepted-strong); }
.stat-done::before { background: var(--done-strong); }

.stat-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  margin-bottom: 10px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.stat-device .stat-icon { background: var(--accent-weak); color: var(--accent); }
.stat-pending .stat-icon { background: var(--pending-bg); color: var(--pending); }
.stat-progress .stat-icon { background: var(--accepted-bg); color: var(--accepted); }
.stat-done .stat-icon { background: var(--done-bg); color: var(--done); }

.stat-num {
  display: block;
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  display: block;
  margin-top: 5px;
  font-size: 0.85rem;
  font-weight: 600;
}

.stat-sub {
  display: block;
  margin-top: 1px;
  font-size: 0.76rem;
  color: var(--text-subtle);
}

/* ---------- Painel ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}

.panel-flush { background: transparent; border: none; box-shadow: none; padding: 4px 0 0; }

.panel-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-bottom: 16px;
}

.panel-title {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.panel-title .icon { font-size: 18px; color: var(--text-muted); }

.panel-title h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.panel-count {
  margin-left: auto;
  color: var(--text-subtle);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.hint {
  flex-basis: 100%;
  color: var(--text-muted);
  font-size: 0.84rem;
  margin: 4px 0 0;
  max-width: 62ch;
}

/* ---------- Tabela (dispositivos) ---------- */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--text-subtle);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

.col-action { text-align: right; }
td.col-action { text-align: right; }

.mac {
  font-family: ui-monospace, "SF Mono", "Roboto Mono", Menlo, monospace;
  font-size: 0.82rem;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.device-name { font-weight: 600; }
.muted { color: var(--text-subtle); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-pending { color: var(--pending); background: var(--pending-bg); }
.badge-accepted { color: var(--accepted); background: var(--accepted-bg); }
.badge-done { color: var(--done); background: var(--done-bg); }

/* ---------- Botões ---------- */
button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.06s ease;
}

button .icon { font-size: 15px; }
button:hover { background: var(--accent-hover); }
button:active { transform: translateY(1px); }

button.small {
  padding: 6px 13px;
  font-size: 0.8rem;
}

button.ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border-strong);
}
button.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--text-subtle);
}

button.approve {
  background: var(--done-bg);
  color: var(--done);
  border-color: transparent;
}
button.approve:hover { background: var(--done); color: #fff; }

/* Foco acessível */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
button:focus-visible { outline-offset: 2px; }

/* ---------- Formulário ---------- */
#activity-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 20px;
  align-items: end;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field-wide { grid-column: 1 / -1; }

label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.optional { color: var(--text-subtle); font-weight: 400; }

input, select {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

input::placeholder { color: var(--text-subtle); }

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.feedback {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.feedback.is-success { color: var(--done); font-weight: 600; }
.feedback.is-error { color: var(--danger); font-weight: 600; }

/* ---------- Lista de atividades (cards) ---------- */
.activity-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
}

.activity {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-subtle);
  border-radius: var(--radius);
  padding: 15px 17px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.16s ease, transform 0.1s ease;
}

.activity:hover {
  box-shadow: var(--shadow-card);
  transform: translateY(-1px);
}

.act-pending { border-left-color: var(--pending-strong); }
.act-accepted { border-left-color: var(--accepted-strong); }
.act-done { border-left-color: var(--done-strong); }

.activity-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.activity-head {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.activity-id {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

.activity-pallet {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.98rem;
  letter-spacing: -0.01em;
}
.activity-pallet .icon { font-size: 15px; color: var(--text-muted); }

.activity-route {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 4px;
}
.activity-route .pin { font-size: 14px; color: var(--text-subtle); }
.activity-route .arrow { font-size: 14px; color: var(--text-subtle); flex: none; }
.activity-route .loc { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.activity-desc {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.activity-device {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 10px;
}
.activity-device .icon { font-size: 14px; }

/* Linha do tempo */
.timeline {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.tl-step {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.7rem;
  color: var(--text-subtle);
}

.tl-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tl-label::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
}

.tl-time { font-size: 0.74rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.tl-step.reached .tl-label { color: var(--text-muted); }
.tl-step.reached .tl-label::before { background: var(--text-muted); border-color: var(--text-muted); }

.tl-step.reached.step-created .tl-label { color: var(--pending); }
.tl-step.reached.step-created .tl-label::before { background: var(--pending-strong); border-color: var(--pending-strong); }
.tl-step.reached.step-accepted .tl-label { color: var(--accepted); }
.tl-step.reached.step-accepted .tl-label::before { background: var(--accepted-strong); border-color: var(--accepted-strong); }
.tl-step.reached.step-done .tl-label { color: var(--done); }
.tl-step.reached.step-done .tl-label::before { background: var(--done-strong); border-color: var(--done-strong); }

/* ---------- Estados vazios ---------- */
.empty-row td { padding: 0; border: none; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 36px 20px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 30px; color: var(--text-subtle); }
.empty-state strong { color: var(--text); font-weight: 600; font-size: 0.95rem; }
.empty-state span { font-size: 0.84rem; max-width: 42ch; }

.activity-list .empty-state {
  grid-column: 1 / -1;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

/* ---------- Responsivo ---------- */
@media (max-width: 860px) {
  .overview { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .topbar, main { padding-left: 18px; padding-right: 18px; }
  #activity-form { grid-template-columns: 1fr; }
  .activity-list { grid-template-columns: 1fr; }
  .live-text { display: none; }
  .live { padding: 8px; }
}

@media (max-width: 420px) {
  .overview { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
