/* ══════════════════════════════════════════════════════════
   VPS Container Dashboard — Styles
   Dark professional theme, optimized for readability
   ══════════════════════════════════════════════════════════ */

/* ── Reset & Variables ────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* Colors */
  --bg-primary: #0f1117;
  --bg-secondary: #161822;
  --bg-card: #1c1e2e;
  --bg-card-hover: #222438;
  --bg-input: #12131e;
  --bg-modal: #1a1c2b;

  --border: #2a2d3e;
  --border-focus: #6366f1;

  --text-primary: #e4e5ea;
  --text-secondary: #8b8ea0;
  --text-muted: #5c5f73;

  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.15);

  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --info: #3b82f6;
  --building: #a78bfa;
  --building-bg: rgba(167, 139, 250, 0.1);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Spacing */
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Transitions */
  --transition: 150ms ease;
  --transition-slow: 300ms ease;
}

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

/* ── Login Screen ─────────────────────────────────────── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 0%, rgba(99, 102, 241, 0.08) 0%, transparent 60%),
              var(--bg-primary);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  animation: fadeUp 0.4s ease;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo svg {
  margin-bottom: 16px;
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.login-logo p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
}

/* ── Topbar ───────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.system-indicators {
  display: flex;
  gap: 16px;
  margin-right: 8px;
}

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

.indicator-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition);
}

.indicator.connected .indicator-dot { background: var(--success); box-shadow: 0 0 6px rgba(34, 197, 94, 0.4); }
.indicator.disconnected .indicator-dot { background: var(--danger); }

/* ── Main Content ─────────────────────────────────────── */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

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

.action-bar-left h2 {
  font-size: 20px;
  font-weight: 600;
}

.action-bar-right {
  display: flex;
  gap: 8px;
}

.badge {
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
}

/* ── App Cards Grid ───────────────────────────────────── */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.app-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.app-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(99, 102, 241, 0.3);
  transform: translateY(-1px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
}

.app-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.app-card-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.app-card-repo {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  word-break: break-all;
}

.app-card-meta {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

.app-card-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.app-card-stats {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.app-card-actions {
  display: flex;
  gap: 6px;
  margin-top: 14px;
}

/* ── Status Badges ────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 10px;
  border-radius: 99px;
}

.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-running { background: var(--success-bg); color: var(--success); }
.status-running::before { background: var(--success); box-shadow: 0 0 6px rgba(34, 197, 94, 0.5); }

.status-stopped { background: var(--danger-bg); color: var(--danger); }
.status-stopped::before { background: var(--danger); }

.status-building, .status-cloning, .status-starting {
  background: var(--building-bg); color: var(--building);
}
.status-building::before, .status-cloning::before, .status-starting::before {
  background: var(--building);
  animation: pulse 1.5s infinite;
}

.status-error { background: var(--danger-bg); color: var(--danger); }
.status-error::before { background: var(--danger); }

.status-pending { background: var(--warning-bg); color: var(--warning); }
.status-pending::before { background: var(--warning); }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-card); color: var(--text-primary); border-color: var(--text-muted); }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: #dc2626; }

.btn-success {
  background: var(--success);
  color: white;
}

.btn-warning {
  background: var(--warning);
  color: #000;
}

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 11px; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 4px; }
.btn-icon:hover { color: var(--danger); }
.btn-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 24px; line-height: 1; padding: 0 4px; }
.btn-close:hover { color: var(--text-primary); }

/* ── Form Elements ────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
  flex: 1;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group small {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="number"],
.form-group input[type="password"],
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  transition: border-color var(--transition);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-row {
  display: flex;
  gap: 12px;
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

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

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

/* ── Env Vars Editor ──────────────────────────────────── */
.env-editor {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.env-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.env-row input {
  flex: 1;
  padding: 7px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
}

.env-row input:focus {
  outline: none;
  border-color: var(--border-focus);
}

.btn-remove-env {
  font-size: 18px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Modal ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  animation: fadeUp 0.2s ease;
}

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

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ── Drawer (App Detail Panel) ────────────────────────── */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  justify-content: flex-end;
  animation: fadeIn 0.15s ease;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.drawer-panel {
  position: relative;
  width: 520px;
  max-width: 90vw;
  background: var(--bg-modal);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  animation: slideIn 0.2s ease;
  overflow-y: auto;
}

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

.drawer-header h3 {
  font-size: 18px;
  font-weight: 600;
}

.drawer-tabs {
  display: flex;
  overflow-x: auto;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  gap: 0;
}

.tab {
  padding: 12px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}

.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Overview Tab ─────────────────────────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.info-item {
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 12px;
}

.info-item .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.info-item .value {
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-mono);
  word-break: break-all;
}

.control-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ── Log Viewer ───────────────────────────────────────── */
.logs-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.log-viewer {
  background: #0a0b10;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.7;
  color: #c8ccd4;
  min-height: 300px;
  max-height: 60vh;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── History Tab ──────────────────────────────────────── */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-input);
  border-radius: var(--radius);
  font-size: 13px;
}

.history-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.history-dot.success { background: var(--success); }
.history-dot.error { background: var(--danger); }

.history-action {
  font-weight: 500;
  min-width: 60px;
}

.history-message {
  flex: 1;
  color: var(--text-secondary);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-time {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
}

/* ── Proxy Tab ────────────────────────────────────────── */
.proxy-info-card {
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 16px;
}

.proxy-info-card .info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.proxy-info-card .info-row:last-child { border-bottom: none; }
.proxy-info-card .info-label { color: var(--text-secondary); }
.proxy-info-card .info-value { font-family: var(--font-mono); font-weight: 500; }

/* ── Webhook Info ─────────────────────────────────────── */
.webhook-info {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 20px;
  margin-bottom: 20px;
}

.webhook-info h4 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.webhook-field {
  margin-bottom: 10px;
}

.webhook-field label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.webhook-field code {
  display: block;
  margin-top: 4px;
  padding: 8px 10px;
  background: var(--bg-primary);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  word-break: break-all;
  cursor: pointer;
}

.webhook-field code:hover { background: #0d0e16; }

/* ── Settings Tab ─────────────────────────────────────── */
.danger-zone {
  margin-top: 24px;
  padding: 16px;
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius);
  background: var(--danger-bg);
}

.danger-zone h4 {
  color: var(--danger);
  font-size: 14px;
  margin-bottom: 8px;
}

.danger-zone p {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.panel-actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
}

/* ── Empty State ──────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--text-muted);
  text-align: center;
}

.empty-state h3 {
  margin-top: 16px;
  font-size: 18px;
  color: var(--text-secondary);
}

.empty-state p {
  margin-top: 8px;
  font-size: 14px;
}

/* ── Toast Notifications ──────────────────────────────── */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  min-width: 280px;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  animation: slideDown 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(--info); }
.toast.warning { border-left: 3px solid var(--warning); }

.toast-exit { animation: fadeOut 0.2s ease forwards; }

/* ── Loading Spinner ──────────────────────────────────── */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.btn .spinner {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

/* ── Animations ───────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Hidden override (CSS display beats [hidden] attr) ── */
[hidden] {
  display: none !important;
}

/* ── Scrollbar ────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 640px) {
  .apps-grid { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }
  .topbar { padding: 10px 16px; }
  .main { padding: 16px; }
  .system-indicators { display: none; }
  .drawer-panel { width: 100%; max-width: 100vw; }
  .info-grid { grid-template-columns: 1fr; }
}
