/* =====================================================================
   Design system — clean/minimalist SaaS-dashboard style (Stripe/Linear/
   Notion-settings inspired). Every visual token lives in :root as a CSS
   variable so the whole app can be re-themed from one place; every rule
   below consumes those variables rather than hardcoding colors, so the
   brand green stays the single source of truth for "primary" everywhere
   (buttons, focus rings, active nav states, checkboxes, badges).

   Signature choice: BORDER (not shadow) is the primary card/input
   delimiter, with a very soft shadow reserved for genuinely "floating"
   surfaces (modals, dropdown results, the mobile bottom sheet) — mixing
   both on every card reads as heavier than either alone.
   ===================================================================== */

:root {
  /* Brand */
  --primary-color: #0b3d2e;
  --primary-color-dark: #082e22;
  --primary-color-light: #e8f5ee;
  --primary-color-ring: rgba(11, 61, 46, 0.15);
  /* A touch lighter than --primary-color, used only as the gradient's
     "light" stop — never assigned to text/border/anything needing solid
     brand-green contrast, so this doesn't ripple into a11y-sensitive uses. */
  --primary-color-light-stop: #145a41;
  /* 135deg diagonal, dark -> slightly-lighter green — applied to the
     topbar, primary buttons, and the mobile bottom nav so "primary brand
     surface" reads as one deliberate family rather than three flat greens
     that happen to match. --primary-color itself stays solid (borders,
     focus rings, icon fills, etc still need one exact hex to compare
     against) — only surfaces large enough to show a gradient use this. */
  --primary-gradient: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-color-light-stop) 100%);
  --primary-gradient-hover: linear-gradient(135deg, var(--primary-color-dark) 0%, var(--primary-color) 100%);

  /* Neutrals — a hair of green hue mixed into the grays (not pure #888/
     #ccc) so borders/backgrounds read as "chosen to match the brand"
     rather than a default gray plucked from nowhere. */
  --gray-25: #fbfcfb;
  --gray-50: #f6f8f7;
  --gray-100: #eef1ef;
  --gray-200: #e2e8e5;
  --gray-300: #cdd6d2;
  --gray-400: #9aa8a3;
  --gray-500: #6b7975;
  --gray-600: #4d5854;
  --gray-700: #384039;
  --gray-900: #1a201d;

  /* Semantic accents — complement the brand green, never replace it.
     Each has a -bg (badge background), a solid (badge text/icon/border),
     and a -dark (hover/pressed state) tone so every consumer of a given
     meaning reaches for the SAME three variables instead of inventing a
     one-off shade. Fixed semantic mapping used everywhere in this app:
       danger  = destructive / error / expired / failed
       warning = pending / trial / processing-but-needs-attention
       success = online / active / confirmed / healthy
       info    = neutral in-progress / informational (never "bad", never
                 "good" — e.g. "still compressing", a link) */
  --danger-color: #c22b3d;
  --danger-color-dark: #a32334;
  --danger-color-bg: #fdeced;
  --danger-color-border: #f1aeb5;
  --warning-color: #8a6d00;
  --warning-color-dark: #6e5700;
  --warning-color-bg: #fff4d6;
  --warning-color-border: #ffe69c;
  --success-color: #0a7a2f;
  --success-color-dark: #086124;
  --success-color-bg: #e3f6e9;
  --success-color-border: #b6e3c4;
  --info-color: #0b5fff;
  --info-color-dark: #094ccc;
  --info-color-bg: #e8f0ff;
  --info-color-border: #b8d0ff;

  /* Surfaces */
  --surface: #ffffff;
  --surface-muted: var(--gray-50);
  --page-bg: var(--gray-50);
  --border-color: var(--gray-200);
  --border-color-strong: var(--gray-300);

  /* Text */
  --text-primary: var(--gray-900);
  --text-secondary: var(--gray-600);
  --text-muted: var(--gray-500);

  /* Shape */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;

  /* Elevation — reserved for floating surfaces only (see comment above) */
  --shadow-sm: 0 1px 2px rgba(20, 30, 25, 0.06);
  --shadow-md: 0 4px 16px rgba(20, 30, 25, 0.10);
  --shadow-lg: 0 12px 32px rgba(20, 30, 25, 0.16);
  /* Slightly stronger/tinted-green shadow used only under the gradient
     primary button on hover — a plain --shadow-sm read as too flat once
     the button itself stopped being a flat fill. */
  --shadow-primary-hover: 0 6px 16px rgba(11, 61, 46, 0.28);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter",
    Roboto, Helvetica, Arial, sans-serif;

  /* Motion — -base is the default for anything hover/focus/toggle-like;
     -fast stays for the few spots (button :active press) that need to
     feel instant rather than eased. */
  --transition-fast: 0.12s ease;
  --transition-base: 0.22s ease;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--page-bg);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

a {
  color: var(--info-color);
}

/* ---------------------------------------------------------------------
   Topbar
   --------------------------------------------------------------------- */

.topbar {
  background: var(--primary-gradient);
  color: #fff;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.topbar h1 {
  font-size: 1.05rem;
  margin: 0;
  font-weight: 700;
}

.topbar-user {
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 14px;
  color: rgba(255, 255, 255, 0.9);
}

.topbar nav {
  display: flex;
  gap: 22px;
  font-size: 0.88rem;
}

.topbar nav a {
  color: rgba(255, 255, 255, 0.72);
  text-decoration: none;
  font-weight: 600;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.topbar nav a.active,
.topbar nav a:hover {
  color: #fff;
  border-bottom-color: rgba(255, 255, 255, 0.55);
}

/* ---------------------------------------------------------------------
   Buttons
   --------------------------------------------------------------------- */

button, .btn {
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--primary-color);
  background: var(--primary-gradient);
  color: #fff;
  cursor: pointer;
  transition: background var(--transition-base), border-color var(--transition-base),
    box-shadow var(--transition-base), transform var(--transition-fast);
}

button:hover:not(:disabled), .btn:hover:not(:disabled) {
  background: var(--primary-gradient-hover);
  border-color: var(--primary-color-dark);
  box-shadow: var(--shadow-primary-hover);
}

button:active:not(:disabled), .btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.98);
  box-shadow: none;
}

button:focus-visible, .btn:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

button.secondary, .btn.secondary {
  background: var(--surface);
  color: var(--primary-color);
  border-color: var(--border-color-strong);
}

button.secondary:hover:not(:disabled), .btn.secondary:hover:not(:disabled) {
  background: var(--primary-color-light);
  border-color: var(--primary-color);
  color: var(--primary-color-dark);
  box-shadow: var(--shadow-sm);
}

button.danger, .btn.danger {
  background: var(--danger-color);
  border-color: var(--danger-color);
}

button.danger:hover:not(:disabled), .btn.danger:hover:not(:disabled) {
  background: var(--danger-color-dark);
  border-color: var(--danger-color-dark);
  box-shadow: 0 6px 16px rgba(194, 43, 61, 0.28);
}

button:disabled, .btn:disabled {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
  transform: none;
}

/* Tab-style toggle buttons (e.g. kajian.html's "Kajian Reguler" / "Poster
   Jumat" switch) — inactive tabs look like .secondary buttons, the active
   one switches to the normal primary-gradient button look. Deliberately
   reuses the existing button base rather than introducing a whole separate
   tab-widget style, so it inherits focus-visible/disabled handling for free. */
.tab-btn {
  background: var(--surface);
  color: var(--primary-color);
  border-color: var(--border-color-strong);
}

.tab-btn.active {
  background: var(--primary-gradient);
  color: #fff;
  border-color: var(--primary-color);
}

/* ---------------------------------------------------------------------
   Layout / cards
   --------------------------------------------------------------------- */

.container {
  max-width: 1000px;
  margin: 32px auto;
  padding: 0 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 26px;
  margin-bottom: 24px;
}

.card h2 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 1.15rem;
}

.card h2 + p.text-muted {
  margin-top: 0;
}

/* ---------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------- */

.form-row {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* One base rule for every text-like control, everywhere (not just inside
   .form-row) — the old CSS only styled `.form-row input`, leaving a few
   standalone controls (e.g. changelog-admin's per-row Flutter-status
   select) on raw browser chrome. Native color/file pickers are excluded
   below via :not() rather than styled generically, since they need their
   own treatment (see the dedicated rules further down). */
input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]),
select,
textarea {
  font-family: inherit;
  font-size: 0.94rem;
  color: var(--text-primary);
  padding: 9px 12px;
  border: 1px solid var(--border-color-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  width: 100%;
}

.form-row input, .form-row select, .form-row textarea {
  /* Kept as an explicit (higher-specificity) alias of the base rule above
     purely so nothing regresses for controls inside .form-row — the two
     rules are intentionally IDENTICAL in every property that matters,
     this just wins the specificity race against the base selector. */
  font-size: 0.94rem;
  padding: 9px 12px;
  border: 1px solid var(--border-color-strong);
  border-radius: var(--radius-md);
}

input:not([type="checkbox"]):not([type="radio"])::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-color-ring);
}

/* Custom dropdown arrow replacing the OS-native one — appearance: none
   strips the native chrome (including the native arrow) in every
   evergreen browser; the SVG chevron below is inlined as a data URI so it
   needs no extra asset/request and can't be blocked by the artifact CSP
   this app is sometimes previewed under. */
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%236b7975' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5.5 7.5l4.5 4.5 4.5-4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 36px;
  cursor: pointer;
}

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

/* Native color swatch — deliberately NOT styled through the generic input
   rule above (Chrome/Edge/Firefox all render this with their own internal
   swatch box that clips oddly under a large border-radius/border). A
   slim, small, square treatment reads as "a color chip", not a broken
   text input. */
input[type="color"] {
  width: 44px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border-color-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--surface);
}

/* Native file picker — left as browser-default chrome (no custom "choose
   file" button was in scope here) but given the same border/radius
   language as every other control so it doesn't look like a leftover
   unstyled element sitting next to modernized ones. */
input[type="file"] {
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--text-secondary);
  padding: 8px 10px;
  border: 1px dashed var(--border-color-strong);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  width: 100%;
  cursor: pointer;
}

/* ---------------------------------------------------------------------
   Custom checkbox — appearance: none + a hand-drawn checkmark, replacing
   every plain browser checkbox (the 4 identified in the audit: Ramadan
   auto-theme toggle, separate-Iqomah toggle, changelog's "N/A" flag,
   user-edit's "Aktif" flag). The .switch/.switch-slider pill toggle
   (running-texts.html) is a DIFFERENT, deliberately-kept component for
   "is this thing on" state — this is for "is this box ticked" state; the
   two look different on purpose, matching the two different questions
   they ask.
   --------------------------------------------------------------------- */

input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  min-width: 20px;
  border: 1.5px solid var(--border-color-strong);
  border-radius: 5px;
  background: var(--surface);
  cursor: pointer;
  position: relative;
  transition: background var(--transition-base), border-color var(--transition-base), transform var(--transition-fast);
  flex-shrink: 0;
}

input[type="checkbox"]:hover {
  border-color: var(--primary-color);
}

input[type="checkbox"]:active {
  transform: scale(0.9);
}

input[type="checkbox"]:checked {
  background: var(--primary-gradient);
  border-color: var(--primary-color);
}

input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ---------------------------------------------------------------------
   Status / feedback text
   --------------------------------------------------------------------- */

.error-message {
  color: var(--danger-color);
  font-size: 0.88rem;
  min-height: 1.3em;
}

.success-message {
  color: var(--success-color);
  font-size: 0.88rem;
  min-height: 1.3em;
}

/* ---------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border-color);
}

th {
  background: var(--surface-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

tr:hover td {
  background: var(--surface-muted);
}

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.74rem;
  font-weight: 700;
  transition: background var(--transition-base), color var(--transition-base);
}

/* status-online = device reachable = success. status-pending = device
   paired but not yet confirmed online = warning (needs attention, not
   yet "good"). status-offline stays neutral gray, not danger — an
   offline device isn't necessarily broken (could just be powered off
   overnight), so it's deliberately NOT painted as an error state; see
   the color-audit note this rule's comment replaces. */
.status-online {
  background: var(--success-color-bg);
  color: var(--success-color);
}

.status-offline {
  background: var(--gray-100);
  color: var(--text-muted);
}

.status-pending {
  background: var(--warning-color-bg);
  color: var(--warning-color);
}

.mosque-picker-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.mosque-picker-list li {
  padding: 14px 4px;
  border-bottom: 1px solid var(--border-color);
  transition: background var(--transition-base);
}

.mosque-picker-list li:hover {
  background: var(--surface-muted);
}

.mosque-picker-list li:active {
  background: var(--primary-color-light);
}

.mosque-picker-list a {
  text-decoration: none;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  display: block;
  transition: color var(--transition-fast);
}

.mosque-picker-list a:hover {
  color: var(--primary-color);
}

.mosque-picker-list .mosque-address {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---------------------------------------------------------------------
   Login
   --------------------------------------------------------------------- */

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

.login-card {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 36px;
  width: 340px;
  box-shadow: var(--shadow-md);
}

.login-card h1 {
  font-size: 1.35rem;
  margin-top: 0;
  text-align: center;
}

.login-card button {
  width: 100%;
  margin-top: 10px;
}

/* ---------- Media grid ---------- */

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.media-tile {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
  transition: border-color var(--transition-base), box-shadow var(--transition-base), transform var(--transition-base);
}

.media-tile:hover {
  border-color: var(--border-color-strong);
  box-shadow: var(--shadow-sm);
  transform: translateY(-2px);
}

.media-tile-preview {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
  background: var(--gray-100);
}

.media-tile-preview.video-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--text-muted);
}

.media-tile-info {
  padding: 10px 12px;
}

.media-tile-name {
  font-size: 0.85rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-tile-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.media-tile-actions {
  padding: 0 12px 12px;
}

.media-tile-actions button {
  width: 100%;
  font-size: 0.8rem;
  padding: 7px;
}

.media-tile-status {
  padding: 5px 12px;
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
}

/* processing = "working on it, nothing wrong yet" = info, not warning —
   the old warning/amber coloring made an in-progress upload look like it
   needed attention, which incorrectly matched the visual weight of the
   trial-expiring-soon banner below. */
.media-tile-status-processing {
  background: var(--info-color-bg);
  color: var(--info-color);
}

.media-tile-status-failed {
  background: var(--danger-color-bg);
  color: var(--danger-color);
  cursor: help;
}

/* "this item is live in the display rotation right now" — success, same
   family as .status-online, rather than the ad-hoc solid brand-green
   inline style it replaces (see media.html). */
.media-tile-status-active {
  background: var(--success-color-bg);
  color: var(--success-color);
}

/* ---------- Media card grid (media.html "Kelola Media") ----------
   Grid of cards — big thumbnail with a status overlay anchored to its
   bottom edge, actions below. Replaces the earlier horizontal-row layout;
   kept as a distinct class family (.media-card-*) rather than reusing
   .active-rotation-* or .media-tile-status, since neither was sized right
   for this shape (row = horizontal flex; tile-status = full-width bar that
   overlapped neighbors when reused loosely — see the overlay notes below). */
.media-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 8px;
}

.media-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.media-card:hover {
  border-color: var(--border-color-strong);
  box-shadow: var(--shadow-sm);
}

.media-card-thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--gray-100);
}

.media-card-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-card-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  color: var(--text-muted);
}

/* Reorder controls float in the thumbnail's top-right corner — a card grid
   has no left-hand column to anchor them to like the old row layout did. */
.media-card-reorder {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  z-index: 2;
}

.media-card-reorder button {
  padding: 3px 8px;
  font-size: 0.78rem;
  line-height: 1;
  min-width: 28px;
  box-shadow: var(--shadow-sm);
}

/* Status overlay anchored to the thumbnail's bottom edge — semi-transparent
   gradient so it reads on top of any image, without needing a separate
   full-width bar (that's what caused the earlier badge-overlap bug). */
.media-card-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 18px 8px 8px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.65), rgba(0, 0, 0, 0));
}

.media-card-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  color: #fff;
}

.media-card-badge-success {
  background: var(--success-color);
}

.media-card-badge-neutral {
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(2px);
}

.media-card-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.media-card-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.media-card-actions button {
  width: 100%;
  padding: 7px 10px;
  font-size: 0.82rem;
}

/* Compact inline pill — used by statusPillHtml() (PROCESSING/FAILED), sits
   inside .media-card-overlay alongside the active/inactive badge above.
   Deliberately separate from .media-tile-status (full-width bar meant for
   theme-template.html's picker) and from .media-card-badge (solid-color
   active/inactive state) — this one keeps the same semantic color families
   used everywhere else in this app. */
.media-status-pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.media-status-pill-success {
  background: var(--success-color-bg);
  color: var(--success-color);
}

.media-status-pill-neutral {
  background: var(--gray-100);
  color: var(--text-muted);
}

.media-status-pill-info {
  background: var(--info-color-bg);
  color: var(--info-color);
}

.media-status-pill-danger {
  background: var(--danger-color-bg);
  color: var(--danger-color);
  cursor: help;
}

/* Section divider between the active-rotation group and the inactive
   group within the same merged "Kelola Media" list — a plain heading-like
   label, not a full card boundary, since both groups now live inside one
   card. */
.media-group-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  padding: 4px 2px;
  margin-top: 4px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 8px;
}

.media-group-label:first-child {
  margin-top: 0;
}

.media-group-label-inactive {
  margin-top: 20px;
  color: var(--text-muted);
}

.progress-bar-track {
  width: 100%;
  height: 8px;
  background: var(--gray-100);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin: 10px 0;
}

.progress-bar-fill {
  height: 100%;
  background: var(--primary-color);
  width: 0%;
  transition: width 0.15s ease;
}

/* ---------- Toggle switch (pill) — see the doc comment on the custom
   checkbox rules above for how this differs intentionally from a
   checkbox. ---------- */

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: var(--gray-300);
  border-radius: 22px;
  transition: background var(--transition-base);
}

.switch-slider::before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  border-radius: 50%;
  transition: transform var(--transition-base);
  box-shadow: var(--shadow-sm);
}

.switch input:checked + .switch-slider {
  background: var(--primary-gradient);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(18px);
}

/* Pressed feedback (mousedown/touch) — a toggle that only ever animates
   on the checked/unchecked transition feels unresponsive the instant
   it's tapped, before that transition even starts. Widening the thumb
   instead of scaling it avoids fighting the translateX() above (a
   transform: scale(...) translateX(...) combo would need to duplicate
   the checked-state offset in both rules to not visually jump). */
.switch-slider:active::before {
  width: 20px;
}

.switch input:checked + .switch-slider:active::before {
  transform: translateX(14px);
}

/* ---------- Playlist ---------- */

.playlist-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.playlist-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.playlist-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  gap: 12px;
  background: var(--surface);
}

.playlist-item-info {
  flex: 1;
}

.playlist-item-actions {
  display: flex;
  gap: 8px;
}

.playlist-item-actions button {
  padding: 5px 12px;
  font-size: 0.8rem;
}

/* ---------- Running text ---------- */

.running-text-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
}

.running-text-content {
  flex: 1;
}

.running-text-content input {
  width: 100%;
}

.inline-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 24px;
}

.inline-form .form-row {
  flex: 1;
  margin-bottom: 0;
}

/* ---------- Modal (pairing code) ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 25, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 36px;
  width: 360px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.pairing-code-display {
  font-size: 3.5rem;
  font-weight: bold;
  letter-spacing: 0.3em;
  margin: 20px 0;
  color: var(--primary-color);
}

.pairing-countdown {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.pairing-countdown.expired {
  color: var(--danger-color);
  font-weight: 600;
}

.modal-close-btn {
  margin-top: 8px;
}

/* ---------- Changelog notification bell ---------- */

.changelog-bell {
  position: relative;
  background: transparent;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
  color: #fff;
}

.changelog-bell-badge {
  position: absolute;
  top: -2px;
  right: 0;
  background: var(--danger-color);
  color: #fff;
  border-radius: var(--radius-pill);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  line-height: 1.3;
}

.changelog-entry {
  border-bottom: 1px solid var(--border-color);
  padding: 14px 0;
}

.changelog-entry:last-of-type {
  border-bottom: none;
}

.changelog-entry h3 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.changelog-entry p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ---------- Device table extras ---------- */

.device-actions {
  display: flex;
  gap: 8px;
}

.device-actions button {
  padding: 5px 12px;
  font-size: 0.8rem;
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ---------- Location search (mosque-edit.html) ---------- */

.location-search-results {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  position: absolute;
  z-index: 20;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.location-search-results li {
  padding: 9px 14px;
  cursor: pointer;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--gray-100);
}

.location-search-results li:last-child {
  border-bottom: none;
}

.location-search-results li:hover,
.location-search-results li.active {
  background: var(--surface-muted);
}

.hidden {
  display: none !important;
}

/* Persistent trial-status strip, shown just under the topbar for every
   non-SUPER_ADMIN user of a TRIAL mosque. Amber while still running,
   red once trialExpiresAt has passed — same "small but clearly visible"
   intent as display-web's debug-badge conventions, just user-facing here. */
.trial-banner {
  padding: 10px 24px;
  font-size: 0.9rem;
  text-align: center;
}

.trial-banner-active {
  background: var(--warning-color-bg);
  color: var(--warning-color);
  border-bottom: 1px solid var(--warning-color-border);
}

.trial-banner-expired {
  background: var(--danger-color-bg);
  color: var(--danger-color);
  border-bottom: 1px solid var(--danger-color-border);
}

.subscription-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.74rem;
  font-weight: 700;
}

.subscription-badge-trial {
  background: var(--warning-color-bg);
  color: var(--warning-color);
}

.subscription-badge-active {
  background: var(--success-color-bg);
  color: var(--success-color);
}

.subscription-badge-expired,
.subscription-badge-suspended {
  background: var(--danger-color-bg);
  color: var(--danger-color);
}

/* =====================================================================
   Mobile responsive layer — additive only. Everything above this point
   is the original desktop-first styling and is left completely
   untouched; every rule below is scoped to `max-width: 768px` (a
   conventional phone/small-tablet breakpoint) so desktop (>768px)
   renders byte-for-byte the same as before this section existed.
   ===================================================================== */

/* ---------- Bottom navigation + "Lainnya" bottom sheet (nav.js) ----------
   Desktop keeps the existing horizontal <nav> inside .topbar unchanged —
   #bottom-nav/.more-sheet* are built by nav.js but only ever made visible
   below the 768px breakpoint (see the media query further down); at
   desktop widths they stay `display: none` and take up no space. */
.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  background: var(--primary-gradient);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow-md);
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px 10px;
  min-height: 56px;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.65);
  text-decoration: none;
  font-family: inherit;
  cursor: pointer;
  transition: color var(--transition-base), background var(--transition-base);
}

.bottom-nav-item:active {
  background: rgba(255, 255, 255, 0.08);
}

.bottom-nav-icon {
  width: 22px;
  height: 22px;
  display: block;
}

.bottom-nav-icon svg {
  width: 100%;
  height: 100%;
}

.bottom-nav-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* Active item highlighted with the same accent used for "current" state
   elsewhere in this app (e.g. .preset-card.selected's green) — icon AND
   label both switch to full-white/accent so it reads clearly against the
   dimmed (0.65 opacity) inactive items either side of it. The soft
   top-lit gradient pill behind it echoes the topbar/button gradient
   treatment instead of a flat highlight color, so "this is the active
   tab" reads as part of the same visual language as the rest of the
   brand-green surfaces. */
.bottom-nav-item.active {
  color: #ffffff;
  position: relative;
}

.bottom-nav-item.active::before {
  content: "";
  position: absolute;
  inset: 4px 6px;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0.04) 100%);
  z-index: -1;
}

.bottom-nav-item.active .bottom-nav-icon {
  color: #6fd88a;
}

/* ---------- "Lainnya" bottom sheet ---------- */

.more-sheet-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 25, 0.5);
  z-index: 210;
}

.more-sheet-overlay.open {
  display: block;
}

.more-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 211;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  max-height: 75vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  box-shadow: var(--shadow-lg);
}

.more-sheet.open {
  transform: translateY(0);
}

.more-sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--gray-300);
  margin: 10px auto 0;
}

.more-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 8px;
}

.more-sheet-header strong {
  font-size: 1rem;
  color: var(--text-primary);
}

.more-sheet-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.3rem;
  padding: 4px 8px;
  cursor: pointer;
}

.more-sheet-list {
  display: flex;
  flex-direction: column;
  padding: 4px 8px 24px;
}

.more-sheet-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 12px;
  min-height: 44px;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.98rem;
  background: transparent;
  border: none;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.more-sheet-item:active {
  background: var(--surface-muted);
}

.more-sheet-item.active {
  color: var(--primary-color);
  font-weight: 700;
  background: var(--primary-color-light);
}

.more-sheet-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.more-sheet-icon svg {
  width: 100%;
  height: 100%;
}

.more-sheet-item.active .more-sheet-icon {
  color: var(--primary-color);
}

.more-sheet-logout {
  margin-top: 8px;
  border-top: 1px solid var(--border-color);
  border-radius: 0;
  padding-top: 18px;
  color: var(--danger-color);
  font-weight: 600;
}

/* ---------- Responsive tables -> stacked cards ----------
   Applies to every plain <table> used for list data (Device, Kelola
   User) — a table with many narrow columns is the single worst pattern
   on a phone (forces horizontal scrolling to read a row). Each <td>'s
   `data-label` attribute (added in the HTML) supplies the field name as
   a generated ::before label, so the exact same table markup/JS render
   functions work unchanged on both desktop (real table) and mobile
   (stacked card) — no separate mobile-only render path to keep in sync. */

@media (max-width: 768px) {
  body {
    font-size: 16px;
  }

  /* Single .container rule (not split across two blocks) — the
     padding-bottom reserves room equal to the fixed bottom nav's own
     height (56px content + safe-area inset) so the LAST card/element on
     any page is never rendered underneath it; every page shares this via
     .container, so no per-page opt-in was needed. */
  .container {
    padding: 0 14px calc(56px + env(safe-area-inset-bottom, 0px) + 16px);
    margin: 16px auto;
  }

  .card {
    padding: 18px;
    border-radius: var(--radius-md);
  }

  .card h2 {
    font-size: 1.05rem;
  }

  /* Topbar: hide the desktop horizontal nav (replaced by #bottom-nav
     below). The user/email/logout cluster also collapses to just the
     bell — full email + role text wastes too much of a phone's top bar
     and wraps awkwardly; it's still reachable inside the "Lainnya" sheet. */
  .topbar {
    padding: 10px 14px;
  }

  .topbar h1 {
    font-size: 1rem;
  }

  .topbar > nav {
    display: none;
  }

  .topbar-user .topbar-user-text,
  .topbar-user #logout-btn {
    display: none;
  }

  .bottom-nav {
    display: flex;
  }

  /* Buttons/inputs: enforce the 44px minimum touch target and make sure
     text stays readable — desktop's tighter 8px/16px padding is a bit
     small to comfortably tap. */
  button, .btn {
    min-height: 44px;
    padding: 10px 16px;
    font-size: 1rem;
  }

  .device-actions button,
  .playlist-item-actions button,
  .media-tile-actions button {
    min-height: 40px;
  }

  .form-row input, .form-row select, .form-row textarea,
  input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]),
  select {
    min-height: 44px;
    font-size: 1rem;
  }

  input[type="checkbox"] {
    width: 22px;
    height: 22px;
    min-width: 22px;
  }

  input[type="checkbox"]:checked::after {
    left: 7px;
    top: 3px;
  }

  /* Two-column form rows (Latitude/Longitude, Nama PIC/No. HP) stack to
     one column — a phone screen is too narrow for two side-by-side
     inputs to stay comfortably tappable. */
  .form-row-inline {
    flex-direction: column;
    gap: 0;
  }

  .inline-form {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-form .form-row {
    margin-bottom: 14px;
  }

  /* Running text row: the desktop single-line layout (toggle - input -
     Simpan - Hapus all in one flex row) squeezes the text input down to
     2-3 visible characters on a phone once two buttons compete for the
     same line. Switching to wrap lets the toggle+input stay on their own
     first line (input given flex-basis: 100% so it always claims the
     full remaining width instead of shrinking) and the two buttons drop
     to a second line below — same markup, same JS, purely a flow change. */
  .running-text-row {
    flex-wrap: wrap;
    row-gap: 10px;
  }

  .running-text-content {
    flex-basis: 100%;
  }

  .running-text-row button {
    flex: 1;
    min-height: 40px;
  }

  /* Table -> card list. Header row is visually hidden (not removed —
     screen readers still get it) since each cell now carries its own
     label; each <tr> becomes a bordered card, each <td> a labeled row
     inside it. */
  table, thead, tbody, th, td, tr {
    display: block;
  }

  table {
    border: none;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  tbody tr {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    padding: 4px 14px;
  }

  tbody tr:hover td {
    background: transparent;
  }

  td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 0;
    border-bottom: 1px solid var(--gray-100);
    text-align: right;
  }

  tr td:last-child {
    border-bottom: none;
  }

  td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-secondary);
    text-align: left;
    flex-shrink: 0;
  }

  /* Action cells (buttons) read better left-aligned/stacked than
     right-aligned next to a label — the label-as-::before trick only
     makes sense for plain text/badge cells. */
  td[data-label="Aksi"] {
    justify-content: flex-start;
  }

  td[data-label="Aksi"]::before {
    display: none;
  }

  .device-actions,
  .playlist-item-actions {
    flex-wrap: wrap;
    width: 100%;
  }

  .device-actions button {
    flex: 1;
    min-width: 100px;
  }

  /* Modals: full-width on small screens instead of a fixed 320-360px
     box that leaves awkward side margins on a phone. */
  .modal-box {
    width: 92vw;
    max-width: 400px;
    padding: 28px 22px;
  }

  .login-card {
    width: 90vw;
    max-width: 340px;
  }

  /* Media grid: fewer/narrower columns so tiles stay a comfortable tap
     size instead of shrinking to the desktop 160px minimum. */
  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
  }

  /* Media card grid: 1-2 narrower columns on phones instead of the desktop
     180px minimum, and actions stay stacked full-width for comfortable
     44px tap targets. */
  .media-card-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }

  .media-card-actions button {
    min-height: 40px;
  }
}
