/* Painel do Isle. Sem framework; claro e escuro por prefers-color-scheme. */

:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --line: #e4e6eb;
  --line-strong: #d3d6dd;
  --ink: #15171c;
  --muted: #646b78;
  --faint: #8d939e;
  --accent: #4f5bd5;
  --accent-ink: #ffffff;
  --accent-soft: #eceefd;
  --focus: #4f5bd5;
  --island: #000000;
  --island-ink: #c9ccd3;
  --island-active: #2a2c31;
  --island-edge: transparent;

  --ok: #17794a;
  --ok-soft: #e3f4ea;
  --warn: #8f5600;
  --warn-soft: #fbefd9;
  --idle: #555c68;
  --idle-soft: #eceef1;
  --bad: #b42318;
  --bad-soft: #fde8e6;

  --radius-s: 6px;
  --radius-m: 10px;
  --shadow-pop: 0 12px 40px rgba(16, 18, 24, 0.18), 0 2px 6px rgba(16, 18, 24, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f12;
    --surface: #16181c;
    --surface-2: #1c1f24;
    --line: #262931;
    --line-strong: #343842;
    --ink: #e8eaef;
    --muted: #949aa6;
    --faint: #6f7581;
    --accent: #8b93f0;
    --accent-ink: #0e0f12;
    --accent-soft: #23264a;
    --focus: #a3aaf5;
    --island: #000000;
    --island-ink: #a9adb6;
    --island-active: #24262b;
    --island-edge: rgba(255, 255, 255, 0.09);

    --ok: #5fd39a;
    --ok-soft: #12291d;
    --warn: #f0b456;
    --warn-soft: #2e2210;
    --idle: #a6acb7;
    --idle-soft: #22252b;
    --bad: #ff8a80;
    --bad-soft: #351816;
    --shadow-pop: 0 16px 48px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.45 var(--font);
  font-feature-settings: "tnum" 1;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 12.5px; letter-spacing: 0; }
.muted { color: var(--muted); }

/* ---------- topo e a ilha ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; }
.brand-mark { width: 26px; height: 12px; border-radius: 999px; background: var(--island); box-shadow: 0 0 0 1px var(--island-edge); }
.brand small { font-weight: 400; color: var(--muted); }

.island {
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--island);
  border-radius: 999px;
  box-shadow: 0 0 0 1px var(--island-edge), 0 6px 18px rgba(0, 0, 0, 0.18);
}
.island a {
  padding: 6px 14px;
  border-radius: 999px;
  color: var(--island-ink);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.island a:hover { color: #ffffff; }
.island a[aria-current="page"] { background: var(--island-active); color: #ffffff; }
.island a:focus-visible { outline-color: #ffffff; outline-offset: -2px; }

.top-end { display: flex; justify-content: flex-end; align-items: center; gap: 10px; min-width: 0; }
.who { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22ch; }

/* ---------- botões e campos ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.btn.danger { color: var(--bad); }
.btn.danger-solid { background: var(--bad); border-color: var(--bad); color: #ffffff; }
@media (prefers-color-scheme: dark) { .btn.danger-solid { color: #1a0b0a; } }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.small { height: 26px; padding: 0 9px; font-size: 12.5px; }
.btn[aria-busy="true"] { cursor: progress; opacity: 0.7; }

.field { display: grid; gap: 6px; }
.field > span, .label { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.input, select.input, textarea.input {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  font-size: 13px;
  min-width: 0;
}
textarea.input { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
.input:disabled { opacity: 0.5; cursor: not-allowed; background: var(--surface-2); }
.input:focus-visible { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
.help { font-size: 12.5px; color: var(--muted); margin: 0; }
.error-text { font-size: 12.5px; color: var(--bad); margin: 0; }

/* ---------- conteúdo ---------- */

main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
h1 { font-size: 22px; line-height: 1.2; font-weight: 600; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 14px; font-weight: 600; margin: 0; letter-spacing: -0.005em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); min-height: 48px; }
.panel-body { padding: 16px; }
.stack { display: grid; gap: 20px; }

/* ---------- tabelas densas ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  background: var(--surface);
}
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
tr.link-row { cursor: pointer; }
tr.link-row:hover td { background: var(--surface-2); }
tr.link-row a { text-decoration: none; font-weight: 500; }
tr.link-row a:hover { text-decoration: underline; }
.cell-email { max-width: 30ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

/* ---------- selos de estado (cor + ícone + texto) ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px 0 6px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge svg { width: 12px; height: 12px; flex: none; }
.badge.active { color: var(--ok); background: var(--ok-soft); }
.badge.suspended { color: var(--warn); background: var(--warn-soft); }
.badge.expired { color: var(--idle); background: var(--idle-soft); border-color: var(--line-strong); border-style: dashed; }
.badge.revoked { color: var(--bad); background: var(--bad-soft); }
.tag { font-size: 12px; color: var(--muted); }

/* ---------- visão geral ---------- */

.overview { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.ledger td.period { font-weight: 500; }
.ledger td.money { text-align: right; }
.money-list { display: grid; gap: 2px; justify-items: end; }
.money-list .none { color: var(--faint); }
.ledger tr.total td { font-weight: 600; background: var(--surface-2); }
.big-count { font-size: 15px; font-weight: 600; }

.states-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--surface-2); gap: 2px; margin: 4px 0 14px; }
.states-bar span { display: block; min-width: 3px; }
.states-bar .active { background: var(--ok); }
.states-bar .suspended { background: var(--warn); }
.states-bar .expired { background: var(--idle); opacity: 0.55; }
.states-bar .revoked { background: var(--bad); }
.legend { display: grid; gap: 2px; margin: 0; }
.legend > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.legend > div:last-child { border-bottom: 0; }
.legend dt { display: flex; align-items: center; gap: 8px; }
.legend dd { margin: 0; font-weight: 600; }
.legend a { text-decoration: none; }
.legend a:hover { text-decoration: underline; }

/* ---------- lista de licenças ---------- */

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.toolbar .search { flex: 1 1 260px; }
.segmented { display: inline-flex; padding: 2px; border: 1px solid var(--line-strong); border-radius: var(--radius-s); background: var(--surface-2); flex-wrap: wrap; }
.segmented button { border: 0; background: transparent; height: 26px; padding: 0 10px; border-radius: 4px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line-strong); font-weight: 500; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.pager .btns { display: flex; gap: 6px; }

/* ---------- detalhe ---------- */

.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: 13px; margin-bottom: 10px; }
.back:hover { color: var(--ink); }
.detail-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 8px; }
.detail-head h1 { word-break: break-all; }
.keyline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 22px; }
.keyline .mono { padding: 4px 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); user-select: all; }
.detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-rows: auto 1fr;
  grid-template-areas: "data side" "rest side";
  gap: 20px;
  align-items: start;
}
.detail-data { grid-area: data; }
.detail .actions { grid-area: side; }
.detail-rest { grid-area: rest; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0; margin: 0; }
.facts dt, .facts dd { padding: 8px 0; border-bottom: 1px solid var(--line); margin: 0; }
.facts dt { color: var(--muted); padding-right: 24px; }
.facts dt:nth-last-child(2), .facts dd:last-child { border-bottom: 0; }
.actions { display: grid; gap: 0; }
.action-group { padding: 14px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.action-group:last-child { border-bottom: 0; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row .input { flex: 1 1 140px; }
.events { list-style: none; margin: 0; padding: 0; }
.events li { display: grid; grid-template-columns: 132px 1fr; gap: 12px; padding: 9px 16px; border-bottom: 1px solid var(--line); font-size: 13px; }
.events li:last-child { border-bottom: 0; }
.events time { color: var(--muted); }
.events .actor { color: var(--muted); }

/* ---------- nova chave ---------- */

.form { display: grid; gap: 18px; max-width: 560px; }
.choice { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; }
.choice label, .check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.choice input, .check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.created { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--ok); border-radius: var(--radius-m); background: var(--ok-soft); max-width: 560px; }
.created p { margin: 0; }

/* ---------- diálogo, aviso, carregando ---------- */

dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
}
dialog::backdrop { background: rgba(8, 9, 12, 0.45); }
dialog[open] { animation: pop 0.16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } }
.dialog-body { padding: 20px 20px 4px; }
.dialog-body h2 { font-size: 16px; margin-bottom: 8px; }
.dialog-body p { margin: 0; color: var(--muted); }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 18px 20px 20px; }

.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 20; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--island);
  color: #ffffff;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  animation: toast-in 0.2s ease-out;
}
.toast.error { background: var(--bad); }
@media (prefers-color-scheme: dark) { .toast.error { color: #1a0b0a; } .toast { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1), 0 10px 30px rgba(0, 0, 0, 0.5); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.loading { padding: 48px 0; text-align: center; color: var(--muted); }
.notice { padding: 12px 16px; border: 1px solid var(--line-strong); border-radius: var(--radius-m); background: var(--surface); }

/* ---------- login ---------- */

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: min(380px, 100%); display: grid; gap: 22px; }
.login .brand { justify-content: center; font-size: 15px; }
.login .brand-mark { width: 52px; height: 22px; }
.login .panel-body { display: grid; gap: 14px; padding: 22px; }
.login h1 { font-size: 18px; }
.login p { margin: 0; color: var(--muted); }
.login .btn { height: 36px; width: 100%; }
.login .input { height: 36px; }
.sent { display: grid; gap: 6px; }
.dev-box { border-top: 1px dashed var(--line-strong); padding-top: 14px; display: grid; gap: 8px; }

/* ---------- celular ---------- */

@media (max-width: 860px) {
  .overview { grid-template-columns: 1fr; }
  .detail { grid-template-columns: 1fr; grid-template-rows: auto; grid-template-areas: "data" "side" "rest"; }
}

@media (max-width: 640px) {
  .top { grid-template-columns: 1fr auto; padding: 10px 16px; gap: 10px; }
  .top .island { grid-column: 1 / -1; grid-row: 2; justify-content: space-between; overflow-x: auto; }
  .island a { padding: 6px 12px; flex: 1; text-align: center; }
  .who { display: none; }
  main { padding: 20px 16px 72px; }
  h1 { font-size: 19px; }
  .toolbar { padding: 12px; }
  .toolbar .search { flex-basis: 100%; }
  .segmented { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
  .segmented button { flex: none; }
  .hide-sm { display: none; }
  td, th { padding: 8px 10px; }
  .cell-email { max-width: 18ch; }
  .events li { grid-template-columns: 1fr; gap: 2px; }
  .facts { grid-template-columns: 1fr; }
  .facts dt { padding-bottom: 0; border-bottom: 0; font-size: 12.5px; }
  .facts dd { padding-top: 2px; }
  .pager { flex-wrap: wrap; }
}

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

fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.plain legend { padding: 0; margin-bottom: 6px; }
.note-box { border-top: 1px solid var(--line); }
