/* Portal do Transportador — design tokens e componentes base */

:root {
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-border: #e2e6ec;
  --color-text: #1a2233;
  --color-text-muted: #667085;
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-contrast: #ffffff;
  --color-success: #16a34a;
  --color-danger: #dc2626;
  --color-warning: #d97706;
  --color-sidebar-bg: #111827;
  --color-sidebar-text: #cbd5e1;
  --color-sidebar-text-active: #ffffff;
  --radius-sm: 6px;
  --radius-md: 10px;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 0.06);
  --shadow-md: 0 4px 12px rgb(16 24 40 / 0.08);
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f1420;
    --color-surface: #171d2b;
    --color-border: #2a3141;
    --color-text: #e5e9f0;
    --color-text-muted: #94a0b8;
    --color-primary: #3b82f6;
    --color-primary-hover: #60a5fa;
    --color-sidebar-bg: #0b0f18;
    --color-sidebar-text: #94a0b8;
    --color-sidebar-text-active: #ffffff;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 16px rgb(0 0 0 / 0.5);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
}

#app { min-height: 100vh; }

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .5rem; font-weight: 600; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }

/* --- Layout autenticado --- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--color-sidebar-bg);
  color: var(--color-sidebar-text);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 1.5rem;
  padding: 0 .5rem;
}

.sidebar__nav { display: flex; flex-direction: column; gap: .25rem; flex: 1; }

.sidebar__link {
  display: block;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
  color: var(--color-sidebar-text);
  font-weight: 500;
}

.sidebar__link:hover { background: rgb(255 255 255 / 0.06); text-decoration: none; }
.sidebar__link.is-active { background: var(--color-primary); color: var(--color-sidebar-text-active); }

.sidebar__section {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #64748b;
  margin: 1rem .75rem .35rem;
}

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1.5rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.topbar__user { display: flex; align-items: center; gap: .75rem; }
.topbar__user-name { font-weight: 600; }
.topbar__user-meta { color: var(--color-text-muted); font-size: .8rem; }

.content { padding: 1.5rem; flex: 1; }

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: .75rem;
}

/* --- Cartões / superfícies --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.card + .card { margin-top: 1rem; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }

.stat-tile { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 1rem 1.1rem; }
.stat-tile__label { color: var(--color-text-muted); font-size: .8rem; margin-bottom: .35rem; }
.stat-tile__value { font-size: 1.6rem; font-weight: 700; }

/* --- Formulários --- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .9rem 1.1rem; }
.form-grid--single { grid-template-columns: 1fr; }

.field { display: flex; flex-direction: column; gap: .3rem; }
.field--full { grid-column: 1 / -1; }

.field label { font-weight: 600; font-size: .82rem; }

.field input, .field select, .field textarea {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: .55rem .65rem;
  font-size: .88rem;
  background: var(--color-surface);
  color: var(--color-text);
  font-family: inherit;
}

.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.field-error { color: var(--color-danger); font-size: .78rem; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--color-danger); }

.form-actions { display: flex; gap: .6rem; margin-top: 1.1rem; justify-content: flex-end; }

/* --- Botões --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: .55rem 1rem;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--color-primary);
  color: var(--color-primary-contrast);
}

.btn:hover { background: var(--color-primary-hover); }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn--ghost { background: transparent; color: var(--color-text); border-color: var(--color-border); }
.btn--ghost:hover { background: var(--color-bg); }

.btn--danger { background: var(--color-danger); }
.btn--danger:hover { background: #b91c1c; }

.btn--sm { padding: .35rem .65rem; font-size: .78rem; }

/* --- Tabela --- */
.table-wrap { overflow-x: auto; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); }

table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead th {
  text-align: left;
  padding: .7rem .9rem;
  color: var(--color-text-muted);
  font-weight: 600;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
tbody td { padding: .65rem .9rem; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-bg); }

.table-toolbar { display: flex; justify-content: space-between; align-items: center; padding: .85rem; gap: .75rem; flex-wrap: wrap; }
.table-empty { padding: 2rem; text-align: center; color: var(--color-text-muted); }
.table-actions { display: flex; gap: .4rem; justify-content: flex-end; }

.pagination { display: flex; align-items: center; gap: .5rem; padding: .75rem .9rem; border-top: 1px solid var(--color-border); justify-content: flex-end; }
.pagination__info { color: var(--color-text-muted); font-size: .8rem; margin-right: .5rem; }

/* --- Badges/status --- */
.badge {
  display: inline-block;
  padding: .18rem .55rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  background: var(--color-bg);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}
.badge--success { background: rgb(22 163 74 / 0.12); color: var(--color-success); border-color: transparent; }
.badge--danger { background: rgb(220 38 38 / 0.12); color: var(--color-danger); border-color: transparent; }
.badge--warning { background: rgb(217 119 6 / 0.12); color: var(--color-warning); border-color: transparent; }
.badge--primary { background: rgb(37 99 235 / 0.12); color: var(--color-primary); border-color: transparent; }

/* --- Auth pages --- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card { width: 100%; max-width: 420px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 2rem; box-shadow: var(--shadow-md); }
.auth-card__brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.1rem; margin-bottom: 1.5rem; }
.auth-card__footer { margin-top: 1.25rem; text-align: center; font-size: .85rem; color: var(--color-text-muted); }

.alert { padding: .7rem .9rem; border-radius: var(--radius-sm); font-size: .85rem; margin-bottom: 1rem; }
.alert--danger { background: rgb(220 38 38 / 0.08); color: var(--color-danger); border: 1px solid rgb(220 38 38 / 0.25); }
.alert--success { background: rgb(22 163 74 / 0.08); color: var(--color-success); border: 1px solid rgb(22 163 74 / 0.25); }
.alert--info { background: rgb(37 99 235 / 0.08); color: var(--color-primary); border: 1px solid rgb(37 99 235 / 0.25); }

/* --- Modal --- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgb(15 20 30 / 0.5);
  display: flex; align-items: center; justify-content: center; padding: 1.5rem; z-index: 100;
}
.modal { background: var(--color-surface); border-radius: var(--radius-md); padding: 1.5rem; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-md); }
.modal__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.modal__close { border: none; background: none; font-size: 1.2rem; cursor: pointer; color: var(--color-text-muted); }

/* --- Toast --- */
.toast-root { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: .5rem; z-index: 200; }
.toast {
  background: var(--color-text); color: var(--color-surface); padding: .65rem 1rem; border-radius: var(--radius-sm);
  font-size: .85rem; box-shadow: var(--shadow-md); opacity: 0; transform: translateY(6px); transition: all .2s ease;
}
.toast--visible { opacity: 1; transform: translateY(0); }
.toast--danger { background: var(--color-danger); }
.toast--success { background: var(--color-success); }

/* --- Utilitários --- */
.text-muted { color: var(--color-text-muted); }
.flex-row { display: flex; align-items: center; gap: .5rem; }
.mt-1 { margin-top: 1rem; }
.thread { display: flex; flex-direction: column; gap: .75rem; }
.thread-item { border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: .85rem; }
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--color-text-muted); }

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; overflow-x: auto; }
  .sidebar__nav { flex-direction: row; }
  .sidebar__section { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}
