/* Upinion design system — the executable copy of DESIGN.md.
   Linked by every screen at /assets/upinion.css. Tokens + base + components. */

:root {
  /* neutrals — off-white limpo, frio-neutro (nada de creme); camadas bem separadas:
     corpo levemente cinza, painéis/inputs brancos, hairlines nítidas */
  --bg: oklch(1 0 0);
  --surface-2: oklch(0.984 0.0015 264);
  --surface-3: oklch(0.962 0.003 264);
  --ink: oklch(0.225 0.019 265);
  --muted: oklch(0.475 0.017 265);
  --faint: oklch(0.585 0.015 265);
  --line: oklch(0.918 0.004 264);
  --line-2: oklch(0.864 0.006 264);

  /* marca âmbar — refinada: acento quente sobre neutros frios (sem roxo).
     primary = fundo de botão/acento; primary-strong = texto/link (contraste ≥4.5:1) */
  --primary: oklch(0.715 0.138 71);
  --primary-strong: oklch(0.585 0.135 62);
  --primary-soft: oklch(0.967 0.030 80);
  --primary-border: oklch(0.865 0.062 78);
  --on-primary: oklch(0.235 0.03 68);
  --focus: oklch(0.62 0.13 250);

  /* semantic (light) */
  --success: oklch(0.60 0.13 156); --success-soft: oklch(0.958 0.038 156);
  --danger: oklch(0.565 0.19 25);  --danger-soft: oklch(0.955 0.035 25);
  --warning: oklch(0.70 0.15 62);  --warning-soft: oklch(0.958 0.04 62);
  --info: oklch(0.58 0.10 248);    --info-soft: oklch(0.955 0.025 248);

  /* type */
  --font-sans: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --t-xs: 12px; --t-sm: 13px; --t-base: 14px; --t-md: 15px;
  --t-lg: 17px; --t-xl: 20px; --t-2xl: 24px; --t-3xl: 30px;

  /* shape refinada (crisp, sem excesso de arredondamento) + sombras leves e frias */
  --r-1: 5px; --r-2: 7px; --r-3: 10px; --r-4: 13px; --r-pill: 999px;
  --shadow-sm: 0 1px 2px oklch(0.24 0.02 264 / 0.06), 0 1px 3px oklch(0.24 0.02 264 / 0.04);
  --shadow-md: 0 4px 16px oklch(0.24 0.02 264 / 0.08);
  --shadow-lg: 0 18px 50px oklch(0.24 0.02 264 / 0.16);
  --ring: 0 0 0 3px oklch(0.62 0.13 250 / 0.28);
  --dur: 160ms; --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  /* z-scale */
  --z-dropdown: 1000; --z-sticky: 1100; --z-backdrop: 1200;
  --z-modal: 1300; --z-toast: 1400; --z-tooltip: 1500;

  --maxw: 1080px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-sans); font-size: var(--t-base); line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0 0 .4em; font-weight: 700; letter-spacing: -0.018em; text-wrap: balance; line-height: 1.15; }
h1 { font-size: var(--t-3xl); } h2 { font-size: var(--t-xl); } h3 { font-size: var(--t-lg); }
p { margin: 0 0 1em; max-width: 68ch; text-wrap: pretty; }
a { color: var(--primary-strong); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
.mono, code, kbd { font-family: var(--font-mono); }
code { background: var(--surface-3); padding: 1px 6px; border-radius: var(--r-1); font-size: 0.9em; color: var(--ink); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
::selection { background: var(--primary-soft); color: var(--ink); }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 99px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--faint); }

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-1);
}

/* ---------- buttons ---------- */
.btn, .btn-primary, .btn-ghost, .btn-danger, .btn-quiet, .btn-sm, .btn-lg,
button.primary, a.primary, button.ghost, a.ghost {
  --_bg: var(--surface-3); --_fg: var(--ink); --_bd: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: 600 var(--t-base)/1 var(--font-sans); letter-spacing: -0.005em;
  padding: 10px 16px; border-radius: var(--r-2); border: 1px solid var(--_bd);
  background: var(--_bg); color: var(--_fg); cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: color-mix(in oklch, var(--_bg), var(--ink) 7%); }
.btn:active { transform: translateY(0.5px); }
.btn:disabled, .btn[disabled], .btn.is-disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-sm { padding: 7px 12px; font-size: var(--t-sm); border-radius: var(--r-1); }
.btn-lg { padding: 13px 22px; font-size: var(--t-md); }

.btn-primary, .btn.primary, .primary {
  --_bg: var(--primary); --_fg: var(--on-primary); --_bd: transparent;
}
.btn-primary:hover, .btn.primary:hover, .primary:hover { background: var(--primary-strong); }

.btn-ghost, .btn.ghost, .ghost {
  --_bg: var(--surface-2); --_fg: var(--ink); --_bd: var(--line-2);
}
.btn-ghost:hover, .btn.ghost:hover, .ghost:hover { background: var(--surface-3); border-color: var(--faint); }

.btn-quiet { --_bg: transparent; --_fg: var(--muted); --_bd: transparent; padding-inline: 10px; }
.btn-quiet:hover { --_fg: var(--ink); background: var(--surface-3); }

.btn-danger { --_bg: var(--danger); --_fg: #fff; }
.btn-danger:hover { background: color-mix(in oklch, var(--danger), black 10%); }

.btn.is-loading { color: transparent !important; position: relative; pointer-events: none; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid currentColor; border-top-color: transparent; color: var(--_fg);
  animation: u-spin 0.7s linear infinite;
}
@keyframes u-spin { to { transform: rotate(360deg); } }

/* icon button */
.icon, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0; border: 1px solid transparent;
  background: var(--surface-3); color: var(--ink); border-radius: var(--r-1);
  cursor: pointer; font-size: 14px; line-height: 1;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.icon:hover, .icon-btn:hover { background: color-mix(in oklch, var(--surface-3), var(--ink) 8%); }

/* ---------- form controls ---------- */
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=search], input[type=url], input:not([type]), select, textarea, .field {
  font: 400 var(--t-base)/1.4 var(--font-sans); color: var(--ink);
  background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--r-1);
  padding: 9px 11px; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
textarea { line-height: 1.55; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus, .field:focus {
  outline: none; border-color: var(--primary); box-shadow: var(--ring);
}
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236a7180' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
label { font-size: var(--t-sm); font-weight: 600; color: var(--muted); display: block; margin: 0 0 5px; }

/* ---------- surfaces ---------- */
.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-3); padding: 18px 20px; }
.panel { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-3); padding: 16px; }
.divider { height: 1px; background: var(--line); border: 0; margin: 16px 0; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-xs); font-weight: 600;
  padding: 3px 9px 3px 8px; border-radius: var(--r-pill); background: var(--surface-3); color: var(--muted);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-live { background: var(--success-soft); color: var(--success); }
.badge-draft { background: var(--surface-3); color: var(--muted); }
.badge-warn { background: var(--warning-soft); color: var(--warning); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-amber { background: var(--primary-soft); color: var(--primary-strong); }
.pill { display: inline-flex; align-items: center; font-size: var(--t-xs); font-weight: 600; padding: 2px 9px; border-radius: var(--r-pill); background: var(--surface-3); color: var(--muted); }

/* ---------- tabs (segmented) ---------- */
.tabs { display: inline-flex; gap: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-2); padding: 3px; }
.tabs button, .tab { border: 0; background: transparent; color: var(--muted); font: 600 var(--t-sm)/1 var(--font-sans); padding: 8px 14px; border-radius: var(--r-1); cursor: pointer; transition: background var(--dur) var(--ease), color var(--dur) var(--ease); }
.tabs button.on, .tab.on, .tab[aria-selected=true] { background: var(--bg); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---------- table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.table th { text-align: left; font-weight: 600; color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--line-2); background: var(--surface-2); }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--line); }
.table tr:hover td { background: var(--surface-2); }
.table .num, .table .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- empty + skeleton ---------- */
.empty { text-align: center; color: var(--muted); background: var(--surface-2); border: 1px dashed var(--line-2); border-radius: var(--r-3); padding: 34px 24px; }
.empty h3 { color: var(--ink); }
.skeleton { background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%); background-size: 200% 100%; border-radius: var(--r-1); animation: u-shimmer 1.3s var(--ease) infinite; }
@keyframes u-shimmer { to { background-position: -200% 0; } }

/* ---------- topbar + brand ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 11px 20px;
  background: color-mix(in oklch, var(--bg), transparent 8%); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: var(--z-sticky);
}
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 700; font-size: var(--t-lg); letter-spacing: -0.02em; color: var(--ink); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; flex: none; border-radius: 7px; display: block; }
.spacer { flex: 1; }

/* ---------- toast ---------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: var(--z-toast);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: var(--r-2); box-shadow: var(--shadow-lg); font-size: var(--t-sm); font-weight: 500; }

/* ---------- dialog ---------- */
dialog { border: 1px solid var(--line); border-radius: var(--r-4); padding: 0; box-shadow: var(--shadow-lg); color: var(--ink); max-width: 92vw; }
dialog::backdrop { background: oklch(0.24 0.02 264 / 0.4); backdrop-filter: blur(2px); }

/* ---------- utilities ---------- */
.stack { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap-narrow { max-width: 760px; margin-inline: auto; }
.link { color: var(--primary-strong); font-weight: 600; }
.u-mono { font-family: var(--font-mono); }

/* ---- Barra superior compartilhada (appbar.js) ---- */
.appbar { position: sticky; top: 0; z-index: var(--z-sticky, 30); background: color-mix(in oklch, var(--bg), transparent 8%);
  backdrop-filter: saturate(1.2) blur(8px); border-bottom: 1px solid var(--line); }
.appbar-in { max-width: var(--maxw); margin: 0 auto; padding: 10px 24px; display: flex; align-items: center; gap: 14px; }
.appbar-spacer { flex: 1; }
.appbar-brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; }
.appbar-brand img { display: block; }
.appnav { display: flex; align-items: center; gap: 2px; margin-left: 6px; }
.appnav-link { position: relative; padding: 7px 13px; border-radius: var(--r-1); color: var(--muted); font-weight: 600; font-size: var(--t-sm); text-decoration: none; transition: color var(--dur) var(--ease), background var(--dur) var(--ease); }
.appnav-link:hover { color: var(--ink); background: var(--surface-3); }
.appnav-link.on { color: var(--ink); background: var(--primary-soft); }
.avatar { width: 34px; height: 34px; flex: none; border-radius: 50%; border: 1px solid var(--primary-border);
  background: var(--primary-soft); color: var(--primary-strong); font: 700 12px/1 var(--font-sans); letter-spacing: 0.02em;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: box-shadow var(--dur) var(--ease); }
.avatar:hover { box-shadow: 0 0 0 3px var(--primary-soft); }
.acct { position: relative; }
.acct-menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 244px; background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--r-2, 10px); box-shadow: var(--shadow-lg); padding: 6px; }
.acct-menu[hidden] { display: none; }
.acct-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px 10px; }
.acct-av { width: 36px; height: 36px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-strong);
  font: 700 13px/1 var(--font-sans); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.acct-head b { display: block; font-size: var(--t-sm); }
.acct-head small { display: block; color: var(--muted); font-size: var(--t-xs, 12px); word-break: break-all; }
.acct-menu a, .acct-danger { display: block; width: 100%; text-align: left; padding: 8px 11px; border-radius: var(--r-1);
  color: var(--ink); font-weight: 500; font-size: var(--t-sm); text-decoration: none; background: none; border: none; cursor: pointer; }
.acct-menu a:hover { background: var(--surface-3); text-decoration: none; }
.acct-sep { height: 1px; background: var(--line); margin: 5px 2px; }
.acct-danger { color: var(--danger); }
.acct-danger:hover { background: var(--danger-soft); }
@media (max-width: 620px) { .appbar-in { gap: 8px; padding: 9px 14px; } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
