:root {
  --bg: #070a0e;
  --panel: #0d1219;
  --card: #121822;
  --card-hover: #18212e;
  --input-bg: #0a0f16;
  --border: #1f2b3b;
  --border-hover: #2e3e54;
  --border-active: #388bfd;
  --fg: #e6edf3;
  --fg-dim: #8b949e;
  --fg-muted: #57606a;
  --primary: #388bfd;
  --primary-hover: #58a6ff;
  --success: #3fb950;
  --success-bg: rgba(63, 185, 80, 0.12);
  --warn: #d29922;
  --warn-bg: rgba(210, 153, 34, 0.12);
  --danger: #f85149;
  --danger-bg: rgba(248, 81, 73, 0.12);
  --radius: 8px;
  --radius-sm: 6px;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --font-sans: "Plus Jakarta Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
}

body {
  min-height: 100vh;
  padding: 16px 24px 40px 24px;
  margin: 0 auto;
  max-width: 1600px;
}

[hidden], .view-panel[hidden] {
  display: none !important;
}

input, select, textarea {
  background: var(--input-bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12.5px;
  font-family: var(--font-sans);
  outline: none;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  background: #0f1722;
  box-shadow: 0 0 0 2px rgba(56, 139, 253, 0.2);
}

input::placeholder, textarea::placeholder {
  color: #57606a;
}

.app-header {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  width: 100%;
}

.header-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  width: 100%;
}

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

.brand-logo {
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  color: #fff;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.05em;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  box-shadow: 0 0 16px rgba(139, 92, 246, 0.4);
}

.brand-title h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-title h1 span {
  color: var(--fg-dim);
  font-weight: 400;
}

.badge-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid rgba(63, 185, 80, 0.3);
  padding: 2px 8px;
  border-radius: 99px;
  text-transform: uppercase;
  font-weight: 600;
}

.pulse {
  width: 6px;
  height: 6px;
  background-color: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(63, 185, 80, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(63, 185, 80, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(63, 185, 80, 0); }
}

.nav-tabs-wrapper {
  width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 2px;
}

.nav-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  width: 100%;
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--fg-dim);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--fg);
  background: var(--card);
}

.tab-btn.active {
  color: #fff;
  background: var(--card);
  border-color: var(--border-active);
  box-shadow: 0 0 10px rgba(56, 139, 253, 0.2);
  font-weight: 600;
}

.badge {
  background: var(--border);
  color: var(--fg-dim);
  font-size: 10px;
  font-family: var(--font-mono);
  padding: 1px 6px;
  border-radius: 99px;
}

.auth-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.token-wrap {
  display: flex;
  align-items: center;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 4px;
}

.token-wrap input {
  background: transparent !important;
  border: none !important;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 8px;
  width: 130px;
  box-shadow: none !important;
}

.token-wrap button {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  color: var(--fg-dim);
}

.status-tag {
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--fg-dim);
}

.status-tag.ok {
  color: var(--success);
  border-color: rgba(63, 185, 80, 0.3);
  background: var(--success-bg);
}

.status-tag.err {
  color: var(--danger);
  border-color: rgba(248, 81, 73, 0.3);
  background: var(--danger-bg);
}

.btn-primary, .btn-secondary, .btn-danger, .btn-success {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 12px rgba(56, 139, 253, 0.4);
}

.btn-secondary {
  background: var(--card);
  border-color: var(--border);
  color: var(--fg);
}
.btn-secondary:hover {
  background: var(--card-hover);
  border-color: var(--border-hover);
}

.btn-danger {
  background: var(--danger-bg);
  border-color: rgba(248, 81, 73, 0.4);
  color: var(--danger);
}
.btn-danger:hover { background: rgba(248, 81, 73, 0.25); }

.btn-success {
  background: var(--success-bg);
  border-color: rgba(63, 185, 80, 0.4);
  color: var(--success);
}
.btn-success:hover { background: rgba(63, 185, 80, 0.25); }

.view-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
  max-width: 100%;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  width: 100%;
}

.section-title h2 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.panel-desc {
  font-size: 12px;
  color: var(--fg-dim);
  margin-top: 3px;
}

.refresh-indicator {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--fg-dim);
}

.grid-2col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 18px;
  width: 100%;
}

.grid-3col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  width: 100%;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  width: 100%;
}

.kpi-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  width: 100%;
}

.kpi-icon {
  font-size: 22px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kpi-data {
  display: flex;
  flex-direction: column;
}

.kpi-label {
  font-size: 11px;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.kpi-value {
  font-size: 20px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--fg);
}

.kpi-warn {
  border-color: rgba(210, 153, 34, 0.4);
}
.kpi-warn .kpi-value {
  color: var(--warn);
}

.ops-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 18px;
  width: 100%;
}

.panel-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  width: 100%;
}

.panel-card h3 {
  font-size: 15px;
  font-weight: 700;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.status-banner {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--card);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--success);
}

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

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

.table-container {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  width: 100%;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th {
  background: var(--card);
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  vertical-align: middle;
}

.data-table tr:hover td {
  background: rgba(56, 139, 253, 0.04);
}

.chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 10.5px;
  font-family: var(--font-mono);
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--card);
}

.state-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 600;
}

.state-badge.on {
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid rgba(63, 185, 80, 0.3);
}

.state-badge.off {
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid rgba(248, 81, 73, 0.3);
}

.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 19px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--border);
  transition: 0.2s;
  border-radius: 20px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 13px;
  width: 13px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  transition: 0.2s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(17px);
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}

.user-autocomplete-wrapper {
  position: relative;
  width: 100%;
}

.user-autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #0d131a;
  border: 1px solid var(--border-active);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  z-index: 100;
  max-height: 220px;
  overflow-y: auto;
}

.user-autocomplete-item {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: background 0.15s ease;
  font-size: 11.5px;
}

.user-autocomplete-item:last-child {
  border-bottom: none;
}

.user-autocomplete-item:hover, .user-autocomplete-item.active {
  background: rgba(56, 139, 253, 0.15);
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-desc {
  font-size: 11.5px;
  color: var(--fg-dim);
  margin-top: 2px;
}

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

.custom-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 9, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  padding: 16px;
  animation: cmFadeIn 0.15s ease-out;
}

.custom-modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
  animation: cmScaleIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.custom-modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.custom-modal-icon {
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--border);
}

.custom-modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--fg);
  letter-spacing: -0.01em;
}

.custom-modal-message {
  font-size: 13.5px;
  color: var(--fg-dim);
  line-height: 1.55;
  word-break: break-word;
}

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

@keyframes cmFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes cmScaleIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@media (max-width: 1024px) {
  body {
    padding: 14px 16px;
  }
  .grid-2col {
    grid-template-columns: 1fr;
  }
  .ops-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    padding: 10px 10px;
    font-size: 12px;
  }
  .app-header {
    padding: 10px 12px;
  }
  .header-top-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .auth-bar {
    width: 100%;
    justify-content: space-between;
  }
  .token-wrap {
    flex: 1;
  }
  .token-wrap input {
    width: 100%;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .panel-card {
    padding: 14px;
  }
}
