:root {
  --bg: #f6f1ea;
  --ink: #0b1f22;
  --muted: #6c6f6b;
  --card: #ffffff;
  --accent: #d27a2c;
  --accent-2: #2f7a76;
  --accent-3: #2b4d4a;
  --danger: #c4473d;
  --shadow: 0 20px 60px rgba(12, 18, 18, 0.12);
  --radius: 18px;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Space Grotesk", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sans);
  color: var(--ink);
  background: radial-gradient(circle at top left, #fdf7ee, var(--bg));
  overflow-x: hidden;
}

.bg-glow {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 10% 10%, rgba(210, 122, 44, 0.18), transparent 40%),
    radial-gradient(circle at 90% 20%, rgba(47, 122, 118, 0.16), transparent 45%),
    radial-gradient(circle at 50% 90%, rgba(43, 77, 74, 0.12), transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.noise {
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
}

.screen {
  position: relative;
  z-index: 1;
  padding: 32px;
}

.hidden {
  display: none !important;
}

.login-card {
  max-width: 420px;
  margin: 8vh auto 0;
  background: var(--card);
  padding: 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: rise 0.6s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #f2b266);
  box-shadow: 0 12px 24px rgba(210, 122, 44, 0.25);
}

.brand.mini .brand-mark {
  width: 28px;
  height: 28px;
}

.brand-title {
  font-weight: 700;
  font-size: 22px;
}

.brand-subtitle {
  font-size: 13px;
  color: var(--muted);
  font-family: var(--mono);
}

h1, h2, h3 {
  margin: 0 0 12px;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

.form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

label {
  display: grid;
  gap: 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

input, select, textarea {
  font-family: var(--sans);
  font-size: 15px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(11, 31, 34, 0.12);
  background: #fff;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(47, 122, 118, 0.15);
}

.btn {
  font-family: var(--sans);
  font-weight: 600;
  border-radius: 999px;
  border: none;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 12px 24px rgba(210, 122, 44, 0.28);
}

.btn.primary:hover {
  transform: translateY(-1px);
}

.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid rgba(11, 31, 34, 0.1);
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

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

.pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(47, 122, 118, 0.12);
  color: var(--accent-3);
  font-size: 13px;
  font-family: var(--mono);
}

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 24px;
  margin-top: 24px;
}

.sidebar {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
  font-size: 14px;
  align-content: start;
  grid-auto-rows: min-content;
  align-self: start;
  height: max-content;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  height: 44px !important;
  min-height: 44px !important;
  line-height: 1 !important;
  flex: 0 0 44px;
  align-self: start;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  gap: 10px;
}

.nav-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-family: var(--mono);
  background: rgba(47, 122, 118, 0.12);
  color: var(--accent-3);
  flex: 0 0 auto;
}

.nav-label {
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-toggle {
  justify-self: flex-end;
}

.sidebar.collapsed .nav-label {
  display: none;
}

.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 10px 8px;
}

.sidebar.collapsed .nav-icon {
  margin: 0;
}

.sidebar.collapsed .sidebar-toggle {
  justify-self: center;
}

.nav-item.active {
  background: rgba(210, 122, 44, 0.12);
  color: var(--ink);
}

.content {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  min-height: 70vh;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.grid {
  display: grid;
  gap: 16px;
}

.metrics-row {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  margin-bottom: 16px;
}

.card {
  background: #fff;
  border-radius: 16px;
  padding: 18px;
  border: 1px solid rgba(11, 31, 34, 0.06);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.table-scroll {
  max-height: 70vh;
  overflow: auto;
  border-radius: 12px;
}

.table-scroll.small {
  max-height: 240px;
}

.table.compact th,
.table.compact td {
  padding: 6px 8px;
  font-size: 12px;
}

.audit-filters {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 16px;
}

.audit-actions {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.table th, .table td {
  padding: 10px 8px;
  border-bottom: 1px solid rgba(11, 31, 34, 0.06);
  text-align: left;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-family: var(--mono);
  background: rgba(47, 122, 118, 0.12);
  color: var(--accent-3);
}

.tag.ok {
  background: rgba(35, 140, 87, 0.12);
  color: #238c57;
}

.tag.warn {
  background: rgba(196, 71, 61, 0.12);
  color: #c4473d;
}

.tag.offline {
  background: rgba(196, 71, 61, 0.12);
  color: var(--danger);
}

.error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn-row .btn {
  padding: 8px 14px;
  font-size: 13px;
}

pre.mono {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  background: rgba(11, 31, 34, 0.04);
  padding: 10px 12px;
  border-radius: 12px;
}

.mono {
  font-family: var(--mono);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(11, 31, 34, 0.32);
  display: grid;
  place-items: center;
  z-index: 30;
}

.modal-card {
  background: var(--card);
  padding: 22px;
  border-radius: var(--radius);
  width: min(520px, 90vw);
  box-shadow: var(--shadow);
  max-height: 85vh;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-card {
  position: relative;
}

.modal-save {
  position: static;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-body {
  max-height: 65vh;
  overflow-y: auto;
  padding-right: 6px;
}

.modal-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(11, 31, 34, 0.06);
}

.key-list {
  max-height: 200px;
  overflow: auto;
  padding-right: 6px;
}

.key-item {
  word-break: break-all;
  margin-bottom: 8px;
}

.key-input {
  resize: vertical;
  min-height: 96px;
  word-break: break-all;
}

.btn.small {
  padding: 6px 12px;
  font-size: 12px;
}

textarea {
  resize: vertical;
  max-width: 100%;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-row .toggle-pass {
  white-space: nowrap;
}

.token-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  background: var(--accent-3);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 40;
}

.terminal-shell {
  display: grid;
  gap: 18px;
}

.terminal-grid {
  display: grid;
  gap: 14px;
}

.terminal-card {
  border-radius: 16px;
  background: #0b1214;
  color: #f6f1ea;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.terminal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  font-family: var(--mono);
}

.terminal-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.terminal-viewport {
  width: 100%;
  min-height: 420px;
  height: 60vh;
  max-height: 680px;
  border-radius: 12px;
  background: #060a0c;
  overflow: hidden;
}

.terminal-viewport .xterm,
.terminal-viewport .xterm-screen,
.terminal-viewport .xterm-viewport {
  width: 100%;
  height: 100%;
}

.terminal-viewport .xterm canvas {
  max-width: 100%;
}

.terminal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.terminal-pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 12px;
  font-family: var(--mono);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    grid-auto-flow: column;
    overflow-x: auto;
    grid-auto-columns: minmax(160px, 1fr);
  }
}

.sidebar-collapsed .layout {
  grid-template-columns: 90px 1fr;
}

.terminal-detached .topbar,
.terminal-detached .sidebar {
  display: none;
}

.terminal-detached .layout {
  grid-template-columns: 1fr;
  margin-top: 0;
}

.terminal-detached .content {
  min-height: 90vh;
}

.terminal-detached .terminal-viewport {
  height: calc(100vh - 140px);
  min-height: calc(100vh - 140px);
  max-height: none;
}

@media (max-width: 900px) {
  .metrics-row {
    grid-template-columns: 1fr;
  }
}
