:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-hover: #22263a;
  --border: #2a2e3f;
  --text: #e4e4e7;
  --text-muted: #71717a;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-dim: rgba(99,102,241,0.15);
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --radius: 10px;
  --sidebar-w: 240px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ========================================
   Layout
   ======================================== */
.app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease;
}

.sidebar-header {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
}

.sidebar-header .subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.nav-links {
  list-style: none;
  padding: 8px 0;
  flex: 1;
}

.nav-links a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.15s;
}

.nav-links a:hover,
.nav-links a.active {
  background: var(--bg-card-hover);
  color: var(--text);
}

.nav-links a.active {
  border-left: 3px solid var(--primary);
}

.nav-links .nav-icon {
  width: 18px;
  text-align: center;
  font-size: 15px;
  flex-shrink: 0;
}

.nav-links .nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.nav-section {
  padding: 12px 20px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sidebar-bottom {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.account-selector {
  padding: 12px 20px;
}

.account-selector select {
  width: 100%;
  padding: 8px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

/* Main content */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 24px 32px;
  max-width: 1200px;
  width: 100%;
}

/* Mobile top bar */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  z-index: 150;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}

.mobile-header h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  flex: 1;
}

.hamburger {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}

.hamburger:active {
  background: var(--bg-card-hover);
}

/* Overlay for mobile menu */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 190;
}

/* ========================================
   Cards
   ======================================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

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

/* ========================================
   Status Grid
   ======================================== */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

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

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

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ========================================
   Badges
   ======================================== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-info { background: rgba(59,130,246,0.15); color: var(--info); }
.badge-primary { background: var(--primary-dim); color: var(--primary-hover); }
.badge-muted { background: rgba(113,113,122,0.15); color: var(--text-muted); }

/* ========================================
   Buttons
   ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { opacity: 0.85; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.85; }
.btn-warning { background: var(--warning); color: #000; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg-card-hover); color: var(--text); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
  font-size: 16px;
}

/* ========================================
   Logs
   ======================================== */
.log-container {
  background: #0a0c10;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  max-height: 600px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  line-height: 1.6;
  -webkit-overflow-scrolling: touch;
}

.log-line {
  padding: 2px 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-line.error { color: var(--danger); }
.log-line.warn { color: var(--warning); }
.log-line.info { color: var(--text); }
.log-line.debug { color: var(--text-muted); }

.log-time { color: var(--text-muted); }
.log-msg { color: var(--text); }
.log-data { color: #a78bfa; }

/* ========================================
   Tables
   ======================================== */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
}

.data-table tr:hover td {
  background: var(--bg-card-hover);
}

.tweet-content {
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
   Filters
   ======================================== */
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.filter-btn:hover,
.filter-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ========================================
   Charts
   ======================================== */
.chart-container {
  width: 100%;
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ========================================
   Toast
   ======================================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 1000;
  animation: toastIn 0.3s ease;
  max-width: 90vw;
  text-align: center;
}

.toast-success { background: var(--success); color: white; }
.toast-error { background: var(--danger); color: white; }

@keyframes toastIn {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ========================================
   Login
   ======================================== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  padding: 16px;
}

.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
}

.login-box h1 {
  font-size: 22px;
  margin-bottom: 8px;
  color: var(--primary);
}

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

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
}

.login-btn { width: 100%; padding: 10px; margin-top: 8px; }
.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 12px;
  display: none;
}

/* ========================================
   Action bar
   ======================================== */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
}

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

/* ========================================
   Process info bar
   ======================================== */
.process-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow-x: auto;
}

.process-bar .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.process-bar .dot.online { background: var(--success); box-shadow: 0 0 8px var(--success); }
.process-bar .dot.stopped { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.process-bar .dot.unknown { background: var(--warning); }

.process-info {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.process-info span {
  color: var(--text);
  font-weight: 600;
}

/* ========================================
   Mode Switch
   ======================================== */
.mode-switch {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.mode-switch button {
  flex: 1;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.mode-switch button.active {
  background: var(--primary);
  color: white;
}

/* ========================================
   Proposal Cards
   ======================================== */
.proposal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  transition: border-color 0.15s;
}

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

.proposal-card.pending {
  border-left: 3px solid var(--warning);
}

.proposal-card.approved {
  border-left: 3px solid var(--success);
}

.proposal-card.rejected {
  border-left: 3px solid var(--danger);
  opacity: 0.6;
}

.proposal-card.posted {
  border-left: 3px solid var(--info);
}

.proposal-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.proposal-content {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}

.proposal-content textarea {
  width: 100%;
  min-height: 80px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.6;
  resize: vertical;
}

.proposal-content textarea:focus {
  border-color: var(--primary);
  outline: none;
}

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

.char-count {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

.char-count.over { color: var(--danger); font-weight: 600; }

/* ========================================
   Spinner
   ======================================== */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ========================================
   Empty state
   ======================================== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 13px;
  max-width: 300px;
  margin: 0 auto;
}

/* ========================================
   Notification banner
   ======================================== */
.push-banner {
  background: var(--primary-dim);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}

.push-banner .push-text { flex: 1; }

/* ========================================
   Tab bar (for settings etc)
   ======================================== */
.tab-bar {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-bar button {
  padding: 10px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

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

/* ========================================
   Bottom fixed bar (mobile-friendly)
   ======================================== */
.sticky-bar {
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 100;
}

/* ========================================
   Responsive: Tablet
   ======================================== */
@media (max-width: 1024px) {
  .main { padding: 20px; }
  .tweet-content { max-width: 250px; }
}

/* ========================================
   Responsive: Mobile
   ======================================== */
@media (max-width: 768px) {
  .mobile-header { display: flex; }

  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .main {
    margin-left: 0;
    padding: 72px 16px 16px;
    max-width: 100%;
  }

  .page-title { font-size: 18px; }

  .status-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .stat-card { padding: 12px; }
  .stat-value { font-size: 22px; }

  .process-bar {
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 12px;
  }

  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 6px; }
  .tweet-content { max-width: 180px; font-size: 12px; }

  .card { padding: 14px; }

  .action-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .action-bar .actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .log-container { font-size: 11px; padding: 10px; }

  .proposal-card { padding: 12px; }

  .filters { gap: 4px; }
  .filter-btn { padding: 6px 10px; font-size: 11px; }

  /* Analytics responsive */
  .analytics-grid-2 {
    grid-template-columns: 1fr !important;
  }

  .sticky-bar {
    padding: 10px 16px;
  }

  .toast {
    bottom: 16px;
    left: 16px;
    right: 16px;
    transform: none;
    max-width: none;
  }

  @keyframes toastIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }
}

/* ========================================
   Responsive: Small phones
   ======================================== */
@media (max-width: 380px) {
  .status-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 20px; }
  .btn { padding: 8px 12px; font-size: 12px; }
}

/* ========================================
   Pull-to-refresh indicator
   ======================================== */
.refresh-indicator {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%) translateY(-40px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 12px;
  color: var(--text-muted);
  z-index: 100;
  transition: transform 0.2s;
  display: none;
}

.refresh-indicator.visible {
  display: block;
  transform: translateX(-50%) translateY(8px);
}

/* ========================================
   Utils
   ======================================== */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }
