:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #d9e0e6;
  --border-strong: #b9c4ce;
  --text: #1d2a35;
  --muted: #607080;
  --accent: #0b5f8a;
  --accent-dark: #084766;
  --accent-soft: #e6f1f7;
  --success: #1f7a4d;
  --success-soft: #e8f5ee;
  --warning: #8a6100;
  --warning-soft: #fbf1d9;
  --danger: #a12b2b;
  --danger-soft: #fbeaea;
  --neutral-soft: #edf1f4;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(18, 38, 54, 0.08), 0 4px 12px rgba(18, 38, 54, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

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

h1, h2, h3, h4 { margin: 0 0 0.5rem; line-height: 1.25; }
h2 { font-size: 1.25rem; margin-top: 1.5rem; }
h3 { font-size: 1.05rem; margin-top: 1.25rem; }
p { margin: 0.4rem 0 0.8rem; }

code, pre { font-family: var(--mono); font-size: 0.86em; }
code { background: var(--neutral-soft); padding: 0.1rem 0.3rem; border-radius: 3px; }
pre {
  background: #15212b;
  color: #e7eef4;
  padding: 1rem;
  border-radius: var(--radius);
  overflow: auto;
  max-height: 32rem;
  font-size: 0.8rem;
  line-height: 1.45;
}

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex: 0 0 240px;
  background: #10222f;
  color: #dce7ef;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 1.1rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand__mark {
  background: #0b5f8a;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.35rem 0.45rem;
  border-radius: 6px;
  font-size: 0.8rem;
}

.brand__title { font-weight: 600; font-size: 0.98rem; }
.brand__subtitle { font-size: 0.72rem; color: #8ba4b6; text-transform: uppercase; letter-spacing: 0.06em; }

.nav { padding: 0.9rem 0.6rem; display: flex; flex-direction: column; gap: 0.15rem; flex: 1; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: #c7d6e1;
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  font-size: 0.92rem;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.06); text-decoration: none; color: #fff; }
.nav-link--active { background: #0b5f8a; color: #fff; }
.nav-icon { width: 1.1rem; text-align: center; opacity: 0.8; }

.sidebar__foot { padding: 1rem; border-top: 1px solid rgba(255, 255, 255, 0.08); }

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

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar__title { font-weight: 600; font-size: 1rem; }
.topbar__user { display: flex; align-items: center; gap: 1rem; }
.user__name { font-weight: 600; font-size: 0.9rem; }
.user__meta { font-size: 0.78rem; color: var(--muted); display: flex; align-items: center; gap: 0.4rem; }

.content { padding: 1.5rem; max-width: 1280px; width: 100%; }

.page-title { font-size: 1.45rem; margin-bottom: 0.25rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1.1rem;
}

.card--flush { padding: 0; overflow: hidden; }
.card__head {
  padding: 0.85rem 1.2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--surface-2);
}
.card__head h2, .card__head h3 { margin: 0; }
.card__body { padding: 1.1rem 1.2rem; }

.grid { display: grid; gap: 1.1rem; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stack { display: flex; flex-direction: column; gap: 0.8rem; }
.row { display: flex; gap: 0.8rem; align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 0.45rem 0.8rem;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--ghost { background: transparent; }
.btn--small { padding: 0.3rem 0.55rem; font-size: 0.8rem; }
.btn--block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

form.inline { display: inline; }

label { display: block; font-weight: 600; font-size: 0.86rem; margin-bottom: 0.25rem; }
.label-hint { font-weight: 400; color: var(--muted); font-size: 0.8rem; }

input[type="text"], input[type="search"], input[type="datetime-local"], input[type="date"],
input[type="number"], input[type="password"], select, textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
textarea { min-height: 8rem; font-family: var(--mono); font-size: 0.82rem; }
textarea.code { min-height: 22rem; }

.field { margin-bottom: 0.9rem; }
.field--inline { display: flex; align-items: center; gap: 0.5rem; }
.field--inline input[type="checkbox"] { width: auto; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1rem; margin: 0 0 1rem; }
.fieldset legend { font-weight: 600; font-size: 0.88rem; padding: 0 0.3rem; }

.alert {
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert p { margin: 0.25rem 0 0; }
.alert--success { background: var(--success-soft); border-color: #b7dfc9; color: #145737; }
.alert--danger { background: var(--danger-soft); border-color: #efc4c4; color: #7d2020; }
.alert--warning { background: var(--warning-soft); border-color: #e8d49b; color: #6b4b00; }
.alert__hint { font-size: 0.84rem; }

.badge {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--neutral-soft);
  color: #435260;
  white-space: nowrap;
}
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--role { background: var(--accent-soft); color: var(--accent-dark); }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.kv { display: grid; grid-template-columns: minmax(9rem, 14rem) 1fr; gap: 0.35rem 1rem; padding: 0.3rem 0; border-bottom: 1px dashed var(--border); }
.kv:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); font-size: 0.84rem; }
.kv dd { margin: 0; font-size: 0.9rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.8rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem 1rem; }
.stat__label { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.stat__value { font-size: 1.15rem; font-weight: 600; margin-top: 0.2rem; }

.recent-list { list-style: none; margin: 0; padding: 0; }
.recent-list li { display: flex; gap: 0.5rem; align-items: center; justify-content: space-between; padding: 0.45rem 0; border-bottom: 1px solid var(--border); }
.recent-list li:last-child { border-bottom: 0; }
.recent-list a { font-weight: 500; }

.json-block { margin-top: 0.6rem; }
.json-block summary { cursor: pointer; color: var(--accent); font-size: 0.85rem; font-weight: 500; }
.json-block pre { margin-top: 0.5rem; }

.definition-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0.7rem; }
.definition-item { border: 1px solid var(--border); border-radius: 6px; padding: 0.65rem 0.75rem; background: var(--surface-2); }
.definition-item__title { font-weight: 600; font-size: 0.88rem; }
.definition-item__meta { font-size: 0.8rem; color: var(--muted); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 3px solid var(--border); padding: 0 0 0.8rem 0.9rem; margin-left: 0.3rem; }
.timeline li:last-child { padding-bottom: 0; }

.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.5rem; background: #10222f; }
.auth-card { background: var(--surface); border-radius: 12px; padding: 1.6rem; width: 100%; max-width: 420px; box-shadow: 0 20px 45px rgba(0, 0, 0, 0.25); }
.brand--auth { border: 0; padding: 0 0 1rem; color: var(--text); }
.brand--auth .brand__title { color: var(--text); }
.brand--auth .brand__subtitle { color: var(--muted); }

.notice-panel { background: var(--accent-soft); border: 1px solid #b9d7e6; border-radius: var(--radius); padding: 0.9rem 1rem; font-size: 0.9rem; }
.danger-panel { background: var(--danger-soft); border: 1px solid #efc4c4; border-radius: var(--radius); padding: 0.9rem 1rem; font-size: 0.9rem; }
.empty-state { text-align: center; padding: 2.2rem 1rem; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); margin-bottom: 0.3rem; }

.inline-form { display: flex; gap: 0.6rem; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; flex: 1 1 180px; }
.inline-form .field--narrow { flex: 0 1 140px; }

.section-nav { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.section-nav a { padding: 0.35rem 0.6rem; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); font-size: 0.84rem; }
.section-nav a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

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

@media (max-width: 980px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar__foot { display: none; }
  .grid--2, .grid--3, .grid--4 { grid-template-columns: 1fr; }
  .content { padding: 1rem; }
  .topbar { padding: 0.6rem 1rem; }
  .kv { grid-template-columns: 1fr; gap: 0.1rem; }
}
