:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --border: #d8e1ed;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --surface: #eef3f9;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(37, 99, 235, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 99, 235, 0.045) 1px, transparent 1px),
    var(--bg);
  background-size: 34px 34px;
}

.login-shell {
  width: min(440px, 100%);
}

.login-panel {
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-row.compact {
  padding: 18px 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  color: #ffffff;
  background: #111827;
  font-weight: 800;
}

.brand-row h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.brand-row p,
.topbar p,
.tool-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.login-form {
  display: grid;
  gap: 10px;
  margin-top: 28px;
}

.login-form label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-form input,
.user-form input,
.user-form select {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  background: #ffffff;
}

.login-form input:focus,
.user-form input:focus,
.user-form select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.login-form button,
.user-form button,
.secondary-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

.login-form button:hover,
.user-form button:hover,
.secondary-button:hover {
  background: var(--accent-dark);
}

.form-message {
  min-height: 20px;
  margin: 2px 0 0;
  color: #b42318;
  font-size: 13px;
}

.form-message.is-success {
  color: #047857;
}

.nav-rail {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: 260px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  transition: width 160ms ease, transform 160ms ease, box-shadow 160ms ease;
  overflow: hidden;
}

body.nav-collapsed .nav-rail {
  width: 64px;
}

body.nav-collapsed .nav-rail:hover {
  width: 260px;
  box-shadow: var(--shadow);
}

body.nav-collapsed .nav-rail .nav-text {
  opacity: 0;
  pointer-events: none;
}

body.nav-collapsed .nav-rail:hover .nav-text {
  opacity: 1;
  pointer-events: auto;
}

body.nav-collapsed .nav-child {
  padding-left: 12px !important;
}

body.nav-collapsed .nav-rail:hover .nav-child {
  padding-left: 22px !important;
}

.nav-text {
  transition: opacity 120ms ease;
}

.nav-list {
  display: grid;
  gap: 5px;
  padding: 10px;
}

.nav-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.nav-parent {
  margin-top: 4px;
}

.nav-children {
  display: grid;
  gap: 3px;
  margin: 0 0 8px;
}

.nav-child {
  min-height: 38px;
  padding: 8px 12px 8px 22px !important;
  font-size: 13px !important;
  font-weight: 650 !important;
}

.nav-child .nav-icon {
  flex-basis: 24px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  font-size: 12px;
}

.nav-list a.active,
.nav-list a:hover {
  color: var(--text);
  background: var(--surface);
}

.nav-icon {
  display: grid;
  place-items: center;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: #f5f7fb;
  color: var(--text);
  font-weight: 800;
}

.content {
  min-width: 0;
  margin-left: 260px;
  min-height: 100vh;
  padding-top: 73px;
  transition: margin-left 160ms ease;
}

body.nav-collapsed .content {
  margin-left: 64px;
}

.topbar {
  position: fixed;
  z-index: 30;
  top: 0;
  right: 0;
  left: 260px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 73px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  transition: left 160ms ease;
}

body.nav-collapsed .topbar {
  left: 64px;
}

.topbar-left,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar h2 {
  margin: 0;
  font-size: 20px;
}

.nav-toggle {
  display: grid;
  place-items: center;
  width: 36px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
}

body.nav-collapsed .nav-toggle {
  transform: rotate(180deg);
}

.nav-restore-tab {
  position: fixed;
  z-index: 45;
  top: 88px;
  left: 0;
  display: none;
  place-items: center;
  width: 44px;
  height: 48px;
  border: 1px solid var(--border);
  border-left: 0;
  border-radius: 0 10px 10px 0;
  color: #ffffff;
  background: #111827;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.16);
}

.secondary-button {
  display: inline-grid;
  place-items: center;
  min-width: 82px;
  min-height: 38px;
  padding: 0 13px;
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

.secondary-button:hover {
  background: #dfe8f3;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 28px;
}

.tool-card {
  display: flex;
  gap: 14px;
  min-height: 132px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.tool-card:hover {
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: var(--shadow);
}

.tool-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 800;
}

.tool-card strong {
  display: block;
  font-size: 16px;
}

.tool-card span {
  display: inline-block;
  margin-top: 14px;
  color: #047857;
  font-size: 12px;
  font-weight: 800;
}

.content-panel {
  min-height: calc(100vh - 73px);
}

.admin-panel {
  padding: 28px;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 18px;
}

.account-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(260px, 340px) minmax(260px, 340px);
  gap: 18px;
  align-items: start;
}

.user-form,
.user-table-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.user-form {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 18px;
}

.user-form h3,
.section-head h3 {
  margin: 0;
  font-size: 16px;
}

.user-form label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.module-fieldset {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.module-fieldset legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.module-checks {
  display: grid;
  gap: 8px;
}

.module-checks.compact {
  min-width: 190px;
}

.module-check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.module-check input {
  width: 16px;
  height: 16px;
}

.user-table-panel {
  min-width: 0;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.table-wrap {
  overflow: auto;
}

.user-table {
  width: 100%;
  min-width: 940px;
  border-collapse: collapse;
}

.user-table th,
.user-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 14px;
  vertical-align: middle;
}

.user-table th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
  text-transform: uppercase;
}

.role-select {
  min-width: 118px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-weight: 700;
}

.danger-button {
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #b91c1c;
  background: #fff5f5;
  cursor: pointer;
  font-weight: 700;
}

.danger-button:hover {
  background: #fee2e2;
}

.table-action {
  margin: 3px 6px 3px 0;
}

.account-summary {
  padding: 18px;
}

.account-summary dl {
  display: grid;
  gap: 10px;
  margin: 0;
}

.account-summary dl div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.account-summary dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.account-summary dd {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.account-summary h4 {
  margin: 18px 0 10px;
  font-size: 14px;
}

.module-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.module-badge {
  display: inline-grid;
  place-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: #1e3a8a;
  background: #dbeafe;
  font-size: 13px;
  font-weight: 800;
}

.system-grid {
  display: grid;
  gap: 18px;
}

.system-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.metric-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 112px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.metric-card-copy {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.metric-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-card strong {
  font-size: 24px;
  line-height: 1.1;
}

.metric-card small {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-ring {
  --value: 0deg;
  --metric-color: var(--accent);
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 72px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: conic-gradient(var(--metric-color) var(--value), #e2e8f0 0deg);
}

.metric-ring::after {
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: #ffffff;
  content: "";
}

.metric-ring-value {
  position: relative;
  z-index: 1;
  color: var(--text) !important;
  font-size: 13px !important;
  font-weight: 900 !important;
  text-transform: none !important;
}

.metric-ring.is-empty {
  --metric-color: #cbd5e1;
}

.memory-ring {
  --metric-color: #0891b2;
}

.disk-ring {
  --metric-color: #d97706;
}

.metric-runtime-icon {
  display: grid;
  place-items: center;
  flex: 0 0 72px;
  width: 72px;
  height: 72px;
  border: 8px solid #dbeafe;
  border-radius: 50%;
  color: #1e40af;
  background: #ffffff;
  font-weight: 900;
}

.module-table {
  min-width: 780px;
}

.module-source {
  display: inline-grid;
  place-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  color: #334155;
  background: #e2e8f0;
  font-size: 12px;
  font-weight: 800;
}

.module-enabled-toggle {
  width: 18px;
  height: 18px;
}

.module-import-form {
  display: grid;
}

.module-import-body {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.module-import-body label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.module-import-body textarea {
  width: 100%;
  min-height: 220px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
  background: #ffffff;
  font: 13px/1.45 Consolas, "Cascadia Mono", monospace;
  outline: none;
  resize: vertical;
}

.module-import-body textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.hint code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #eef2f7;
}

.tool-frame-wrap {
  height: calc(100vh - 73px);
  padding: 0;
  overflow: hidden;
  background: #ffffff;
}

.tool-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #ffffff;
}

@media (max-width: 820px) {
  .nav-rail {
    width: 64px;
  }

  .nav-rail:hover {
    width: 260px;
    box-shadow: var(--shadow);
  }

  .nav-rail .nav-text {
    opacity: 0;
    pointer-events: none;
  }

  .nav-rail:hover .nav-text {
    opacity: 1;
    pointer-events: auto;
  }

  .content,
  body.nav-collapsed .content {
    margin-left: 64px;
    padding-top: 148px;
  }

  .topbar,
  body.nav-collapsed .topbar {
    left: 64px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    min-height: 148px;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .content-panel,
  .tool-frame-wrap {
    min-height: calc(100vh - 148px);
  }

  .tool-frame-wrap {
    height: calc(100vh - 148px);
  }

  .admin-layout,
  .account-layout {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }
}
