:root {
  --font-ui: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', Consolas, monospace;
  --bg: #f4f7f1;
  --bg-soft: #dfe8d8;
  --card: #ffffff;
  --text: #1d2a1f;
  --muted: #4d5d50;
  --line: #c9d6c6;
  --primary: #1f8a53;
  --primary-strong: #0b6d3c;
  --warning: #d88a00;
  --danger: #c7392f;
  --shadow: 0 15px 40px rgba(21, 52, 29, 0.12);
}

html[data-theme='dark'] {
  --bg: #111916;
  --bg-soft: #1a2a24;
  --card: #1f2f28;
  --text: #f1f7f3;
  --muted: #b5c6ba;
  --line: #365045;
  --primary: #44c47b;
  --primary-strong: #37a967;
  --warning: #e4b23c;
  --danger: #f56a5f;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  background:
    radial-gradient(circle at 0% 0%, rgba(31, 138, 83, 0.15), transparent 35%),
    radial-gradient(circle at 100% 20%, rgba(216, 138, 0, 0.08), transparent 30%),
    var(--bg);
  min-height: 100vh;
}

h1, h2, h3 {
  letter-spacing: 0.02em;
  margin-top: 0;
}

a {
  color: var(--primary-strong);
}

input, select, textarea, button {
  font: inherit;
  border-radius: 12px;
}

input, select, textarea {
  width: 100%;
  margin-top: 0.4rem;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding: 0.7rem 0.8rem;
}

button {
  border: 0;
  padding: 0.7rem 1rem;
  background: var(--primary);
  color: white;
  cursor: pointer;
  box-shadow: var(--shadow);
}

button.secondary {
  background: var(--bg-soft);
  color: var(--text);
}

button.danger {
  background: var(--danger);
}

button.tiny {
  margin-left: 0.4rem;
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
  border-radius: 8px;
  box-shadow: none;
}

.flash {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 50;
  padding: 0.8rem 1rem;
  border-radius: 10px;
  color: white;
  background: var(--primary-strong);
}

.flash.error {
  background: var(--danger);
}

.auth-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
}

.auth-card {
  width: min(520px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 2rem;
}

.subtitle {
  color: var(--muted);
}

.auth-links {
  margin-top: 1rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--line);
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

html[data-theme='dark'] .sidebar {
  background: rgba(17, 25, 22, 0.8);
}

.brand {
  font-size: 1.2rem;
  font-weight: 700;
  padding: 0.5rem;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.sidebar nav a {
  text-decoration: none;
  color: var(--text);
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
}

.sidebar nav a.active,
.sidebar nav a:hover {
  background: var(--bg-soft);
}

.sidebar nav a.sub-link {
  margin-left: 0.8rem;
  font-size: 0.8rem;
  color: var(--muted);
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
}

.spacer {
  flex: 1;
}

.content {
  padding: 1.2rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.quick-search {
  display: inline-flex;
  gap: 0.5rem;
  align-items: center;
}

.quick-search input {
  min-width: 320px;
}

.user-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  background: var(--card);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.kpi-grid {
  margin: 1rem 0;
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.kpi-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  background: var(--card);
}

.kpi-card p {
  font-size: 2rem;
  margin: 0;
}

.kpi-card.warning p { color: var(--warning); }
.kpi-card.danger p { color: var(--danger); }

.panel {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem;
  background: var(--card);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.panel-head h2 {
  margin-bottom: 0;
}

.toggle-panel-body[hidden] {
  display: none;
}

.grid-form {
  display: grid;
  gap: 0.8rem;
}

.grid-form.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-form .full {
  grid-column: 1 / -1;
}

.grid-form button {
  width: fit-content;
}

.inline-form {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  margin-right: 0.4rem;
}

.secret-input {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.secret-input input {
  margin-top: 0;
}

.secret-input .tiny {
  margin-left: 0;
  flex: 0 0 auto;
}

.inline-form input,
.inline-form select {
  width: 120px;
  margin-top: 0;
  padding: 0.35rem 0.45rem;
  border-radius: 8px;
}

.plain-link {
  align-self: center;
}

.hierarchy-l1 h2 {
  margin-bottom: 0.2rem;
}

.hierarchy-l2 {
  margin-top: 0.9rem;
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 0.7rem;
}

.row-warning td {
  background: rgba(216, 138, 0, 0.07);
}

.status-warn {
  color: var(--warning);
  font-weight: 600;
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow-x: auto;
  display: block;
}

thead th {
  text-align: left;
  color: var(--muted);
  font-size: 0.85rem;
}

th, td {
  padding: 0.65rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  font-size: 0.8rem;
}

.badge.warning {
  background: rgba(216, 138, 0, 0.12);
  border-color: rgba(216, 138, 0, 0.35);
  color: #8c5800;
}

.badge.danger {
  background: rgba(199, 57, 47, 0.12);
  border-color: rgba(199, 57, 47, 0.35);
  color: #8f1f18;
}

.badge.type-badge {
  font-weight: 700;
  letter-spacing: 0.04em;
}

.type-list {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.secret {
  font-family: var(--font-mono);
}

@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 700px) {
  .grid-form.two {
    grid-template-columns: 1fr;
  }

  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .secret-input {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .quick-search {
    width: 100%;
  }

  .quick-search input {
    min-width: 0;
  }

  .auth-links {
    flex-direction: column;
  }
}
