@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #0c0a14;
  --bg-2: #12101c;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-solid: #1a1628;
  --surface-2: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.1);
  --text: #f8fafc;
  --text-muted: #a8b0c8;
  --rainbow: linear-gradient(90deg, #ff6b6b, #feca57, #48dbfb, #ff9ff3, #54a0ff, #5f27cd);
  --rainbow-soft: linear-gradient(135deg, rgba(255,107,107,.15), rgba(254,202,87,.12), rgba(72,219,251,.15), rgba(255,159,243,.12), rgba(84,160,255,.15));
  --r-red: #ff6b6b;
  --r-orange: #feca57;
  --r-yellow: #ffe66d;
  --r-green: #1dd1a1;
  --r-cyan: #48dbfb;
  --r-blue: #54a0ff;
  --r-purple: #a55eea;
  --r-pink: #ff9ff3;
  --primary: #a55eea;
  --primary-hover: #8854d0;
  --accent: #48dbfb;
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.15);
  --success: #1dd1a1;
  --success-soft: rgba(29, 209, 161, 0.15);
  --warning: #feca57;
  --radius: 16px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Outfit, system-ui, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 20% -10%, rgba(255, 107, 107, 0.18), transparent 50%),
    radial-gradient(ellipse 60% 40% at 80% 0%, rgba(84, 160, 255, 0.15), transparent 45%),
    radial-gradient(ellipse 50% 30% at 50% 100%, rgba(165, 94, 234, 0.12), transparent 50%);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  min-height: 100vh;
}

/* App shell — left sidebar layout */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface-solid);
  border-right: 2px solid transparent;
  border-image: var(--rainbow) 1;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  backdrop-filter: blur(12px);
}

.sidebar .brand {
  margin-bottom: 28px;
  padding: 4px 10px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.sidebar-nav a {
  display: block;
  width: 100%;
}

.sidebar-nav a.nav-logout {
  margin-top: auto;
  margin-left: 0;
}

.app-main {
  flex: 1;
  margin-left: 240px;
  min-width: 0;
}

/* Legacy topbar (unused) */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 58px;
  background: var(--surface-solid);
  border-bottom: 2px solid transparent;
  border-image: var(--rainbow) 1;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 16px;
  background: var(--rainbow);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand img, .brand-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid transparent;
  background: linear-gradient(var(--bg), var(--bg)) padding-box,
              var(--rainbow) border-box;
  -webkit-text-fill-color: initial;
}

.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.nav a:hover {
  color: var(--text);
  background: var(--surface);
  border-color: rgba(255, 255, 255, 0.08);
}

.nav a.active {
  color: #fff;
  background: var(--rainbow);
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(165, 94, 234, 0.35);
}

.nav a.nav-logout {
  color: var(--r-red);
  margin-left: 4px;
}

.nav a.nav-logout:hover {
  background: var(--danger-soft);
  border-color: rgba(255, 107, 107, 0.3);
}

.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 48px; }

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

.page-header h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: var(--rainbow);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-header p { margin: 0; color: var(--text-muted); font-size: 14px; }

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--r-green);
  background: var(--success-soft);
  border: 1px solid rgba(29, 209, 161, 0.35);
}

.live-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--r-green);
  box-shadow: 0 0 8px var(--r-green);
  animation: pulse 2s ease-in-out infinite;
}

.live-pulse.fetching { animation: pulse-fast 0.5s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

@keyframes pulse-fast {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.sidebar-live {
  margin-top: auto;
  padding: 14px 16px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 600;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
}

.sidebar-live.is-online {
  color: var(--r-green);
  background: var(--success-soft);
}

.sidebar-live.is-offline {
  color: #e17055;
  background: rgba(225, 112, 85, 0.08);
}

.sidebar-live .live-pulse {
  flex-shrink: 0;
}

.sidebar-live.is-online .live-pulse {
  background: var(--r-green);
  box-shadow: 0 0 8px var(--r-green);
}

.sidebar-live.is-offline .live-pulse {
  background: #e17055;
  box-shadow: 0 0 8px rgba(225, 112, 85, 0.6);
  animation: none;
  opacity: 0.85;
}

.stat .value.stat-flash {
  animation: stat-flash 0.6s ease;
}

@keyframes stat-flash {
  0% { color: var(--r-yellow); transform: scale(1.08); }
  100% { color: inherit; transform: scale(1); }
}

.quick-send-status {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
}

.quick-send-status.is-online {
  color: var(--r-green);
  background: var(--success-soft);
  border: 1px solid rgba(29, 209, 161, 0.35);
}

.quick-send-status.is-offline {
  color: #e17055;
  background: rgba(225, 112, 85, 0.1);
  border: 1px solid rgba(225, 112, 85, 0.35);
}

.send-progress-panel {
  margin-top: 18px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid rgba(84, 160, 255, 0.35);
  background: rgba(84, 160, 255, 0.08);
}

.send-progress-panel h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 700;
}

.send-progress-status {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
}

.send-progress-status.is-active { color: var(--r-blue); }
.send-progress-status.is-success { color: var(--r-green); }
.send-progress-status.is-error { color: var(--r-red); }

.send-progress-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.send-step {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

.send-step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}

.send-step-active { color: var(--r-blue); font-weight: 600; }
.send-step-active .send-step-dot {
  background: var(--r-blue);
  box-shadow: 0 0 8px rgba(84, 160, 255, 0.6);
  animation: send-pulse 1.2s ease infinite;
}

.send-step-done { color: var(--r-green); }
.send-step-done .send-step-dot { background: var(--r-green); }

.send-step-pending .send-step-dot { background: var(--border); }

@keyframes send-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}

.btn:disabled,
.btn.btn-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn.is-busy {
  opacity: 0.75;
  cursor: wait;
}

.meta-live {
  color: var(--text-muted);
  font-size: 11px;
}

.card {
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--rainbow);
}

.card-highlight {
  background: linear-gradient(165deg, rgba(26, 22, 40, 0.95) 0%, rgba(18, 16, 28, 0.98) 100%);
  border-color: rgba(165, 94, 234, 0.25);
}

.card-highlight::before { height: 4px; }

h2 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.stat:nth-child(1) .value { color: var(--r-red); }
.stat:nth-child(2) .value { color: var(--r-orange); }
.stat:nth-child(3) .value { color: var(--r-yellow); }
.stat:nth-child(4) .value { color: var(--r-cyan); }
.stat:nth-child(5) .value { color: var(--r-green); }
.stat:nth-child(6) .value { color: var(--r-purple); }

.stat .value { font-size: 28px; font-weight: 800; line-height: 1; }
.stat .label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text);
}

input[type="text"], input[type="password"], input[type="number"], input[type="tel"], input[type="file"], select, textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 14px;
  background: var(--bg-2);
  color: var(--text);
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--r-purple);
  box-shadow: 0 0 0 3px rgba(165, 94, 234, 0.25);
}

textarea { min-height: 120px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: var(--rainbow);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 20px rgba(165, 94, 234, 0.3);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(165, 94, 234, 0.45);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

.btn-secondary:hover { background: rgba(255, 255, 255, 0.08); box-shadow: none; }

.btn-accent {
  background: linear-gradient(135deg, var(--r-cyan), var(--r-blue));
  box-shadow: 0 4px 20px rgba(72, 219, 251, 0.3);
}

.btn-danger {
  background: linear-gradient(135deg, var(--r-red), #ee5a6f);
  box-shadow: 0 4px 20px rgba(255, 107, 107, 0.3);
}

.btn-danger:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-small { padding: 6px 12px; font-size: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  border-bottom: 1px solid var(--border);
  padding: 11px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  background: var(--surface);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }

a { color: var(--r-cyan); }
a:hover { color: var(--r-pink); }

.alert {
  padding: 14px 16px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-size: 13px;
  border: 1px solid;
}

.alert-success {
  background: var(--success-soft);
  color: var(--r-green);
  border-color: rgba(29, 209, 161, 0.35);
}

.alert-error {
  background: var(--danger-soft);
  color: var(--r-red);
  border-color: rgba(255, 107, 107, 0.35);
}

.alert-info {
  background: rgba(84, 160, 255, 0.12);
  color: var(--r-blue);
  border-color: rgba(84, 160, 255, 0.35);
}

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 100% 80% at 50% -20%, rgba(255, 107, 107, 0.2), transparent 50%),
    radial-gradient(ellipse 80% 60% at 100% 50%, rgba(84, 160, 255, 0.15), transparent 45%),
    radial-gradient(ellipse 80% 60% at 0% 80%, rgba(165, 94, 234, 0.15), transparent 45%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
  text-align: center;
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--rainbow);
}

.login-card .brand-logo {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin: 0 auto 16px;
  object-fit: cover;
  border: 3px solid transparent;
  background: linear-gradient(var(--bg), var(--bg)) padding-box, var(--rainbow) border-box;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 800;
  background: var(--rainbow);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-card form { text-align: left; margin-top: 24px; }

.muted { color: var(--text-muted); font-size: 13px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 200px; }

code {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  background: var(--surface);
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--r-cyan);
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-pending, .badge-queued, .badge-sending { background: rgba(254, 202, 87, 0.2); color: var(--r-orange); }
.badge-sent, .badge-completed, .badge-delivered { background: var(--success-soft); color: var(--r-green); }
.badge-failed { background: var(--danger-soft); color: var(--r-red); }
.badge-draft { background: var(--surface); color: var(--text-muted); }
.badge-online { background: var(--success-soft); color: var(--r-green); }
.badge-offline { background: var(--danger-soft); color: var(--r-red); }
.badge-sim-ready { background: rgba(59, 130, 246, 0.15); color: #2563eb; }
.badge-no-sim { background: rgba(245, 158, 11, 0.15); color: #b45309; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--r-green); box-shadow: 0 0 8px var(--r-green); }
.status-dot.off { background: var(--r-red); box-shadow: 0 0 8px var(--r-red); }

.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }

.device-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  background: var(--surface);
  transition: border-color 0.2s ease;
}

.device-card-rainbow:hover { border-color: rgba(165, 94, 234, 0.4); }

.device-card h3 { margin: 0 0 6px; font-size: 15px; font-weight: 700; }
.device-card .meta { font-size: 12px; color: var(--text-muted); }

.device-actions {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.steps { display: grid; gap: 10px; }

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

.step-num {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--rainbow);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-box {
  text-align: center;
  padding: 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: inline-block;
}

.mobile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.dashboard-split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.card-danger {
  border-color: rgba(255, 107, 107, 0.3);
  background: linear-gradient(165deg, rgba(40, 20, 28, 0.9), rgba(26, 22, 40, 0.95));
}

.card-danger h2 { color: var(--r-red); }

.cleanup-actions { display: grid; gap: 16px; margin-top: 8px; }
.cleanup-form {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.cleanup-form p { margin: 0 0 10px; font-size: 13px; }
.cleanup-form input[type="text"] { max-width: 160px; margin-bottom: 10px; }
.cleanup-form-all { border-color: rgba(255, 107, 107, 0.35); background: rgba(255, 107, 107, 0.06); }

@media (max-width: 768px) {
  .mobile-grid, .dashboard-split { grid-template-columns: 1fr; }
  .app-shell { flex-direction: column; }
  .sidebar {
    position: relative;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 2px solid transparent;
    border-image: var(--rainbow) 1;
    padding: 14px 16px;
  }
  .sidebar .brand { margin-bottom: 12px; }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: none;
  }
  .sidebar-nav a { width: auto; }
  .sidebar-nav a.nav-logout { margin-top: 0; }
  .app-main { margin-left: 0; }
}
