/* tikm - mobile first. Base styles target a phone; wider layouts are added with min-width queries. */

:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --soft: #f3f5f7;
  --ink: #161a1e;
  --muted: #667085;
  --line: #dfe3e8;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e2f4f1;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --dark: #0f1417;
  --radius: 14px;
  --tabbar-h: 60px;
  --side-w: 236px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .05);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0e10;
    --surface: #151a1e;
    --soft: #1d2328;
    --ink: #eef1f4;
    --muted: #9aa4af;
    --line: #2a3138;
    --accent: #2dd4bf;
    --accent-ink: #04201c;
    --accent-soft: #11332f;
    --danger: #ff8a80;
    --danger-soft: #3a1815;
    --warn: #f5c451;
    --warn-soft: #36290a;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  overflow-wrap: anywhere;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 20px; line-height: 1.2; }
h2 { font-size: 16px; line-height: 1.3; }
small, .small { font-size: 12.5px; }
.muted { color: var(--muted); }
.center { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 16px; }
.center.more { min-height: 0; padding: 18px 0; }
.error { color: var(--danger); font-size: 14px; }

/* ---- controls (inputs are 16px so iOS never zooms; targets are >= 44px) ---- */

button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 16px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; padding: 0; flex: none; accent-color: var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  color: var(--ink);
  touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.ghost { background: var(--soft); border-color: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }

.iconBtn, .roundBtn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}
.ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.field { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
.field > input, .field > select, .field > textarea { color: var(--ink); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); cursor: pointer; }
.check small { color: var(--muted); }
.checks { display: grid; gap: 4px; border: 0; padding: 0; margin: 0; }
.checks legend { color: var(--muted); font-size: 14px; padding: 0; margin-bottom: 4px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.form { display: grid; gap: 14px; }

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 1px 10px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.live { background: var(--accent); color: var(--accent-ink); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  min-width: 0;
}
.cardHead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; min-height: 36px; }
.cardHead select { width: auto; min-height: 36px; padding: 4px 10px; font-size: 14px; }

.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- shell ---- */

.brand { display: flex; align-items: center; gap: 12px; }
.brand small { display: block; color: #9aa4af; }
.mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: #e63b57; color: #fff; font-weight: 800; font-size: 22px;
}

.side { display: none; }
.content { min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(8px + var(--safe-top)) 14px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.topActions { display: flex; gap: 8px; }
#views { padding: 4px 14px 24px; display: grid; }
.view { display: grid; gap: 14px; align-content: start; min-width: 0; }
.cols { display: grid; gap: 14px; }

.banner, .activity {
  margin: 0 14px 10px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
}
.banner { background: var(--warn-soft); color: var(--warn); }
.activity {
  display: flex; align-items: center; gap: 10px;
  background: var(--accent-soft); color: var(--accent);
  border: 0; width: calc(100% - 28px); text-align: left; cursor: pointer;
}
.activity .spinner { width: 16px; height: 16px; border-width: 2px; flex: none; }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  min-height: 48px;
}
.tab.active { color: var(--accent); font-weight: 600; }

/* ---- dashboard ---- */

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric { padding: 14px; }
.metric span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.metric strong { font-size: 24px; line-height: 1.1; }
.metric.alert strong { color: var(--danger); }

.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: 64px 1fr 36px; gap: 10px; align-items: center; font-size: 13px; }
.bar i { display: block; height: 10px; border-radius: 999px; background: var(--accent); min-width: 4px; }
.bar .track { background: var(--soft); border-radius: 999px; overflow: hidden; }
.bar span:last-child { text-align: right; color: var(--muted); }

.list { display: grid; }
.item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line); min-height: 56px;
  width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; color: inherit;
}
.list > .item:last-child { border-bottom: 0; padding-bottom: 0; }
button.item { cursor: pointer; }
.item .main { min-width: 0; display: grid; gap: 2px; }
.item .main small { color: var(--muted); }

.strip { display: grid; grid-auto-flow: column; grid-auto-columns: 42%; gap: 10px; overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 4px; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.strip .tile { scroll-snap-align: start; }

/* ---- video tiles ---- */

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  aspect-ratio: 9 / 14;
  border: 0;
  border-radius: 12px;
  overflow: hidden;
  background: #1b2126;
  color: #fff;
  cursor: pointer;
  text-align: left;
}
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.tile .shade {
  position: absolute; inset: auto 0 0 0;
  padding: 28px 10px 9px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .78));
  display: grid; gap: 1px;
}
.tile strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile small { color: rgba(255, 255, 255, .8); font-size: 11.5px; }
.tile .badge {
  position: absolute; top: 8px; left: 8px;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: rgba(0, 0, 0, .55); color: #fff;
}
.tile .fav { position: absolute; top: 6px; right: 8px; color: #ff5d7a; font-size: 16px; text-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
.tile.noFile { display: grid; place-items: center; background: var(--soft); color: var(--muted); }

/* ---- library ---- */

.filters { display: grid; gap: 8px; }
.filterRow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pillCheck { border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: var(--surface); }
.resultCount { font-size: 13px; }

/* ---- profiles ---- */

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cards { display: grid; gap: 12px; }
.profileCard { display: grid; gap: 12px; }
.profileCard h2 { font-size: 18px; }
.profileTop { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div { background: var(--soft); border-radius: 10px; padding: 8px 10px; }
.stats b { display: block; font-size: 16px; }
.stats span { color: var(--muted); font-size: 12px; }
.actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.switch { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; color: var(--muted); font-size: 13px; }
.switch input { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; min-height: 0; padding: 0; border-radius: 999px; border: 0; background: var(--line); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }

/* ---- runs / logs ---- */

pre.log {
  margin: 0; padding: 12px; max-height: 50vh; overflow: auto;
  background: #0f1417; color: #d7dee6; border-radius: 10px;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
pre.log .warn { color: #f5c451; }
pre.log .error { color: #ff8a80; font-size: inherit; }
.progress { height: 10px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.kv { display: grid; gap: 10px; }
.kv > div { display: flex; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.kv > div:last-child { border-bottom: 0; padding-bottom: 0; }
.kv span:first-child { color: var(--muted); flex: none; }
.kv span:last-child { text-align: right; }

/* ---- sign-in ---- */

.loginCard { width: min(380px, 100%); display: grid; gap: 16px; }
.loginCard .brand { justify-content: center; }
.loginCard .brand strong { font-size: 22px; }

/* ---- dialogs: bottom sheet on phones, centered card on larger screens ---- */

dialog {
  border: 0; padding: 0; color: var(--ink); background: var(--surface);
  width: 100%; max-width: 100%; max-height: 92vh; max-height: 92dvh;
  margin: auto 0 0; border-radius: 18px 18px 0 0;
  overflow: auto; overscroll-behavior: contain;
}
dialog::backdrop { background: rgba(5, 8, 10, .6); }
dialog[open] { animation: sheetIn .18s ease-out; }
@keyframes sheetIn { from { transform: translateY(24px); opacity: 0; } }
.sheetBody { display: grid; gap: 14px; padding: 18px 16px calc(18px + var(--safe-bottom)); }
.sheetHead { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
dialog.sheet.small { max-width: 420px; margin: auto; border-radius: 18px; }
.player { width: 100%; max-height: 62vh; max-height: 62dvh; aspect-ratio: 9 / 16; object-fit: contain; background: #000; border-radius: 12px; justify-self: center; }

#toasts { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); z-index: 100; display: grid; gap: 8px; pointer-events: none; justify-items: center; }
.toast { pointer-events: auto; max-width: 440px; padding: 11px 16px; border-radius: 12px; background: #20272d; color: #fff; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .3); animation: sheetIn .2s ease-out; }
.toast.bad { background: #8f1f16; }

/* ---- feed: fills the screen above the tab bar ---- */

.feedView {
  position: fixed;
  inset: 0;
  z-index: 60;  /* above the tab bar and sidebar: the feed owns the whole screen */
  display: block;
  background: #050505;
}
body.inFeed .topbar, body.inFeed .banner, body.inFeed .activity, body.inFeed .tabbar, body.inFeed .side { display: none; }
body.inFeed { padding: 0; overflow: hidden; }
body.inFeed #toasts { bottom: calc(16px + var(--safe-bottom)); z-index: 100; }
.feedRail {
  height: 100%;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  overscroll-behavior-y: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.feedRail::-webkit-scrollbar { display: none; }
.feedItem {
  position: relative;
  height: 100%;
  display: grid;
  place-items: center;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  background: #050505;
}
.feedItem video { width: 100%; height: 100%; object-fit: cover; background: #050505; }
.feedOverlay {
  position: absolute; left: 14px; right: 70px; bottom: calc(22px + var(--safe-bottom));
  color: #fff; pointer-events: none; display: grid; gap: 3px;
  text-shadow: 0 2px 16px rgba(0, 0, 0, .8);
}
.feedOverlay strong { font-size: 17px; }
.feedOverlay span { font-size: 12.5px; color: rgba(255, 255, 255, .8); }
.feedOverlay p { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.feedFav {
  position: absolute; right: 12px; bottom: calc(26px + var(--safe-bottom)); z-index: 2;
  background: rgba(0, 0, 0, .45); color: #fff; border-color: rgba(255, 255, 255, .2);
}
.feedFav.on { color: #ff5d7a; }
.feedItem .videoStatus { position: absolute; left: 14px; bottom: calc(100px + var(--safe-bottom)); color: rgba(255, 255, 255, .85); font-size: 12px; }
.feedItem .playHint {
  position: absolute; inset: 0; display: none; place-items: center; pointer-events: none;
}
.feedItem.paused .playHint { display: grid; }
.playHint svg { width: 72px; height: 72px; fill: rgba(255, 255, 255, .85); filter: drop-shadow(0 2px 12px rgba(0, 0, 0, .6)); }
.feedEmpty { height: 100%; display: grid; place-items: center; color: #fff; text-align: center; padding: 24px; }
.feedBtn {
  position: absolute; top: calc(10px + var(--safe-top)); right: 12px; z-index: 5;
  background: rgba(8, 8, 8, .7); color: #fff; border-color: rgba(255, 255, 255, .2);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
}
.feedAudio { right: 64px; }
.feedFs { right: 116px; }
.feedBack { right: auto; left: 12px; }
.feedFilters {
  position: absolute; top: calc(62px + var(--safe-top)); left: 12px; right: 12px; z-index: 5;
  display: grid; gap: 8px; padding: 10px; max-width: 360px; margin-left: auto;
  border: 1px solid rgba(255, 255, 255, .18); border-radius: 14px;
  background: rgba(10, 10, 10, .88); color: #fff;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
}
.feedFilters input, .feedFilters select { background: rgba(32, 32, 32, .95); color: #fff; border-color: rgba(255, 255, 255, .2); }

/* ---- >= 600px: roomier ---- */

@media (min-width: 600px) {
  #views { padding-inline: 20px; }
  .topbar, .banner, .activity { margin-inline: 0; }
  .topbar { padding-inline: 20px; }
  .banner, .activity { margin-inline: 20px; }
  .activity { width: calc(100% - 40px); }
  .metrics { grid-template-columns: repeat(4, 1fr); }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .strip { grid-auto-columns: 24%; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .filters { grid-template-columns: 1fr; }
  .filterRow { grid-template-columns: 1fr 1fr; }
  dialog { max-width: 560px; margin: auto; border-radius: 18px; }
  .feedItem video { max-width: 520px; object-fit: contain; }
  .feedOverlay { left: max(14px, calc(50% - 246px)); right: max(70px, calc(50% - 190px)); }
  .feedFav { right: max(12px, calc(50% - 250px)); }
}

/* ---- >= 900px: sidebar layout ---- */

@media (min-width: 900px) {
  body { padding-bottom: 0; padding-left: var(--side-w); }
  .tabbar { display: none; }
  .side {
    position: fixed; inset: 0 auto 0 0; width: var(--side-w);
    display: flex; flex-direction: column; gap: 24px;
    padding: 20px 14px; background: var(--dark); color: #fff; z-index: 25;
  }
  .side nav { display: grid; gap: 6px; }
  .side .tab {
    display: flex; justify-content: flex-start; gap: 12px;
    padding: 0 12px; min-height: 44px; border-radius: 10px;
    font-size: 15px; color: #cbd3dc;
  }
  .side .tab:hover { background: #1c2329; }
  .side .tab.active { background: #1f2a30; color: #fff; }
  .sideFoot { margin-top: auto; color: #9aa4af; font-size: 12px; display: grid; gap: 6px; }
  #settingsBtn { display: none; }
  .topbar { padding-top: 16px; background: transparent; }
  h1 { font-size: 24px; }
  #views { padding: 4px 28px 32px; max-width: 1280px; }
  .topbar { padding-inline: 28px; }
  .banner, .activity { margin-inline: 28px; }
  .activity { width: calc(100% - 56px); }
  .cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); }
  .strip { grid-auto-columns: 168px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
  .filters { grid-template-columns: 1.4fr 2fr 2fr; align-items: center; }
  .filterRow { grid-template-columns: 1fr 1fr; }
  #toasts { bottom: 20px; }
  .actions { grid-template-columns: repeat(4, auto); justify-content: start; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
