:root {
  --bg: #f7fafc;
  --text: #1a202c;
  --muted: #718096;
  --primary: #2b6cb0;
  --primary-dark: #1a365d;
  --card: #ffffff;
  --border: #e2e8f0;
  --danger: #c53030;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(26, 32, 44, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--primary); }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 1.25rem; }

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--primary-dark); }
.brand-logo { display: block; height: 38px; width: auto; }
a.brand { text-decoration: none; }
.topbar nav a {
  margin-left: 1rem;
  text-decoration: none;
  color: var(--muted);
}

.hero { padding: 4.5rem 1.25rem 3rem; }
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 700;
}
.hero h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  line-height: 1.15;
  margin: 0.5rem 0 1rem;
  color: var(--primary-dark);
}
.lead { font-size: 1.15rem; color: var(--muted); max-width: 640px; }
.hero-actions { margin-top: 1.75rem; display: flex; gap: 0.75rem; flex-wrap: wrap; }

.btn {
  display: inline-block;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  border: 1px solid transparent;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  padding: 2rem 1.25rem 3rem;
}
.features article, .schools {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.schools { margin-bottom: 3rem; }
.footer { padding: 2rem 1.25rem 3rem; color: var(--muted); font-size: 0.95rem; }

.page-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, color-mix(in srgb, var(--tenant-primary, #2b6cb0) 12%, white), #edf2f7);
}
.login-card {
  width: min(420px, calc(100vw - 2rem));
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  border: 1px solid var(--border);
}
.school-badge {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--tenant-primary, #2b6cb0) 15%, white);
  color: var(--tenant-accent, var(--primary-dark));
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}
.login-card h1 {
  margin: 0 0 0.35rem;
  font-size: 1.6rem;
  color: var(--tenant-accent, var(--primary-dark));
}
.login-card .subtitle { color: var(--muted); margin: 0 0 1.5rem; }
.login-logo {
  display: block;
  width: min(200px, 100%);
  height: auto;
  margin: 0 0 1rem;
}
label { display: block; font-weight: 600; margin-top: 1rem; }
input {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
button[type="submit"] {
  width: 100%;
  margin-top: 1.25rem;
  padding: 0.75rem;
  border: 0;
  border-radius: 8px;
  background: var(--tenant-primary, var(--primary));
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.error {
  margin-top: 1rem;
  color: var(--danger);
  font-size: 0.95rem;
  min-height: 1.2rem;
}
.dashboard {
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1.25rem 3rem;
}
.dashboard-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.dashboard h1 { margin-top: 0; color: var(--tenant-accent, var(--primary-dark)); }
.meta { color: var(--muted); }
.logout {
  margin-top: 1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
}

.page-admin .login-card { border-top: 4px solid #1a202c; }
.page-admin .school-badge { background: #edf2f7; color: #1a202c; }

/* School console layout */
.page-console {
  min-height: 100vh;
  display: flex;
  background: var(--bg);
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--tenant-accent, var(--primary-dark));
  color: #fff;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: sticky;
  top: 0;
  align-self: flex-start;
}

.sidebar-head {
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: #f8fafc;
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 0.85rem;
}

.sidebar-brand img {
  flex-shrink: 0;
  border-radius: 8px;
}

.sidebar .school-badge {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  margin-bottom: 0.5rem;
}

.sidebar-user {
  font-size: 0.9rem;
  opacity: 0.85;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
  display: flex;
  flex-direction: column;
}

.nav-item {
  display: block;
  padding: 0.75rem 1.25rem;
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  border-left-color: #fff;
  color: #fff;
  font-weight: 600;
}

.sidebar-logout {
  margin: 1rem;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
}

.sidebar-logout:hover {
  background: rgba(255, 255, 255, 0.1);
}

.console-main {
  flex: 1;
  min-width: 0;
  padding: 1.75rem 2rem 3rem;
}

.console-header {
  margin-bottom: 1.5rem;
}

.console-header h1 {
  margin: 0;
  font-size: 1.75rem;
  color: var(--tenant-accent, var(--primary-dark));
}

.panel { display: none; }
.panel.active { display: block; }

.panel-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.panel-lead {
  margin: 0 0 1.25rem;
  color: var(--muted);
}

.empty-state {
  padding: 2rem 1.5rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  text-align: center;
  background: #fafafa;
}

.empty-state strong {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.panel-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.panel-toolbar .panel-lead { margin: 0; }

.section-title {
  font-size: 1rem;
  margin: 1.5rem 0 0.75rem;
  color: var(--tenant-accent, var(--primary-dark));
}

.hint { margin-bottom: 0.75rem; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.data-table th,
.data-table td {
  text-align: left;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--border);
}
.data-table th { color: var(--muted); font-weight: 600; font-size: 0.85rem; }

.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.85rem; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-in_progress { background: #dbeafe; color: #1e40af; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-skipped_offline { background: #fee2e2; color: #991b1b; }
.badge-failed { background: #fee2e2; color: #991b1b; }

.device-apps-group {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: #fafafa;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.device-apps-group h3 { margin: 0 0 0.5rem; font-size: 0.95rem; }
.device-apps-group ul { margin: 0; padding-left: 1.25rem; }

.online-dot {
  color: #059669;
  font-size: 0.8rem;
  font-weight: 600;
}

.modal {
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  max-width: 480px;
  width: calc(100vw - 2rem);
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(0,0,0,0.4); }
.modal form { padding: 1.5rem; }
.modal h2 { margin: 0 0 1rem; font-size: 1.25rem; }
.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}
.deploy-target { border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem 1rem; margin: 1rem 0; }
.deploy-target legend { font-weight: 600; padding: 0 0.25rem; }
.checkbox { display: block; margin: 0.35rem 0; font-weight: normal; }
.device-pick { margin-top: 0.5rem; max-height: 160px; overflow-y: auto; }
.hidden { display: none !important; }

button.btn-primary {
  width: auto;
  margin-top: 0;
  background: var(--tenant-primary, var(--primary));
}

.branding-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}
.branding-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  background: #fafafa;
}
.preview-box {
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0.75rem 0;
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 0.5rem;
}
.preview-box img, .preview-icon img {
  max-width: 120px;
  max-height: 120px;
  object-fit: contain;
}
.preview-slides {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.slide-thumb {
  width: 80px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
}
.preview-video video {
  max-width: 100%;
  max-height: 200px;
}
.file-label {
  display: block;
  margin: 0.5rem 0;
  font-weight: 600;
  font-size: 0.9rem;
}
.file-label input { margin-top: 0.35rem; font-weight: normal; }
textarea {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  box-sizing: border-box;
}
.media-mode { margin: 0.75rem 0 1rem; }
.success-msg { color: #059669; font-size: 0.95rem; min-height: 1.2rem; }

.subscription-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  background: linear-gradient(135deg, color-mix(in srgb, var(--tenant-primary, #2b6cb0) 8%, white), #fff);
}
.sub-inner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}
.sub-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.sub-value { font-size: 1.1rem; font-weight: 600; margin-top: 0.25rem; }

.invoice-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  margin-bottom: 1rem;
}

.badge-type-monthly { background: #dbeafe; color: #1e40af; }
.badge-type-yearly { background: #e0e7ff; color: #3730a3; }
.badge-type-one_time { background: #f3e8ff; color: #6b21a8; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-paid { background: #d1fae5; color: #065f46; }
.badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-cancelled { background: #f1f5f9; color: #64748b; }
.badge-active { background: #d1fae5; color: #065f46; }
.badge-past_due { background: #fee2e2; color: #991b1b; }
.badge-canceled { background: #f1f5f9; color: #64748b; }

.billing-meta { margin-bottom: 1rem; }
.billing-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.billing-tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.65rem 1rem;
  margin-bottom: -1px;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.billing-tab.active {
  color: var(--tenant-primary, var(--primary));
  border-bottom-color: var(--tenant-primary, var(--primary));
}
.billing-tab-panel { display: none; }
.billing-tab-panel.active { display: block; }
.billing-cycle-toggle { display: flex; gap: 1rem; margin-bottom: 1rem; }
.subscription-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; }

.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}
.plan-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  background: var(--card);
  box-shadow: var(--shadow);
}
.plan-card.plan-selected { border-color: var(--tenant-primary, var(--primary)); box-shadow: 0 0 0 2px color-mix(in srgb, var(--tenant-primary, #2b6cb0) 25%, transparent); }
.plan-card.plan-current { background: color-mix(in srgb, var(--tenant-primary, #2b6cb0) 6%, white); }
.plan-card h3 { margin: 0 0 0.35rem; }
.plan-devices { color: var(--muted); margin: 0 0 0.5rem; font-size: 0.95rem; }
.plan-price { font-size: 1.75rem; font-weight: 700; margin: 0; color: var(--tenant-accent, var(--primary-dark)); }
.plan-period { font-size: 0.95rem; font-weight: 500; color: var(--muted); }
.plan-over { margin: 0.25rem 0 0.5rem; }
.plan-estimate { margin: 0 0 0.75rem; }
.plan-features { list-style: none; padding: 0; margin: 0 0 1rem; font-size: 0.9rem; }
.plan-features li { padding: 0.15rem 0; }
.plan-features li.off { color: var(--muted); opacity: 0.65; }
.plan-enterprise { margin-bottom: 1.5rem; }

.payment-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  background: #fff;
}
.payment-form label { display: block; margin-top: 0.75rem; }
.payment-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.payment-form .btn { margin-top: 1rem; }

.billing-alert {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

@media (max-width: 768px) {
  .page-console { flex-direction: column; }
  .sidebar {
    width: 100%;
    min-height: auto;
    position: static;
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.5rem;
  }
  .nav-item {
    border-left: 0;
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }
  .nav-item.active { border-left: 0; background: rgba(255,255,255,0.2); }
  .sidebar-logout { display: none; }
  .console-main { padding: 1rem; }
}

@media (max-width: 600px) {
  .hero { padding-top: 3rem; }
}

/* Live View */
.live-view-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1.25rem;
  margin-top: 1rem;
}
.live-device-sidebar {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  background: #fafafa;
  max-height: 70vh;
  overflow-y: auto;
}
.live-device-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
.live-device-item.selected {
  border-color: var(--tenant-primary, var(--primary));
  box-shadow: 0 0 0 1px var(--tenant-primary, var(--primary));
}
.live-device-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
  flex-shrink: 0;
}
.live-device-dot.online { background: #16a34a; }
.live-device-name { font-weight: 600; flex: 1 1 100%; }
.live-device-meta { font-size: 0.8rem; color: var(--muted); }
.live-view-main { min-width: 0; }
.live-header-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.live-header-row h2 { margin: 0; font-size: 1.25rem; }
.live-badge { background: #fee2e2; color: #b91c1c; }
.live-controls {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
}
.live-panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.live-pane {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #0f172a;
}
.live-pane-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: #1e293b;
  color: #f8fafc;
}
.live-pane-head h3 { margin: 0; font-size: 0.95rem; }
.live-pane-body {
  position: relative;
  aspect-ratio: 16 / 10;
  background: #020617;
}
.live-frame {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.live-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  text-align: center;
  color: #94a3b8;
  font-size: 0.9rem;
}
.live-status {
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}
.live-status-info { background: #eff6ff; color: #1d4ed8; }
.live-status-warn { background: #fffbeb; color: #b45309; }
.live-status-error { background: #fef2f2; color: #b91c1c; }

@media (max-width: 900px) {
  .live-view-layout { grid-template-columns: 1fr; }
  .live-panes { grid-template-columns: 1fr; }
}

/* Activity / Monitor & History */
.activity-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}
.activity-filters label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.activity-filters select {
  min-width: 180px;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.activity-event {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
  margin-bottom: 0.75rem;
  background: #fff;
}
.activity-event-main {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}
.activity-thumb {
  width: 120px;
  height: 90px;
  object-fit: cover;
  border-radius: 6px;
  background: #0f172a;
  flex-shrink: 0;
}
.activity-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}
.activity-event-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}
.activity-media { margin-top: 0.75rem; }
.activity-video {
  width: 100%;
  max-width: 420px;
  border-radius: 6px;
  background: #000;
}
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.85rem; }
