:root {
  --bg: #0b1120;
  --bg-elevated: #111b2e;
  --bg-card: #152138;
  --bg-input: #0e1628;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --emerald: #10b981;
  --emerald-dark: #059669;
  --emerald-soft: rgba(16, 185, 129, 0.15);
  --sky: #38bdf8;
  --sky-dark: #0284c7;
  --sky-soft: rgba(56, 189, 248, 0.14);
  --violet: #a78bfa;
  --violet-soft: rgba(167, 139, 250, 0.15);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.15);
  --danger: #f43f5e;
  --danger-soft: rgba(244, 63, 94, 0.16);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

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

.tiny {
  font-size: 12.5px;
}

.grow {
  flex: 1 1 0;
  min-width: 0;
}

.spacer {
  flex: 1;
}

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

.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.app-shell {
  min-height: 100dvh;
}

/* Center / Login Screens */
.center-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 18px;
  text-align: center;
  gap: 14px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.login-card h1 {
  margin: 4px 0 0;
  font-size: 24px;
  letter-spacing: -0.02em;
}

.login-card p {
  margin: 0;
}

.login-card form {
  width: 100%;
  margin-top: 10px;
  text-align: left;
}

.brand-badge.large {
  width: 68px;
  height: 68px;
  border-radius: 20px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.25);
  display: grid;
  place-items: center;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid rgba(148, 163, 184, 0.2);
  border-top-color: var(--emerald);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 17, 32, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mini {
  border-radius: 8px;
  flex-shrink: 0;
}

.app-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.net-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.net-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sky);
  flex-shrink: 0;
}

.net-status.is-lan .dot {
  background: var(--emerald);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.7);
}

.net-status.is-offline .dot {
  background: var(--amber);
}

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

/* Main Content */
.content {
  max-width: 960px;
  margin: 0 auto;
  padding: 14px 16px calc(92px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Banners */
.banner {
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.banner-warn {
  background: var(--amber-soft);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fde68a;
}

.banner-info {
  background: var(--sky-soft);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: #e0f2fe;
}

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

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

.search-wrap {
  position: relative;
  flex: 1 1 240px;
}

.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  padding: 11px 14px 11px 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.search-wrap input:focus {
  border-color: var(--sky);
}

.mode-switch {
  display: flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 3px;
}

.mode-pill {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.mode-pill.active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* Group Chips */
.chips-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.chips-row::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.chip.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.48);
  color: #e0f2fe;
}

/* Device Grid & Cards */
.device-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 720px) {
  .device-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.device-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s, transform 0.15s;
}

.device-card.is-lan-match {
  border-color: rgba(16, 185, 129, 0.36);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-title-wrap {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}

.star-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 19px;
  line-height: 1;
  padding: 3px;
  cursor: pointer;
  flex-shrink: 0;
}

.star-btn.active {
  color: var(--amber);
}

.card-name {
  margin: 0;
  font-size: 16.5px;
  font-weight: 700;
  word-break: break-word;
}

.card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.badge {
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.14);
  color: var(--text-muted);
}

.badge-lan {
  background: var(--emerald-soft);
  color: #6ee7b7;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: #cbd5e1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  padding: 5px 9px;
  border-radius: 9px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-pill:active {
  transform: scale(0.97);
}

.meta-pill .tag {
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  text-transform: uppercase;
}

.meta-pill-pass {
  border-color: rgba(245, 158, 11, 0.3);
  color: #fcd34d;
}

.card-notes {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* Action Buttons inside Card */
.card-actions {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.connect-btn {
  flex: 1 1 0;
  min-height: 44px;
  border-radius: 13px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  transition: filter 0.15s, transform 0.1s;
  text-decoration: none;
}

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

.connect-lan-primary {
  background: linear-gradient(135deg, var(--emerald), var(--emerald-dark));
  color: #022c22;
}

.connect-lan-secondary {
  background: var(--emerald-soft);
  border-color: rgba(16, 185, 129, 0.32);
  color: #6ee7b7;
}

.connect-online-primary {
  background: linear-gradient(135deg, var(--sky), var(--sky-dark));
  color: #082f49;
}

.connect-online-secondary {
  background: var(--sky-soft);
  border-color: rgba(56, 189, 248, 0.32);
  color: #7dd3fc;
}

.connect-vpn {
  background: var(--violet-soft);
  border-color: rgba(167, 139, 250, 0.35);
  color: #ddd6fe;
  flex: 0.78 1 0;
}

.connect-file {
  flex: 0 0 44px;
  background: var(--bg-input);
  border-color: var(--border);
  color: var(--text-muted);
  font-size: 16px;
}

/* Buttons & Inputs */
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:active {
  transform: scale(0.95);
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

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

.btn-sm {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 10px;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: linear-gradient(135deg, var(--sky), var(--sky-dark));
  color: #082f49;
}

.btn-emerald {
  background: linear-gradient(135deg, var(--emerald), var(--emerald-dark));
  color: #022c22;
}

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

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: rgba(244, 63, 94, 0.35);
  color: #fda4af;
}

/* FAB */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 18px;
  border: none;
  background: linear-gradient(135deg, var(--emerald), var(--sky));
  color: #042f2e;
  box-shadow: 0 12px 28px rgba(16, 185, 129, 0.35);
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 25;
}

.fab:active {
  transform: scale(0.95);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 46px 20px;
  background: var(--bg-elevated);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.empty-state h3 {
  margin: 0 0 6px;
}

.empty-state p {
  margin: 0 auto 18px;
  max-width: 340px;
}

/* Form Elements */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: #cbd5e1;
}

.field input,
.field textarea,
.field select,
.settings-card input,
.settings-card select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.settings-card input:focus {
  border-color: var(--sky);
}

.field-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.input-with-btn {
  display: flex;
  gap: 8px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--emerald);
  flex-shrink: 0;
}

.form-error {
  margin: 0;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: #fecdd3;
  font-size: 13px;
}

/* Modals (Bottom sheet on mobile, centered on desktop) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 640px) {
  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }
}

.modal-sheet {
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 22px 22px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}

@media (min-width: 640px) {
  .modal-sheet {
    border-radius: 22px;
  }
}

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

.modal-header h2 {
  margin: 0;
  font-size: 17px;
}

.modal-body {
  padding: 16px 18px calc(22px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
}

/* Settings Cards */
.settings-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}

.settings-card h3 {
  margin: 0 0 6px;
  font-size: 14.5px;
}

.settings-card p {
  margin: 0 0 8px;
}

.ip-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  margin-bottom: 10px;
  font-size: 13px;
}

.ip-box code {
  color: #6ee7b7;
  font-weight: 700;
  overflow-wrap: anywhere;
  text-align: right;
}

.saved-ip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.saved-ip-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--emerald-soft);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #a7f3d0;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
}

.saved-ip-tag button {
  border: none;
  background: transparent;
  color: #fecdd3;
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(26px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  background: #1e293b;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  max-width: 90vw;
  text-align: center;
}
