:root {
  --paper: #FFFFFF;
  --canvas: #F5F6F8;
  --ink: #1D2433;
  --muted: #5B6475;
  --rule: #E2E5EA;
  --rule-strong: #C9CED6;
  --accent: #2747C9;
  --accent-hover: #1E39A6;
  --accent-soft: #EEF1FC;
  --ok: #1C7C4A;
  --ok-soft: #E8F4EE;
  --warn: #8A5300;
  --warn-soft: #FBF1DF;
  --danger: #B42318;
  --danger-soft: #FCEBEA;
  --line-green: #06C755;
  --whatsapp-green: #25D366;
  --radius: 6px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

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

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 24px; line-height: 1.25; }
h2 { font-size: 17px; line-height: 1.35; }
h3 { font-size: 15px; }
p { margin: 0; }

/* ---------- App layout ---------- */

.app {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--canvas);
  border-right: 1px solid var(--rule);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark {
  width: 18px; height: 18px; border-radius: 4px;
  background: var(--accent);
  box-shadow: inset -6px -6px 0 0 #6F86E8;
}
.brand-name { font-weight: 600; font-size: 16px; }

.org-switch {
  display: flex; flex-direction: column;
  padding: 10px 10px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.org-name { font-weight: 500; }
.org-meta { font-size: 13px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--ink);
}
.nav-link:hover { background: #ECEEF2; text-decoration: none; }
.nav-link.is-active { background: var(--paper); box-shadow: inset 3px 0 0 var(--accent); font-weight: 500; }
.nav-note { font-size: 12px; color: var(--muted); font-weight: 400; }

.sidebar-footer {
  margin-top: auto;
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 12px 10px 0;
  border-top: 1px solid var(--rule);
  font-size: 14px;
}
.signed-in-as { font-weight: 500; }

.main { padding: 32px 40px 64px; max-width: 1040px; width: 100%; }

.page-header {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px;
  margin-bottom: 24px;
}
.page-header p { color: var(--muted); margin-top: 4px; }
.back-link { display: inline-block; font-size: 14px; margin-bottom: 10px; }

.section { margin-top: 36px; }
.section-header {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  margin-bottom: 12px;
}
.section-header p { color: var(--muted); font-size: 14px; }

/* ---------- Buttons and forms ---------- */

.button {
  display: inline-flex; align-items: center; justify-content: center;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font: inherit; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.button:hover { background: var(--canvas); text-decoration: none; }
.button-primary { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
.button-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button-danger { background: var(--danger); border-color: var(--danger); color: #FFFFFF; }
.button-danger:hover { background: #8F1C13; }
.button-small { height: 30px; padding: 0 10px; font-size: 14px; }
.button:disabled { opacity: 0.5; cursor: not-allowed; }

.link-button {
  border: 0; background: none; padding: 0;
  font: inherit; color: var(--accent); cursor: pointer;
}
.link-button:hover { text-decoration: underline; }
.link-button.is-danger { color: var(--danger); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 500; font-size: 14px; }
.field-hint { font-size: 13px; color: var(--muted); }
.input {
  height: 40px; padding: 0 12px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  font: inherit; color: var(--ink);
  background: var(--paper);
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.input[readonly] { background: var(--canvas); color: var(--muted); }
.input-code { letter-spacing: 0.3em; font-size: 18px; width: 170px; }
.form-error { color: var(--danger); font-size: 14px; margin-bottom: 12px; }

/* ---------- Tables ---------- */

.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
th { font-size: 13px; font-weight: 500; color: var(--muted); background: var(--canvas); }
tbody tr:last-child td { border-bottom: 0; }
td.amount, th.amount { text-align: right; }
td.actions { text-align: right; white-space: nowrap; }
td.actions > * + * { margin-left: 14px; }
.cell-sub { display: block; font-size: 13px; color: var(--muted); }
tfoot td { font-weight: 600; border-top: 1px solid var(--rule-strong); border-bottom: 0; }

/* ---------- Status ---------- */

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-ok { color: var(--ok); }
.status-warn { color: var(--warn); }
.status-danger { color: var(--danger); }
.status-muted { color: var(--muted); }

.notice {
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--canvas);
  border: 1px solid var(--rule);
  font-size: 14px;
}
.notice-warn { background: var(--warn-soft); border-color: #EBD3A6; }

.platform-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 8px; }
.platform-dot-line { background: var(--line-green); }
.platform-dot-whatsapp { background: var(--whatsapp-green); }

/* ---------- Tabs ---------- */

.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--rule); margin-bottom: 20px; }
.tab {
  border: 0; background: none; padding: 10px 0;
  font: inherit; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab[aria-selected="true"] { color: var(--ink); font-weight: 500; border-bottom-color: var(--accent); }
.tab-count { color: var(--muted); font-weight: 400; margin-left: 4px; }

/* ---------- Plugins list ---------- */

.plugin-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--rule); border-radius: var(--radius); }
.plugin-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 24px; align-items: center;
  padding: 18px 20px; border-bottom: 1px solid var(--rule);
}
.plugin-row:last-child { border-bottom: 0; }
.plugin-row h3 a { color: var(--ink); }
.plugin-row p { color: var(--muted); font-size: 14px; margin-top: 2px; }
.plugin-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 8px; font-size: 14px; }

.plugin-detail { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 40px; align-items: start; }
.plugin-detail .lead { font-size: 17px; color: var(--ink); margin-bottom: 16px; max-width: 62ch; }
.plugin-detail .body-text { color: var(--muted); max-width: 66ch; }
.feature-list { margin: 12px 0 0; padding-left: 20px; }
.feature-list li { margin-bottom: 6px; }
.screenshot-placeholder {
  margin-top: 28px;
  aspect-ratio: 16 / 9;
  border: 1px dashed var(--rule-strong);
  border-radius: var(--radius);
  background: repeating-linear-gradient(135deg, var(--canvas) 0 12px, #FAFBFC 12px 24px);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px;
}
.pricing-panel { border: 1px solid var(--rule); border-radius: var(--radius); }
.pricing-item { padding: 18px 20px; border-bottom: 1px solid var(--rule); display: flex; flex-direction: column; gap: 8px; }
.pricing-item:last-child { border-bottom: 0; }
.price { font-size: 20px; font-weight: 600; }
.price-unit { font-size: 14px; color: var(--muted); font-weight: 400; }

/* ---------- Billing ---------- */

.bill-total { display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px; }
.bill-total strong { font-size: 32px; font-weight: 600; letter-spacing: -0.02em; }
.bill-total span { color: var(--muted); }
.chart-box { border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px 16px 8px; height: 320px; }

.details { display: grid; grid-template-columns: 220px minmax(0, 1fr); margin: 0; border: 1px solid var(--rule); border-radius: var(--radius); }
.details dt, .details dd { margin: 0; padding: 12px 16px; border-bottom: 1px solid var(--rule); }
.details dt { color: var(--muted); font-size: 14px; background: var(--canvas); }
.details dt:last-of-type, .details dd:last-of-type { border-bottom: 0; }
.mono-id { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px; }

/* ---------- Auth pages ---------- */

.auth { min-height: 100vh; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 48px; background: var(--canvas); }
.auth-panel { width: 100%; max-width: 400px; background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; padding: 32px; }
.auth-panel .brand { padding: 0; margin-bottom: 28px; }
.auth-panel h1 { font-size: 21px; margin-bottom: 6px; }
.auth-panel .intro { color: var(--muted); margin-bottom: 24px; }
.auth-panel .button { width: 100%; height: 40px; }
.auth-footnote { margin-top: 20px; font-size: 14px; color: var(--muted); }
.auth-wide { max-width: 520px; }

.steps { list-style: none; counter-reset: step; margin: 0 0 8px; padding: 0; }
.steps > li { counter-increment: step; position: relative; padding-left: 36px; margin-bottom: 22px; }
.steps > li::before {
  content: counter(step);
  position: absolute; left: 0; top: 0;
  width: 24px; height: 24px; border-radius: 50%;
  border: 1px solid var(--rule-strong);
  font-size: 13px; font-weight: 500;
  display: flex; align-items: center; justify-content: center;
}
.steps h2 { font-size: 15px; margin-bottom: 4px; }
.steps p { color: var(--muted); font-size: 14px; }

.qr { width: 180px; height: 180px; display: block; border: 1px solid var(--rule); border-radius: var(--radius); margin: 12px 0; }
.secret-key { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px; background: var(--canvas); padding: 2px 6px; border-radius: 4px; }

/* ---------- Dialog and toast ---------- */

dialog {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: 0 12px 32px rgba(29, 36, 51, 0.16);
}
dialog::backdrop { background: rgba(29, 36, 51, 0.32); }
.dialog-body { padding: 24px 24px 8px; }
.dialog-body h2 { margin-bottom: 10px; }
.dialog-body p { color: var(--muted); margin-bottom: 12px; }
.dialog-body p strong { color: var(--ink); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px 20px; }
.dialog-qr { display: flex; justify-content: center; }

.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translate(-50%, 16px);
  background: var(--ink); color: #FFFFFF;
  padding: 10px 16px; border-radius: var(--radius);
  font-size: 14px;
  opacity: 0; pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.empty-state { padding: 32px 20px; text-align: center; color: var(--muted); }
.empty-state .button { margin-top: 12px; }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

/* ---------- Narrow screens ---------- */

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; padding: 12px 16px; gap: 10px; border-right: 0; border-bottom: 1px solid var(--rule); }
  .org-switch, .sidebar-footer { display: none; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav-note { display: none; }
  .nav-link.is-active { box-shadow: inset 0 -2px 0 var(--accent); }
  .main { padding: 24px 16px 48px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .plugin-detail { grid-template-columns: minmax(0, 1fr); }
  .details { grid-template-columns: minmax(0, 1fr); }
  .details dt { border-bottom: 0; padding-bottom: 2px; }
  .details dd { padding-top: 2px; }
  .plugin-row { grid-template-columns: minmax(0, 1fr); }
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

[hidden] { display: none !important; }
