:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --surface: #151920;
  --surface-2: #1b2028;
  --border: #343b46;
  --text: #f4f6f8;
  --muted: #a8b0bc;
  --green: #42d69d;
  --cyan: #4fc3e8;
  --coral: #ff7a78;
  --amber: #f0bf58;
  --twitch: #9146ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-size: 15px; }
a { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { color: var(--muted); line-height: 1.5; }

.topbar { min-height: 74px; padding: 14px max(18px, calc((100vw - 1240px) / 2)); display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--border); background: #101319; }
.brand-block, .identity, .target-identity { display: flex; align-items: center; gap: 12px; }
.brand-mark, .login-brand { display: grid; place-items: center; width: 42px; aspect-ratio: 1; border-radius: 6px; background: var(--green); color: #07120e; font-weight: 900; }
.brand-block strong { display: block; font-size: 17px; }
.brand-block span, .identity span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.identity img, .target-identity img { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; }
.identity form { margin: 0 0 0 8px; }

.navigation { display: flex; gap: 4px; padding: 8px max(18px, calc((100vw - 1240px) / 2)); border-bottom: 1px solid var(--border); background: #101319; overflow-x: auto; }
.navigation a { padding: 8px 12px; border-radius: 5px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.navigation a:hover { color: var(--text); background: var(--surface-2); }
.navigation a[aria-current="page"] { color: #07120e; background: var(--green); font-weight: 800; }

.page { width: min(1240px, calc(100% - 36px)); margin: 24px auto 48px; }
footer { padding: 24px; color: var(--muted); text-align: center; font-size: 12px; border-top: 1px solid var(--border); }

.button { display: inline-flex; min-height: 40px; align-items: center; justify-content: center; padding: 9px 14px; border: 1px solid var(--border); border-radius: 5px; background: #242b35; color: var(--text); font: inherit; font-weight: 750; text-decoration: none; cursor: pointer; }
.button:hover { border-color: var(--cyan); }
.button.primary { background: var(--green); border-color: var(--green); color: #07120e; }
.button.warning { background: var(--amber); border-color: var(--amber); color: #1b1200; }
.button.danger { background: var(--coral); border-color: var(--coral); color: #1c0606; }
.button.twitch { width: 100%; background: var(--twitch); border-color: var(--twitch); }
.button.subtle { min-height: 34px; padding: 6px 10px; background: transparent; }
.button:disabled { opacity: .45; cursor: not-allowed; }

input, select, textarea { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 5px; background: #0e1218; color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--cyan) 55%, transparent); border-color: var(--cyan); }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }

.login-tool { width: min(420px, 100%); margin: 10vh auto; padding: 28px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.login-brand { width: 50px; margin-bottom: 22px; }
.login-tool h1 { margin-bottom: 6px; }
.login-status { margin-top: 18px; color: var(--muted); font-size: 12px; text-align: center; }

.flash { margin-bottom: 16px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); }
.flash.success { border-color: color-mix(in srgb, var(--green) 65%, var(--border)); color: #b9f6dc; }
.flash.error { border-color: color-mix(in srgb, var(--coral) 65%, var(--border)); color: #ffd0cf; }
.flash.warning { border-color: color-mix(in srgb, var(--amber) 65%, var(--border)); color: #ffe2a3; }

.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric { min-height: 112px; padding: 16px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.metric > span { display: block; color: var(--muted); font-size: 12px; }
.metric > strong { display: block; margin: 9px 0; font-size: 22px; overflow-wrap: anywhere; }
.metric small { color: var(--muted); }

.work-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.tool, .target-tool, .history-section, .integration-tool, .update-tool, .log-tool { margin-bottom: 16px; padding: 18px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.tool-head, .section-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.tool-head h2, .section-head h1, .section-head h2 { margin-bottom: 4px; }
.tool-head p, .section-head p { margin: 0; font-size: 13px; }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.settings-form { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 2fr) minmax(160px, .7fr) auto; align-items: end; gap: 12px; }

.target-identity { flex-wrap: wrap; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.target-identity img { width: 58px; height: 58px; }
.target-identity h2 { margin-bottom: 3px; }
.target-identity p { margin: 0; }
.target-status { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.pill { display: inline-flex; align-items: center; min-height: 26px; padding: 4px 8px; border-radius: 999px; background: #2a313c; color: var(--muted); font-size: 12px; font-weight: 800; white-space: nowrap; }
.pill.ok { background: #133c31; color: #adf5d8; }
.pill.error { background: #49272c; color: #ffd1d3; }
.pill.warning { background: #443821; color: #ffe0a0; }
.status-line, .info-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.status-line span, .info-row span { color: var(--muted); }
.action-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.action-tool { display: grid; align-content: start; gap: 12px; min-height: 220px; padding: 15px; border: 1px solid var(--border); border-radius: 5px; background: #11151b; }
.action-tool h3 { margin-bottom: 0; }
.action-tool .button { align-self: end; margin-top: auto; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 10px; border-bottom: 1px solid var(--border); color: var(--muted); text-align: left; font-size: 11px; text-transform: uppercase; }
td { padding: 11px 10px; border-bottom: 1px solid #292f38; vertical-align: top; }
.empty { padding: 24px; border: 1px dashed var(--border); color: var(--muted); text-align: center; }
.info-grid { border-top: 1px solid var(--border); }
.log-tool pre { min-height: 280px; max-height: 520px; margin: 0; padding: 14px; overflow: auto; border: 1px solid var(--border); border-radius: 5px; background: #090c10; color: #d7e0e8; white-space: pre-wrap; }
.error-page { max-width: 680px; margin: 12vh auto; text-align: center; }
.error-page > span { color: var(--coral); font-size: 64px; font-weight: 900; }

@media (max-width: 820px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .identity { width: 100%; }
  .identity form { margin-left: auto; }
  .metric-grid, .metric-grid.four, .work-grid, .action-grid, .settings-form { grid-template-columns: 1fr; }
  .action-tool { min-height: 0; }
}

@media (max-width: 600px) {
  .page { width: min(100% - 20px, 1240px); margin-top: 12px; }
  .topbar { padding: 12px; }
  .brand-block strong { font-size: 15px; }
  .tool-head, .section-head, .status-line, .info-row { align-items: flex-start; flex-direction: column; }
  .inline-form { grid-template-columns: 1fr; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { display: none; }
  tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  td { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 8px; padding: 5px 0; border: 0; overflow-wrap: anywhere; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
}
