/* Movidesk Importer — CSS próprio, sem dependências externas (UI-20) e compatível com CSP sem inline. */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --success: #15803d;
  --success-soft: #dcfce7;
  --info: #0369a1;
  --info-soft: #e0f2fe;
  --neutral-soft: #f1f5f9;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #0f172a;
    --border: #1f2937;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-soft: #1e3a8a;
    --danger: #f87171;
    --danger-soft: #450a0a;
    --warning: #fbbf24;
    --warning-soft: #422006;
    --success: #4ade80;
    --success-soft: #052e16;
    --info: #38bdf8;
    --info-soft: #082f49;
    --neutral-soft: #1e293b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
code, .mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Layout ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1280px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 16px; min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand img { width: 24px; height: 24px; }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a {
  padding: 6px 10px; border-radius: 8px; color: var(--muted); white-space: nowrap; font-weight: 500;
}
.nav a:hover { background: var(--neutral-soft); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.usermenu { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.usermenu form { margin: 0; }
.container { max-width: 1280px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 16px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stack > * + * { margin-top: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card > .actions, .card > .stack { margin-top: 16px; }
.card > h2 + .kv, .card > h2 + .table-wrap { margin-top: 4px; }
.stat .value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat .label { color: var(--muted); font-size: .85rem; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--neutral-soft); color: var(--muted);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.st-success, .st-ok { background: var(--success-soft); color: var(--success); }
.st-failed, .st-error { background: var(--danger-soft); color: var(--danger); }
.st-partial { background: var(--warning-soft); color: var(--warning); }
.st-running { background: var(--info-soft); color: var(--info); }
.st-running::before { animation: pulse 1.2s ease-in-out infinite; }
.st-queued, .st-cancelled, .st-skipped { background: var(--neutral-soft); color: var(--muted); }
.role-admin { background: var(--primary-soft); color: var(--primary); }
@keyframes pulse { 50% { opacity: .25; } }

/* ---------- Alertas ---------- */
.alert {
  border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; border: 1px solid transparent;
  background: var(--info-soft); color: var(--info);
}
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert strong { font-weight: 700; }
.alert ul { margin: .25rem 0 0; padding-left: 1.2rem; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  cursor: pointer; white-space: nowrap; line-height: 1.3;
}
.btn:hover { background: var(--neutral-soft); text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-sm { padding: 4px 10px; font-size: .85rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; margin: 0; }
.nowrap-form { flex-wrap: nowrap; }
.nowrap-form select { width: auto; min-width: 140px; }

/* ---------- Formulários ---------- */
label { display: block; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .hint { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.field .error { color: var(--danger); font-size: .85rem; margin-top: 4px; }
.field.has-error input, .field.has-error textarea, .field.has-error select { border-color: var(--danger); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local],
select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text); font: inherit;
}
textarea { font-family: var(--mono); min-height: 140px; resize: vertical; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; padding: 3px; background: var(--surface-2); flex-wrap: wrap; gap: 2px; }
.segmented label { margin: 0; font-weight: 500; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--primary); }
fieldset { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
legend { font-weight: 600; margin-bottom: 6px; padding: 0; }

.filters { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }
.filters .field { margin: 0; }
.filters label { font-size: .8rem; color: var(--muted); }

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

table.logs td { font-family: var(--mono); font-size: .82rem; padding: 4px 10px; }
table.logs td.msg { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 320px; }
.lvl-ERROR { color: var(--danger); font-weight: 700; }
.lvl-WARNING { color: var(--warning); font-weight: 700; }
.lvl-DEBUG { color: var(--muted); }

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

/* ---------- Abas ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 24px 0 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs .count { background: var(--neutral-soft); border-radius: 999px; padding: 0 6px; font-size: .75rem; margin-left: 4px; }

/* ---------- Progresso ---------- */
progress { width: 100%; height: 8px; border: 0; border-radius: 999px; overflow: hidden; background: var(--neutral-soft); appearance: none; }
progress::-webkit-progress-bar { background: var(--neutral-soft); }
progress::-webkit-progress-value { background: var(--primary); }
progress::-moz-progress-bar { background: var(--primary); }
progress:not([value])::-webkit-progress-bar { background: linear-gradient(90deg, var(--neutral-soft), var(--primary-soft), var(--neutral-soft)); }

.run-active { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--surface-2); }
.run-active + .run-active { margin-top: 8px; }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; }
.code-input { font-family: var(--mono); font-size: 1.6rem; letter-spacing: .5em; text-align: center; }
.auth-links { margin-top: 12px; justify-content: space-between; }
.processing-paused { border-color: var(--warning); background: var(--warning-soft); }
.processing-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.processing-bar form { margin: 0; }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; margin: 0; }
.nav-count { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700; text-align: center; line-height: 18px; }
.who-link { display: inline-flex; align-items: center; gap: 8px; color: var(--text); padding: 4px 8px; border-radius: 8px; }
.who-link:hover, .who-link.active { background: var(--neutral-soft); text-decoration: none; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: inline-grid; place-items: center; font-weight: 700; font-size: .85rem; }
.auth-alt { text-align: center; margin-top: 14px; font-size: .9rem; }
.auth-card h1 { font-size: 1.15rem; }
.pending-card { border-color: var(--primary); margin-bottom: 16px; }
.stack-gap { margin-bottom: 16px; }
.mt { margin-top: 20px; }
.auth-card .brand { justify-content: center; font-size: 1.15rem; margin-bottom: 16px; }

.secret-box {
  font-family: var(--mono); font-size: 1.1rem; padding: 10px 12px; border-radius: 8px;
  background: var(--surface-2); border: 1px dashed var(--border); user-select: all; overflow-wrap: anywhere;
}

.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  .usermenu .who { display: none; }
  .who-link { padding: 2px; }
  .hide-sm { display: none; }
  dl.kv { grid-template-columns: 1fr; gap: 0 0; }
  dl.kv dd { margin-bottom: 8px; }
}
