/* =========================================================
   言乃葉栞 Dashboard — 和モダン theme (light / dark 両対応)
   クラス名は app.js が依存しているため変更しないこと。
   ========================================================= */

:root {
  color-scheme: light dark;

  /* --- surfaces (light: 生成りの和紙) --- */
  --bg: #f3efe6;
  --bg-grad: radial-gradient(1200px 620px at 100% -10%, #efeadf 0%, #f3efe6 55%, #f0ebe0 100%);
  --panel: #fffdf8;
  --panel-2: #f7f3ea;
  --line: #e5ddcd;
  --line-strong: #d6ccb7;

  /* --- ink（墨） --- */
  --text: #232a30;
  --muted: #6f7680;
  --faint: #9a9082;

  /* --- accent（藍 / indigo） --- */
  --accent: #3a5a86;
  --accent-strong: #2b466b;
  --accent-soft: #e9eef6;
  --accent-line: #c3d0e4;
  --on-accent: #ffffff;

  /* --- states --- */
  --danger: #b0473c;          /* 弁柄・朱寄り */
  --danger-soft: #fbeae7;
  --danger-line: #eecac4;
  --warning: #97690c;
  --warning-soft: #fbf1d8;
  --ok: #2f7a58;              /* 若竹 */
  --ok-soft: #e6f2ea;

  /* --- sidebar（墨紺） --- */
  --side-bg: #1b2230;
  --side-bg-2: #222c3d;
  --side-text: #eef1f6;
  --side-muted: #9aa6b8;
  --side-line: #313c50;
  --side-item: #cfd7e4;
  --side-active-bg: rgba(122, 158, 214, 0.16);
  --side-active-line: #7ea2d8;

  --shadow: 0 12px 30px -12px rgba(28, 34, 45, 0.22);
  --shadow-sm: 0 2px 8px -4px rgba(28, 34, 45, 0.18);
  --radius: 12px;
  --radius-sm: 9px;

  --font:
    "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Noto Sans JP",
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Menlo", "Consolas", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141c;
    --bg-grad: radial-gradient(1200px 620px at 100% -10%, #172033 0%, #10141c 60%);
    --panel: #171c26;
    --panel-2: #1e2531;
    --line: #29313f;
    --line-strong: #333d4d;

    --text: #e7eaf0;
    --muted: #98a1b0;
    --faint: #6b7484;

    --accent: #7ba1d6;
    --accent-strong: #97b7e2;
    --accent-soft: #1d2635;
    --accent-line: #33445e;
    --on-accent: #0f1420;

    --danger: #e08479;
    --danger-soft: #2c1f1e;
    --danger-line: #48302c;
    --warning: #d9ad5b;
    --warning-soft: #2a2314;
    --ok: #66c199;
    --ok-soft: #16261f;

    --side-bg: #131922;
    --side-bg-2: #182131;
    --side-text: #e7ecf4;
    --side-muted: #8b95a6;
    --side-line: #262f3e;
    --side-item: #b9c2d1;
    --side-active-bg: rgba(123, 161, 214, 0.14);
    --side-active-line: #7ba1d6;

    --shadow: 0 16px 34px -16px rgba(0, 0, 0, 0.6);
    --shadow-sm: 0 2px 8px -4px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

::selection {
  background: var(--accent-soft);
}

/* ---------- layout ---------- */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 264px 1fr;
}

/* ---------- sidebar ---------- */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  background: linear-gradient(180deg, var(--side-bg-2) 0%, var(--side-bg) 46%);
  color: var(--side-text);
  border-right: 1px solid var(--side-line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--side-line);
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #4d6da0, #33507b);
  color: #fff;
  border-radius: 11px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 4px 12px -4px rgba(51, 80, 123, 0.7);
}

.brand h1 {
  font-size: 17px;
  letter-spacing: 0.06em;
  margin: 0;
  line-height: 1.25;
  color: #fff;
}

.brand p {
  margin: 3px 0 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--side-muted);
}

.select-label {
  display: block;
  margin-bottom: -10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--side-muted);
}

/* form controls (content area default) */
select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  padding: 9px 11px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:focus,
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.sidebar select {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--side-line);
  color: var(--side-text);
}

.sidebar select:focus {
  border-color: var(--side-active-line);
  box-shadow: 0 0 0 3px rgba(126, 162, 216, 0.18);
}

.nav {
  display: grid;
  gap: 3px;
}

.nav-item {
  position: relative;
  min-height: 38px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--side-item);
  text-align: left;
  padding: 9px 12px 9px 14px;
  cursor: pointer;
  font-size: 13.5px;
  letter-spacing: 0.02em;
  transition: background 0.14s ease, color 0.14s ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}

.nav-item.active {
  background: var(--side-active-bg);
  color: #fff;
  font-weight: 600;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  border-radius: 3px;
  background: var(--side-active-line);
}

.local-note {
  margin-top: auto;
  border: 1px solid var(--side-line);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: grid;
  gap: 5px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--side-muted);
  background: rgba(255, 255, 255, 0.02);
}

.local-note strong {
  color: var(--side-text);
  font-size: 12px;
  letter-spacing: 0.04em;
}

/* ---------- main ---------- */
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 76px;
  padding: 16px 30px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h2 {
  margin: 0;
  font-size: 23px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- buttons ---------- */
.icon-button,
.primary-button,
.secondary-button,
.danger-button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease,
    box-shadow 0.15s ease;
}

.icon-button:active,
.primary-button:active,
.secondary-button:active,
.danger-button:active {
  transform: translateY(1px);
}

.icon-button {
  width: 40px;
  padding: 0;
  background: var(--panel);
  border-color: var(--line-strong);
  color: var(--muted);
  font-size: 18px;
  border-radius: 50%;
}

.icon-button:hover {
  color: var(--accent);
  border-color: var(--accent-line);
}

.primary-button,
.primary-link {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-sm);
}

.primary-button:hover,
.primary-link:hover {
  background: var(--accent-strong);
}

.primary-link {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.secondary-button {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line-strong);
}

.secondary-button:hover {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.danger-button {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger-line);
}

.danger-button:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* ---------- content ---------- */
.content {
  padding: 24px 30px 48px;
}

.grid {
  display: grid;
  gap: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}

.stat,
.panel,
.plugin-row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.stat {
  position: relative;
  padding: 16px 16px 18px;
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--accent), transparent);
  opacity: 0.55;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  margin-bottom: 8px;
}

.stat strong {
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.panel {
  padding: 18px;
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.panel h3 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* ---------- detail panel ---------- */
.detail-panel {
  margin-top: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 16px;
}

.detail-panel h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.detail-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.detail-heading h3 {
  margin: 4px 0 0;
  font-size: 18px;
}

.detail-grid {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}

.detail-grid div {
  min-width: 0;
}

.detail-grid dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.detail-grid dd {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
  font-size: 13.5px;
}

/* ---------- plugin rows ---------- */
.plugin-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  padding: 18px;
}

.plugin-row h3 {
  margin: 0 0 5px;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 9px;
}

.plugin-row p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 13px;
}

.plugin-controls {
  display: flex;
  gap: 8px;
  align-items: start;
}

/* ---------- setup steps ---------- */
.setup-list {
  display: grid;
  gap: 12px;
}

.setup-step {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.setup-step h3 {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 9px;
}

.setup-step p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 13px;
}

/* ---------- summary box ---------- */
.summary-box {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}

.summary-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}

.summary-box pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.6;
  font-family: inherit;
  font-size: 13.5px;
}

/* ---------- forms ---------- */
.settings-form {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 16px;
  display: grid;
  gap: 14px;
}

.panel.settings-form,
.settings-form.panel {
  border-top: 1px solid var(--line);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label,
.field span {
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: 0.01em;
  color: var(--text);
}

.filter-bar {
  display: grid;
  grid-template-columns:
    minmax(180px, 1.4fr) minmax(150px, 1fr) minmax(150px, 1fr)
    minmax(150px, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.filter-bar.compact {
  grid-template-columns: minmax(180px, 1.6fr) minmax(150px, 1fr) minmax(150px, 1fr) auto;
}

.filter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.help {
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
}

textarea {
  min-height: 84px;
  resize: vertical;
  font-family: inherit;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
  cursor: pointer;
}

.toggle input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- tables ---------- */
.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

tbody tr {
  transition: background 0.1s ease;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--accent-soft) 55%, transparent);
}

tr:last-child td {
  border-bottom: 0;
}

/* ---------- badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--line);
}

.badge.ok {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: color-mix(in srgb, var(--ok) 30%, transparent);
}

.badge.warn {
  color: var(--warning);
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 30%, transparent);
}

.badge.off {
  color: var(--faint);
}

/* ---------- alerts ---------- */
.alert {
  margin: 18px 30px 0;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--warning);
  border-left-width: 4px;
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.alert.ok {
  border-color: var(--ok);
  background: var(--ok-soft);
  color: var(--ok);
}

.alert.warn {
  border-color: var(--warning);
  background: var(--warning-soft);
  color: var(--warning);
}

.hidden {
  display: none !important;
}

.empty {
  padding: 22px;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
  font-size: 13px;
}

code {
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.change-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}

.json-block {
  margin: 0;
  max-width: 360px;
  max-height: 180px;
  overflow: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.json-block.wide {
  max-width: none;
  overflow-wrap: anywhere;
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    min-height: auto;
  }

  .topbar {
    padding: 14px 18px;
  }

  .content {
    padding: 18px 18px 40px;
  }

  .alert {
    margin: 14px 18px 0;
  }

  .stats-grid,
  .panel-grid,
  .form-grid,
  .filter-bar,
  .filter-bar.compact,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .plugin-row {
    grid-template-columns: 1fr;
  }

  .setup-step {
    grid-template-columns: 1fr;
  }
}

/* ---------- auth: login gate & user chip ---------- */
.login-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  background-image: var(--bg-grad);
  z-index: 100;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 36px 32px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.login-card .brand-mark {
  width: 56px;
  height: 56px;
  font-size: 30px;
  border-radius: 15px;
  margin: 0 auto 18px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
  letter-spacing: 0.08em;
}

.login-card p {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.7;
}

.login-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 24px;
  background: #5865f2;
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
  transition: background 0.15s ease;
}

.login-button:hover {
  background: #4752c4;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 6px 5px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.text-button {
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 5px 12px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.text-button:hover {
  color: var(--accent);
  border-color: var(--accent-line);
}
