/* ── Portainer-inspired design tokens ───────────────────────── */
:root {
  --bg-body:        #1a242d;
  --bg-sidebar:     #1b2a32;
  --bg-card:        #263443;
  --bg-card-hover:  #2d3d4f;
  --bg-input:       #1e2e3a;
  --bg-header:      #1f2f3c;

  --border:         #2d4050;
  --border-focus:   #4dbbee;

  --text-primary:   #d9e0e6;
  --text-secondary: #8ba1b1;
  --text-muted:     #56748a;

  --accent:         #4dbbee;
  --accent-hover:   #6ecdf5;
  --accent-dim:     rgba(77,187,238,.15);

  --success:        #23d18b;
  --warning:        #ffcc00;
  --danger:         #f44f4f;
  --info:           #4dbbee;

  --sidebar-width:  220px;
  --header-height:  54px;
  --radius:         6px;
  --radius-sm:      4px;
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: Inter, system-ui, sans-serif;
  font-size: 13px;
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo .logo-icon {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #0d1b24;
}
.sidebar-logo .logo-text {
  font-size: 14px; font-weight: 600;
  color: var(--text-primary);
  letter-spacing: .3px;
}

.sidebar-section {
  padding: 20px 0 6px;
}
.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: 0 18px 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 18px;
  color: var(--text-secondary);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all .15s;
  user-select: none;
}
.nav-item:hover {
  background: var(--accent-dim);
  color: var(--text-primary);
}
.nav-item.active {
  border-left-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}
.nav-item .nav-icon { font-size: 15px; width: 18px; text-align: center; }
.nav-item .nav-label { font-size: 13px; }

.sidebar-footer {
  margin-top: auto;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}
.status-dot.offline { background: var(--danger); }
.status-text { font-size: 11px; color: var(--text-secondary); }

/* ── Main layout ─────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-height);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.content { padding: 24px; flex: 1; }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-title {
  font-size: 13px; font-weight: 600;
  color: var(--text-primary);
  display: flex; align-items: center; gap: 8px;
}
.card-title .icon { color: var(--accent); }

/* ── Stat cards ──────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color .15s;
}
.stat-card:hover { border-color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .6px; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text-primary); line-height: 1; }
.stat-sub { font-size: 11px; color: var(--text-secondary); }
.stat-icon { font-size: 20px; color: var(--accent); margin-bottom: 4px; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-success { background: rgba(35,209,139,.15); color: var(--success); }
.badge-warning { background: rgba(255,204,0,.15); color: var(--warning); }
.badge-danger  { background: rgba(244,79,79,.15);  color: var(--danger); }
.badge-info    { background: rgba(77,187,238,.15);  color: var(--info); }
.badge-muted   { background: rgba(139,161,177,.1);  color: var(--text-secondary); }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600;
  border: none; cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #0d1b24; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(244,79,79,.3); }
.btn-danger:hover { background: rgba(244,79,79,.1); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--accent); }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn-icon { padding: 6px; }

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  transition: color .15s;
}
thead th:hover { color: var(--text-primary); }
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:hover { background: var(--bg-card-hover); }
tbody td { padding: 11px 14px; color: var(--text-primary); font-size: 13px; }
tbody tr:last-child { border-bottom: none; }

/* ── Toggle ──────────────────────────────────────────────────── */
.toggle {
  position: relative; display: inline-block;
  width: 36px; height: 20px; cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 20px;
  transition: .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: .2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Form inputs ─────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.form-input, .form-select, .form-textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: 13px;
  width: 100%;
  transition: border-color .15s;
  outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-select { appearance: none; cursor: pointer; }
.form-hint { font-size: 11px; color: var(--text-muted); }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%; max-width: 480px;
  padding: 24px;
  animation: modal-in .15s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── URL item (list) ─────────────────────────────────────────── */
.url-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.url-item:hover { background: var(--bg-card-hover); }
.url-item:last-child { border-bottom: none; }
.url-label { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.url-value {
  font-size: 11px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 340px;
}
.url-actions { margin-left: auto; display: flex; gap: 4px; flex-shrink: 0; }

/* ── Log feed ────────────────────────────────────────────────── */
.log-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.log-item:last-child { border-bottom: none; }
.log-time { color: var(--text-muted); flex-shrink: 0; font-size: 11px; margin-top: 1px; }
.log-msg { color: var(--text-secondary); line-height: 1.5; }
.log-msg strong { color: var(--text-primary); }

/* ── Section header ──────────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.section-title { font-size: 15px; font-weight: 600; }
.section-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Source tab ──────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.tab {
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600;
  cursor: pointer; color: var(--text-secondary);
  border: 1px solid transparent;
  transition: all .15s;
}
.tab:hover { color: var(--text-primary); }
.tab.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ── Settings row ────────────────────────────────────────────── */
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-info .setting-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.setting-info .setting-desc { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

/* ── Telegram status ─────────────────────────────────────────── */
.cred-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.cred-row:last-child { border-bottom: none; }
.cred-key { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.cred-val { font-size: 12px; color: var(--text-muted); font-family: monospace; }

/* ── Grid layout ─────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── Utility ─────────────────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-1 { margin-top: 4px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); font-size: 11px; }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

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

/* ── Page transitions ────────────────────────────────────────── */
.page { animation: fade-in .15s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }

/* ── Mobile bottom nav (hidden on desktop) ───────────────────── */
.mobile-nav { display: none; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }

  .main { margin-left: 0; }

  .topbar { padding: 0 14px; }
  .topbar-title { font-size: 14px; }

  .content {
    padding: 14px;
    padding-bottom: 76px; /* room for bottom nav */
  }

  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
  .stat-value { font-size: 22px; }

  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  .section-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .section-header > div:last-child { display: flex; flex-wrap: wrap; gap: 6px; }

  .modal-backdrop { align-items: flex-end; }
  .modal {
    max-width: 100%;
    margin: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 90vh;
    overflow-y: auto;
  }

  .url-value { max-width: 160px; }

  .table-wrap { font-size: 12px; }
  thead th { padding: 8px 10px; }
  tbody td { padding: 9px 10px; }

  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 62px;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    z-index: 100;
  }
  .mobile-nav-item {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 3px;
    color: var(--text-muted);
    cursor: pointer;
    transition: color .15s;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-nav-item.active { color: var(--accent); }
  .mobile-nav-item:active { opacity: .7; }
  .mobile-nav-icon { font-size: 17px; line-height: 1; }
  .mobile-nav-label { font-size: 10px; font-weight: 600; letter-spacing: .3px; }
}
