/* BenMikrotikIran - Dark Theme */
:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d28;
  --bg-card: #1e2132;
  --bg-hover: #252940;
  --bg-input: #151825;
  --border: #2a2e3f;
  --text-primary: #e4e6ef;
  --text-secondary: #8b8fa3;
  --text-muted: #555972;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --orange: #f97316;
  --cyan: #06b6d4;
  --purple: #a855f7;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

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

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

.sidebar {
  width: 220px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s;
}

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

.sidebar-header h1 {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
}

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

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }

.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  font-weight: 600;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

.main {
  flex: 1;
  margin-left: 220px;
  padding: 24px;
  min-height: 100vh;
  min-width: 0;
  overflow-x: hidden;
}

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

.page-header h2 { font-size: 22px; font-weight: 600; }

/* --- Cards --- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  transition: transform 0.15s, box-shadow 0.15s;
}

.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.stat-card .label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

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

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

.stat-card.green .value { color: var(--green); }
.stat-card.blue .value { color: var(--accent); }
.stat-card.cyan .value { color: var(--cyan); }
.stat-card.orange .value { color: var(--orange); }
.stat-card.red .value { color: var(--red); }
.stat-card.purple .value { color: var(--purple); }

/* --- Tables --- */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 24px;
}

.table-toolbar {
  display: flex;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  align-items: center;
}

.search-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  min-width: 200px;
}

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

.filter-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-btn:hover, .filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th:hover { color: var(--text-secondary); }
th .sort-indicator { margin-left: 4px; font-size: 10px; opacity: 0.7; }
th.sorted { color: var(--accent); }
th.sorted .sort-indicator { opacity: 1; }

td {
  padding: 10px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-hover); }

/* --- Status Indicators --- */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.offline { background: var(--text-muted); }
.status-dot.slow { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.status-dot.down { background: var(--red); box-shadow: 0 0 6px var(--red); }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-warning { background: var(--orange); color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm { padding: 4px 8px; font-size: 11px; }
.btn-icon { padding: 6px; width: 30px; height: 30px; justify-content: center; }

/* --- Usage Bar --- */
.usage-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}

.usage-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.usage-bar-fill.ok { background: var(--green); }
.usage-bar-fill.warn { background: var(--yellow); }
.usage-bar-fill.danger { background: var(--red); }

/* --- Sparkline window buttons --- */
.spark-win-btn{background:rgba(255,255,255,.06);border:1px solid var(--border);color:var(--text-muted);font-size:11px;padding:3px 10px;border-radius:6px;cursor:pointer;transition:all .15s}
.spark-win-btn:hover{background:rgba(255,255,255,.1);color:var(--text-primary)}
.spark-win-btn.active{background:var(--accent);color:#fff;border-color:var(--accent);font-weight:600}

/* --- Modal / Panel --- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  justify-content: center;
  align-items: flex-start;
  padding-top: 60px;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 560px;
  max-width: 95vw;
  max-height: 80vh;
  overflow-y: auto;
}

.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; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

.modal-body { padding: 20px 24px; }

.modal-section {
  margin-bottom: 20px;
}

.modal-section h4 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

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

.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--text-secondary); }
.detail-value { color: var(--text-primary); font-weight: 500; }

.alert-item {
  padding: 10px 12px;
  background: var(--bg-input);
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  border-left: 3px solid var(--yellow);
}

.alert-item.dual-device { border-left-color: var(--orange); }
.alert-item.blocked-content { border-left-color: var(--red); }
.alert-item.recharged { border-left-color: var(--green); }
.alert-item.over-limit { border-left-color: var(--red); }
.alert-item.nordvpn-down { border-left-color: var(--orange); }
.alert-item.nordvpn-rotation { border-left-color: var(--cyan); }
.alert-item.backup { border-left-color: var(--green); }
.alert-item.high-cpu { border-left-color: var(--red); }
.alert-time { color: var(--text-muted); font-size: 11px; }

textarea.notes-input {
  width: 100%;
  min-height: 80px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  color: var(--text-primary);
  font-size: 13px;
  resize: vertical;
  outline: none;
}

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

/* --- Login --- */
.login-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: var(--bg-primary);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 380px;
  text-align: center;
}

.login-card h1 {
  font-size: 20px;
  color: var(--accent);
  margin-bottom: 8px;
}

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

.form-group {
  margin-bottom: 16px;
  text-align: left;
}

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

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

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

.login-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}

.login-btn:hover { background: var(--accent-hover); }

.login-error {
  color: var(--red);
  font-size: 13px;
  margin-bottom: 12px;
}

/* --- Tags --- */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.tag-vless { background: rgba(168,85,247,0.2); color: #c084fc; border: 1px solid rgba(168,85,247,0.3); }
.tag-wg { background: rgba(136,25,29,0.25); color: #f87171; border: 1px solid rgba(136,25,29,0.4); }
.tag-online { background: rgba(34,197,94,0.2); color: var(--green); }
.tag-offline { background: rgba(85,89,114,0.2); color: var(--text-muted); }
.tag-isp-zitel1 { background: rgba(59,130,246,0.2); color: #60a5fa; border: 1px solid rgba(59,130,246,0.3); }
.tag-isp-shatel2 { background: rgba(249,115,22,0.2); color: #fb923c; border: 1px solid rgba(249,115,22,0.3); }
.tag-isp-zitel2 { background: rgba(59,130,246,0.15); color: #93c5fd; border: 1px solid rgba(59,130,246,0.2); }

/* Group tags */
.tag-group {
  background: rgba(6,182,212,0.15);
  color: var(--cyan);
  border: 1px solid rgba(6,182,212,0.3);
  font-size: 10px;
  padding: 1px 6px;
}

/* Color-coded user tags */
.user-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  margin-right: 3px;
}
.user-tag.red { background: rgba(239,68,68,0.2); color: #f87171; }
.user-tag.blue { background: rgba(59,130,246,0.2); color: #60a5fa; }
.user-tag.green { background: rgba(34,197,94,0.2); color: #4ade80; }
.user-tag.yellow { background: rgba(234,179,8,0.2); color: #fde047; }
.user-tag.purple { background: rgba(168,85,247,0.2); color: #c084fc; }
.user-tag.cyan { background: rgba(6,182,212,0.2); color: #22d3ee; }
.user-tag.orange { background: rgba(249,115,22,0.2); color: #fb923c; }

/* --- Toggle Switch --- */
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--text-muted);
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle.on { background: var(--green); }

.toggle::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
}

.toggle.on::after { transform: translateX(18px); }

/* --- Loading Skeleton --- */
@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: 200px 0; }
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-hover) 50%, var(--bg-card) 75%);
  background-size: 400px 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}

.skeleton-card {
  height: 100px;
  border-radius: 12px;
}

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  width: 60%;
}

.skeleton-text.short { width: 40%; }
.skeleton-text.long { width: 80%; }

.skeleton-row {
  height: 48px;
  margin-bottom: 4px;
}

/* --- Toast Notifications --- */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  pointer-events: auto;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  max-width: 360px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.info { background: var(--accent); }
.toast.warning { background: var(--orange); }

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

@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(100px); }
}

/* --- Sparkline --- */
.sparkline-container {
  display: inline-block;
  width: 80px;
  height: 24px;
  vertical-align: middle;
}

.sparkline-container canvas {
  width: 100%;
  height: 100%;
}

/* --- Health indicators --- */
.health-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.health-dot.healthy { background: var(--green); box-shadow: 0 0 6px var(--green); }
.health-dot.slow { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.health-dot.down { background: var(--red); box-shadow: 0 0 6px var(--red); }

/* --- Chart container --- */
.chart-container {
  position: relative;
  height: 300px;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 16px;
}

/* --- Offline banner --- */
.offline-banner {
  display: none;
  background: var(--orange);
  color: #fff;
  text-align: center;
  padding: 8px;
  font-size: 12px;
  font-weight: 600;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 250;
}

.offline-banner.show { display: block; }

/* --- Responsive --- */
.menu-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 150;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 18px;
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; padding: 12px; padding-top: 56px; padding-bottom: env(safe-area-inset-bottom, 16px); max-width: 100vw; overflow-x: hidden; }
  .menu-toggle { display: block; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 14px; }
  .stat-card .value { font-size: 22px; }
  .stat-card .label { font-size: 10px; }
  .table-toolbar { flex-direction: column; gap: 8px; align-items: stretch; }
  .table-toolbar > .search-input { width: 100%; min-width: unset; }
  .filter-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
  .filter-btn { padding: 6px 10px; font-size: 11px; }
  .filter-sep { display: none; }
  .modal { width: 95vw; max-height: 90vh; }
  .modal-overlay { padding-top: 20px; }
  table th, table td { padding: 8px 8px; font-size: 11px; }
  .desktop-only { display: none !important; }
  .mobile-only { display: block !important; }
  .btn { padding: 8px 12px; font-size: 12px; min-height: 36px; }
  .btn-sm { padding: 6px 10px; min-height: 32px; }
  .page-header h2 { font-size: 18px; }
  .nav-item { padding: 12px 12px; font-size: 14px; }
  .login-card { padding: 28px 20px; width: 90vw; }
  .form-input { padding: 12px 14px; font-size: 16px; }
  .login-btn { padding: 14px; font-size: 16px; }
  [style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }
  #toast-container { top: auto; bottom: 60px; right: 12px; left: 12px; }
  .toast { max-width: 100%; }
  .chart-container { height: 200px; }

  /* --- Page header mobile --- */
  .page-header { flex-wrap: wrap; gap: 10px; }
  .page-header > div { width: 100%; }

  /* --- Users page usage bar fix --- */
  .usage-bar { min-width: 60px; height: 6px; }
}

/* iPhone notch / safe area */
@supports (padding: env(safe-area-inset-top)) {
  .menu-toggle { top: calc(env(safe-area-inset-top, 0px) + 12px); }
  .main { padding-top: calc(env(safe-area-inset-top, 0px) + 56px); }
  .sidebar { padding-top: env(safe-area-inset-top, 0px); }
}

html { -webkit-text-size-adjust: 100%; overflow-x: hidden; max-width: 100vw; }

/* --- Desktop/Mobile visibility --- */
.mobile-only { display: none; }
.desktop-only { display: block; }

/* --- User Cards (mobile) --- */
.user-card {
  margin: 10px 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.user-card:active { background: var(--bg-hover); }
.user-card:first-child { margin-top: 12px; }
.user-card:last-child { margin-bottom: 12px; }
.uc-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}
.uc-top > .status-dot { margin-top: 6px; flex-shrink: 0; }
.uc-name { flex: 1; min-width: 0; }
.uc-name-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 700;
  padding: 2px 0;
  width: 100%;
  outline: none;
}
.uc-email {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  border-top: 1px solid var(--border);
  padding-top: 2px;
}
.uc-tags { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.uc-mid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 16px;
  margin: 8px 0;
  padding-left: 18px;
}
.uc-stat { display: flex; justify-content: space-between; font-size: 12px; }
.uc-label { color: var(--text-muted); }
.uc-stat span:last-child { color: var(--text-primary); font-weight: 500; }
.uc-bottom {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  padding-left: 18px;
  flex-wrap: wrap;
}
#user-cards { padding: 4px 0; background: var(--bg-primary); }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- QR Modal --- */
.qr-img { max-width: 280px; margin: 20px auto; display: block; }

/* --- Config Box --- */
.config-box {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--cyan);
  max-height: 200px;
  overflow-y: auto;
}

/* --- Select input --- */
select.form-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b8fa3' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
