/* ═══════════════════════════════════════════════════════════════
   ETunnel Admin Panel — Dark Theme
   ═══════════════════════════════════════════════════════════════ */

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

:root {
  --bg:          #0a0e27;
  --bg-card:     #151932;
  --bg-card2:    #1a1f3a;
  --bg-input:    #1a1f3a;
  --border:      #252b47;
  --border-focus:#00d4ff;
  --primary:     #00d4ff;
  --primary-hover:#00b8e6;
  --danger:      #ff5370;
  --danger-hover:#ff3355;
  --success:     #00e8a2;
  --warning:     #ffb627;
  --text:        #e6e9f0;
  --text-muted:  #7982a9;
  --text-dim:    #4a5577;
  --sidebar-w:   260px;
  --radius:      8px;
  --radius-sm:   5px;
  --shadow:      0 8px 32px rgba(0,0,0,0.4);
  --transition:  0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Screens ─────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: flex; }

/* ─── Login ───────────────────────────────────────────────────── */
#login-screen {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, #1a2240 0%, var(--bg) 70%);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}
.logo-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 0.75rem;
  background: linear-gradient(135deg, var(--primary), #0099ff);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  box-shadow: 0 4px 16px rgba(0, 212, 255, 0.3);
}
.login-logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.login-logo p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
  font-weight: 400;
}

/* ─── Dashboard Layout ────────────────────────────────────────── */
#dashboard-screen {
  min-height: 100vh;
  flex-direction: row;
}

/* ─── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  flex-shrink: 0;
  transition: transform var(--transition);
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), #0099ff);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.sidebar-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  letter-spacing: -0.01em;
}
.sidebar-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-weight: 500;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
  position: relative;
}
.nav-item:hover { background: var(--bg-card2); color: var(--text); }
.nav-item.active {
  background: rgba(0, 212, 255, 0.08);
  color: var(--primary);
  border-left: 3px solid var(--primary);
  padding-left: calc(1rem - 3px);
}
.nav-icon {
  font-size: 1.15rem;
  width: 1.25rem;
  text-align: center;
  line-height: 1;
  opacity: 0.9;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.feed-url-box {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.9rem;
}
.feed-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.feed-url {
  font-size: 0.72rem;
  color: var(--primary);
  word-break: break-all;
  margin-bottom: 0.5rem;
  font-family: 'Consolas', 'Monaco', monospace;
  line-height: 1.5;
}

/* ─── Main Content ────────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── Topbar ──────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  display: none;
  padding: 0.25rem;
  line-height: 1;
}
.topbar-title {
  font-weight: 600;
  font-size: 1rem;
  flex: 1;
  color: var(--text);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.badge {
  font-size: 0.75rem;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.2rem 0.75rem;
  color: var(--text-muted);
}

/* ─── Views ───────────────────────────────────────────────────── */
.view { display: none; padding: 1.5rem; flex-direction: column; gap: 1rem; }
.view.active { display: flex; }

/* ─── Toolbar ─────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}
.search-input {
  flex: 1;
  min-width: 200px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.55rem 0.9rem;
  font-size: 0.875rem;
  outline: none;
  transition: border-color var(--transition);
}
.search-input:focus { border-color: var(--border-focus); }
.toolbar-right { display: flex; gap: 0.5rem; }
.select-sm {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  font-size: 0.8rem;
  cursor: pointer;
  outline: none;
}
.select-sm:focus { border-color: var(--border-focus); }

/* ─── Servers Grid ────────────────────────────────────────────── */
.servers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

.server-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  position: relative;
}
.server-card:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(79,110,247,0.2), var(--shadow);
}
.server-card.offline { opacity: 0.6; }

.server-card-header {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}
.server-flag { font-size: 2rem; line-height: 1; flex-shrink: 0; }
.server-meta { flex: 1; min-width: 0; }
.server-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.server-location { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.1rem; }

.server-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.25rem 0.75rem;
  border-radius: 99px;
  flex-shrink: 0;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.server-status.online {
  color: var(--success);
  background: rgba(0, 232, 162, 0.12);
  border: 1px solid rgba(0, 232, 162, 0.2);
}
.server-status.offline {
  color: var(--danger);
  background: rgba(255, 83, 112, 0.12);
  border: 1px solid rgba(255, 83, 112, 0.2);
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.server-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 0.5rem;
  font-size: 0.78rem;
}
.detail-row {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.detail-label { color: var(--text-muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; }
.detail-value {
  color: var(--text);
  font-family: monospace;
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.server-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.tag {
  font-size: 0.68rem;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  background: rgba(0, 212, 255, 0.1);
  color: var(--primary);
  border: 1px solid rgba(0, 212, 255, 0.25);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.server-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ─── Empty State ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}
.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  opacity: 0.3;
  filter: grayscale(1);
}
.empty-state h3 {
  font-size: 1.15rem;
  color: var(--text);
  margin-bottom: 0.5rem;
  font-weight: 600;
}
.empty-state p {
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
  line-height: 1.7;
  color: var(--text-muted);
}

/* ─── Stats ───────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}
.stat-card.online { border-color: rgba(62,207,142,0.3); }
.stat-card.offline { border-color: rgba(224,82,82,0.3); }
.stat-icon {
  font-size: 1.5rem;
  margin-bottom: 0.6rem;
  opacity: 0.7;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--text); margin-bottom: 0.25rem; }
.stat-label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.protocol-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.5rem 0;
}
.proto-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.proto-name { width: 120px; font-size: 0.85rem; color: var(--text-muted); }
.proto-bar-wrap { flex: 1; background: var(--bg-card2); border-radius: 99px; height: 8px; overflow: hidden; }
.proto-bar { height: 100%; background: var(--primary); border-radius: 99px; transition: width 0.4s ease; }
.proto-count { width: 2rem; text-align: right; font-size: 0.85rem; font-weight: 600; color: var(--text); }

/* ─── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}
.card-body { padding: 1.25rem; }
.card-body p { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 0.75rem; }

/* ─── Import / Export ─────────────────────────────────────────── */
.ie-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.ie-grid .full-width { grid-column: 1 / -1; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  margin: 0.75rem 0;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary);
  background: rgba(79,110,247,0.06);
}
.drop-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.drop-zone p { font-size: 0.83rem; color: var(--text-muted); line-height: 1.6; }
.drop-zone code { color: var(--primary); font-size: 0.85rem; }

.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.feed-info { padding: 0; }
.feed-info p { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.code-block {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--primary);
  word-break: break-all;
}
.form-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}
.input-full {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.9rem;
  font-size: 0.875rem;
  outline: none;
}
.input-full:focus { border-color: var(--border-focus); }

/* ─── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition), opacity var(--transition);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger    { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-secondary { background: rgba(79,110,247,0.15); color: var(--primary); border-color: rgba(79,110,247,0.3); }
.btn-secondary:hover:not(:disabled) { background: rgba(79,110,247,0.25); }
.btn-ghost     { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-card2); color: var(--text); }
.btn-warning   { background: rgba(240,160,48,0.15); color: var(--warning); border-color: rgba(240,160,48,0.3); }
.btn-warning:hover:not(:disabled) { background: rgba(240,160,48,0.25); }
.btn-sm  { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-full { width: 100%; }
.btn-spinner { display: inline-block; }

/* ─── Forms ───────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.form-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.55rem 0.9rem;
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--border-focus); }
.form-group select { cursor: pointer; }
.textarea-mono { font-family: monospace; resize: vertical; }
.font-mono { font-family: monospace; }
.required { color: var(--danger); }

.form-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
}
.form-check input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
  cursor: pointer;
}

.input-with-btn {
  display: flex;
  gap: 0.5rem;
}
.input-with-btn input { flex: 1; }

/* flex helpers */
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.w-24 { width: 90px; flex-shrink: 0; }
.w-28 { width: 110px; flex-shrink: 0; }

/* ─── Alerts ──────────────────────────────────────────────────── */
.alert {
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  border: 1px solid transparent;
}
.alert-success { background: rgba(62,207,142,0.1); border-color: rgba(62,207,142,0.3); color: var(--success); }
.alert-error   { background: rgba(224,82,82,0.1);  border-color: rgba(224,82,82,0.3);  color: var(--danger); }
.alert-info    { background: rgba(79,110,247,0.1); border-color: rgba(79,110,247,0.3); color: var(--primary); }
.error-msg { font-size: 0.83rem; color: var(--danger); text-align: center; margin-top: 0.5rem; }

/* ─── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.modal-sm { max-width: 400px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 1rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
}
.modal-close:hover { color: var(--text); background: var(--bg-card2); }
.modal-body { padding: 1.25rem 1.5rem; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* ─── Tabs ────────────────────────────────────────────────────── */
.modal-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tab-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-btn:hover:not(.active) { color: var(--text); }

.tab-panel { display: none; padding: 1.25rem 1.5rem; flex-direction: column; gap: 0.9rem; }
.tab-panel.active { display: flex; }

/* ─── Parse Preview ───────────────────────────────────────────── */
.parse-preview {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.9rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem 0.75rem;
}
.parse-preview .preview-row { display: flex; flex-direction: column; gap: 0.1rem; }
.parse-preview .preview-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }
.parse-preview .preview-value { color: var(--text); font-family: monospace; font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Toast ───────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--text);
  box-shadow: var(--shadow);
  max-width: 320px;
  pointer-events: auto;
  animation: slideIn 0.2s ease;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--primary); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes fadeOut {
  to { opacity: 0; transform: translateX(100%); }
}
.toast.removing { animation: fadeOut 0.2s ease forwards; }

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

/* ─── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .ie-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .servers-grid { grid-template-columns: 1fr; }
  .modal { max-height: 95vh; }
  .modal-tabs .tab-btn { font-size: 0.8rem; padding: 0.65rem 0.5rem; }
  .form-row { flex-direction: column; }
  .w-24, .w-28 { width: 100%; }
  .topbar-actions .badge { display: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .view { padding: 1rem; }
  .topbar { padding: 0.75rem 1rem; }
}
