/* =========================================================================
   ProxyFleet Panel - Dark theme styles
   ========================================================================= */

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #232733;
  --border: #2d3140;
  --text: #e1e4ed;
  --text2: #8b90a0;
  --accent: #4f8cff;
  --green: #34d399;
  --red: #f87171;
  --orange: #fbbf24;
  --font: 'SF Mono', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
  --radius: 6px;
  --transition: 150ms ease;
}

/* ---- Reset ---- */

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

[hidden] {
  display: none !important;
}

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

input, select, textarea, button {
  font-family: var(--font);
  font-size: 13px;
}

/* ---- Scrollbar ---- */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* =========================================================================
   Login Screen
   ========================================================================= */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}

.login-subtitle {
  color: var(--text2);
  margin-bottom: 24px;
  font-size: 12px;
}

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

/* =========================================================================
   Form Elements
   ========================================================================= */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  color: var(--text2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

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

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

.input-sm {
  width: auto;
  flex: 1;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text2);
  font-size: 12px;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  accent-color: var(--accent);
}

/* =========================================================================
   Buttons
   ========================================================================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  font-size: 12px;
}

.btn:hover {
  background: var(--border);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover {
  background: #3b78eb;
}

.btn-danger {
  border-color: var(--red);
  color: var(--red);
}

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

.btn-sm {
  padding: 4px 10px;
  font-size: 11px;
}

.btn-block {
  display: block;
  width: 100%;
}

.btn-copy {
  padding: 2px 8px;
  font-size: 10px;
  vertical-align: middle;
  margin-left: 6px;
}

/* =========================================================================
   Header
   ========================================================================= */

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-title {
  font-size: 16px;
  font-weight: 700;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* ---- WS Indicator ---- */

.ws-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ws-connected {
  background: var(--green);
  box-shadow: 0 0 4px var(--green);
}

.ws-disconnected {
  background: var(--red);
}

/* =========================================================================
   Stats Bar
   ========================================================================= */

.stats-bar {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  overflow-x: auto;
  flex-wrap: wrap;
}

.stat-card {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 130px;
  flex: 1;
}

.stat-label {
  color: var(--text2);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
}

.stat-green { color: var(--green); }
.stat-red { color: var(--red); }

/* =========================================================================
   Device List
   ========================================================================= */

.device-list-header {
  padding: 12px 20px 0;
}

.device-list-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.device-list {
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.device-card {
  display: grid;
  grid-template-columns: 10px 1fr 130px 60px 90px 80px 60px 50px 32px;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}

.device-card:hover {
  background: var(--surface2);
  border-color: var(--accent);
}

/* Status dot */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-online { background: var(--green); box-shadow: 0 0 4px var(--green); }
.status-offline { background: var(--text2); }
.status-warmup { background: var(--orange); box-shadow: 0 0 4px var(--orange); }

/* Device info cells */
.device-name {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-ip {
  color: var(--text2);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-clean {
  background: rgba(52, 211, 153, 0.15);
  color: var(--green);
}

.badge-dirty {
  background: rgba(248, 113, 113, 0.15);
  color: var(--red);
}

.badge-unknown {
  background: rgba(139, 144, 160, 0.15);
  color: var(--text2);
}

.device-pof {
  color: var(--text2);
  font-size: 11px;
}

.device-temp {
  color: var(--text2);
  font-size: 11px;
}

.device-battery {
  color: var(--text2);
  font-size: 11px;
}

/* Health dot in card */
.health-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.health-ok { background: var(--green); }
.health-bad { background: var(--red); }

.device-rotate-btn {
  padding: 2px 6px;
  font-size: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
}

.device-rotate-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* =========================================================================
   Modals
   ========================================================================= */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}


.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal-lg {
  max-width: 640px;
}

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

.modal-header h2 {
  font-size: 15px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

/* =========================================================================
   Device Detail Modal
   ========================================================================= */

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.detail-item {
  display: flex;
  flex-direction: column;
}

.detail-label {
  color: var(--text2);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.detail-value {
  font-size: 13px;
  word-break: break-all;
}

.proxy-strings {
  margin-bottom: 20px;
}

.proxy-strings h3 {
  font-size: 12px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.proxy-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  padding: 6px 10px;
  background: var(--surface2);
  border-radius: var(--radius);
  font-size: 11px;
  word-break: break-all;
}

.proxy-row code {
  flex: 1;
  color: var(--text);
}

.proxy-row .btn-copy {
  flex-shrink: 0;
}

.detail-section {
  margin-bottom: 16px;
}

.detail-section h3 {
  font-size: 12px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* =========================================================================
   Export Modal
   ========================================================================= */

.export-result {
  margin-top: 16px;
}

.export-result textarea {
  width: 100%;
  resize: vertical;
  font-size: 11px;
  margin-bottom: 8px;
}

/* =========================================================================
   Settings Modal
   ========================================================================= */

.settings-section {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.settings-section:last-of-type {
  border-bottom: none;
}

.settings-section h3 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

.whitelist-list {
  margin-bottom: 10px;
}

.whitelist-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--surface2);
  border-radius: var(--radius);
  margin-bottom: 4px;
  font-size: 12px;
}

.whitelist-row .wl-ip {
  color: var(--text);
}

.whitelist-row .wl-label {
  color: var(--text2);
  margin-left: 8px;
}

.whitelist-row .btn-sm {
  flex-shrink: 0;
}

.register-token {
  display: inline-block;
  padding: 6px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  word-break: break-all;
  user-select: all;
}

.settings-actions {
  margin-top: 16px;
}

/* =========================================================================
   QR / Add Device Modal
   ========================================================================= */

.qr-display {
  text-align: center;
  padding: 20px;
}

.qr-display p {
  color: var(--text2);
  margin-bottom: 10px;
  font-size: 12px;
}

.qr-display .btn {
  margin-top: 12px;
}

.text-muted {
  color: var(--text2);
  font-size: 12px;
  margin-bottom: 12px;
}

/* =========================================================================
   Toast Notifications
   ========================================================================= */

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  max-width: 380px;
}

.toast {
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text);
  animation: toast-in 200ms ease-out;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.toast-info { border-left: 3px solid var(--accent); }
.toast-success { border-left: 3px solid var(--green); }
.toast-error { border-left: 3px solid var(--red); }
.toast-warning { border-left: 3px solid var(--orange); }

.toast-dismiss {
  animation: toast-out 200ms ease-in forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* =========================================================================
   Responsive
   ========================================================================= */

@media (max-width: 900px) {
  .device-card {
    grid-template-columns: 10px 1fr 100px 60px;
    gap: 8px;
  }
  .device-pof,
  .device-temp,
  .device-battery,
  .health-dot-cell,
  .device-rotate-btn {
    display: none;
  }
}

@media (max-width: 600px) {
  .header {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-right {
    width: 100%;
    justify-content: flex-start;
  }
  .stats-bar {
    flex-direction: column;
  }
  .stat-card {
    min-width: auto;
  }
  .device-card {
    grid-template-columns: 10px 1fr 60px;
    gap: 6px;
    padding: 8px 10px;
  }
  .device-ip {
    display: none;
  }
  .detail-grid {
    grid-template-columns: 1fr;
  }
  .modal {
    max-height: 90vh;
  }
}
