/* ---------- Fonts ---------- */
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('/static/fonts/inter-400.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 500; font-display: swap;
  src: url('/static/fonts/inter-500.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 600; font-display: swap;
  src: url('/static/fonts/inter-600.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('/static/fonts/inter-700.woff2') format('woff2'); }
@font-face { font-family: 'Noto Sans JP'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('/static/fonts/notosansjp-400.woff2') format('woff2'); }
@font-face { font-family: 'Noto Sans JP'; font-style: normal; font-weight: 500; font-display: swap;
  src: url('/static/fonts/notosansjp-500.woff2') format('woff2'); }
@font-face { font-family: 'Noto Sans JP'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('/static/fonts/notosansjp-700.woff2') format('woff2'); }

:root {
  --font-ui: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  --bg: #0b0d12;
  --panel: #13161e;
  --panel-2: #181c26;
  --border: #232936;
  --border-soft: #1c212d;
  --text: #e7ecf3;
  --text-dim: #94a0b6;
  --muted: #8390a5;
  --accent: #5bb1ff;
  --accent-hi: #7cc2ff;
  --accent-bg: rgba(91, 177, 255, 0.12);
  --green: #4ade80;
  --orange: #fbbf24;
  --red: #ef6b73;
  --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --radius: 8px;
  --radius-sm: 6px;
  --sidebar-w: 220px;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hi); }

/* ---------- Layout shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  padding: 18px 20px;
  font-weight: 700; letter-spacing: .02em; font-size: 16px;
  border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: 10px;
}
.sidebar .brand .logo-img {
  width: 36px; height: 36px; border-radius: 8px; object-fit: cover; display: block;
}
.sidebar nav { flex: 1; padding: 10px; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-weight: 500;
  margin-bottom: 2px;
}
.sidebar nav a:hover { background: var(--panel-2); color: var(--text); }
.sidebar nav a.active { background: var(--accent-bg); color: var(--accent-hi); }
.sidebar nav a .ico { width: 18px; text-align: center; }
.sidebar .me { padding: 12px 16px; border-top: 1px solid var(--border-soft); font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.sidebar .me a { font-size: 12px; }

.main { padding: 28px 32px; min-width: 0; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px;
  gap: 16px; flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: .01em; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.page-head .actions label { white-space: nowrap; }
.page-head .actions select { width: auto; }

/* ---------- Cards ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 12px; font-size: 14px; font-weight: 600; color: var(--text-dim); letter-spacing: .02em; }
.cards { display: grid; gap: 16px; align-items: start; }
.cards.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .cards.cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .cards.cols-4 { grid-template-columns: 1fr; } }
/* Masonry packing (applied to the system grid via JS in views/system.js).
   Cards keep their column span, but each reserves only as many implicit row
   tracks as its measured height needs; dense flow then backfills the gaps that
   differing card heights would otherwise leave under the shorter cards. The
   `masonry` class is added only after JS sets per-card grid-row spans, so
   without JS it degrades gracefully to the plain grid above. grid-auto-rows
   must stay in sync with MROW in system.js. */
.cards.masonry { grid-auto-rows: 4px; grid-auto-flow: row dense; }

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat .v { font-size: 24px; font-weight: 700; color: var(--text); }
.stat .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Form ---------- */
.form-grid { display: grid; gap: 14px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid .span-all { grid-column: 1 / -1; }
.form-row { display: grid; gap: 6px; }
/* In multi-column form grids, push each input to the bottom of its cell so inputs
   line up even when labels wrap to different heights. */
.form-grid[class*="cols-"] .form-row:not(.span-all) { grid-template-rows: 1fr auto; }
.form-row label { font-size: 12px; color: var(--text-dim); font-weight: 500; white-space: pre-line; }
.form-row .hint { font-size: 12px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  outline: none;
  width: 100%;
  transition: border .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input[disabled], select[disabled] { opacity: .6; cursor: not-allowed; }
.input-with-button { display: grid; grid-template-columns: 1fr auto; gap: 6px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--accent); color: #0a131e;
  font-weight: 600; font-size: 13px;
  cursor: pointer;
  transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { background: var(--accent-hi); border-color: var(--accent-hi); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--panel-2); border-color: var(--accent); color: var(--accent-hi); }
.btn.danger { background: var(--red); border-color: var(--red); color: #2a0608; }
.btn.danger:hover { background: #d8595f; border-color: #d8595f; }
.btn.warning { background: var(--orange); border-color: var(--orange); color: #2a1c00; }
.btn.warning:hover { background: #f59e0b; border-color: #f59e0b; }
.btn.ghost { background: transparent; color: var(--text-dim); border-color: transparent; padding: 6px 10px; }
.btn.ghost:hover { background: var(--panel-2); color: var(--text); }
.btn[disabled] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
/* System page: let action buttons wrap long non-Japanese labels at word
   boundaries (spaces). Short labels (incl. Japanese/CJK) fit on one line and are
   unaffected. Scoped to .sys-view so other pages keep single-line buttons.
   Table row-action buttons (.btn.sm) are excluded. */
.sys-view .btn:not(.sm) { white-space: normal; text-align: center; max-width: 12rem; line-height: 1.25; }
/* Solid (filled) action buttons: blue (edit) and green (view), matching the
   filled style of .btn.warning rather than a translucent tint. */
.btn.edit  { background: var(--accent); color: #0a131e; border-color: var(--accent); }
.btn.edit:hover  { background: var(--accent-hi); border-color: var(--accent-hi); }
.btn.view  { background: var(--green); color: #06240f; border-color: var(--green); }
.btn.view:hover  { background: #3bc56a; border-color: #3bc56a; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: var(--panel-2); }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: rgba(255,255,255,0.02); }
/* Sortable column headers (makeSorter): clickable and keyboard-focusable. */
th[data-sortable="1"]:hover, th[data-sortable="1"]:focus-visible { background: var(--accent-bg); color: var(--accent-hi); }
td .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.cell-mono { font-family: 'JetBrains Mono', 'Menlo', monospace; font-size: 12px; color: var(--text-dim); }

/* ---------- Tags ---------- */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text-dim);
}
.tag.accent { background: var(--accent-bg); border-color: rgba(91,177,255,.3); color: var(--accent-hi); }
.tag.green  { background: rgba(74,222,128,.12); border-color: rgba(74,222,128,.3); color: var(--green); }
.tag.warning{ background: rgba(251,191,36,.12); border-color: rgba(251,191,36,.3); color: var(--orange); }
.tag.red    { background: rgba(239,107,115,.12); border-color: rgba(239,107,115,.3); color: var(--red); }
.tag.muted  { color: var(--muted); }
.tag.plain  { background: transparent; border: 0; padding: 0; font-size: 14px; }
.tag.plain.green { color: var(--green); }
.tag.plain.red   { color: var(--red); }

/* ---------- Bars (CPU/Mem) ---------- */
#dash-grid.edit-mode > .card { cursor: grab; outline: 2px dashed transparent; transition: outline-color .1s; }
#dash-grid.edit-mode > .card:active { cursor: grabbing; }
#dash-grid > .card.dragging { opacity: .4; }
#dash-grid > .card.drop-target { outline-color: var(--accent); }
.card-edit-bar { display: flex; justify-content: space-between; align-items: center; margin: -8px -8px 8px; padding: 4px 8px; background: rgba(91,177,255,.08); border-bottom: 1px dashed var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.bar { background: var(--panel-2); border-radius: 8px; overflow: hidden; height: 10px; border: 1px solid var(--border-soft); }
.bar > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-hi)); transition: width .35s ease; }
.bar.warn > div { background: linear-gradient(90deg, var(--orange), #f59e0b); }
.bar.crit > div { background: linear-gradient(90deg, var(--red), #d8595f); }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6); backdrop-filter: blur(2px);
  display: grid; place-items: center; z-index: 50;
}
.modal {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,.5);
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  display: flex; flex-direction: column;
}
.modal.lg { width: min(800px, calc(100vw - 32px)); }
/* The dialog itself takes focus on open (openModal) only as a starting point for Tab. */
.modal:focus { outline: none; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--border-soft); display: flex; justify-content: space-between; align-items: center; }
.modal header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal .body { padding: 20px; overflow-y: auto; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--border-soft); display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- Path picker ---------- */
.picker-bar { display: flex; gap: 4px; align-items: center; margin-bottom: 8px; padding: 6px 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: 'JetBrains Mono', monospace; font-size: 12px; word-break: break-all; }
.picker-list { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); max-height: 360px; overflow-y: auto; }
.picker-list .item { padding: 8px 12px; cursor: pointer; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border-soft); }
.picker-list .item:not(.static):hover { background: var(--accent-bg); color: var(--accent-hi); }
.picker-list .item.parent { color: var(--text-dim); font-style: italic; }
/* Non-clickable rows (loading / empty / file entries in the library preview). */
.picker-list .item.static { cursor: default; }

/* ---------- Multi-select chips ---------- */
.multiselect { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; display: flex; flex-wrap: wrap; gap: 6px; max-height: 200px; overflow-y: auto; }
.multiselect .opt { display: flex; align-items: center; gap: 6px; padding: 5px 10px; background: var(--panel); border: 1px solid var(--border-soft); border-radius: 999px; cursor: pointer; font-size: 12px; transition: border .15s, background .15s; }
.multiselect .opt input[type=checkbox] { margin: 0; accent-color: var(--accent); }
.multiselect .opt:not(.disabled):hover { border-color: var(--accent); }
.multiselect .opt:has(input:checked) { border-color: var(--accent); background: var(--accent-bg); color: var(--accent-hi); }
.multiselect.disabled { opacity: .45; pointer-events: none; filter: grayscale(.4); }

/* ---------- Switch / Checkbox ---------- */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { appearance: none; width: 36px; height: 20px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; position: relative; cursor: pointer; transition: background .15s; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 999px; background: var(--text-dim); transition: left .18s, background .15s; }
.switch input:checked { background: var(--accent); border-color: var(--accent); }
.switch input:checked::after { left: 18px; background: #0a131e; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column-reverse; gap: 10px; z-index: 100; pointer-events: none; }
.toast { background: var(--accent); border: 1px solid var(--accent-hi); color: #04121f; font-weight: 600; padding: 18px 22px; border-radius: var(--radius-sm); box-shadow: 0 8px 28px rgba(0,0,0,.7); min-width: 340px; max-width: 560px; font-size: 16px; line-height: 1.55; animation: slideUp .18s ease-out; pointer-events: auto; }
.toast.err { background: var(--red); border-color: #f8a5aa; color: #2a0608; }
.toast.ok { background: var(--green); border-color: #86efac; color: #06150c; }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Restart overlay (fullscreen, with spinner) ---------- */
.restart-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.72); backdrop-filter: blur(3px);
  display: flex; flex-direction: column; gap: 18px;
  justify-content: center; align-items: center;
}
.restart-overlay .restart-msg { color: var(--text); font-size: 15px; }
.spinner {
  width: 48px; height: 48px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.18); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Login ---------- */
/* Centered with flexbox. The earlier shift-on-select issue was caused by
   position:fixed siblings (.lang-corner), now removed, so centering is safe. */
.login-body { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 16px; background: radial-gradient(ellipse at top, #1a2235, var(--bg)); }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 32px; width: 360px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 700; text-align: center; }
.login-card .login-icon { display: block; margin: 0 auto 12px; width: 96px; height: 96px; border-radius: 18px; }
.login-card .form-row { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; }
.login-card .err { color: var(--red); margin-top: 12px; font-size: 13px; }
.login-card .login-version { margin-top: 18px; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- Utilities ---------- */
.muted { color: var(--muted); }
.dim { color: var(--text-dim); }
.row { display: flex; gap: 10px; align-items: center; }
.mono { font-family: 'JetBrains Mono', 'Menlo', monospace; font-size: 12px; }
.right { text-align: right; }
.center { text-align: center; }
.hidden { display: none !important; }
.no-data { padding: 40px; text-align: center; color: var(--muted); font-size: 13px; }
/* Default-password warning shown above every admin view (router.js). */
.pw-warn { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin: 0 0 18px; padding: 12px 16px; border: 1px solid var(--orange); border-radius: var(--radius-sm); background: rgba(251,191,36,.12); color: var(--text); font-size: 14px; }
.pw-warn a { font-weight: 600; }
