/* Pro UI — scoped, modern polish for the dashboard (RTL friendly) */

.dashboard-ui {
  --ui-bg: var(--background-color);
  --ui-card: var(--card-color);
  --ui-text: var(--text-color);
  --ui-muted: var(--text-secondary-color);
  --ui-border: var(--border-color);
  --ui-brand: #00a884; /* WhatsApp green */
  --ui-brand-2: #128c7e;
  --ui-accent: #1ea7d9; /* subtle cyan accent */
  --ui-danger: #e74c3c;
  --ui-warning: #f0ad4e;
  --ui-success: #22c55e;
  --ui-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}

/* Light theme readability overrides */
[data-theme="light"] .dashboard-ui .status-item .text { color: var(--text-color); }
[data-theme="light"] .dashboard-ui .connection-area h3 { color: var(--text-color); }
[data-theme="light"] .dashboard-ui #connectionTips {
  background: #e7f8f3 !important;
  border-color: #9ee7d8 !important;
  color: #064e3b;
}
[data-theme="light"] .dashboard-ui #connectionTips h5 { color: #03624a; }

/* Tabs in light mode: darker text and subtle light background */
[data-theme="light"] .dashboard-ui .tab-link {
  color: var(--text-color);
  border-color: rgba(0,0,0,.08);
  background:
    radial-gradient(120% 120% at 100% 0%, rgba(0,0,0,.03), transparent 60%),
    linear-gradient(180deg, #ffffff, #f6f9fb);
  box-shadow: 0 4px 10px rgba(0,0,0,.08);
}
[data-theme="light"] .dashboard-ui .tab-link:hover {
  color: var(--text-color);
  border-color: rgba(0,168,132,.45);
  box-shadow: 0 10px 18px rgba(0,168,132,.12), 0 2px 6px rgba(0,0,0,.10);
}
[data-theme="light"] .dashboard-ui .tab-link i { color: var(--text-color); }
[data-theme="light"] .dashboard-ui .tab-link.active { color: #fff; }

/* Light theme: tab strip contrast */
[data-theme="light"] .dashboard-ui .tabs { border-bottom: 1px solid rgba(0,0,0,.06); }
[data-theme="light"] .dashboard-ui .tabs::-webkit-scrollbar-track { background: #e9edef; }

/* Container polish */
.dashboard-ui.container {
  border: 1px solid rgba(255,255,255,.06);
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.0)) var(--ui-card);
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
}

/* Header — glossy gradient, compact layout */
.dashboard-ui .header {
  background: linear-gradient(90deg, var(--ui-brand-2) 0%, var(--ui-brand) 60%, var(--ui-accent) 120%);
  border-bottom: 1px solid rgba(255,255,255,.15);
  padding: 16px 22px;
}

.dashboard-ui .header h2 {
  font-weight: 800;
  letter-spacing: .3px;
}

.dashboard-ui .controls {
  gap: 8px;
}
.dashboard-ui .controls button {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.08);
  backdrop-filter: blur(6px);
}
.dashboard-ui .controls button:hover {
  background: rgba(255,255,255,.18);
}

/* Status bar — cards with glow and clear colors */
.dashboard-ui .status-bar {
  background: transparent;
  padding: 18px;
  gap: 12px;
}

.dashboard-ui .status-item {
  min-width: 140px;
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02));
  border: 1px solid rgba(255,255,255,.06);
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  position: relative;
  overflow: hidden;
}
.dashboard-ui .status-item::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(180deg, var(--ui-accent), transparent);
}
.dashboard-ui .status-item.online::before { background: linear-gradient(180deg, var(--ui-success), transparent); }
.dashboard-ui .status-item.offline::before { background: linear-gradient(180deg, var(--ui-danger), transparent); }

.dashboard-ui .status-item .icon { font-size: 1.3rem; }
.dashboard-ui .status-item .text { color: var(--ui-muted); }

/* Connection area card */
.dashboard-ui .connection-area {
  border: 1px dashed rgba(255,255,255,.12);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(0,168,132,0.05), rgba(255,255,255,0.02));
}
.dashboard-ui .connection-area h3 {
  color: #e7fdf6;
  font-weight: 800;
}
.dashboard-ui #connectionTips {
  background: rgba(0,168,132,0.08) !important;
  border: 1px solid rgba(0,168,132,0.25);
  color: #c9f3e8;
}
.dashboard-ui #connectionTips h5 { color: #aaf2e4; }

.dashboard-ui #qrActions .btn { width: auto; min-width: 180px; }

/* Connection buttons side-by-side (responsive) — only buttons, not tips */
.dashboard-ui #connectBtnContainer {
  display: flex !important;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  align-items: stretch;
}
.dashboard-ui #connectBtnContainer > .btn {
  flex: 1 1 320px; /* two columns on wide screens */
  max-width: 520px;
}
.dashboard-ui #connectBtnContainer > :not(.btn) {
  flex-basis: 100%; /* tips and paragraph span full width below */
}
@media (max-width: 640px) {
  .dashboard-ui #connectBtnContainer > .btn { flex-basis: 100%; }
}

/* Buttons — consistent, tactile design (scoped) */
.dashboard-ui .btn {
  border-radius: 10px;
  font-weight: 800;
  letter-spacing: .2px;
  border: 1px solid transparent;
  box-shadow: 0 6px 16px rgba(0,0,0,.25);
}
.dashboard-ui .btn:active { transform: translateY(1px); }

.dashboard-ui .btn-lg { padding: 12px 18px; font-size: 0.98rem; }
.dashboard-ui .btn-sm { padding: 8px 12px; font-size: .92rem; }

.dashboard-ui .btn-primary {
  background: linear-gradient(180deg, var(--ui-brand) 0%, var(--ui-brand-2) 100%);
  border-color: rgba(0,168,132,.5);
}
.dashboard-ui .btn-primary:hover { filter: brightness(1.05); }

.dashboard-ui .btn-warning {
  background: linear-gradient(180deg, #f6c453, var(--ui-warning));
  color: #1f2937;
  border-color: rgba(240,173,78,.5);
}
.dashboard-ui .btn-secondary {
  background: linear-gradient(180deg, #374151, #1f2937);
  color: #e5e7eb;
  border-color: rgba(255,255,255,.1);
}
.dashboard-ui .btn-danger {
  background: linear-gradient(180deg, #ff6666, var(--ui-danger));
  border-color: rgba(231,76,60,.5);
}

/* Tabs — lively, modern cards with micro-interactions */
.dashboard-ui .tabs {
  display: flex;
  gap: 14px;
  padding: 12px 16px;
  background: transparent;
  /* Always one row with smooth horizontal scrolling */
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: rgba(0,168,132,.35) transparent;
  scrollbar-width: thin;
  scroll-snap-type: x proximity;
}
.dashboard-ui .tabs::-webkit-scrollbar { height: 6px; }
.dashboard-ui .tabs::-webkit-scrollbar-track { background: transparent; }
.dashboard-ui .tabs::-webkit-scrollbar-thumb { background: rgba(0,168,132,.35); border-radius: 10px; }

.dashboard-ui .tab-link {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  padding: 12px 18px;
  border: 1px solid rgba(255,255,255,.08);
  background:
    radial-gradient(120% 120% at 100% 0%, rgba(255,255,255,.08), transparent 60%),
    linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.03));
  color: #d7efe7;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  transition: transform .25s ease, box-shadow .3s ease, border-color .2s ease, color .2s ease;
  flex: 0 0 auto;           /* prevent shrinking so row can scroll */
  white-space: nowrap;      /* keep label on one line */
  scroll-snap-align: start; /* nicer momentum scroll */
}
.dashboard-ui .tab-link i {
  font-size: 1.05rem;
  opacity: .95;
  transition: transform .25s ease, color .2s ease;
}
.dashboard-ui .tab-link::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(255,255,255,.18), rgba(255,255,255,0) 30%);
  opacity: 0;
  transition: opacity .25s ease;
  pointer-events: none;
}
.dashboard-ui .tab-link:hover {
  transform: translateY(-3px);
  color: #ecfff8;
  border-color: rgba(0,168,132,.38);
  box-shadow: 0 10px 20px rgba(0,168,132,.18), 0 2px 6px rgba(0,0,0,.25);
}
.dashboard-ui .tab-link:hover::before { opacity: .5; }
.dashboard-ui .tab-link:hover i { transform: translateY(-2px); color: #a9ffe6; }

.dashboard-ui .tab-link.active {
  background: linear-gradient(90deg, var(--ui-brand-2) 0%, var(--ui-brand) 100%);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 14px 28px rgba(0,168,132,.35), 0 3px 10px rgba(0,0,0,.25);
  animation: uiGlowPulse 2.6s ease-in-out infinite;
}
.dashboard-ui .tab-link.active i { color: #fff; }
.dashboard-ui .tab-link.active::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: -30%;
  width: 28%;
  background: linear-gradient(90deg, rgba(255,255,255,.22), rgba(255,255,255,.04));
  transform: skewX(-18deg);
  filter: blur(.5px);
  animation: uiShineSweep 4s infinite linear;
  pointer-events: none;
}

@keyframes uiGlowPulse {
  0%, 100% { box-shadow: 0 12px 24px rgba(0,168,132,.28), 0 2px 8px rgba(0,0,0,.22); }
  50% { box-shadow: 0 16px 34px rgba(0,168,132,.40), 0 4px 12px rgba(0,0,0,.28); }
}
@keyframes uiShineSweep {
  0% { transform: translateX(-140%) skewX(-18deg); }
  100% { transform: translateX(260%) skewX(-18deg); }
}

/* Forms */
.dashboard-ui .form-control {
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(255,255,255,.03);
}
.dashboard-ui .form-control:focus {
  border-color: rgba(0,168,132,.5);
  box-shadow: 0 0 0 3px rgba(0,168,132,.18);
}

/* Send options cards */
.dashboard-ui .send-option-card {
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02));
}
.dashboard-ui .send-option-card.active {
  border-color: rgba(0,168,132,.65);
  box-shadow: 0 8px 18px rgba(0,168,132,.18);
}

/* Queue and groups list tweaks */
.dashboard-ui .queue-item,
.dashboard-ui .group-item {
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.02));
}

/* Light theme — clearer cards and list items */
[data-theme="light"] .dashboard-ui .queue-item,
[data-theme="light"] .dashboard-ui .group-item,
[data-theme="light"] .dashboard-ui .send-option-card,
[data-theme="light"] .dashboard-ui .snippet-container {
  background: linear-gradient(180deg, #ffffff, #f7fafc);
  border: 1px solid rgba(0,0,0,.06);
  color: var(--text-color);
  box-shadow: 0 4px 10px rgba(0,0,0,.06);
}

/* Snippet container polish */
.dashboard-ui .snippet-container {
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.08);
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.015));
}

/* Small utilities */
.dashboard-ui .btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.dashboard-ui .muted { color: var(--ui-muted); }
.dashboard-ui .badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .72rem; }
.dashboard-ui .badge.success { background: rgba(34,197,94,.15); color: #b9f6ca; border: 1px solid rgba(34,197,94,.35); }
.dashboard-ui .badge.warn { background: rgba(240,173,78,.15); color: #ffe0b2; border: 1px solid rgba(240,173,78,.35); }

/* Toast (global, RTL aware) */
.ui-toast { position: fixed; bottom: 16px; inset-inline-end: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.ui-toast-msg {
  pointer-events: auto;
  padding: 10px 14px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(0,0,0,.85), rgba(0,0,0,.75));
  color: #eafaf3;
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 8px 18px rgba(0,0,0,.35);
  transform: translateY(10px);
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
}
.ui-toast-msg.show { opacity: 1; transform: translateY(0); }
.ui-toast-msg.success { border-color: rgba(34,197,94,.45); }
.ui-toast-msg.error { border-color: rgba(231,76,60,.55); }

/* API Subtabs */
.dashboard-ui .api-subtabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0 18px;
  /* make it scrollable when content overflows */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: rgba(0,168,132,.35) transparent;
  scrollbar-width: thin;
  padding-bottom: 4px; /* room for scrollbar */
}
.dashboard-ui .api-subtabs::-webkit-scrollbar { height: 6px; }
.dashboard-ui .api-subtabs::-webkit-scrollbar-track { background: transparent; }
.dashboard-ui .api-subtabs::-webkit-scrollbar-thumb { background: rgba(0,168,132,.35); border-radius: 10px; }
.dashboard-ui .api-subtab-link {
  border-radius: 12px;
  padding: 10px 14px;
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.03));
  border: 1px solid rgba(255,255,255,.08);
  color: #d8efe7;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  transition: transform .2s ease, box-shadow .25s ease, color .2s ease, border-color .2s ease;
  flex: 0 0 auto; /* prevent shrinking so row can scroll */
  scroll-snap-align: start;
}
.dashboard-ui .api-subtab-link:hover { transform: translateY(-2px); border-color: rgba(0,168,132,.35); color: #ecfff8; }
.dashboard-ui .api-subtab-link.active {
  background: linear-gradient(90deg, var(--ui-brand-2), var(--ui-brand));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 10px 18px rgba(0,168,132,.28);
}
.dashboard-ui .api-subtab-content { display: none; }
.dashboard-ui .api-subtab-content.active { display: block; }

/* On small screens, force single row with horizontal scroll */
@media (max-width: 680px) {
  .dashboard-ui .api-subtabs {
    flex-wrap: nowrap;
    scroll-snap-type: x proximity;
  }
}

/* Light theme for subtabs */
[data-theme="light"] .dashboard-ui .api-subtab-link {
  color: var(--text-color);
  background: linear-gradient(180deg, #fff, #f6f9fb);
  border-color: rgba(0,0,0,.08);
}
[data-theme="light"] .dashboard-ui .api-subtab-link:hover { color: var(--text-color); box-shadow: 0 6px 12px rgba(0,168,132,.12), 0 2px 6px rgba(0,0,0,.06); }
/* Active state — stronger contrast in Light */
[data-theme="light"] .dashboard-ui .api-subtab-link.active {
  background: linear-gradient(90deg, var(--ui-brand-2), var(--ui-brand));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px rgba(0,168,132,.22), 0 2px 8px rgba(0,0,0,.08);
}

/* MikroTik nested tabs */
.dashboard-ui .mikrotik-subtabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 10px 0 14px;
  /* enable horizontal scroll when content overflows */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: rgba(0,168,132,.35) transparent;
  scrollbar-width: thin;
  padding-bottom: 4px;
}
.dashboard-ui .mikrotik-subtabs::-webkit-scrollbar { height: 6px; }
.dashboard-ui .mikrotik-subtabs::-webkit-scrollbar-track { background: transparent; }
.dashboard-ui .mikrotik-subtabs::-webkit-scrollbar-thumb { background: rgba(0,168,132,.35); border-radius: 10px; }
.dashboard-ui .mikrotik-subtab-link {
  border-radius: 10px; padding: 8px 12px; cursor: pointer;
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.03));
  border: 1px solid rgba(255,255,255,.08); color: #d8efe7;
  box-shadow: 0 2px 6px rgba(0,0,0,.12); transition: all .2s ease;
  flex: 0 0 auto; /* prevent shrinking so row can scroll */
  scroll-snap-align: start;
}
.dashboard-ui .mikrotik-subtab-link:hover { transform: translateY(-1px); border-color: rgba(0,168,132,.35); color: #ecfff8; }
.dashboard-ui .mikrotik-subtab-link.active { background: linear-gradient(90deg, var(--ui-brand-2), var(--ui-brand)); color: #fff; border-color: transparent; }
.dashboard-ui .mt-subtab-content { display: none; }
.dashboard-ui .mt-subtab-content.active { display: block; }
[data-theme="light"] .dashboard-ui .mikrotik-subtab-link { color: var(--text-color); background: linear-gradient(180deg, #fff, #f6f9fb); border-color: rgba(0,0,0,.06); }
[data-theme="light"] .dashboard-ui .mikrotik-subtab-link.active { background: linear-gradient(90deg, var(--ui-brand-2), var(--ui-brand)); color: #fff; border-color: transparent; box-shadow: 0 8px 18px rgba(0,168,132,.22), 0 2px 8px rgba(0,0,0,.08); }

/* --- AI Memory section --- */
.dashboard-ui .ai-memory { display: flex; flex-direction: column; gap: 12px; }
.dashboard-ui .ai-memory .memory-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.dashboard-ui .ai-memory .memory-card {
  border: 1px solid rgba(255,255,255,.08);
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02));
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.dashboard-ui .ai-memory .memory-switch { display: flex; flex-direction: column; gap: 6px; }
.dashboard-ui .ai-memory .memory-label { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.dashboard-ui .ai-memory .memory-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.dashboard-ui .ai-memory .memory-toolbar .title h4 { margin: 0; }
.dashboard-ui .ai-memory .memory-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.dashboard-ui .ai-memory .memory-actions input { flex: 1 1 260px; }
.dashboard-ui .ai-memory .memory-contacts-list { max-height: 180px; overflow: auto; margin-top: 8px; border-radius: 8px; border: 1px solid rgba(255,255,255,.06); }
.dashboard-ui .ai-memory .memory-contacts-list .list-item { padding: 8px 10px; border-bottom: 1px solid rgba(255,255,255,.06); cursor: pointer; }
.dashboard-ui .ai-memory .memory-contacts-list .list-item:hover { background: rgba(255,255,255,.04); }
.dashboard-ui .ai-memory .memory-viewer { background:#111; color:#ddd; padding:10px; border-radius:8px; max-height:220px; overflow:auto; }

.dashboard-ui .ai-memory .memory-health { display:flex; flex-direction:column; gap:8px; }
.dashboard-ui .ai-memory .memory-health-row { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.dashboard-ui .ai-memory .memory-health-title { font-weight:700; display:inline-flex; align-items:center; gap:6px; }
.dashboard-ui .ai-memory .memory-health-status { font-size:.92rem; color: var(--ui-muted); }

@media (max-width: 980px) {
  .dashboard-ui .ai-memory .memory-grid { grid-template-columns: 1fr; }
}

[data-theme="light"] .dashboard-ui .ai-memory .memory-card { background: linear-gradient(180deg, #fff, #f6f9fb); border-color: rgba(0,0,0,.06); }
[data-theme="light"] .dashboard-ui .ai-memory .memory-contacts-list { border-color: rgba(0,0,0,.08); }

/* On small screens, force single row with horizontal scroll */
@media (max-width: 680px) {
  .dashboard-ui .mikrotik-subtabs {
    flex-wrap: nowrap;
    scroll-snap-type: x proximity;
  }
}
