:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1e293b;
  --bg-input: #0f172a;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-primary: #2563eb;
  --accent-primary-hover: #1d4ed8;
  --accent-primary-active: #1e40af;
  
  --border-color: #334155;
  --border-subtle: #1e293b;
  
  --success-bg: rgba(16, 185, 129, 0.15);
  --success-text: #34d399;
  --success-border: #059669;
  
  --warning-bg: rgba(245, 158, 11, 0.15);
  --warning-text: #fbbf24;
  --warning-border: #d97706;
  
  --danger-bg: rgba(239, 68, 68, 0.15);
  --danger-text: #f87171;
  --danger-border: #dc2626;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 1rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.brand-badge {
  background-color: var(--accent-primary);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  letter-spacing: 0.05em;
}

.brand-titles h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.brand-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: block;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--bg-primary);
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  font-size: 0.825rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #10b981;
  display: inline-block;
  box-shadow: 0 0 6px #10b981;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.btn-primary {
  background-color: var(--accent-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--accent-primary-hover);
}

.btn-secondary {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background-color: #475569;
}

.btn-danger {
  background-color: var(--danger-bg);
  color: var(--danger-text);
  border-color: var(--danger-border);
}

.btn-danger:hover {
  background-color: #ef4444;
  color: #ffffff;
}

.btn-outline {
  background-color: transparent;
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-outline:hover {
  background-color: var(--bg-tertiary);
}

.btn-sm {
  font-size: 0.775rem;
  padding: 0.3rem 0.65rem;
}

.btn-icon {
  font-size: 1rem;
  line-height: 1;
}

/* Main content */
.app-main {
  flex: 1;
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.dashboard-section {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
}

.section-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.section-title-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.section-title-group h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.counter-badge {
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
}

.section-hint {
  font-size: 0.825rem;
  color: var(--text-muted);
}

/* Tables */
.table-container {
  overflow-x: auto;
  min-height: 140px;
}

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

.data-table th {
  background-color: rgba(15, 23, 42, 0.6);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.data-table td {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

.node-name-cell {
  font-family: var(--font-mono);
  font-weight: 600;
  color: #60a5fa;
}

.link-id-cell {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.loading-row td {
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: 2.5rem;
}

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.775rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.status-badge.active,
.status-badge.online,
.status-badge.connected {
  background-color: var(--success-bg);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}

.status-badge.connecting,
.status-badge.pending,
.status-badge.applying {
  background-color: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
}

.status-badge.inactive,
.status-badge.offline,
.status-badge.disabled,
.status-badge.failed {
  background-color: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
}

.state-cell {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.state-mismatch-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.725rem;
  font-weight: 600;
  color: #fbbf24;
  background-color: rgba(245, 158, 11, 0.15);
  border: 1px dashed #d97706;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.link-error-msg {
  font-size: 0.775rem;
  color: #f87171;
  background-color: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  margin-top: 0.35rem;
  max-width: 280px;
  word-break: break-word;
}

/* Event Journal */
.event-type-badge {
  font-family: var(--font-mono);
  font-size: 0.775rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background-color: var(--bg-tertiary);
  color: #93c5fd;
  display: inline-block;
}

.event-payload-box {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  max-width: 500px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3.5rem 2rem;
  text-align: center;
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.empty-state-text {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.empty-state-subtext {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 450px;
}

/* Alerts */
.alert {
  padding: 1rem 1.25rem;
  border-radius: 6px;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.alert-error {
  background-color: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
}

.alert-success {
  background-color: var(--success-bg);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-window {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 100%;
  max-width: 640px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  animation: modalEnter 0.15s ease-out;
}

.create-link-modal-window {
  max-width: 680px;
}

@keyframes modalEnter {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.25rem;
  border-radius: 4px;
}

.modal-close:hover {
  color: var(--text-primary);
  background-color: var(--bg-tertiary);
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Forms */
.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.form-control {
  font-family: var(--font-mono);
  font-size: 0.925rem;
  padding: 0.65rem 0.85rem;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
}

.form-select {
  font-family: var(--font-sans);
  cursor: pointer;
}

.form-control:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

.form-hint {
  font-size: 0.775rem;
  color: var(--text-muted);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

/* Direction Confirmation Card */
.link-direction-card {
  background-color: #0b2246;
  border: 2px solid #2563eb;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.direction-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #93c5fd;
  font-size: 0.85rem;
  font-weight: 700;
}

.direction-summary-text {
  font-size: 0.9rem;
  color: #ffffff;
  line-height: 1.45;
  background-color: rgba(15, 23, 42, 0.6);
  padding: 0.65rem 0.85rem;
  border-radius: 6px;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.direction-summary-text strong {
  color: #60a5fa;
}

.direction-summary-text.warning {
  color: #fbbf24;
  border-color: #f59e0b;
  background-color: rgba(69, 26, 3, 0.4);
}

/* Enrollment Code Result */
.enrollment-result-container {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.security-warning-card {
  background-color: #451a03;
  border: 2px solid #f59e0b;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.warning-badge-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #fbbf24;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.025em;
}

.warning-text {
  font-size: 0.825rem;
  color: #fef3c7;
  line-height: 1.45;
}

.result-field-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.result-field-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.result-field-header label {
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.code-box {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.825rem;
  color: #e2e8f0;
  word-break: break-all;
  width: 100%;
}

.fingerprint-box {
  color: #38bdf8;
  font-weight: 600;
}

.enrollment-code-box {
  resize: vertical;
  min-height: 90px;
  line-height: 1.4;
  outline: none;
}

.enrollment-code-box:focus {
  border-color: var(--accent-primary);
}

.result-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-color);
}

.expiration-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.825rem;
  color: var(--text-secondary);
}

.countdown-badge {
  background-color: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-weight: 700;
}

/* Footer */
.app-footer {
  padding: 1.25rem 2rem;
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.footer-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.footer-separator {
  color: var(--border-color);
}

/* Testing Banner & Login Modal */
.testing-banner {
  background-color: var(--warning-bg);
  border-bottom: 1px solid var(--warning-border);
  color: var(--warning-text);
  padding: 0.5rem 2rem;
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
}

.testing-notice-box {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.login-modal-window {
  max-width: 440px;
}

.btn-block {
  width: 100%;
}

/* Utilities */
.hidden {
  display: none !important;
}

.text-muted {
  color: var(--text-muted);
}

.text-danger {
  color: var(--danger-text);
}

/* Responsive */
@media (max-width: 768px) {
  .app-header {
    padding: 1rem;
  }
  .app-main {
    padding: 1rem;
  }
  .app-footer {
    padding: 1rem;
  }
  .modal-window {
    margin: 0.5rem;
  }
  .testing-banner {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
  }
  .form-row-2,
  .form-row-3 {
    grid-template-columns: 1fr;
  }
}
