/* ============================================================
   SunectorManager — Design System
   Dark theme, Inter font, accent: electric blue #3b82f6
   ============================================================ */

:root {
  /* Colors */
  --bg-base:        #0d0f14;
  --bg-surface:     #13161d;
  --bg-elevated:    #1a1e28;
  --bg-hover:       #21263a;
  --bg-active:      #1e2540;

  --border:         #1f2535;
  --border-strong:  #2d3448;

  --text-primary:   #e8eaf0;
  --text-secondary: #8b92a8;
  --text-muted:     #4a5168;

  --accent:         #3b82f6;
  --accent-hover:   #2563eb;
  --accent-glow:    rgba(59, 130, 246, 0.15);
  --accent-glow-s:  rgba(59, 130, 246, 0.08);

  --green:          #22c55e;
  --green-bg:       rgba(34, 197, 94, 0.1);
  --yellow:         #f59e0b;
  --yellow-bg:      rgba(245, 158, 11, 0.1);
  --red:            #ef4444;
  --red-bg:         rgba(239, 68, 68, 0.1);
  --purple:         #a855f7;
  --purple-bg:      rgba(168, 85, 247, 0.1);
  --cyan:           #06b6d4;
  --cyan-bg:        rgba(6, 182, 212, 0.1);
  --orange:         #f97316;
  --orange-bg:      rgba(249, 115, 22, 0.1);

  /* Sidebar */
  --sidebar-w:      240px;
  --sidebar-w-col:  64px;

  /* Spacing */
  --gap:            20px;
  --radius:         12px;
  --radius-sm:      8px;
  --radius-xs:      6px;

  /* Transitions */
  --transition:     0.2s ease;
  --transition-sl:  0.3s ease;
}

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

html { height: 100%; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg-base);
  color: var(--text-primary);
  height: 100%;
  display: flex;
  overflow: hidden;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; outline: none; }
input, select { font-family: inherit; }

.mono { font-family: 'JetBrains Mono', monospace; font-size: 12px; }
.hidden { display: none !important; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width var(--transition-sl), min-width var(--transition-sl);
  overflow: hidden;
  z-index: 100;
  position: relative;
}

.sidebar.collapsed {
  width: var(--sidebar-w-col);
  min-width: var(--sidebar-w-col);
}

/* Header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 60px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  white-space: nowrap;
}

.logo-icon {
  font-size: 22px;
  color: var(--accent);
  flex-shrink: 0;
  line-height: 1;
}

.logo-text {
  font-size: 15px;
  color: var(--text-secondary);
  transition: opacity var(--transition);
}

.logo-text strong { color: var(--text-primary); }

.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-ext,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .server-label {
  opacity: 0;
  pointer-events: none;
}

.sidebar-toggle {
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  padding: 4px 6px;
  border-radius: var(--radius-xs);
  transition: color var(--transition), background var(--transition), transform var(--transition-sl);
  flex-shrink: 0;
  line-height: 1;
}

.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-hover); }
.sidebar.collapsed .sidebar-toggle { transform: rotate(180deg); }

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 12px 8px 4px;
  white-space: nowrap;
  transition: opacity var(--transition);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  white-space: nowrap;
  position: relative;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.nav-item.active .nav-icon { color: var(--accent); }

.nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
  transition: color var(--transition);
}

.nav-label {
  flex: 1;
  font-size: 13.5px;
  font-weight: 500;
  transition: opacity var(--transition);
}

.nav-ext {
  font-size: 11px;
  color: var(--text-muted);
  transition: opacity var(--transition);
}

/* Footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.status-dot.online  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.offline { background: var(--red); }
.status-dot.loading { background: var(--yellow); animation: pulse-dot 1s ease infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.server-label {
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  transition: opacity var(--transition);
}

/* ============================================================
   MAIN AREA
   ============================================================ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 60px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

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

.page-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

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

.topbar-time {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--text-muted);
}

/* ============================================================
   VIEWS
   ============================================================ */
.view {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
}

/* ============================================================
   CARDS GRID
   ============================================================ */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--gap);
  margin-bottom: 32px;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
  display: flex;
  flex-direction: column;
}

.card:hover {
  border-color: var(--border-strong);
}

.card-link {
  cursor: pointer;
}

.card-link:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 8px 24px rgba(0,0,0,0.3);
}

.card-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 18px 12px;
}

.card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.icon-backup   { background: var(--accent-glow);  color: var(--accent); }
.icon-n8n      { background: var(--purple-bg);     color: var(--purple); }
.icon-pynector { background: var(--orange-bg);     color: var(--orange); }
.icon-orange   { background: var(--orange-bg);     color: var(--orange); }
.icon-green    { background: var(--green-bg);      color: var(--green); }

.card-meta {
  flex: 1;
  min-width: 0;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-host {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}

.card-status-badge {
  flex-shrink: 0;
}

.card-body {
  padding: 0 18px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

.stat-value {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: right;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-footer {
  padding: 10px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
}

.card-footer-link {
  justify-content: flex-end;
}

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-ok       { background: var(--green-bg);   color: var(--green); }
.badge-error    { background: var(--red-bg);      color: var(--red); }
.badge-warning  { background: var(--yellow-bg);   color: var(--yellow); }
.badge-loading  { background: var(--bg-elevated); color: var(--text-muted); }
.badge-external { background: var(--bg-elevated); color: var(--text-muted); }
.badge-running  { background: var(--accent-glow); color: var(--accent); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 16px var(--accent-glow);
}

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

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}

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

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

.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid transparent;
}

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

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 20px; font-size: 14px; }

.btn-icon { font-size: 16px; }

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

.btn.loading .btn-icon::before {
  content: '';
  animation: spin 0.8s linear infinite;
}

/* ============================================================
   SECTIONS
   ============================================================ */
.section {
  margin-bottom: 32px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 14px;
}

/* ============================================================
   QUICK ACTIONS GRID
   ============================================================ */
.actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.action-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
  cursor: pointer;
}

.action-card:hover {
  border-color: var(--accent);
  background: var(--accent-glow-s);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.action-card:active { transform: scale(0.98); }

.action-icon {
  font-size: 22px;
  color: var(--accent);
}

.action-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.action-desc {
  font-size: 12px;
  color: var(--text-muted);
}

/* ============================================================
   BACKUP VIEW — PANELS
   ============================================================ */
.backup-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
}

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-full {
  grid-column: 1 / -1;
}

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

.panel-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.panel-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  margin-left: 10px;
}

.panel-body {
  padding: 20px;
  flex: 1;
}

.backup-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Status grid */
.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.status-item {
  background: var(--bg-elevated);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-item-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.status-item-value {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
}

/* ============================================================
   LOG CONSOLE
   ============================================================ */
.log-console {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  min-height: 180px;
  max-height: 360px;
  overflow-y: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  line-height: 1.7;
}

.log-placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.log-entry {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 2px 0;
}

.log-time {
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 80px;
}

.log-type {
  flex-shrink: 0;
  min-width: 52px;
  font-weight: 600;
}

.log-type.info    { color: var(--accent); }
.log-type.success { color: var(--green); }
.log-type.error   { color: var(--red); }
.log-type.warn    { color: var(--yellow); }

.log-msg { color: var(--text-secondary); word-break: break-word; }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  min-width: 280px;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  animation: toast-in 0.25s ease;
}

.toast.removing { animation: toast-out 0.25s ease forwards; }

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

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

.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast-body { flex: 1; }
.toast-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.toast-desc  { font-size: 12px; color: var(--text-secondary); }

.toast.success .toast-icon { color: var(--green); }
.toast.error   .toast-icon { color: var(--red); }
.toast.info    .toast-icon { color: var(--accent); }
.toast.warning .toast-icon { color: var(--yellow); }

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

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fade-in 0.2s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 32px;
  width: 380px;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  animation: modal-in 0.25s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

.modal-icon { font-size: 40px; margin-bottom: 12px; }
.modal-title { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.modal-desc  { font-size: 14px; color: var(--text-secondary); margin-bottom: 24px; }
.modal-actions { display: flex; justify-content: center; gap: 10px; }

/* ============================================================
   TOOLTIPS
   ============================================================ */
.has-tooltip {
  position: relative;
}

.tooltip-content {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  width: 260px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  transform: translateX(-50%) translateY(4px);
  z-index: 500;
  text-align: left;
  font-weight: 400;
}

.has-tooltip:hover .tooltip-content {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Arrow pointing down */
.tooltip-content::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--border-strong);
}

/* Tooltip that opens to the right (for sidebar buttons etc.) */
.tooltip-right .tooltip-content {
  bottom: auto;
  top: 50%;
  left: calc(100% + 10px);
  transform: translateY(-50%) translateX(4px);
}

.tooltip-right:hover .tooltip-content {
  transform: translateY(-50%) translateX(0);
}

.tooltip-right .tooltip-content::after {
  top: 50%;
  left: auto;
  right: 100%;
  transform: translateY(-50%);
  border-top-color: transparent;
  border-right-color: var(--border-strong);
}

/* Inner elements */
.tt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.tt-script {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.tt-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--accent-glow);
  color: var(--accent);
  letter-spacing: 0.03em;
}

.tt-badge-full {
  background: var(--purple-bg);
  color: var(--purple);
}

.tt-body {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 8px;
}

.tt-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  background: var(--bg-hover);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text-primary);
}

.tt-use {
  font-size: 11px;
  color: var(--text-muted);
  padding-top: 8px;
  border-top: 1px solid var(--border);
  line-height: 1.5;
}

.tt-use strong {
  color: var(--yellow);
}

/* ============================================================
   LOGIN OVERLAY
   ============================================================ */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
}

.login-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 40px;
  width: 340px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  animation: modal-in 0.25s ease;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 8px;
}

.login-title {
  font-size: 18px;
  color: var(--text-secondary);
}

.login-title strong { color: var(--text-primary); }

.login-subtitle {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}

.login-input:focus { border-color: var(--accent); }

.login-error {
  font-size: 12px;
  color: var(--red);
  text-align: center;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60%  { transform: translateX(-6px); }
  40%, 80%  { transform: translateX(6px); }
}

.login-box.shake { animation: shake 0.4s ease; }

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

/* ============================================================
   SPINNING ANIMATION
   ============================================================ */
@keyframes spin { to { transform: rotate(360deg); } }
.spinning { display: inline-block; animation: spin 0.8s linear infinite; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .backup-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .sidebar { width: var(--sidebar-w-col); min-width: var(--sidebar-w-col); }
  .sidebar .logo-text,
  .sidebar .nav-label,
  .sidebar .nav-ext,
  .sidebar .nav-section-label,
  .sidebar .server-label { opacity: 0; pointer-events: none; }

  .view { padding: 16px; }
  .topbar { padding: 0 16px; }
  .cards-grid { grid-template-columns: 1fr; }
}
