/* ========= RESET & BASE ========= */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #0e1117;
  color: #c9d1d9;
  min-height: 100vh;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

/* ========= LOGIN SCREEN ========= */
.screen {
  min-height: 100vh;
}

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, #161b28 0%, #0e1117 70%);
}

.login-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0, 0, 0, .4);
}

.login-logo {
  font-size: 3rem;
  margin-bottom: .5rem;
}

.login-card h1 {
  font-size: 1.4rem;
  color: #e6edf3;
  margin-bottom: .25rem;
}

.login-card .subtitle {
  font-size: .85rem;
  color: #7d8590;
  margin-bottom: 1.5rem;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.error-text {
  color: #f85149;
  font-size: .82rem;
  margin-top: .5rem;
  min-height: 1.2em;
}

/* ========= INPUTS ========= */
input[type="text"],
input[type="password"] {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: .65rem .85rem;
  color: #e6edf3;
  font-size: .95rem;
  outline: none;
  transition: border-color .2s;
}

input:focus {
  border-color: #58a6ff;
}

.hint {
  font-size: .78rem;
  color: #7d8590;
  margin-top: .25rem;
}

/* ========= BUTTONS ========= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  border: none;
  border-radius: 8px;
  padding: .6rem 1.1rem;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}

.btn-primary {
  background: #238636;
  color: #fff;
}

.btn-primary:hover {
  background: #2ea043;
}

.btn-danger {
  background: #da3633;
  color: #fff;
}

.btn-danger:hover {
  background: #f85149;
}

.btn-ghost {
  background: transparent;
  color: #7d8590;
  border: 1px solid #30363d;
}

.btn-ghost:hover {
  color: #e6edf3;
  border-color: #7d8590;
}

.btn-sm {
  padding: .35rem .65rem;
  font-size: .8rem;
  border-radius: 6px;
}

.btn-full {
  width: 100%;
}

/* ========= TOPBAR ========= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .8rem 1.5rem;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: .65rem;
}

.topbar-icon {
  font-size: 1.4rem;
}

.topbar h1 {
  font-size: 1.05rem;
  color: #e6edf3;
}

.topbar-right {
  display: flex;
  gap: .5rem;
}

/* ========= SYSTEM HEALTH BAR ========= */
.system-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  padding: .75rem 1.5rem;
  background: #0d1117;
  border-bottom: 1px solid #21262d;
}

.health-item {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .82rem;
  font-weight: 500;
  color: #7d8590;
}

.health-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #484f58;
  display: inline-block;
  transition: background .3s;
}

.health-item.ok .dot {
  background: #3fb950;
  box-shadow: 0 0 6px #3fb95066;
}

.health-item.fail .dot {
  background: #f85149;
  box-shadow: 0 0 6px #f8514966;
}

.health-info span {
  color: #58a6ff;
  font-family: monospace;
  font-size: .8rem;
}

/* ========= BANDWIDTH CHART ========= */
.bandwidth-section {
  padding: .75rem 1.5rem;
  border-bottom: 1px solid #21262d;
}

.bandwidth-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
}

.bandwidth-header h3 {
  font-size: .9rem;
  color: #e6edf3;
  font-weight: 600;
}

.bandwidth-legend {
  display: flex;
  gap: 1rem;
  font-size: .75rem;
  color: #7d8590;
}

.legend-rx {
  color: #58a6ff;
}

.legend-tx {
  color: #3fb950;
}

.chart-container {
  position: relative;
  height: 120px;
}

/* ========= ACTIONS BAR ========= */
.actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
}

.actions-bar h2 {
  font-size: 1.1rem;
  color: #e6edf3;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.badge {
  background: #30363d;
  color: #7d8590;
  font-size: .75rem;
  font-weight: 600;
  padding: .15rem .55rem;
  border-radius: 12px;
}

/* ========= PEER TABLE ========= */
.peer-section {
  padding: 0 1.5rem 2rem;
}

.table-wrap {
  border: 1px solid #21262d;
  border-radius: 10px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

thead {
  background: #161b22;
}

th {
  text-align: left;
  padding: .6rem .85rem;
  font-size: .78rem;
  font-weight: 600;
  color: #7d8590;
  text-transform: uppercase;
  letter-spacing: .03em;
  border-bottom: 1px solid #21262d;
  position: relative;
  user-select: none;
}

.col-resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: col-resize;
  z-index: 10;
}

.col-resize-handle:hover,
.col-resize-handle.active {
  background: #58a6ff;
}

td {
  padding: .65rem .85rem;
  font-size: .88rem;
  border-bottom: 1px solid #21262d;
  vertical-align: middle;
}

.td-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 0;
}

td:last-child {
  white-space: nowrap;
}

td:last-child .btn + .btn {
  margin-left: .35rem;
}

tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #161b2288;
}

.empty-row td {
  text-align: center;
  color: #484f58;
  padding: 2rem;
  white-space: normal;
}

td.mono {
  font-family: monospace;
  font-size: .82rem;
  color: #79c0ff;
}

/* Disabled peer row */
tr.disabled-row {
  opacity: 0.45;
}

tr.disabled-row td {
  color: #484f58;
}

/* Status Dot in Table */
.status-cell {
  display: flex;
  align-items: center;
  gap: .45rem;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-dot.on {
  background: #3fb950;
  box-shadow: 0 0 8px #3fb95055;
}

.status-dot.off {
  background: #484f58;
}

.status-label {
  font-size: .82rem;
}

/* ========= MODALS ========= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: #0e111799;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn .15s;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 14px;
  width: 95%;
  max-width: 560px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .5);
  animation: slideUp .2s;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0.6;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-sm {
  max-width: 400px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #21262d;
}

.modal-header h2 {
  font-size: 1rem;
  color: #e6edf3;
}

.modal-close {
  background: none;
  border: none;
  color: #7d8590;
  font-size: 1.1rem;
  cursor: pointer;
  padding: .25rem .4rem;
  border-radius: 6px;
}

.modal-close:hover {
  background: #21262d;
  color: #e6edf3;
}

.modal-body {
  padding: 1.25rem;
}

.modal-actions {
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

/* Success banner */
.success-banner {
  background: #238636;
  color: #fff;
  padding: .5rem .85rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: .9rem;
  margin-bottom: 1rem;
}

.warn-text {
  color: #d29922;
  font-size: .82rem;
  margin: .5rem 0;
}

/* Result grid */
.result-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1.25rem;
  align-items: start;
}

.result-info p {
  margin-bottom: .35rem;
  font-size: .9rem;
}

.result-qr {
  text-align: center;
}

.qr-label {
  font-size: .78rem;
  color: #7d8590;
  margin-bottom: .5rem;
}

#result-qr-img {
  width: 180px;
  height: 180px;
  border-radius: 8px;
  background: #fff;
}

/* ========= UTILITY ========= */
.mono {
  font-family: monospace;
}

/* ========= RESPONSIVE ========= */

/* --- Tablet / Medium screens --- */
@media (max-width: 1024px) {
  .topbar {
    padding: .7rem 1rem;
  }

  .system-bar {
    padding: .6rem 1rem;
    gap: .5rem;
  }

  .actions-bar {
    padding: .85rem 1rem;
  }

  .peer-section {
    padding: 0 1rem 1.5rem;
  }

  .bandwidth-section {
    padding: .75rem 1rem;
  }
}

/* --- Small screens --- */
@media (max-width: 700px) {
  .topbar {
    padding: .6rem .75rem;
  }

  .topbar h1 {
    font-size: .92rem;
  }

  .system-bar {
    padding: .5rem .75rem;
    gap: .4rem .6rem;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .health-item {
    white-space: nowrap;
    flex-shrink: 0;
  }

  .actions-bar {
    padding: .75rem;
    flex-wrap: wrap;
    gap: .5rem;
  }

  .actions-bar h2 {
    width: 100%;
  }

  .actions-bar > div {
    width: 100%;
    justify-content: flex-end;
  }

  .peer-section {
    padding: 0 .5rem 1.5rem;
  }

  table {
    min-width: 640px;
  }

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

  .result-qr {
    order: -1;
  }

  .bandwidth-section {
    padding: .5rem .75rem;
  }

  .chart-container {
    height: 100px;
  }

  .modal {
    width: 98%;
    border-radius: 12px;
  }
}

/* --- Extra small screens --- */
@media (max-width: 480px) {
  .topbar {
    flex-direction: column;
    gap: .5rem;
    padding: .6rem .75rem;
    align-items: stretch;
  }

  .topbar-left {
    justify-content: center;
  }

  .topbar-right {
    justify-content: center;
  }

  .topbar-right .btn {
    flex: 1;
  }

  .actions-bar > div {
    flex-direction: column;
  }

  .actions-bar .btn {
    width: 100%;
  }

  .bandwidth-header {
    flex-direction: column;
    align-items: flex-start;
    gap: .25rem;
  }
}

/* --- Touch devices --- */
@media (pointer: coarse) {
  .btn-sm {
    min-height: 44px;
    min-width: 44px;
    padding: .5rem .75rem;
    font-size: .84rem;
  }

  .btn {
    min-height: 44px;
  }

  td:last-child {
    white-space: nowrap;
  }
}