/* ═══════════════════════════════════════════════════════ Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #21253a;
  --border:    #2d3154;
  --primary:   #6366f1;
  --primary-h: #4f52d9;
  --danger:    #ef4444;
  --success:   #22c55e;
  --warn:      #f59e0b;
  --text:      #e2e4f0;
  --muted:     #6b7280;
  --radius:    8px;
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ═══════════════════════════════════════════════════════ Auth screen */
.auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  min-height: 100vh;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 0%, #1e2060 0%, var(--bg) 60%);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 48px rgba(0,0,0,.5);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 28px;
  color: #fff;
}

.auth-tabs {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  padding: 8px 0;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  transition: background .15s, color .15s;
}

.auth-tab.active {
  background: var(--primary);
  color: #fff;
}

.auth-form { display: flex; flex-direction: column; gap: 16px; }

.auth-error {
  color: #fca5a5;
  font-size: 0.85rem;
  min-height: 0;
  display: none;
}
.auth-error.show { display: block; }

.auth-info {
  color: #86efac;
  font-size: 0.85rem;
  min-height: 0;
  display: none;
}
.auth-info.show { display: block; }

.copyright {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

/* ═══════════════════════════════════════════════════════ App shell */
.app-shell { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.88rem;
  color: var(--muted);
}

.app {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.app-copyright {
  flex-shrink: 0;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ═══════════════════════════════════════════════════════ Sidebar */
.sidebar {
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
  flex-shrink: 0;
}

.nav-section-label {
  padding: 8px 20px 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  cursor: pointer;
  border-radius: 0;
  color: var(--muted);
  transition: background .15s, color .15s;
  position: relative;
}

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: #fff; }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.nav-icon { font-size: 1rem; }

.nav-count {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 10px;
  display: none;
}
.nav-count.show { display: inline; }

/* ═══════════════════════════════════════════════════════ Main content */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  background: var(--bg);
}

.panel { display: none; max-width: 900px; }
.panel.active { display: block; }

.panel-header { margin-bottom: 24px; }
.panel-header h2 { font-size: 1.4rem; color: #fff; margin-bottom: 4px; }
.panel-header p { color: var(--muted); font-size: 0.9rem; }

.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

/* ═══════════════════════════════════════════════════════ Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.card-title {
  padding: 14px 20px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  color: #fff;
}

.card-body { padding: 16px 20px; }
.card-body p { color: var(--muted); line-height: 1.7; }

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

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 2rem; font-weight: 700; color: #fff; line-height: 1; }
.stat-sub { font-size: 0.8rem; color: var(--muted); }

/* ═══════════════════════════════════════════════════════ Forms */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.field .hint { font-size: 0.78rem; font-weight: 400; color: var(--muted); }

input[type="text"], input[type="email"], input[type="password"],
select, textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 10px 12px;
  width: 100%;
  transition: border-color .15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}

textarea { resize: vertical; }

/* ═══════════════════════════════════════════════════════ Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.88rem;
  font-family: var(--font);
  font-weight: 500;
  transition: background .15s, opacity .15s;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }

.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover  { background: var(--primary-h); }
.btn-danger   { background: var(--danger);   color: #fff; }
.btn-danger:hover   { background: #dc2626; }
.btn-ghost    { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover    { background: var(--surface2); }

/* ═══════════════════════════════════════════════════════ Plan badge */
.plan-badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.plan-free     { background: #374151; color: #9ca3af; }
.plan-standard { background: #1e3a5f; color: #60a5fa; }
.plan-support  { background: #312e81; color: #a5b4fc; }

.plan-hint { font-size: 0.82rem; color: var(--muted); }

/* ═══════════════════════════════════════════════════════ Devices */
.device-list { display: flex; flex-direction: column; gap: 10px; }

.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.device-icon { font-size: 1.6rem; flex-shrink: 0; padding-top: 2px; }

.device-info { flex: 1; }
.device-name { font-weight: 600; color: #fff; }
.device-meta { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

.device-token {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.75rem;
  color: #a5b4fc;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  margin-top: 6px;
  word-break: break-all;
}

.device-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════ Tickets */
.ticket-list { display: flex; flex-direction: column; gap: 10px; }

.ticket-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: border-color .15s;
}
.ticket-row:hover { border-color: var(--primary); }

.ticket-subject { flex: 1; font-weight: 500; color: #fff; }
.ticket-meta { font-size: 0.8rem; color: var(--muted); }

.status-chip {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}
.status-open        { background: #1e3a5f; color: #60a5fa; }
.status-in-progress { background: #422006; color: #fb923c; }
.status-resolved    { background: #14532d; color: #4ade80; }

/* ═══════════════════════════════════════════════════════ Ticket thread */
.ticket-thread {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.thread-msg {
  padding: 14px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.thread-msg.support { border-color: var(--primary); background: #1a1d3a; }

.thread-author {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.thread-msg.support .thread-author { color: #a5b4fc; }
.thread-body { color: var(--text); white-space: pre-wrap; }

.reply-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ═══════════════════════════════════════════════════════ Downloads */
.download-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.download-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.download-icon { font-size: 2.4rem; }
.download-label { font-size: 1.1rem; font-weight: 600; color: #fff; }
.download-note { font-size: 0.82rem; color: var(--muted); }

/* ═══════════════════════════════════════════════════════ Plan grid */
.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.plan-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  transition: border-color .15s;
}

.plan-card.current { border-color: var(--primary); }
.plan-card.current::after {
  content: 'Current';
  position: absolute;
  top: 12px; right: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
}

.plan-name { font-size: 1.1rem; font-weight: 700; color: #fff; }
.plan-price { font-size: 2rem; font-weight: 800; color: #fff; }
.plan-price span { font-size: 1rem; font-weight: 400; color: var(--muted); }
.plan-features { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.plan-features li { font-size: 0.87rem; color: var(--muted); }
.plan-features li::before { content: '✓ '; color: var(--success); }
.plan-confirm-price { font-size: 1.6rem; font-weight: 800; color: var(--text); }
.badge-beta {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: rgba(255, 196, 0, 0.18);
  color: #ffc400;
  border: 1px solid rgba(255, 196, 0, 0.45);
  border-radius: 999px;
  vertical-align: middle;
}

/* ═══════════════════════════════════════════════════════ Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 24px 48px rgba(0,0,0,.6);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}
.modal-header h3 { font-size: 1.1rem; color: #fff; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 1.1rem; }
.modal-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer { padding: 0 24px 20px; display: flex; justify-content: flex-end; gap: 10px; }

.token-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.token-box code {
  flex: 1;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.78rem;
  color: #a5b4fc;
  word-break: break-all;
}

/* ═══════════════════════════════════════════════════════ Locked message */
.locked-msg {
  text-align: center;
  padding: 32px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.locked-msg h3 { font-size: 1.1rem; color: #fff; }
.locked-msg p { color: var(--muted); max-width: 360px; }

/* ═══════════════════════════════════════════════════════ Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 2000;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ═══════════════════════════════════════════════════════ Misc */
.muted { color: var(--muted); }

.tbtn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: var(--font);
  transition: background .15s;
}
.tbtn-ghost { background: transparent; color: var(--text); }
.tbtn-ghost:hover { background: var(--surface2); }

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 40px 16px;
  font-size: 0.9rem;
}
