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

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #f8fafc;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #0f172a;
  --text-muted:   #64748b;
  --text-dim:     #94a3b8;
  --accent:       #2563eb;
  --accent-hover: #1d4ed8;
  --accent-bg:    #eff6ff;
  --accent-text:  #1d4ed8;
  --danger:       #ef4444;
  --danger-bg:    #fef2f2;
  --success:      #22c55e;
  --success-bg:   #f0fdf4;
  --warning:      #f59e0b;
  --warning-bg:   #fffbeb;
  --radius:       10px;
  --radius-sm:    6px;
  --nav-width:    224px;
  --shadow-sm:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:       0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.05);
}

html, body {
  height: 100%;
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App layout ─────────────────────────────────────── */

.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────── */

.sidebar {
  width: var(--nav-width);
  min-width: var(--nav-width);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  text-decoration: none;
}

.sidebar-logo-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-logo-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  letter-spacing: -0.01em;
}

.sidebar-logo-name span {
  font-weight: 400;
  color: var(--text-muted);
}

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

.nav-section {
  padding-top: 16px;
  padding-bottom: 2px;
}

.nav-section:first-child { padding-top: 4px; }

.nav-section-label {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 0 10px 6px;
  display: block;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}

.nav-link:hover { background: #f1f5f9; color: var(--text); }

.nav-link.active {
  background: var(--accent-bg);
  color: var(--accent-text);
}

.nav-link svg { flex-shrink: 0; opacity: 0.65; transition: opacity 0.1s; }
.nav-link:hover svg { opacity: 0.9; }
.nav-link.active svg { opacity: 1; color: var(--accent); }

.sidebar-footer {
  padding: 10px 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ── Main content ───────────────────────────────────── */

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  min-width: 0;
}

/* ── Page header ────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.page-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ── Card ───────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card + .card { margin-top: 16px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.card-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Buttons ────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: background 0.1s, color 0.1s, opacity 0.1s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; pointer-events: none; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: #f8fafc; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: #f1f5f9; color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

.btn-group { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Form ───────────────────────────────────────────── */

.form-group { margin-bottom: 14px; }
.form-group:last-child { margin-bottom: 0; }

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

.form-control {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

.form-control::placeholder { color: var(--text-dim); }

/* Focus ring for the cross-origin Cardknox iFields wrappers. The ring can't be
   pushed into the iframe, so JS toggles this class on the wrapper via
   document.activeElement. The border is set inline on the wrapper, which beats a
   class — hence !important; box-shadow isn't set inline so it applies normally.
   The wrapper's own overflow:hidden clips the child iframe, not its own shadow. */
.ifield-focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

textarea.form-control {
  height: auto;
  padding: 10px 12px;
  resize: vertical;
  min-height: 80px;
}

select.form-control { cursor: pointer; }

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Badges ─────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 500;
}

.badge-success { background: var(--success-bg); color: #16a34a; }
.badge-warning { background: var(--warning-bg); color: #b45309; }
.badge-danger  { background: var(--danger-bg);  color: #dc2626; }
.badge-accent  { background: var(--accent-bg);  color: var(--accent-text); }
.badge-muted   { background: #f1f5f9; color: var(--text-muted); }

/* ── Table ──────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: #fafafa;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

/* ── App list ───────────────────────────────────────── */

/* The icon starts hidden and is revealed only once it actually loads — CSP forbids
   the inline onload/onerror handlers the old portal used, so JS wires it instead.
   Until then (or forever, if the device never uploaded one) the letter shows. */
.app-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  flex-shrink: 0;
  object-fit: cover;
}

.app-avatar {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

/* ── Modal ──────────────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
  animation: modal-in 0.18s ease;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  letter-spacing: -0.01em;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.97) translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

.modal-lg { max-width: 620px; }
.modal-body-scroll { max-height: 60vh; overflow-y: auto; }

/* ── Tabs ───────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  overflow-x: auto;
}

.tab-btn {
  position: relative;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color .12s;
}

.tab-btn::after {
  content: '';
  position: absolute;
  left: 12px; right: 12px; bottom: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  transform: scaleX(0);
  transition: transform .2s cubic-bezier(.2,.8,.2,1);
}

.tab-btn:hover          { color: var(--text); }
.tab-btn.active         { color: var(--accent-text); font-weight: 600; }
.tab-btn.active::after  { transform: scaleX(1); }

.tab-pane        { display: none; animation: tab-fade .22s ease both; }
.tab-pane.active { display: block; }

@keyframes tab-fade {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: none; }
}

/* ── Info grid ──────────────────────────────────────── */

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

.info-item {
  padding: 11px 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.info-item label {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: 600;
  margin-bottom: 4px;
}

.info-item span { font-size: 13.5px; font-weight: 500; word-break: break-word; }

/* ── Command sections ───────────────────────────────── */

.cmd-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}

.cmd-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 14px;
}

/* ── Collapsible policy card ────────────────────────── */

.policy-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  transition: border-color .15s;
}

.policy-card:hover { border-color: #cbd5e1; }

.policy-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 18px;
  cursor: pointer;
  user-select: none;
  transition: background .12s;
}

.policy-header:hover { background: var(--bg); }
.policy-header-text  { flex: 1; }

.policy-title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent-text);
  letter-spacing: .06em;
  text-transform: uppercase;
  margin-bottom: 3px;
}

.policy-subtitle { font-size: 12.5px; color: var(--text-muted); line-height: 1.45; }

.policy-chevron {
  color: var(--accent);
  font-size: 12px;
  margin-left: 12px;
  transition: transform .2s cubic-bezier(.2,.8,.2,1);
}

.policy-chevron.open { transform: rotate(90deg); }

.policy-body      { display: none; padding: 0 18px 18px; }
.policy-body.open { display: block; animation: tab-fade .2s ease both; }

.policy-divider { height: 1px; background: var(--border); margin-bottom: 14px; }

.policy-field-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.policy-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.policy-row-label { font-size: 13.5px; color: var(--text); }

.policy-input,
.policy-textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  transition: border-color .12s, box-shadow .12s;
}

.policy-textarea { resize: vertical; line-height: 1.5; }

.policy-input:focus,
.policy-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.policy-input:disabled,
.policy-textarea:disabled { background: var(--bg); color: var(--text-muted); cursor: not-allowed; }

/* ── Toggle switch ──────────────────────────────────── */

.policy-toggle {
  appearance: none;
  -webkit-appearance: none;
  width: 42px;
  height: 24px;
  background: #cbd5e1;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  margin: 0;
  transition: background .18s;
}

.policy-toggle::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  top: 3px;
  left: 3px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform .2s cubic-bezier(.2,.8,.2,1);
}

.policy-toggle:checked          { background: var(--accent); }
.policy-toggle:checked::after   { transform: translateX(18px); }
.policy-toggle:focus-visible    { outline: 2px solid var(--accent); outline-offset: 2px; }
.policy-toggle:disabled         { opacity: .5; cursor: not-allowed; }

/* ── Checkbox row ───────────────────────────────────── */

.form-check {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 8px;
}

.form-check input[type=checkbox] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
  margin: 0;
}

.form-check label { font-size: 13px; cursor: pointer; color: var(--text); }

/* ── Spacing utilities (used by the ported policy markup) ── */

.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mt-1 { margin-top: 4px; }
.mt-3 { margin-top: 12px; }
.flex   { display: flex; }
.flex-1 { flex: 1; }
.gap-2  { gap: 8px; }
.gap-4  { gap: 16px; }
.w-full { width: 100%; justify-content: center; }

/* ── Stats grid ─────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 22px 20px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  animation: stat-in 0.45s cubic-bezier(.2,.8,.2,1) both;
}

.stat-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.5;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
  border-color: #c7d2fe;
}

.stat-card:nth-child(1) { animation-delay: .04s; }
.stat-card:nth-child(2) { animation-delay: .10s; }
.stat-card:nth-child(3) { animation-delay: .16s; }
.stat-card:nth-child(4) { animation-delay: .22s; }

@keyframes stat-in {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.stat-value {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--text);
  margin-bottom: 8px;
  font-feature-settings: 'tnum';
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ── Utilities ──────────────────────────────────────── */

.text-muted  { color: var(--text-muted); }
.text-success { color: #16a34a; }
.font-mono   { font-family: 'JetBrains Mono', 'Fira Code', monospace; }

/* ── Auth pages ─────────────────────────────────────── */

body.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.auth-wrap {
  width: 100%;
  max-width: 380px;
  padding: 24px 16px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.auth-logo-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}

.auth-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  letter-spacing: -0.02em;
}

.auth-link {
  display: block;
  text-align: center;
  margin-top: 14px;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}

.auth-link:hover { text-decoration: underline; }

/* ── Toast ──────────────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  max-width: 320px;
  animation: toast-in 0.2s ease;
  pointer-events: auto;
}

.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-info    { border-left: 3px solid var(--accent); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ── Mobile topbar ──────────────────────────────────── */

.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
}

.hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
}

.hamburger:hover { background: #f1f5f9; }

.mobile-topbar-logo {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 768px) {
  .mobile-topbar { display: flex; }

  .sidebar-backdrop { display: block; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    z-index: 100;
    transition: transform 0.25s ease;
    box-shadow: none;
  }

  .main-content { padding: 18px; padding-top: 68px; }

  .form-row { grid-template-columns: 1fr; }

  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow); }
  body.nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }

  .page-header { flex-direction: column; align-items: flex-start; }
  .stats-grid  { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .main-content { padding: 12px; padding-top: 64px; }
  .card { padding: 14px; }
}

/* ── Icons ────────────────────────────────────────────────────────────────────
   Drawn on the same 24-unit grid as the Android app; path data lives in js/icons.js.
   Sized in em so an icon scales with the text beside it, and stroked in currentColor
   so it picks up the colour of its button, link or caption with no per-context
   variant. Scoped to .ico so the sidebar's own svg rules (above) are untouched. */
.ico {
  width: 1.05em;
  height: 1.05em;
  flex-shrink: 0;
  vertical-align: -0.16em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Spacing when an icon sits next to a word rather than alone in a button */
.ico-before { margin-right: 6px; }
.ico-after  { margin-left: 6px; }

/* Hero icon — a tonal disc with the glyph centred, as on the app's setup screens */
.ico-hero {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-bg);
  color: var(--accent);
}
.ico-hero .ico { width: 26px; height: 26px; vertical-align: 0; }
