@import url('https://fonts.googleapis.com/css2?family=Public+Sans:wght@400;500;600;700;800&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f5fa;
  --bg2: #eeeff5;
  --card: #ffffff;
  --card2: #ffffff;
  --border: #e7e7ef;
  --text: #3a3541;
  --muted: #8a8796;
  --primary: #9155fd;
  --primary-soft: #f0e8ff;
  --primary-dark: #7b3fe4;
  --cyan: #9155fd;
  --cyan-dim: #9155fd;
  --red: #ff4c51;
  --green: #56ca00;
  --amber: #ffb400;
  --orange: #ff9f43;
  --blue: #16b1ff;
  --shadow: 0 4px 18px rgba(75, 70, 92, 0.08);
  --radius: 12px;
}

html[data-theme="blue"] {
  --primary: #3b82f6;
  --primary-soft: #dbeafe;
  --primary-dark: #2563eb;
  --cyan: #3b82f6;
  --cyan-dim: #3b82f6;
}

html[data-theme="green"] {
  --primary: #16a34a;
  --primary-soft: #dcfce7;
  --primary-dark: #15803d;
  --cyan: #16a34a;
  --cyan-dim: #16a34a;
}

html[data-theme="rose"] {
  --primary: #e11d48;
  --primary-soft: #ffe4e6;
  --primary-dark: #be123c;
  --cyan: #e11d48;
  --cyan-dim: #e11d48;
}

html[data-theme="dark"] {
  --bg: #0f1219;
  --bg2: #171b26;
  --card: #1a1f2e;
  --card2: #1f2538;
  --border: #2a3145;
  --text: #e8eaf0;
  --muted: #9aa3b5;
  --primary: #8b5cf6;
  --primary-soft: #2a2140;
  --primary-dark: #7c3aed;
  --cyan: #8b5cf6;
  --cyan-dim: #8b5cf6;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

html[data-theme="purple"] {
  --primary: #9155fd;
  --primary-soft: #f0e8ff;
  --primary-dark: #7b3fe4;
  --cyan: #9155fd;
  --cyan-dim: #9155fd;
}

html {
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: 'Public Sans', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
  touch-action: manipulation;
}

img, svg, video, canvas { max-width: 100%; height: auto; }

.hidden { display: none !important; }

/* Auth */
.auth-wrap { max-width: 440px; margin: 0 auto; padding: 48px 16px; }
.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-lockup--auth {
  flex-direction: column;
  gap: 14px;
  margin-bottom: 4px;
  text-align: center;
}
.brand-logo {
  display: block;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  object-fit: cover;
  box-shadow: 0 10px 28px rgba(22, 177, 255, 0.18), 0 4px 14px rgba(15, 18, 24, 0.22);
}
.brand-logo--sm {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(15, 18, 24, 0.16);
}
.brand { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; }
.brand span { color: var(--primary); font-style: normal; }
.sub { color: var(--muted); font-size: 0.9rem; margin: 8px 0 24px; }

.tabs { display: flex; gap: 8px; margin-bottom: 20px; background: var(--bg2); padding: 4px; border-radius: 12px; }
.tab {
  flex: 1; padding: 10px; text-align: center; border-radius: 10px;
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-weight: 600; font-size: 0.85rem;
  font-family: inherit;
}
.tab.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

label {
  display: block; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin-bottom: 6px; font-weight: 700;
}

input, select, textarea {
  width: 100%; padding: 12px 14px; background: #fff;
  border: 1px solid var(--border); border-radius: 10px; color: var(--text);
  font-size: 0.9rem; margin-bottom: 14px; font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(145, 85, 253, 0.15);
}

.btn {
  padding: 12px 18px; border: none; border-radius: 10px; font-weight: 700;
  font-size: 0.85rem; cursor: pointer; background: var(--primary);
  color: #fff; transition: 0.2s; box-shadow: 0 4px 12px rgba(145, 85, 253, 0.35);
  font-family: inherit;
}
a.btn {
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; box-sizing: border-box;
}
.btn:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 0.75rem; box-shadow: none; }
.btn-outline {
  background: #fff; border: 1px solid var(--border); color: var(--text);
  box-shadow: none;
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.btn-cyan { background: var(--primary); }
.btn-purple { background: #9155fd; box-shadow: 0 4px 12px rgba(145, 85, 253, 0.35); color: #fff; }
.pdf-panel { text-align: center; padding: 8px 0; }
.pdf-spinner {
  width: 36px; height: 36px; margin: 12px auto 16px;
  border: 3px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: pdfSpin 0.8s linear infinite;
}
@keyframes pdfSpin { to { transform: rotate(360deg); } }
.pdf-preview-wrap {
  width: 100%; max-height: min(52vh, 420px); margin-top: 12px;
  border: 1px solid var(--border); border-radius: 10px; background: #525659;
  overflow: auto; text-align: center;
}
.pdf-preview-loading { padding: 40px 16px; color: #fff; font-size: 0.85rem; }
.pdf-page-canvas {
  display: block; max-width: 100%; height: auto; margin: 8px auto;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.pdf-filename { font-size: 0.85rem; color: var(--muted); word-break: break-all; }
.pdf-success { color: var(--green) !important; }
.pdf-error { color: var(--red); font-weight: 600; }
.btn-danger { background: var(--red); box-shadow: 0 4px 12px rgba(255, 76, 81, 0.3); }

.err { color: var(--red); font-size: 0.85rem; margin-bottom: 12px; text-align: center; }
.ok { color: var(--green); font-size: 0.85rem; margin-bottom: 12px; text-align: center; }
.note {
  font-size: 0.75rem; color: var(--muted); line-height: 1.5; margin-top: 12px;
  padding: 12px; background: var(--bg2); border-radius: 10px; border: 1px solid var(--border);
}

/* App shell */
.app {
  display: flex;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
.sidebar {
  width: 260px; background: #fff; border-right: 1px solid var(--border);
  padding: 20px 14px; flex-shrink: 0; display: flex; flex-direction: column;
  box-shadow: 4px 0 24px rgba(75, 70, 92, 0.04);
}
.sidebar .brand { font-size: 1.15rem; margin: 0; }
.sidebar .brand-lockup { margin-bottom: 2px; min-width: 0; }
.sidebar-user { font-size: 0.75rem; color: var(--muted); margin-bottom: 20px; padding: 0 8px; }
.sidebar-user b { color: var(--primary); }
.nav-section {
  font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: #b0adb8; font-weight: 700; padding: 12px 14px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px;
  border-radius: 10px; color: #6f6b7d; cursor: pointer; font-weight: 600;
  font-size: 0.88rem; margin-bottom: 2px; border: none;
}
.nav-item:hover { background: var(--bg2); color: var(--text); }
.nav-item.active {
  background: var(--primary); color: #fff;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 40%, transparent);
}
.nav-ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; flex-shrink: 0; opacity: 0.9;
}
.nav-ico svg { display: block; }
html[data-theme="dark"] .nav-item { color: #a8b0c0; }
html[data-theme="dark"] .nav-item:hover { background: var(--bg2); color: var(--text); }
html[data-theme="dark"] .nav-section { color: #6b7388; }
html[data-theme="dark"] .tab.active,
html[data-theme="dark"] .tab-inner.active { background: var(--card); }
html[data-theme="dark"] .btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  background: var(--bg2);
  color: var(--text);
  border-color: var(--border);
}
.nav-spacer { flex: 1; }

.main {
  flex: 1;
  padding: 22px 28px;
  overflow-x: hidden;
  overflow-y: auto;
  min-width: 0;
  width: 100%;
  max-width: 100%;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 22px; flex-wrap: wrap; gap: 12px;
}
.topbar h2 { font-size: 1.35rem; font-weight: 700; color: #3a3541; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.search-box {
  display: flex; align-items: center; gap: 8px; background: #fff;
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; min-width: 220px;
  box-shadow: var(--shadow);
}
.search-box input { margin: 0; border: none; background: transparent; padding: 4px 0; box-shadow: none; }

.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-pill, .kpi-card {
  background: #fff; border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat-pill .lbl, .kpi-card .lbl {
  font-size: 0.72rem; text-transform: uppercase; color: var(--muted);
  letter-spacing: 0.04em; font-weight: 700;
}
.stat-pill .val, .kpi-card .val { font-size: 1.6rem; font-weight: 800; margin-top: 6px; color: var(--text); }
.stat-pill .val.green, .kpi-card .val.green { color: var(--green); }
.stat-pill .val.cyan, .kpi-card .val.cyan { color: var(--primary); }
.kpi-card .icon {
  position: absolute; right: 14px; top: 14px; width: 40px; height: 40px;
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
}
.kpi-card .icon svg { display: block; width: 20px; height: 20px; }
.kpi-card .trend { font-size: 0.75rem; margin-top: 6px; font-weight: 600; }
.trend.up { color: var(--green); }
.trend.down { color: var(--red); }
.btn-ico { display: inline-block; vertical-align: -2px; margin-right: 4px; }
.search-box { position: relative; display: flex; align-items: center; }
.search-box .search-ico {
  position: absolute; left: 12px; color: var(--muted); pointer-events: none; z-index: 1;
}
.search-box input { padding-left: 36px !important; }
.apk-ico { color: var(--primary); margin-bottom: 8px; text-align: center; }
.apk-ico svg { display: inline-block; }
.modal-ico {
  display: inline-flex; width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  align-items: center; justify-content: center; flex-shrink: 0;
}
.modal-ico.square { border-radius: 8px; background: #e8f0ff; color: var(--blue, #16b1ff); }
.modal-head { display: flex; align-items: center; gap: 10px; }
.icon-btn .ico { display: flex; align-items: center; justify-content: center; }
.icon-btn .ico svg { display: block; }
.btn-icon svg { display: block; }

.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: #fff; color: var(--muted); font-size: 0.78rem; font-weight: 600;
  cursor: pointer;
}
.chip.active { background: var(--primary-soft); border-color: transparent; color: var(--primary); }

.overview-grid {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 16px;
}

.chart-bars {
  display: flex; align-items: flex-end; gap: 8px; height: 140px; padding-top: 12px;
}
.chart-bars .bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart-bars .bar {
  width: 100%; border-radius: 8px 8px 4px 4px; background: linear-gradient(180deg, #b18aff, #9155fd);
  min-height: 8px; transition: height 0.4s ease;
}
.chart-bars .bar-lbl { font-size: 0.65rem; color: var(--muted); font-weight: 600; }

.ring-wrap { display: flex; align-items: center; gap: 20px; }
.ring {
  width: 120px; height: 120px; border-radius: 50%;
  background: conic-gradient(var(--primary) var(--pct, 0%), #ebe9f1 0);
  display: grid; place-items: center; position: relative;
}
.ring::after {
  content: ''; position: absolute; inset: 14px; border-radius: 50%; background: #fff;
}
.ring span { position: relative; z-index: 1; font-weight: 800; font-size: 1.2rem; color: var(--text); }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; margin-bottom: 8px; color: var(--text); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }

.activity-item {
  display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.activity-item:last-child { border-bottom: none; }
.activity-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; background: var(--primary); }

/* Device grid */
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.device-card {
  background: #fff; border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; cursor: pointer; transition: 0.2s; box-shadow: var(--shadow);
}
.device-card:hover { border-color: #d3c4ff; transform: translateY(-2px); box-shadow: 0 8px 24px rgba(145, 85, 253, 0.12); }
.device-card .row { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.device-card .model { font-weight: 800; font-size: 1rem; color: var(--text); }
.device-card .field { font-size: 0.82rem; margin-bottom: 4px; color: var(--muted); }
.device-card .field b { color: var(--text); }
.device-card .date { font-size: 0.75rem; color: var(--muted); margin-top: 8px; }
.device-card .notes { font-size: 0.75rem; color: var(--primary); margin-top: 4px; font-weight: 600; }
.status-online { color: var(--green); font-weight: 700; font-size: 0.8rem; }
.status-offline { color: var(--orange); font-weight: 700; font-size: 0.8rem; }
.card-actions { display: flex; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--muted); cursor: pointer; display: flex;
  align-items: center; justify-content: center; font-size: 0.9rem;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.icon-btn.danger:hover { border-color: var(--red); color: var(--red); background: #fff0f0; }
.icon-btn.finance { color: var(--amber); font-weight: 800; }
.icon-btn.star.on { color: var(--amber); border-color: #ffe8a3; background: #fff8e1; }

.detail-header {
  display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px;
  width: 100%; max-width: 100%;
}
.detail-title-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  width: 100%; min-width: 0;
}
.detail-title-row h2 {
  flex: 1; min-width: 0; font-size: 1.25rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}
.detail-actions .btn {
  width: 100%;
  min-width: 0;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-sizing: border-box;
}
.detail-actions .btn-danger {
  grid-column: 1 / -1;
}
@media (min-width: 720px) {
  .detail-actions {
    display: flex;
    flex-wrap: wrap;
  }
  .detail-actions .btn {
    width: auto;
    flex: 0 0 auto;
  }
  .detail-actions .btn-danger {
    grid-column: auto;
  }
}

.badge { padding: 4px 12px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; flex-shrink: 0; }
.badge-online { background: #e8f8df; color: var(--green); }
.badge-offline { background: #fff3e8; color: var(--orange); }
.badge-vip { background: #fff4d6; color: #c99200; }

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.detail-grid > .card {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.field-with-btn {
  display: flex; gap: 8px; align-items: center; margin-bottom: 14px;
  width: 100%; max-width: 100%;
}
.field-with-btn input,
.field-with-btn textarea {
  flex: 1; margin-bottom: 0; min-width: 0; max-width: 100%;
}
.field-with-btn-top { align-items: flex-start; }
.field-with-btn .btn { flex-shrink: 0; white-space: nowrap; }

.info-list .info-row {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 0.85rem;
  min-width: 0;
}
.info-list .info-row:last-child { border-bottom: none; }
.info-list .info-lbl { color: var(--muted); flex-shrink: 0; }
.info-list .info-val {
  font-weight: 600; text-align: right; min-width: 0; flex: 1;
  overflow-wrap: anywhere; word-break: break-word;
}

.tabs-inner { display: flex; gap: 6px; margin-bottom: 14px; background: var(--bg2); padding: 4px; border-radius: 12px; }
.tab-inner {
  padding: 8px 14px; border-radius: 8px; background: transparent; border: none;
  color: var(--muted); cursor: pointer; font-size: 0.8rem; font-weight: 600;
}
.tab-inner.active { background: #fff; color: var(--primary); box-shadow: var(--shadow); }

.sms-list { max-height: 420px; overflow-y: auto; }
.sms-item {
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; margin-bottom: 8px;
}
.sms-item .sms-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 6px;
}
.sms-item .sms-sender {
  font-size: 0.78rem; font-weight: 700; color: var(--primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sms-tag {
  flex-shrink: 0; font-size: 0.65rem; font-weight: 800; letter-spacing: 0.04em;
  padding: 2px 8px; border-radius: 999px;
}
.sms-toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 4px;
}
.sms-tag.otp { background: #fff6d6; color: #b45309; }
.sms-tag.important { background: #e8f8df; color: #3f8f00; }
.sms-tag.credit { background: #dcfce7; color: #15803d; }
.sms-tag.debit { background: #fee2e2; color: #b91c1c; }
.sms-item.sms-otp {
  background: #fffbeb; border-color: #f6d977;
}
.sms-item.sms-otp .sms-sender { color: #b45309; }
.sms-item.sms-important {
  background: #f0fdf4; border-color: #86efac;
}
.sms-item.sms-important .sms-sender { color: #16a34a; }
.sms-item.sms-credit {
  background: #ecfdf5; border-color: #4ade80;
}
.sms-item.sms-credit .sms-sender { color: #16a34a; }
.sms-item.sms-credit .body { color: #166534; }
.sms-item.sms-debit {
  background: #fef2f2; border-color: #f87171;
}
.sms-item.sms-debit .sms-sender { color: #dc2626; }
.sms-item.sms-debit .body { color: #991b1b; }
html[data-theme="dark"] .sms-item.sms-otp {
  background: #3a3210; border-color: #6b5a18;
}
html[data-theme="dark"] .sms-tag.otp { background: #4a4018; color: #fbbf24; }
html[data-theme="dark"] .sms-item.sms-important {
  background: #14301a; border-color: #2f6b2f;
}
html[data-theme="dark"] .sms-tag.important { background: #1a3a1a; color: #56ca00; }
html[data-theme="dark"] .sms-item.sms-credit {
  background: #0f2a1a; border-color: #166534;
}
html[data-theme="dark"] .sms-tag.credit { background: #14532d; color: #4ade80; }
html[data-theme="dark"] .sms-item.sms-debit {
  background: #3a1515; border-color: #7f1d1d;
}
html[data-theme="dark"] .sms-tag.debit { background: #7f1d1d; color: #fca5a5; }
.sms-item .body { font-size: 0.85rem; line-height: 1.45; margin-bottom: 8px; white-space: pre-wrap; color: var(--text); }
.sms-item .meta { font-size: 0.7rem; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sms-otp-chip {
  font-family: ui-monospace, monospace; font-weight: 800; letter-spacing: 0.08em;
  background: #fef3c7; color: #92400e; border: 1px solid #f59e0b;
  border-radius: 8px; padding: 4px 10px; cursor: pointer;
}
html[data-theme="dark"] .sms-otp-chip { background: #4a4018; color: #fbbf24; border-color: #a16207; }
.project-stats-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.project-stats-table th, .project-stats-table td {
  text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border);
}
.project-stats-table th { color: var(--muted); font-weight: 600; }
.project-stats-table tr.current td { color: var(--primary); font-weight: 600; }

.send-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
@media (max-width: 600px) { .send-row { grid-template-columns: 1fr; } }

.fb-item {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; margin-bottom: 10px; display: flex; justify-content: space-between;
  align-items: flex-start; gap: 12px; box-shadow: var(--shadow);
}
.fb-item.selected { border-color: var(--primary); background: var(--primary-soft); }
.fb-name { font-weight: 700; }
.fb-url { font-size: 0.7rem; color: var(--muted); font-family: monospace; margin-top: 4px; word-break: break-all; }
.section-title {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin: 20px 0 10px; font-weight: 700;
}

/* Modals */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(58, 53, 65, 0.45); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  backdrop-filter: blur(2px);
}
.modal {
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(58, 53, 65, 0.2);
}
.modal.wide { max-width: 520px; }
.modal-head {
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.modal-head h3 { font-size: 1rem; color: var(--primary); font-weight: 700; }
.modal-body { padding: 16px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); text-align: center; }

.modal-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 10px; display: flex; align-items: center; gap: 12px;
}
.modal-card .dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.modal-card .dot.red { background: var(--red); }
.modal-card .dot.green { background: var(--green); }
.modal-card .lbl { font-size: 0.7rem; color: var(--muted); }
.modal-card .val { font-size: 1rem; font-weight: 700; margin-top: 2px; color: var(--text); }
.modal-card .val.orange { color: var(--orange); }
.modal-card .val.white { color: var(--text); }
.modal-card .val.green { color: var(--green); }

.radio-row { display: flex; gap: 10px; margin-bottom: 14px; }
.radio-card {
  flex: 1; padding: 12px; border-radius: 10px; border: 1px solid var(--border);
  background: #fff; cursor: pointer; text-align: center;
}
.radio-card.selected { border-color: var(--primary); background: var(--primary-soft); }
.radio-card input { margin-right: 6px; }

.finance-bank {
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; margin-bottom: 8px; cursor: pointer;
}
.finance-bank:hover { border-color: var(--primary); }
.finance-bank .name { font-weight: 700; color: var(--primary); }
.finance-bank .bal { font-size: 1.1rem; font-weight: 800; color: var(--amber); margin-top: 4px; }
.finance-bank .sub { font-size: 0.7rem; color: var(--muted); margin-top: 4px; }

.device-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 10px 0 8px;
}
.device-meta-grid .lbl {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}
.device-meta-grid .val {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.device-finance {
  margin: 8px 0 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.22);
}
.device-finance + .device-finance { margin-top: 6px; }
.device-finance__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.device-finance__bank {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #34d399;
}
.device-finance__rupee {
  display: inline-flex;
  width: 16px;
  height: 16px;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: rgba(52, 211, 153, 0.15);
  font-size: 0.7rem;
}
.device-finance__bal {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text);
}
.device-finance__txn {
  margin-top: 6px;
  font-size: 0.7rem;
  font-weight: 600;
}
.device-finance__txn.credit { color: #34d399; }
.device-finance__txn.debit { color: #f87171; }
html[data-theme="dark"] .device-finance {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.25);
}

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

.apk-drop {
  display: block; border: 2px dashed #d5cef0; border-radius: 14px;
  padding: 28px 16px; text-align: center; cursor: pointer;
  background: var(--primary-soft); transition: 0.2s;
}
.apk-drop:hover, .apk-drop.drag {
  border-color: var(--primary); background: #e8dcff;
}
.apk-drop input { display: none; }

/* Mobile shell */
.mobile-bar {
  display: none; align-items: center; gap: 10px;
  margin: -6px -12px 16px; padding: 10px 12px 14px;
  position: sticky; top: 0; z-index: 40;
  background: rgba(244, 245, 250, 0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.mobile-bar-title { font-weight: 800; font-size: 1rem; flex: 1; min-width: 0; }
.mobile-bar-title span { color: var(--primary); }
.mobile-bar-user {
  font-size: 0.7rem; color: var(--muted); max-width: 30%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn-icon {
  width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; color: var(--text); font-size: 1.15rem; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  box-shadow: var(--shadow);
}
.sidebar-top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 4px;
}
.sidebar-close { display: none; }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(58, 53, 65, 0.4);
  z-index: 90; border: none; padding: 0; cursor: pointer;
}
.sidebar-backdrop.open { display: block; }

@media (max-width: 980px) {
  .overview-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .device-grid { grid-template-columns: 1fr; min-width: 0; }
  .device-card { max-width: 100%; min-width: 0; overflow: hidden; }
  .mobile-bar {
    display: flex;
    margin: 0 0 14px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  .sidebar-close { display: inline-flex; }
  .app { display: block; position: relative; width: 100%; max-width: 100%; overflow-x: hidden; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(280px, 86vw);
    z-index: 100; transform: translateX(-105%);
    transition: transform 0.22s ease; box-shadow: 8px 0 32px rgba(58, 53, 65, 0.18);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.open { transform: translateX(0); }
  .main {
    padding: 12px 12px 28px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
  #viewDetail, #viewOverview, #viewDevices, #viewFavorites, #viewProjects, #viewTelegram,
  #viewSecurity, #viewKeys, #viewThemes {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }
  .topbar { width: 100%; max-width: 100%; flex-direction: column; align-items: stretch; }
  .topbar h2 { font-size: 1.15rem; word-break: break-word; white-space: normal; }
  .search-box { min-width: 0; width: 100%; max-width: 100%; box-sizing: border-box; }
  .topbar-actions { width: 100%; max-width: 100%; }
  .topbar-actions select { width: 100%; min-width: 0 !important; max-width: 100%; }
  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 10px; width: 100%; }
  .stat-pill, .kpi-card { min-width: 0; overflow: hidden; }
  .stat-pill .val, .kpi-card .val { font-size: 1.25rem; }
  .card { padding: 14px; width: 100%; max-width: 100%; box-sizing: border-box; overflow: hidden; }
  .fb-item { flex-direction: column; max-width: 100%; }
  .tabs-inner { width: 100%; max-width: 100%; box-sizing: border-box; }
  .tab-inner { flex: 1; text-align: center; padding: 10px 6px; min-width: 0; font-size: 0.75rem; }
  .ring-wrap { flex-direction: column; align-items: flex-start; }
  .field-with-btn { flex-wrap: wrap; }
  .field-with-btn .btn { width: 100%; }
  .modal { max-width: 100%; box-sizing: border-box; padding: 12px; }
  .modal-card { width: 100%; max-width: 100%; margin: 0; }
  .radio-row { flex-direction: column; }
  .info-list .info-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  .info-list .info-val {
    text-align: left;
    width: 100%;
    max-width: 100%;
  }
  /* iOS Safari zooms if inputs < 16px */
  input, select, textarea, .search-box input {
    font-size: 16px !important;
  }
  .key-perms { grid-template-columns: 1fr; }
  .session-row, .akey-row {
    flex-direction: column;
    align-items: stretch;
  }
  .session-row .btn, .akey-row .btn { width: 100%; }
  .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .perm-chips { max-width: 100%; }
  code, pre { max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }
  .sms-list { max-height: min(55vh, 420px); -webkit-overflow-scrolling: touch; }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr 1fr; }
  .auth-wrap { padding: 28px 12px; max-width: 100%; width: 100%; box-sizing: border-box; }
  .detail-actions .btn { font-size: 0.72rem; padding: 10px 6px; }
  .main { padding: 10px 10px 24px; }
  .card { padding: 12px; border-radius: 12px; }
  .brand { font-size: 1.45rem; }
  .tabs { width: 100%; }
  .btn { width: auto; max-width: 100%; }
  .btn-block { width: 100%; }
}

@media (min-width: 981px) {
  .sidebar { transform: none !important; }
  .sidebar-backdrop { display: none !important; }
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}
.theme-swatch {
  appearance: none;
  border: 2px solid var(--border);
  background: var(--card);
  border-radius: 12px;
  padding: 14px 10px;
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.theme-swatch::before {
  content: "";
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--swatch, var(--primary));
  box-shadow: 0 4px 12px color-mix(in srgb, var(--swatch, var(--primary)) 35%, transparent);
}
.theme-swatch.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.session-row, .akey-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.session-row:last-child, .akey-row:last-child { border-bottom: none; }
.session-meta, .akey-meta { font-size: 0.78rem; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.session-row .current-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  margin-left: 6px;
}
.activity-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.activity-item .muted { color: var(--muted); font-size: 0.75rem; margin-top: 4px; }
.owner-only.hidden-guest { display: none !important; }
.guest-banner {
  background: var(--primary-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 14px;
}
.key-perms {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  margin-top: 4px;
}
.key-perm {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}
.key-perm input { width: auto; margin: 0; }
.perm-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.perm-chip {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
}

/* Hacking / panel motion */
@keyframes dpPulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}
@keyframes dpScan {
  0% { transform: translateY(-120%); opacity: 0; }
  30% { opacity: 0.45; }
  100% { transform: translateY(220%); opacity: 0; }
}
@keyframes dpFadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
.auth-wrap .brand-logo {
  animation: dpFadeUp 0.55s ease-out both;
}
.auth-wrap .brand span {
  animation: dpPulse 1.6s ease-in-out infinite;
}
.auth-wrap .card {
  animation: dpFadeUp 0.55s ease-out both;
  position: relative;
  overflow: hidden;
}
.auth-wrap .card::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 28%;
  background: linear-gradient(180deg, transparent, rgba(145, 85, 253, 0.12), transparent);
  animation: dpScan 2.8s linear infinite;
  pointer-events: none;
}
.app .card, .app .nav-item.active {
  animation: dpFadeUp 0.4s ease-out both;
}
.session-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}
.session-row > div:first-child { min-width: 0; }
@media (min-width: 720px) {
  .session-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}
