:root {
  --bg: #f5f5f5;
  --panel: #ffffff;
  --text: #1d2430;
  --muted: #6b7280;
  --line: #d9d9d9;
  --primary: #111111;
  --primary-dark: #000000;
  --danger: #b42318;
  --warning: #b7791f;
  --soft: #eeeeee;
  --soft-strong: #e5e5e5;
  --sidebar: #111111;
  --sidebar-active: #2b2b2b;
  --shadow: 0 16px 50px rgba(0, 0, 0, .10);
  font-family: Inter, Segoe UI, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #0b0b0b;
  --panel: #151515;
  --text: #f5f5f5;
  --muted: #a3a3a3;
  --line: #2f2f2f;
  --primary: #f5f5f5;
  --primary-dark: #ffffff;
  --soft: #202020;
  --soft-strong: #2a2a2a;
  --sidebar: #000000;
  --sidebar-active: #242424;
  --shadow: 0 16px 50px rgba(0, 0, 0, .40);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(0, 0, 0, .04), rgba(255, 255, 255, .02)),
    var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

button, input, select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  min-height: 38px;
  padding: 0 14px;
  background: var(--soft-strong);
  color: var(--text);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button svg, .nav svg, .item-icon svg, .visual-tile svg, .clock-pill svg, .modal-intro svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex: 0 0 auto;
}

button:hover {
  filter: brightness(.97);
}

button.primary {
  background: var(--primary);
  color: var(--panel);
}

button.danger {
  background: #fee4e2;
  color: var(--danger);
}

button.icon {
  width: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 11px;
  background: var(--panel);
  color: var(--text);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 34px;
  position: relative;
}

.login-top-actions {
  position: fixed;
  top: 22px;
  right: 22px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.login-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 34px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 34px;
  font-weight: 800;
  font-size: 20px;
  min-width: 0;
}

.brand span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--panel);
  display: grid;
  place-items: center;
  font-weight: 900;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 16px;
}

.login-logo strong {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.login-logo small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-weight: 800;
}

.login-heading h1 {
  font-size: 32px;
  line-height: 1.1;
  margin: 0 0 10px;
}

.login-heading p {
  color: var(--muted);
  margin: 0;
}

.login-form, .form-grid {
  display: grid;
  gap: 14px;
}

.brand-mark.large {
  width: 64px;
  height: 64px;
  font-size: 24px;
}

.login-submit {
  min-height: 46px;
  width: 100%;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  background: var(--sidebar);
  color: #ffffff;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.sidebar .brand {
  margin: 0;
}

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

.nav button {
  background: transparent;
  color: #cbd5e1;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav button.active {
  background: var(--sidebar-active);
  color: #ffffff;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  color: #cbd5e1;
  font-size: 13px;
}

.content {
  padding: 26px;
  display: grid;
  gap: 20px;
  align-content: start;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-group, .top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.clock-pill {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-weight: 800;
  white-space: nowrap;
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.toolbar-left, .toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.admin-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.admin-summary article {
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
  display: grid;
  align-content: center;
  gap: 8px;
}

.admin-summary strong {
  font-size: 30px;
  line-height: 1;
}

.admin-summary span {
  color: var(--muted);
  font-weight: 800;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel-title {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-title strong {
  display: block;
  font-size: 18px;
}

.panel-title span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 700;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.telemetry-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1px;
  background: var(--line);
}

.telemetry-grid > div {
  min-height: 96px;
  background: var(--panel);
  padding: 14px;
  display: grid;
  align-content: center;
  gap: 5px;
}

.telemetry-grid small {
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 11px;
}

.telemetry-grid strong {
  font-size: 17px;
  overflow-wrap: anywhere;
}

.telemetry-grid span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.diagnostic-panel, .log-health {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 14px;
  display: grid;
  gap: 5px;
}

.diagnostic-panel {
  border-color: #f59e0b;
  background: #fffbeb;
  color: #92400e;
}

:root[data-theme="dark"] .diagnostic-panel {
  background: #2a1d08;
  color: #fbbf24;
}

.diagnostic-panel strong, .log-health strong {
  font-size: 15px;
}

.diagnostic-panel span, .log-health span {
  color: inherit;
  overflow-wrap: anywhere;
}

.log-health.ok {
  border-color: #16a34a;
}

.log-health.warn {
  border-color: #f59e0b;
}

.status-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 78px;
}

.status-card span {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--soft);
  color: var(--primary-dark);
}

.status-card svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.status-card strong {
  display: block;
  font-size: 24px;
  line-height: 1;
}

.status-card small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-weight: 700;
}

.breadcrumb {
  color: var(--muted);
  font-weight: 800;
}

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

.item-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 12px;
  min-height: 150px;
}

.item-icon {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--soft);
  color: var(--primary-dark);
}

.item-card.file .item-icon {
  background: var(--soft);
  color: var(--text);
}

.item-name {
  font-weight: 800;
  word-break: break-word;
}

.item-meta {
  color: var(--muted);
  font-size: 13px;
}

.item-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}

.table-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

td code {
  display: inline-block;
  max-width: 460px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #475467;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.badge.admin {
  background: var(--primary);
  color: var(--panel);
}

.badge.neutral {
  background: var(--soft);
  color: var(--muted);
}

.badge.blocked {
  background: #fee4e2;
  color: var(--danger);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 40, .48);
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal {
  width: min(680px, 100%);
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
  display: grid;
  gap: 16px;
}

.modal-intro {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.modal-intro span {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

.modal-intro p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.modal-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

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

.modal-actions {
  display: flex;
  justify-content: end;
  gap: 10px;
}

.notice {
  padding: 12px 14px;
  border-radius: 8px;
  background: #fff7ed;
  color: #92400e;
  font-weight: 700;
}

.empty {
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 34px;
  color: var(--muted);
  text-align: center;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .login-shell, .shell {
    grid-template-columns: 1fr;
  }

  .login-shell {
    padding: 84px 18px 24px;
  }

  .login-top-actions {
    top: 14px;
    right: 14px;
  }

  .login-card {
    padding: 24px;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 12px;
    gap: 12px;
  }

  .sidebar .brand {
    font-size: 16px;
  }

  .sidebar .brand-mark {
    width: 34px;
    height: 34px;
  }

  .nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav button {
    min-width: max-content;
    min-height: 40px;
    padding: 0 12px;
    justify-content: center;
    font-size: 13px;
  }

  .sidebar-footer {
    margin-top: 0;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 8px;
  }

  .sidebar-footer button {
    min-width: 92px;
  }

  .content {
    padding: 16px;
    gap: 14px;
  }

  .topbar, .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar h1 {
    font-size: 24px;
  }

  .top-actions, .topbar-group {
    justify-content: space-between;
    width: 100%;
  }

  .toolbar-left, .toolbar-right {
    width: 100%;
    justify-content: stretch;
  }

  .toolbar-right button, .admin-actions button {
    flex: 1 1 150px;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-card {
    min-height: 90px;
    align-items: flex-start;
  }

  .status-card strong {
    font-size: 20px;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 10px;
  }

  .item-card {
    min-height: 142px;
    padding: 13px;
  }

  .admin-summary, .two-col {
    grid-template-columns: 1fr;
  }

  .admin-actions {
    padding: 12px;
  }

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

  .modal {
    max-height: calc(100vh - 28px);
    overflow-y: auto;
    padding: 16px;
  }
}

@media (max-width: 520px) {
  .login-card {
    gap: 20px;
  }

  .login-logo {
    align-items: flex-start;
  }

  .login-logo strong {
    font-size: 17px;
  }

  .clock-pill {
    padding: 0 9px;
    font-size: 12px;
  }

  .sidebar-footer {
    grid-template-columns: 1fr;
  }

  .sidebar-footer button {
    width: 100%;
  }

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

  .admin-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  table {
    min-width: 680px;
  }
}
