/* TalesWeaver Server Control. Light and dark theme: system preference, overridable with the Theme button. */
:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #d8dce3;
  --text: #1c2230;
  --muted: #5d6677;
  --accent: #2f6fdf;
  --accent-text: #ffffff;
  --ok: #1d8a4e;
  --warn: #b26b00;
  --bad: #c33a3a;
  --info: #2f6fdf;
  --log-bg: #fbfbfc;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 2px 8px rgb(0 0 0 / 4%);
  --radius: 8px;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #12151b;
    --surface: #1a1e26;
    --surface-2: #232834;
    --border: #2f3542;
    --text: #e3e7ee;
    --muted: #97a0b1;
    --accent: #5b93f5;
    --accent-text: #0d1117;
    --ok: #4cc283;
    --warn: #e0a43a;
    --bad: #f07272;
    --info: #6ea2ff;
    --log-bg: #0f1217;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12151b;
  --surface: #1a1e26;
  --surface-2: #232834;
  --border: #2f3542;
  --text: #e3e7ee;
  --muted: #97a0b1;
  --accent: #5b93f5;
  --accent-text: #0d1117;
  --ok: #4cc283;
  --warn: #e0a43a;
  --bad: #f07272;
  --info: #6ea2ff;
  --log-bg: #0f1217;
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

[hidden] { display: none !important; }

h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 0.5rem; }
a { color: var(--accent); }
.muted { color: var(--muted); font-weight: normal; font-size: 0.9rem; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.5rem; white-space: nowrap; }
.nav { display: flex; flex-wrap: wrap; gap: 0.25rem; flex: 1; }
.nav a {
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent); color: var(--accent-text); }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.user { color: var(--muted); font-size: 0.9rem; }

main { padding: 1.25rem 1rem 3rem; max-width: 1400px; margin: 0 auto; }

/* Controls */
button, .button, input, select {
  font: inherit;
  color: inherit;
}
button, .button {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { border-color: var(--bad); color: var(--bad); }
button.ghost { background: transparent; }
button.small { padding: 0.15rem 0.55rem; font-size: 0.85rem; }
button.active { background: var(--accent); color: var(--accent-text); }
input, select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  min-width: 0;
}
label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--muted); }
label > input, label > select { color: var(--text); font-size: 0.95rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Layout pieces */
.view-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.stat .label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.stat .value { font-size: 1.5rem; font-weight: 600; margin-top: 0.2rem; overflow-wrap: anywhere; }
.stat .value.small { font-size: 1rem; }
.notice {
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--warn);
  border-left-width: 4px;
  border-radius: 6px;
  background: var(--surface);
}
.error { color: var(--bad); margin: 0; }

/* Tables */
.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: 0.5rem 0.7rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: var(--surface-2); }
table.data tr:last-child td { border-bottom: 0; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .actions { display: flex; flex-wrap: wrap; gap: 0.3rem; }
table.data .empty { color: var(--muted); text-align: center; padding: 1.5rem; }
table.data .strong { font-weight: 600; }
.stat .detail { color: var(--muted); font-size: 0.8rem; margin-top: 0.15rem; overflow-wrap: anywhere; }
.hint { margin-top: 0.75rem; }

/* Inline confirmation below a world row */
tr.confirm-row td { background: var(--surface-2); }
.confirm { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.6rem 1rem; }
.confirm-text { width: 100%; margin: 0; color: var(--text); }
.confirm-fields { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.6rem 1rem; flex: 1; }
.confirm-fields input[type="text"] { min-width: 16rem; }
.confirm-actions { display: flex; gap: 0.5rem; }
label.check { flex-direction: row; align-items: center; gap: 0.4rem; color: var(--text); font-size: 0.9rem; }
.mono { font-family: var(--mono); font-size: 0.88rem; overflow-wrap: anywhere; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid currentcolor;
}
.badge.ok { color: var(--ok); }
.badge.warn { color: var(--warn); }
.badge.bad { color: var(--bad); }
.badge.neutral { color: var(--muted); }

/* Characters of an account, opened below its row */
tr.characters-row > td { background: var(--surface-2); padding: 0.75rem; }
/* The panel never widens the account table: it stays as wide as the screen and scrolls its own table. */
.characters { display: flex; flex-direction: column; gap: 0.6rem; position: sticky; left: 0; max-width: calc(100vw - 4.5rem); }
.characters h3 { margin: 0; font-size: 0.95rem; }
.characters .notice, .characters .result { margin: 0; }
.result { padding: 0.5rem 0.8rem; border: 1px solid var(--ok); border-left-width: 4px; border-radius: 6px; background: var(--surface); }
.result.bad { border-color: var(--bad); color: var(--bad); }
table.subtable th { background: var(--surface); }
.dialog-warning { color: var(--bad); font-weight: 600; margin: 0 0 0.8rem; }

/* Login */
.login { display: flex; justify-content: center; padding-top: 8vh; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 0.8rem; }

/* Forms */
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; margin-bottom: 1rem; }
.inline-form h2 { width: 100%; margin: 0; }

/* Logs */
.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 0.75rem; }
.tabs button { border-radius: 6px 6px 0 0; border-bottom: 0; background: transparent; }
.tabs button[aria-selected="true"] { background: var(--surface); border-color: var(--border); font-weight: 600; color: var(--accent); }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.6rem; margin-bottom: 0.75rem; }
.toolbar .grow { flex: 1; min-width: 180px; }
.live { font-size: 0.85rem; color: var(--muted); }
.live.on { color: var(--ok); }
.live.paused { color: var(--warn); }
.log {
  height: calc(100vh - 300px);
  min-height: 300px;
  overflow: auto;
  background: var(--log-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.4rem 0;
}
.log-line { display: grid; grid-template-columns: 6.5rem 3.2rem 9rem 1fr; gap: 0.6rem; padding: 0.05rem 0.7rem; }
.log-line:hover { background: var(--surface-2); }
.log-line .time { color: var(--muted); }
.log-line .category { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-line .message { white-space: pre-wrap; overflow-wrap: anywhere; }
.log-empty { color: var(--muted); padding: 1rem; font-family: inherit; }
.level-trace, .level-debug { color: var(--muted); }
.level-information { color: var(--info); }
.level-warning { color: var(--warn); }
.level-error, .level-critical { color: var(--bad); font-weight: 600; }

pre.code {
  background: var(--log-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.85rem;
  max-height: 60vh;
}

/* Dialog and toast */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.2rem;
  width: min(440px, calc(100vw - 2rem));
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog h2 { margin-top: 0; }
#dialog-fields { display: flex; flex-direction: column; gap: 0.7rem; margin-bottom: 1rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(420px, calc(100vw - 2rem));
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  z-index: 10;
}
.toast.bad { background: var(--bad); color: #ffffff; }

@media (max-width: 720px) {
  .topbar { padding: 0.5rem 0.75rem; }
  .nav { order: 3; flex: 1 1 100%; }
  main { padding: 1rem 0.75rem 2rem; }
  table.data th, table.data td { white-space: nowrap; }
  table.data tr.confirm-row td { white-space: normal; }
  table.data tr.characters-row > td { white-space: normal; padding: 0.5rem; }
  .characters { max-width: calc(100vw - 2.75rem); }
  .confirm-fields input[type="text"] { min-width: 0; width: 100%; }
  .log-line { grid-template-columns: 5.6rem 2.8rem 1fr; }
  .log-line .category { display: none; }
  .log { height: calc(100vh - 380px); }
}
