/* ── Variables ──────────────────────────────────────────────────── */
:root {
  --bg:       #0a0b0e;
  --bg2:      #0f1117;
  --bg3:      #161820;
  --border:   #1e2130;
  --border2:  #252840;
  --text:     #e8eaf0;
  --text2:    #8891aa;
  --text3:    #545c75;
  --accent:   #4f6ef7;
  --accent2:  #3a56e0;
  --accent-g: linear-gradient(135deg, #4f6ef7 0%, #7c3aed 100%);
  --green:    #22c55e;
  --yellow:   #f59e0b;
  --red:      #ef4444;
  --cyan:     #06b6d4;
  --radius:   10px;
  --sidebar:  240px;
  --shadow:   0 4px 24px rgba(0,0,0,.45);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}
input, textarea, select, button { font-family: inherit; font-size: inherit; }
a { text-decoration: none; color: inherit; }
.hidden { display: none !important; }

/* ── Scrollbar ──────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ── Auth Screen ────────────────────────────────────────────────── */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.auth-bg {
  position: absolute; inset: 0; z-index: 0;
  background: radial-gradient(ellipse 80% 60% at 50% -10%, rgba(79,110,247,.18) 0%, transparent 70%);
}
.grid-lines {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(79,110,247,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79,110,247,.05) 1px, transparent 1px);
  background-size: 48px 48px;
}
.auth-container {
  position: relative; z-index: 1;
  width: 100%; max-width: 420px;
  padding: 24px;
}
.auth-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 32px; justify-content: center;
}
.logo-icon { font-size: 28px; color: var(--accent); }
.logo-text { font-size: 20px; font-weight: 300; letter-spacing: .5px; }
.logo-text strong { font-weight: 700; color: var(--accent); }
.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.auth-tabs {
  display: flex; gap: 4px; margin-bottom: 28px;
  background: var(--bg3); border-radius: 8px; padding: 4px;
}
.auth-tab {
  flex: 1; padding: 9px; border: none; background: transparent;
  color: var(--text2); border-radius: 6px; cursor: pointer;
  transition: all .2s; font-weight: 500;
}
.auth-tab.active { background: var(--accent); color: #fff; }
.auth-form { display: flex; flex-direction: column; gap: 18px; }

/* ── Form Elements ──────────────────────────────────────────────── */
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group label { font-size: .8rem; color: var(--text2); font-weight: 500; letter-spacing: .5px; text-transform: uppercase; }
.field-group small { font-size: .75rem; color: var(--text3); }
.field-group input,
.field-group select,
.field-group textarea {
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--radius); color: var(--text);
  padding: 11px 14px; outline: none;
  transition: border-color .2s;
}
.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus { border-color: var(--accent); }
select { appearance: none; cursor: pointer; }
select option { background: var(--bg3); }
textarea { resize: vertical; min-height: 80px; }
.form-error {
  color: var(--red); font-size: .82rem;
  background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.25);
  border-radius: 6px; padding: 9px 12px;
}

/* ── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 20px; border-radius: var(--radius); font-weight: 500;
  cursor: pointer; border: none; transition: all .18s; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost {
  background: transparent; color: var(--text2);
  border: 1px solid var(--border2);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--red); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-sm { padding: 6px 12px; font-size: .82rem; }
.btn-full { width: 100%; }
.btn-icon { background: transparent; border: none; cursor: pointer; color: var(--text2); font-size: 1.1rem; transition: color .2s; padding: 6px; border-radius: 6px; }
.btn-icon:hover { color: var(--text); background: var(--bg3); }

/* ── Layout ─────────────────────────────────────────────────────── */
#main-screen { display: flex; min-height: 100vh; }

/* ── Sidebar ────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar); min-height: 100vh;
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; left: 0; top: 0; bottom: 0; z-index: 100;
  transition: transform .25s;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border);
}
#main-nav {
  flex: 1; overflow-y: auto;
  padding: 12px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--text2); font-size: .9rem;
  transition: all .15s; position: relative;
  cursor: pointer;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: rgba(79,110,247,.15); color: var(--accent); }
.nav-icon { font-size: .9rem; width: 18px; text-align: center; }
.nav-section { margin-top: 8px; }
.nav-divider {
  font-size: .65rem; font-weight: 700; letter-spacing: 1px;
  color: var(--text3); padding: 12px 12px 6px;
}
.badge {
  background: var(--accent); color: #fff;
  font-size: .65rem; font-weight: 700;
  padding: 2px 6px; border-radius: 20px;
  margin-left: auto;
}
.sidebar-footer {
  padding: 16px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-g);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem; flex-shrink: 0;
}
.user-details { flex: 1; overflow: hidden; }
.user-details span { display: block; font-size: .82rem; }
#sidebar-username { color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-badge { font-size: .68rem !important; color: var(--accent); background: rgba(79,110,247,.15); padding: 1px 6px; border-radius: 4px; display: inline-block !important; margin-top: 2px; }

/* ── Mobile header ──────────────────────────────────────────────── */
.mobile-header {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; z-index: 99;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  align-items: center; justify-content: space-between;
}
.mobile-header button { background: transparent; border: none; color: var(--text); font-size: 1.2rem; cursor: pointer; position: relative; }
@media (max-width: 768px) {
  #sidebar { transform: translateX(-100%); }
  #sidebar.open { transform: translateX(0); }
  .mobile-header { display: flex; }
  #content { margin-left: 0 !important; padding-top: 64px !important; }
  .sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; display: none; }
  .sidebar-overlay.show { display: block; }
}

/* ── Content ────────────────────────────────────────────────────── */
#content {
  margin-left: var(--sidebar);
  flex: 1; padding: 32px;
  min-height: 100vh;
}
.page { display: none; }
.page.active { display: block; }
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px; flex-wrap: wrap; gap: 12px;
}
.page-header h1 {
  font-size: 1.6rem; font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
}
.section-title { font-size: 1rem; font-weight: 600; color: var(--text2); margin: 28px 0 16px; text-transform: uppercase; letter-spacing: 1px; font-size: .8rem; }

/* ── Cards ──────────────────────────────────────────────────────── */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 22px;
}
.card-title { font-size: .8rem; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 16px; }

/* ── Stats Grid ─────────────────────────────────────────────────── */
.stats-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
  display: flex; flex-direction: column; gap: 6px;
}
.stat-label { font-size: .75rem; color: var(--text3); text-transform: uppercase; letter-spacing: .8px; font-weight: 600; }
.stat-value { font-size: 1.8rem; font-weight: 700; font-family: 'JetBrains Mono', monospace; }
.stat-sub { font-size: .78rem; color: var(--text2); }

/* ── Dashboard grid ─────────────────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .dash-grid { grid-template-columns: 1fr; } }

/* ── Devices ────────────────────────────────────────────────────── */
.devices-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.device-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px;
  display: flex; align-items: center; gap: 14px;
}
.device-icon { font-size: 1.6rem; }
.device-info { flex: 1; overflow: hidden; }
.device-name { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-key { font-family: 'JetBrains Mono', monospace; font-size: .72rem; color: var(--text3); margin-top: 3px; }
.device-type-badge { font-size: .7rem; color: var(--cyan); background: rgba(6,182,212,.1); padding: 2px 8px; border-radius: 4px; display: inline-block; margin-top: 4px; }
.device-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Plans ──────────────────────────────────────────────────────── */
.plans-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.plan-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; padding: 24px;
  display: flex; flex-direction: column; gap: 14px;
  position: relative; overflow: hidden; transition: border-color .2s;
}
.plan-card:hover { border-color: var(--accent); }
.plan-card.popular { border-color: var(--accent); }
.plan-popular-badge {
  position: absolute; top: 14px; right: -22px;
  background: var(--accent); color: #fff; font-size: .65rem;
  font-weight: 700; padding: 4px 28px; transform: rotate(35deg);
  letter-spacing: .5px;
}
.plan-name { font-size: 1rem; font-weight: 700; }
.plan-price { font-size: 2rem; font-weight: 800; font-family: 'JetBrains Mono', monospace; }
.plan-price span { font-size: .9rem; color: var(--text2); font-weight: 400; }
.plan-features { list-style: none; display: flex; flex-direction: column; gap: 7px; }
.plan-features li { font-size: .85rem; color: var(--text2); display: flex; align-items: center; gap: 8px; }
.plan-features li::before { content: '✓'; color: var(--green); font-weight: 700; }
.current-sub-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; margin-bottom: 12px;
}
.sub-plan-name { font-size: 1.3rem; font-weight: 700; }
.sub-meta { display: flex; gap: 24px; margin: 12px 0; flex-wrap: wrap; }
.sub-meta-item { display: flex; flex-direction: column; gap: 3px; }
.sub-meta-label { font-size: .72rem; color: var(--text3); text-transform: uppercase; letter-spacing: .8px; }
.sub-meta-value { font-weight: 600; }

/* ── Status badges ───────────────────────────────────────────────── */
.status-badge {
  font-size: .7rem; font-weight: 700; padding: 3px 9px; border-radius: 20px;
  text-transform: uppercase; letter-spacing: .5px;
}
.status-open      { background: rgba(6,182,212,.15); color: var(--cyan); }
.status-in_progress { background: rgba(245,158,11,.15); color: var(--yellow); }
.status-resolved  { background: rgba(34,197,94,.15); color: var(--green); }
.status-closed    { background: var(--bg3); color: var(--text3); }
.status-active    { background: rgba(34,197,94,.15); color: var(--green); }
.status-expired   { background: rgba(239,68,68,.15); color: var(--red); }
.status-cancelled { background: var(--bg3); color: var(--text3); }

/* ── Guides ─────────────────────────────────────────────────────── */
.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.filter-btn { padding: 7px 16px; border-radius: 20px; font-size: .82rem; font-weight: 500; border: 1px solid var(--border2); background: transparent; color: var(--text2); cursor: pointer; transition: all .15s; }
.filter-btn:hover, .filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.guides-list { display: grid; gap: 12px; }
.guide-item {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px 22px;
  display: flex; align-items: center; gap: 16px;
  cursor: pointer; transition: border-color .15s;
}
.guide-item:hover { border-color: var(--accent); }
.guide-platform { font-size: .72rem; color: var(--accent); background: rgba(79,110,247,.1); padding: 2px 8px; border-radius: 4px; flex-shrink: 0; }
.guide-title { font-weight: 600; }
.guide-arrow { margin-left: auto; color: var(--text3); }
#guide-content { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 32px; margin-top: 20px; line-height: 1.7; }
#guide-content h1,#guide-content h2,#guide-content h3 { margin: 20px 0 10px; }
#guide-content p { margin-bottom: 12px; color: var(--text2); }
#guide-content code { background: var(--bg3); padding: 2px 6px; border-radius: 4px; font-family: 'JetBrains Mono', monospace; font-size: .85rem; color: var(--cyan); }
#guide-content pre { background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; padding: 16px; overflow-x: auto; margin: 12px 0; }
#guide-content pre code { background: none; padding: 0; }
#guide-content ol,#guide-content ul { padding-left: 20px; color: var(--text2); }
#guide-content li { margin-bottom: 6px; }

/* ── Support / Chat ─────────────────────────────────────────────── */
.tickets-list { display: flex; flex-direction: column; gap: 10px; }
.ticket-item {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px 20px;
  display: flex; align-items: center; gap: 14px;
  cursor: pointer; transition: border-color .15s;
}
.ticket-item:hover { border-color: var(--accent); }
.ticket-item-info { flex: 1; overflow: hidden; }
.ticket-item-subject { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-item-meta { font-size: .78rem; color: var(--text3); margin-top: 3px; }
.ticket-unread { background: var(--accent); color: #fff; font-size: .65rem; font-weight: 700; padding: 2px 8px; border-radius: 20px; flex-shrink: 0; }

.ticket-chat-header {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 20px; padding-bottom: 16px;
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.ticket-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }

#chat-messages, #admin-chat-messages {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px;
  min-height: 300px; max-height: 500px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
  margin-bottom: 16px;
}
.msg {
  display: flex; flex-direction: column; gap: 4px;
  max-width: 80%;
}
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; }
.msg-bubble {
  padding: 10px 14px; border-radius: 12px;
  line-height: 1.5; font-size: .9rem;
  word-break: break-word;
}
.msg.mine .msg-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.msg.theirs .msg-bubble { background: var(--bg3); border: 1px solid var(--border2); border-bottom-left-radius: 3px; }
.msg.admin-msg .msg-bubble { background: rgba(245,158,11,.1); border: 1px solid rgba(245,158,11,.25); }
.msg-meta { font-size: .7rem; color: var(--text3); padding: 0 4px; }
.chat-input-bar { display: flex; gap: 10px; align-items: flex-end; }
.chat-input-bar textarea { flex: 1; background: var(--bg2); border: 1px solid var(--border2); border-radius: var(--radius); color: var(--text); padding: 11px 14px; resize: none; outline: none; }
.chat-input-bar textarea:focus { border-color: var(--accent); }

/* ── Notifications ──────────────────────────────────────────────── */
#notifications-list { display: flex; flex-direction: column; gap: 10px; }
.notif-item {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px 20px;
  display: flex; gap: 14px; align-items: flex-start;
  transition: border-color .15s;
}
.notif-item.unread { border-color: var(--border2); }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-top: 6px; }
.notif-dot.info    { background: var(--cyan); }
.notif-dot.warning { background: var(--yellow); }
.notif-dot.error   { background: var(--red); }
.notif-dot.success { background: var(--green); }
.notif-body { flex: 1; }
.notif-title { font-weight: 600; margin-bottom: 4px; }
.notif-text { font-size: .85rem; color: var(--text2); line-height: 1.5; }
.notif-date { font-size: .72rem; color: var(--text3); margin-top: 6px; }
.notif-read-btn { background: transparent; border: none; color: var(--text3); cursor: pointer; font-size: .75rem; flex-shrink: 0; transition: color .15s; }
.notif-read-btn:hover { color: var(--accent); }

/* ── Toast ──────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--bg2); border: 1px solid var(--border2);
  border-left: 4px solid var(--accent);
  border-radius: 10px; padding: 14px 18px;
  min-width: 260px; max-width: 360px;
  box-shadow: var(--shadow);
  animation: slideIn .25s ease;
  display: flex; align-items: center; gap: 10px;
}
.toast.success { border-left-color: var(--green); }
.toast.error   { border-left-color: var(--red); }
.toast.warning { border-left-color: var(--yellow); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { to { transform: translateX(110%); opacity: 0; } }

/* ── Modal ──────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); }
.modal-content {
  position: relative; z-index: 1;
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 16px; padding: 32px;
  width: 100%; max-width: 480px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 18px;
}
.modal-content h2 { font-size: 1.2rem; font-weight: 700; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ── Data table ─────────────────────────────────────────────────── */
#users-table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; font-size: .75rem; text-transform: uppercase;
  letter-spacing: .8px; color: var(--text3); font-weight: 600;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: .88rem; vertical-align: middle; }
.data-table tr:hover td { background: var(--bg3); }

/* ── Admin notif list ────────────────────────────────────────────── */
#admin-notif-list { display: flex; flex-direction: column; gap: 10px; }
.admin-notif-item {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px 20px;
  display: flex; align-items: center; gap: 14px;
}
.admin-notif-item .notif-body { flex: 1; }

/* ── Guide editor ────────────────────────────────────────────────── */
.editor-form { display: flex; flex-direction: column; gap: 18px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .field-row { grid-template-columns: 1fr; } }
#edit-guide-content { font-family: 'JetBrains Mono', monospace; font-size: .85rem; background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--radius); color: var(--text); padding: 14px; outline: none; }
#edit-guide-content:focus { border-color: var(--accent); }
#admin-guides-list { display: flex; flex-direction: column; gap: 10px; }

/* ── Search input ────────────────────────────────────────────────── */
input[type="search"] {
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--radius); color: var(--text);
  padding: 9px 14px; outline: none;
}
input[type="search"]:focus { border-color: var(--accent); }

/* ── Spinner ─────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  animation: spin .6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { display: flex; align-items: center; justify-content: center; padding: 48px; }

/* ── Empty state ─────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text3); }
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state p { font-size: .9rem; }
