/* Almarai covers Arabic script only (unicode-range), so Latin text keeps the system font. */
@font-face {
  font-family: 'Almarai';
  font-weight: 400;
  font-display: swap;
  src: url('fonts/almarai-400.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: 'Almarai';
  font-weight: 700;
  font-display: swap;
  src: url('fonts/almarai-700.woff2') format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+FB50-FDFF, U+FE70-FEFC;
}

:root {
  /* TUNE: Control the (dark theme colours). Crimson accent on neutral graphite. */
  --accent: #E5364B;
  --heading: #F4F4F5;
  --ink: #D8D8DB;
  --ink-muted: #8E8E94;
  --bg: #09090A;
  --surface: #121213;
  --surface-raised: #1A1A1C;
  --line: #2B2B2E;
  --grid-line: rgba(255, 255, 255, 0.022);
  --alert: #F0605A;
  --c: var(--ink-muted);
  /* TUNE: Control the (number font). Clock, counters and times. */
  --mono: 'Cascadia Mono', Consolas, 'Courier New', monospace;
}

[data-theme='light'] {
  /* TUNE: Control the (light theme colours). Brand: Teal accent, Dark Navy headings, Warm Black body text. */
  --accent: #00A7B5;
  --heading: #20264C;
  --ink: #4B4845;
  --ink-muted: #7A7672;
  --bg: #EEF0F2;
  --surface: #FFFFFF;
  --surface-raised: #F6F7F8;
  --line: #D5D7DB;
  --grid-line: rgba(32, 38, 76, 0.035);
  --alert: #C23B36;
}

* { box-sizing: border-box; margin: 0; border-radius: 0; }

html {
  /* TUNE: Control the (overall scale). 1rem is 16px on a 1920x1080 screen and grows with the screen. */
  font-size: min(0.8333vw, 1.4815vh);
  height: 100%;
}

body {
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  background-color: var(--bg);
  /* TUNE: Control the (background grid). Size of the faint grid squares. */
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 3rem 3rem;
  /* TUNE: Control the (fonts). Almarai for Arabic, the system font for Latin. */
  font-family: 'Almarai', 'Segoe UI', Tahoma, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  padding: 0.9rem 1rem 0;
  gap: 0.9rem;
}

.number { font-family: var(--mono); font-variant-numeric: tabular-nums; direction: ltr; }

.icon,
.event-icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
}
.icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  color: var(--c);
}

.top {
  display: flex;
  align-items: stretch;
  gap: 1.2rem;
  flex: none;
  height: 4rem;
}

.brand { display: flex; align-items: center; gap: 0.9rem; }
.brand-logo { width: 3rem; height: 3rem; flex: none; }
h1 { font-size: 1.75rem; font-weight: 700; color: var(--heading); white-space: nowrap; }

.sample-badge {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--heading);
  border: 1px solid var(--heading);
  padding: 0.15rem 0.6rem;
  white-space: nowrap;
}
.sample-badge[data-status='connected'] { display: none; }
.sample-badge[data-status='offline'],
.sample-badge[data-status='sourceError'] { background: var(--alert); border-color: var(--alert); color: #FFFFFF; }

.filter {
  display: flex;
  margin-inline: auto;
  background: var(--surface);
  border: 1px solid var(--line);
}
.filter button {
  display: grid;
  grid-template-columns: auto auto auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 0.8rem;
  font: inherit;
  color: var(--ink-muted);
  background: none;
  border: 0;
  border-inline-start: 1px solid var(--line);
  padding-inline: 0.8rem 1.1rem;
  cursor: pointer;
  white-space: nowrap;
  text-align: start;
}
.filter button:first-child { border-inline-start: 0; }
.filter button:hover { color: var(--heading); background: var(--surface-raised); }
.filter .tile {
  grid-row: 1 / 3;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
}
.filter .name { font-size: 0.85rem; font-weight: 700; align-self: end; }
.filter .count {
  grid-column: 2;
  grid-row: 2;
  align-self: start;
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--heading);
  direction: ltr;
  text-align: start;
}
.filter .spark {
  grid-column: 3;
  grid-row: 1 / 3;
  /* TUNE: Control the (activity sparkline size). */
  width: 5.5rem;
  height: 2rem;
  color: var(--c);
  opacity: 0.55;
}
.filter button.active {
  color: var(--heading);
  background: color-mix(in srgb, var(--c) 20%, var(--surface));
}
.filter button.active .spark { opacity: 1; }

.tools { display: flex; align-items: center; gap: 0.4rem; }
.toggle {
  display: grid;
  place-items: center;
  width: 2.6rem;
  height: 2.6rem;
  font-size: 1.1rem;
  color: var(--ink-muted);
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: pointer;
}
.toggle[hidden] { display: none; }
/* The technical status bar is for the admin user. A guest sees the dashboard only. */
[data-role='guest'] .statusbar { display: none; }
[data-role='guest'] body { padding-bottom: 0.9rem; }
.toggle .icon { color: inherit; }
.toggle:hover { border-color: var(--accent); color: var(--heading); }
.toggle.small { width: 1.9rem; height: 1.9rem; font-size: 0.95rem; }

button:focus-visible,
.gutter:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  line-height: 1.15;
  padding-inline-start: 1.2rem;
  border-inline-start: 1px solid var(--line);
}
#clock { font-family: var(--mono); font-size: 2rem; font-weight: 700; color: var(--heading); direction: ltr; }
#date { font-size: 0.85rem; color: var(--ink-muted); }

.grid {
  --gutter: 0.9rem;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-areas:
    'live g1 bubbles g2 feed'
    'live g1 g3      g2 feed'
    'live g1 cloud   g2 feed';
}

.gutter {
  display: grid;
  place-items: center;
  touch-action: none;
}
.gutter-col { cursor: col-resize; }
.gutter-row { cursor: row-resize; }
.gutter::before {
  content: '';
  width: 0.2rem;
  height: 1.1rem;
  opacity: 0.6;
  background: linear-gradient(to bottom, var(--ink-muted) 0.2rem, transparent 0.2rem) 0 0 / 0.2rem 0.45rem repeat-y;
}
.gutter-row::before {
  width: 1.1rem;
  height: 0.2rem;
  background: linear-gradient(to right, var(--ink-muted) 0.2rem, transparent 0.2rem) 0 0 / 0.45rem 0.2rem repeat-x;
}
.gutter:hover { background: var(--line); }
.gutter:hover::before { opacity: 1; }

/* Corner brackets frame each panel. They are drawn with borders, not shadows. */
.panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.panel::before,
.panel::after {
  content: '';
  position: absolute;
  width: 0.75rem;
  height: 0.75rem;
  border: 0 solid var(--accent);
  pointer-events: none;
}
.panel::before { top: -1px; inset-inline-start: -1px; border-top-width: 2px; border-inline-start-width: 2px; }
.panel::after { bottom: -1px; inset-inline-end: -1px; border-bottom-width: 2px; border-inline-end-width: 2px; }
.live-panel { grid-area: live; }
.bubbles-panel { grid-area: bubbles; }
.cloud-panel { grid-area: cloud; }
.feed-panel { grid-area: feed; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex: none;
  min-height: 2.7rem;
  padding: 0.35rem 0.9rem;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--line);
}
h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--heading);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  white-space: nowrap;
}
.marker { width: 0.55rem; height: 0.55rem; background: var(--accent); flex: none; }
.marker.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }

.empty {
  position: absolute;
  inset: 2.7rem 0 0;
  display: grid;
  place-items: center;
  color: var(--ink-muted);
  font-size: 1rem;
}
.empty[hidden] { display: none; }

.live-controls { display: flex; align-items: center; gap: 0.5rem; }
.segmented { display: flex; border: 1px solid var(--line); }
.segmented button,
.live-channels button {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-muted);
  background: none;
  border: 0;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  white-space: nowrap;
}
.segmented button { font-family: var(--mono); }
.segmented button + button { border-inline-start: 1px solid var(--line); }
.live-channels {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex: none;
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid var(--line);
}
.live-channels button { border: 1px solid var(--line); }
.segmented button:hover,
.live-channels button:hover { color: var(--heading); }
.segmented button[aria-pressed='true'],
.live-channels button[aria-pressed='true'] { background: var(--accent); color: #FFFFFF; border-color: var(--accent); }

.live { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 1px; background: #000000; }
.live-slot { position: relative; flex: 1; min-height: 0; background: #000000; }
.live-slot iframe { display: block; width: 100%; height: 100%; border: 0; }
.live-label {
  position: absolute;
  top: 0.4rem;
  inset-inline-start: 0.4rem;
  padding: 0.1rem 0.45rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: #FFFFFF;
  background: var(--accent);
  pointer-events: none;
}

.bubbles { flex: 1; min-height: 0; position: relative; overflow: hidden; }

/* The topic circles are the one exception to the zero border-radius rule: the brief asks for circles. */
.bubble {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 50%;
  /* TUNE: Control the (sphere shading). Highlight position, then highlight, body and edge colours. */
  background: radial-gradient(
    circle at 34% 26%,
    color-mix(in srgb, var(--c) 50%, white) 0%,
    color-mix(in srgb, var(--c) 82%, black) 40%,
    color-mix(in srgb, var(--c) 32%, black) 100%
  );
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.25;
  font-weight: 700;
  color: #FFFFFF;
  will-change: transform;
  overflow: hidden;
}
/* min-content puts one word per line, which is what the font-size calculation in views.js assumes. */
.bubble-label { width: min-content; max-width: 86%; }
.bubble-count {
  font-family: var(--mono);
  font-size: 0.75em;
  color: #FFFFFF;
  opacity: 0.85;
}
.bubble.tiny > * { display: none; }

.zone-label {
  position: absolute;
  bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transform: translateX(-50%);
  padding: 0.15rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--surface-raised);
  border: 1px solid var(--line);
  white-space: nowrap;
  transition: left 0.6s ease;
}
.zone-label[hidden] { display: none; }

.cloud { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.word {
  position: absolute;
  top: 0;
  left: 0;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  color: var(--c);
  transition: transform 1.4s cubic-bezier(0.3, 0.7, 0.2, 1), font-size 1.4s ease, opacity 0.8s ease, color 0.8s ease;
}

.feed {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.post {
  flex: none;
  display: flex;
  gap: 0.8rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--line);
  border-inline-start: 0.2rem solid transparent;
}
.post > .event-icon { width: 1.6rem; height: 1.6rem; margin-top: 0.15rem; }
.post-content { flex: 1; min-width: 0; }
/* TUNE: Control the (new post highlight). How long a new post stays marked. */
.post.enter { animation: enter 0.45s ease-out, fresh 20s linear; }
@keyframes enter { from { opacity: 0; transform: translateY(-0.8rem); } }
@keyframes fresh {
  0%, 85% { border-inline-start-color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, transparent); }
  100% { border-inline-start-color: transparent; background: transparent; }
}
.post header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}
.author { font-weight: 700; color: var(--heading); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.handle { color: var(--ink-muted); direction: ltr; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ago { margin-inline-start: auto; color: var(--accent); font-weight: 700; white-space: nowrap; }
.post time,
.post .time { font-family: var(--mono); font-size: 0.8rem; color: var(--ink-muted); text-decoration: none; direction: ltr; }
.post a.time:hover { color: var(--heading); text-decoration: underline; }
.post p { font-size: 1rem; line-height: 1.55; color: var(--ink); overflow-wrap: anywhere; }

.statusbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 1.6rem;
  height: 2rem;
  margin-inline: -1rem;
  padding-inline: 1rem;
  font-size: 0.8rem;
  color: var(--ink-muted);
  background: var(--surface);
  border-top: 1px solid var(--line);
  white-space: nowrap;
}
.sb-item { display: flex; align-items: center; gap: 0.5rem; }
.sb-item[hidden] { display: none; }
.sb-item b { color: var(--heading); font-weight: 700; }
/* TUNE: Control the (status lights). Green is working, yellow is an issue, red is offline. */
.sb-light { width: 0.7rem; height: 0.7rem; background: var(--ink-muted); }
.sb-light[data-state='ok'] { background: #3ECF8E; animation: pulse 1.6s ease-in-out infinite; }
.sb-light[data-state='issue'] { background: #F2C14E; animation: pulse 0.9s ease-in-out infinite; }
.sb-light[data-state='off'] { background: var(--alert); animation: pulse 0.9s ease-in-out infinite; }

.login {
  margin: auto;
  width: 24rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 2rem;
}
.login .brand { justify-content: center; margin-bottom: 0.5rem; }
.login label { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.95rem; font-weight: 700; color: var(--heading); }
.login input {
  font: inherit;
  font-size: 1.1rem;
  color: var(--heading);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 0.65rem 0.8rem;
}
.login input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.login button {
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  color: #FFFFFF;
  background: var(--accent);
  border: 0;
  padding: 0.75rem;
  cursor: pointer;
}
.login button:disabled { opacity: 0.6; cursor: wait; }
.login-error { min-height: 1.4rem; font-size: 0.95rem; font-weight: 700; color: var(--alert); }

@media (prefers-reduced-motion: reduce) {
  .word, .post.enter, .pulse, .sb-light, .zone-label { transition: none; animation: none; }
}
