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

:root {
  --bg:         #0f1117;
  --surface:    #1a1d27;
  --surface2:   #22263a;
  --border:     #2e3250;
  --primary:    #4f7ef8;
  --primary-h:  #3a6ae0;
  --success:    #22c55e;
  --danger:     #ef4444;
  --warning:    #f59e0b;
  --text:       #e2e8f0;
  --muted:      #6b7280;
  --radius:     8px;
  --radius-lg:  12px;
  --shadow:     0 4px 24px rgba(0,0,0,.45);
  --font:       'Inter', system-ui, -apple-system, sans-serif;
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

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

/* ── Layout ───────────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; }

/* Login page */
#login-page {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 24px;
}
#login-page.active { display: flex; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card p  { color: var(--muted); margin-bottom: 28px; font-size: 13px; }

/* Sidebar */
#sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
}

.sidebar-logo {
  padding: 0 20px 24px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.3px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo span { font-size: 22px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--muted);
  cursor: pointer;
  border-radius: 0;
  transition: background .15s, color .15s;
  font-size: 13.5px;
  user-select: none;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--surface2); color: var(--primary); font-weight: 500; }
.nav-item .icon { width: 18px; text-align: center; font-size: 16px; }

.sidebar-spacer { flex: 1; }

.sidebar-user {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.sidebar-user .avatar {
  width: 30px; height: 30px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-name { font-weight: 500; truncate: ellipsis; }
.sidebar-user .logout-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  border-radius: 4px;
}
.sidebar-user .logout-btn:hover { color: var(--danger); }

/* Main content */
#main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.page {
  display: none;
  flex-direction: column;
  padding: 32px;
  gap: 24px;
  flex: 1;
}
.page.active { display: flex; }

/* ── Components ───────────────────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.page-header h2 { font-size: 20px; font-weight: 600; }
.page-header p  { color: var(--muted); margin-top: 2px; font-size: 13px; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.stat-card .stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.stat-card .stat-value.green  { color: var(--success); }
.stat-card .stat-value.blue   { color: var(--primary); }
.stat-card .stat-value.red    { color: var(--danger); }

/* Table */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }

.empty-state {
  text-align: center;
  padding: 48px 0;
  color: var(--muted);
}
.empty-state .icon { font-size: 36px; margin-bottom: 12px; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}
.badge-green  { background: rgba(34,197,94,.15);  color: var(--success); }
.badge-blue   { background: rgba(79,126,248,.15); color: var(--primary); }
.badge-red    { background: rgba(239,68,68,.15);  color: var(--danger); }
.badge-yellow { background: rgba(245,158,11,.15); color: var(--warning); }
.badge-gray   { background: rgba(107,114,128,.15); color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--surface2); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,.1); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 7px; min-width: 32px; justify-content: center; }

/* Forms */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12px; font-weight: 500; color: var(--muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row.thirds { grid-template-columns: 1fr 1fr 1fr; }

input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--surface); }

/* Toggle switch */
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { display: none; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* Modal */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(2px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow);
  animation: slide-up .2s ease;
}
.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; font-weight: 600; }
.modal-close {
  background: none; border: none;
  color: var(--muted); cursor: pointer;
  font-size: 20px; padding: 2px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Alert */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-danger  { background: rgba(239,68,68,.12);  border: 1px solid rgba(239,68,68,.3);  color: var(--danger); }
.alert-success { background: rgba(34,197,94,.12);  border: 1px solid rgba(34,197,94,.3);  color: var(--success); }
.alert-info    { background: rgba(79,126,248,.12); border: 1px solid rgba(79,126,248,.3); color: var(--primary); }

/* Toast notification */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex; flex-direction: column;
  gap: 8px; z-index: 999;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 12px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: slide-up .2s ease;
  display: flex; align-items: center; gap: 8px;
  max-width: 320px;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-info    { border-left: 3px solid var(--primary); }

/* Phone number badge */
.phone { font-family: monospace; color: var(--primary); }

/* Message preview */
.msg-text {
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
}

/* Send SMS form */
.send-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 600px;
}

/* Config form */
.config-section {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.config-section h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* Monospace token display */
.token-value {
  font-family: monospace;
  font-size: 12px;
  background: var(--bg);
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  word-break: break-all;
  color: var(--success);
}

/* Loading spinner */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 12px;
}

/* Message direction indicator */
.dir-indicator { font-size: 16px; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar { display: none; }
  .page { padding: 20px 16px; }
  .form-row { grid-template-columns: 1fr; }
  .form-row.thirds { grid-template-columns: 1fr; }
}
