:root {
  color-scheme: light;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --ink: #17211b;
  --muted: #66756c;
  --line: #dfe8e2;
  --accent: #166534;
  --accent-strong: #104d28;
  --danger: #b42318;
  --shadow: 0 12px 40px rgba(23, 33, 27, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

.public-home-body .topbar {
  display: none;
}

.public-home-body .container {
  width: 100%;
  min-height: 100vh;
  margin: 0;
}

.public-home {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
}

.public-home p {
  margin: 0;
  color: var(--ink);
  font-size: clamp(20px, 3vw, 34px);
  font-weight: 800;
}

.admin-version {
  margin: -28px auto 28px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px clamp(18px, 4vw, 48px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0;
}

nav {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.container {
  width: min(1440px, calc(100% - 32px));
  margin: 34px auto 56px;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

h1, h2, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1.08;
}

h2 {
  font-size: 18px;
}

p {
  color: var(--muted);
}

.panel, .auth-panel, .metrics article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  margin-bottom: 22px;
  padding: 22px;
}

.analytics-panel {
  padding: 24px;
}

.analytics-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.analytics-head h2 {
  margin-bottom: 4px;
}

.analytics-head p {
  margin-bottom: 0;
}

.range-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbf9;
}

.range-tabs button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.range-tabs button:hover,
.range-tabs button.active {
  background: #ffffff;
  color: var(--accent);
  box-shadow: 0 1px 6px rgba(23, 33, 27, 0.08);
}

.chart-wrap {
  height: 360px;
}

.chart-wrap canvas {
  height: 100%;
}

.top-usage-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 20px;
}

.top-usage-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfdfc;
}

.top-usage-grid h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.top-list {
  display: grid;
  gap: 8px;
}

.top-list-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
}

.top-list-row:hover {
  border-color: var(--line);
  background: #fff;
  text-decoration: none;
}

.rank {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #e9f2ec;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
}

.top-item-main {
  min-width: 0;
}

.top-item-main strong,
.top-item-main small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-item-main small {
  color: var(--muted);
  font-size: 12px;
}

.top-count {
  font-weight: 900;
}

.narrow {
  max-width: 720px;
}

.auth-panel {
  max-width: 430px;
  margin: 8vh auto;
  padding: 30px;
}

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

.metrics article {
  padding: 20px;
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 14px;
}

.metrics strong {
  display: block;
  margin-top: 6px;
  font-size: 32px;
}

.grid-two {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 22px;
}

.stack {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  color: var(--ink);
  font: inherit;
}

textarea {
  width: 260px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}

.copy-code {
  cursor: pointer;
}

.copy-message {
  display: block;
  min-height: 18px;
  margin-top: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

input:focus {
  outline: 3px solid rgba(22, 101, 52, 0.16);
  border-color: var(--accent);
}

.editable-target {
  border-color: #9dccf4;
  background: #edf7ff;
}

.editable-target:focus {
  outline-color: rgba(37, 99, 235, 0.18);
  border-color: #3484d6;
  background: #ffffff;
}

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:hover, .button:hover {
  background: var(--accent-strong);
  text-decoration: none;
}

.button.secondary {
  background: #e9f2ec;
  color: var(--accent);
}

.small {
  min-height: 34px;
  padding: 0 12px;
}

.ghost, .link-button {
  min-height: auto;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}

.ghost:hover, .link-button:hover {
  background: transparent;
  text-decoration: underline;
}

.danger {
  color: var(--danger);
}

.inline {
  display: inline;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.alert {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid #f0b5ad;
  border-radius: 8px;
  background: #fff1ef;
  color: var(--danger);
  font-weight: 700;
}

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

.filter-bar {
  margin-bottom: 16px;
  max-width: 520px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1040px;
}

th, td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.truncate {
  max-width: 460px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  min-width: 168px;
  white-space: nowrap;
}

.actions .inline {
  display: inline-flex;
}

.admin-note {
  display: block;
  margin-bottom: 3px;
  color: var(--ink);
}

.usage-line {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.qr-download, .icon-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  cursor: pointer;
}

button.icon-action {
  min-height: 36px;
  appearance: none;
  font: inherit;
}

.qr-download:hover, .icon-action:hover {
  border-color: var(--accent);
  background: #edf7ff;
  color: var(--accent);
  text-decoration: none;
}

.icon-action.danger {
  color: var(--danger);
}

.icon-action.danger:hover {
  border-color: var(--danger);
  background: #fff1ef;
  color: var(--danger);
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
}

.status.on {
  background: #e6f6ec;
  color: var(--accent);
}

.status.off {
  background: #f2f4f3;
  color: var(--muted);
}

.empty {
  color: var(--muted);
  text-align: center;
}

canvas {
  width: 100%;
  height: 300px;
}

.mini-list {
  display: grid;
  gap: 10px;
}

.mini-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.video-shell {
  display: grid;
  gap: 12px;
  min-height: calc(100vh - 120px);
  align-content: center;
}

.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 0;
  background: #0e1511;
  box-shadow: none;
}

.video-frame iframe, .video-frame video {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.video-frame iframe {
  opacity: 0;
}

.video-frame iframe.active {
  opacity: 1;
}

.video-play {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  min-height: 100%;
  border-radius: 0;
  background:
    linear-gradient(rgba(14, 21, 17, 0.18), rgba(14, 21, 17, 0.28)),
    var(--video-poster, linear-gradient(135deg, #102218, #21352a));
  background-position: center;
  background-size: cover;
  color: #fff;
}

.video-play span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: clamp(74px, 9vw, 108px);
  height: clamp(74px, 9vw, 108px);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.35);
  font-size: clamp(28px, 4vw, 44px);
  animation: playPulse 1.7s ease-out infinite;
}

.video-play i {
  margin-left: 0.12em;
}

.safevideo-footer {
  color: #8b9690;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

@keyframes playPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.34);
  }
  70% {
    transform: scale(1.04);
    box-shadow: 0 0 0 22px rgba(255, 255, 255, 0);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(255, 255, 255, 0);
  }
}

.embed-body {
  margin: 0;
  background: #0e1511;
}

.embed-container {
  width: 100%;
  margin: 0;
}

.embed-shell {
  position: relative;
  width: 100%;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #0e1511;
}

.embed-frame {
  border-radius: 0;
  box-shadow: none;
}

.embed-brand {
  position: absolute;
  right: 14px;
  bottom: 10px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 12px;
  font-weight: 700;
}

@media (max-width: 760px) {
  .topbar, .page-head {
    align-items: stretch;
    flex-direction: column;
  }

  .analytics-head {
    flex-direction: column;
  }

  .range-tabs {
    width: 100%;
    overflow-x: auto;
  }

  .range-tabs button {
    flex: 1 0 auto;
  }

  .chart-wrap {
    height: 300px;
  }

  .top-usage-grid {
    grid-template-columns: 1fr;
  }

  .metrics, .grid-two {
    grid-template-columns: 1fr;
  }

  nav {
    gap: 12px;
  }
}

@media (max-width: 1180px) {
  .table-wrap {
    overflow-x: visible;
  }

  #shortlinks-table, #safevideos-table {
    min-width: 0;
  }

  #shortlinks-table thead, #safevideos-table thead {
    display: none;
  }

  #shortlinks-table, #shortlinks-table tbody, #shortlinks-table tr, #shortlinks-table td,
  #safevideos-table, #safevideos-table tbody, #safevideos-table tr, #safevideos-table td {
    display: block;
    width: 100%;
  }

  #shortlinks-table tr, #safevideos-table tr {
    padding: 16px 0;
    border-bottom: 1px solid var(--line);
  }

  #shortlinks-table td, #safevideos-table td {
    display: grid;
    grid-template-columns: minmax(96px, 140px) minmax(0, 1fr);
    gap: 14px;
    padding: 7px 0;
    border-bottom: 0;
  }

  #shortlinks-table td::before, #safevideos-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
  }

  #shortlinks-table td:first-child, #safevideos-table td:first-child {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  #shortlinks-table td:first-child::before, #safevideos-table td:first-child::before {
    content: none;
  }

  #shortlinks-table .truncate, #safevideos-table .truncate {
    max-width: none;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  #shortlinks-table .actions, #safevideos-table .actions {
    justify-content: flex-start;
    min-width: 0;
  }
}
