/* What If Studio CMS. Màu theo bảng màu đã kiểm tra độ tương phản, có chế độ tối. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --border: rgba(11, 11, 11, 0.1);
  --border-strong: rgba(11, 11, 11, 0.2);
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: rgba(42, 120, 214, 0.1);
  --accent-track: #cde2fb;
  --bar-muted: #c3c2b7;
  --button: #256abf;
  --button-hover: #1c5cab;
  --good: #0ca30c;
  --good-ink: #006300;
  --good-wash: rgba(12, 163, 12, 0.1);
  --warn: #fab219;
  --warn-ink: #7a4f00;
  --warn-wash: rgba(250, 178, 25, 0.16);
  --bad: #d03b3b;
  --bad-ink: #b02a2a;
  --bad-wash: rgba(208, 59, 59, 0.1);
  --focus: #2a78d6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #898781;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.2);
    --grid: #2c2c2a;
    --axis: #383835;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-wash: rgba(57, 135, 229, 0.14);
    --accent-track: #0d366b;
    --bar-muted: #52514e;
    --button: #256abf;
    --button-hover: #2a78d6;
    --good-ink: #0ca30c;
    --good-wash: rgba(12, 163, 12, 0.16);
    --warn-ink: #fab219;
    --warn-wash: rgba(250, 178, 25, 0.14);
    --bad-ink: #e66767;
    --bad-wash: rgba(208, 59, 59, 0.18);
    --focus: #86b6ef;
    --shadow: none;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--page);
  color: var(--text);
  font: 15px/1.5 var(--font);
}

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

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
  font-weight: 600;
}

h1 {
  font-size: 1.6rem;
}

h2 {
  font-size: 1.15rem;
}

h3 {
  font-size: 1rem;
}

p {
  margin: 0.5rem 0;
}

code,
pre {
  font-family: var(--mono);
  font-size: 0.85em;
}

code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--surface-2);
  overflow-wrap: anywhere;
}

img {
  max-width: 100%;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  min-height: 0 !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  z-index: 10;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.skip-link:focus {
  left: 8px;
}

/* --- Khung trang ------------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 10px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 650;
  white-space: nowrap;
}

.brand:hover {
  text-decoration: none;
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--text-2);
  white-space: nowrap;
}

.nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.nav a[aria-current="page"] {
  background: var(--accent-wash);
  color: var(--accent-ink);
  font-weight: 600;
}

.page {
  flex: 1;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.page-narrow {
  justify-content: center;
}

.footer {
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.section-head {
  margin-bottom: 12px;
}

.section-head-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.sub,
.hint,
.meta {
  color: var(--text-2);
}

.sub {
  margin: 4px 0 0;
}

.hint {
  margin: 4px 0 0;
  font-size: 0.85rem;
}

.meta {
  font-size: 0.8rem;
}

.back {
  margin: 0;
}

.grow {
  flex: 1;
  min-width: 0;
}

.inline {
  display: inline;
  margin: 0;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.anchor {
  scroll-margin-top: 72px;
}

/* --- Thẻ ------------------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}

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

.card > .sub {
  margin-bottom: 12px;
}

.empty {
  padding: 28px 20px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr));
  gap: 16px;
  align-items: start;
}

/* --- Nút và ô nhập ----------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 550;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
}

.btn:hover {
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--button);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--button-hover);
}

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

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn-ghost {
  color: var(--text-2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger-text {
  color: var(--bad-ink);
}

.btn-danger-text:hover:not(:disabled) {
  background: var(--bad-wash);
  color: var(--bad-ink);
}

.btn-block {
  width: 100%;
  margin-top: 8px;
}

input[type="text"],
input[type="email"],
input[type="password"],
select {
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input::placeholder {
  color: var(--muted);
}

input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 0;
  border-color: transparent;
}

select {
  width: auto;
  max-width: 280px;
}

.label {
  font-weight: 550;
}

.input-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.input-row input {
  flex: 1;
  min-width: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: max-content minmax(0, 420px);
  gap: 10px 16px;
  align-items: center;
  margin-top: 12px;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 8px 0;
}

.copy-row code {
  padding: 8px 10px;
  font-size: 0.85rem;
}

/* --- Thông báo và trạng thái --------------------------------------------------------- */

.flashes {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.notice-icon {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  background: var(--muted);
}

.notice-ok {
  background: var(--good-wash);
}

.notice-ok .notice-icon {
  background: var(--good);
}

.notice-info {
  background: var(--accent-wash);
}

.notice-info .notice-icon {
  background: var(--button);
}

.notice-warn {
  background: var(--warn-wash);
}

.notice-warn .notice-icon {
  background: var(--warn);
  color: #0b0b0b;
}

.notice-error {
  background: var(--bad-wash);
}

.notice-error .notice-icon {
  background: var(--bad);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 550;
  white-space: nowrap;
}

.status-icon {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
}

.status-ok {
  color: var(--good-ink);
}

.status-ok .status-icon {
  background: var(--good);
}

.status-warn {
  color: var(--warn-ink);
}

.status-warn .status-icon {
  background: var(--warn);
  color: #0b0b0b;
}

.status-error {
  color: var(--bad-ink);
}

.status-error .status-icon {
  background: var(--bad);
}

.status-running {
  color: var(--accent-ink);
}

.status-running .status-icon {
  background: var(--button);
}

.status-idle {
  color: var(--text-2);
}

.status-idle .status-icon {
  background: var(--muted);
}

.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
  vertical-align: 1px;
}

.tag-accent {
  background: var(--accent-wash);
  color: var(--accent-ink);
}

.tag-warn {
  background: var(--warn-wash);
  color: var(--warn-ink);
}

/* --- Số liệu ------------------------------------------------------------------------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  gap: 12px;
}

.kpi {
  padding: 16px;
}

.kpi-label {
  color: var(--text-2);
  font-size: 0.85rem;
}

.kpi-value {
  margin-top: 4px;
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.2;
}

.kpi-foot {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 1.4em;
  margin-top: 4px;
}

.delta {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.delta-up {
  color: var(--good-ink);
}

.delta-down {
  color: var(--bad-ink);
}

.delta-flat {
  color: var(--text-2);
}

.chart {
  position: relative;
  height: 240px;
  margin-top: 8px;
}

.setup .steps {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 12px;
}

.step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.step-mark {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  font-size: 0.8rem;
  font-weight: 650;
}

.step-done .step-mark {
  border-color: transparent;
  background: var(--good);
  color: #fff;
}

.step-done a {
  color: var(--text-2);
  text-decoration: line-through;
}

.goals {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 16px;
}

.goal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.goal-num {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Thanh tiến độ: phần đã đạt màu nhấn, phần còn lại là sắc nhạt hơn của cùng màu */
progress {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 8px;
  border: 0;
  border-radius: 4px;
  background: var(--accent-track);
  color: var(--accent);
  overflow: hidden;
}

progress::-webkit-progress-bar {
  background: var(--accent-track);
  border-radius: 4px;
}

progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: 4px;
}

progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: 4px;
}

.share {
  display: flex;
  align-items: center;
  gap: 8px;
}

.share progress {
  flex: 1;
  min-width: 60px;
  height: 6px;
  background: transparent;
}

.share progress::-webkit-progress-bar {
  background: transparent;
}

.share .bar-muted::-webkit-progress-value {
  background: var(--bar-muted);
}

.share .bar-muted::-moz-progress-bar {
  background: var(--bar-muted);
}

.share .num {
  min-width: 3.5em;
  text-align: right;
}

.share-col {
  width: 40%;
}

/* --- Bảng ---------------------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  margin: 0 -20px;
  padding: 0 20px;
}

.table-scroll {
  max-height: 420px;
  overflow-y: auto;
}

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

.table th,
.table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--grid);
  text-align: left;
  vertical-align: middle;
}

.table th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.table tbody tr:last-child td {
  border-bottom: 0;
}

.table tbody tr:hover td {
  background: var(--surface-2);
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table th .sort {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.table th .sort:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

.table th .sort::after {
  content: "↕";
  color: var(--muted);
  font-size: 0.75rem;
}

.table th[aria-sort="descending"] .sort::after {
  content: "↓";
  color: var(--text);
}

.table th[aria-sort="ascending"] .sort::after {
  content: "↑";
  color: var(--text);
}

.videos td:first-child {
  min-width: 300px;
}

.standout td {
  background: var(--accent-wash);
}

.video-cell,
.channel-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.video-cell img {
  flex: none;
  width: 96px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2);
}

.video-cell a {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--text);
  font-weight: 550;
}

.avatar {
  flex: none;
  border-radius: 50%;
  background: var(--surface-2);
}

.avatar-sm {
  width: 32px;
  height: 32px;
}

.channel-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.notes {
  margin: 16px 0 0;
  padding-left: 18px;
  color: var(--text-2);
  font-size: 0.85rem;
}

.table-view summary {
  cursor: pointer;
  color: var(--accent-ink);
  font-weight: 550;
}

.table-view[open] summary {
  margin-bottom: 12px;
}

details summary {
  cursor: pointer;
}

.log {
  margin: 8px 0 0;
  padding: 10px 12px;
  max-width: 640px;
  max-height: 320px;
  overflow: auto;
  border-radius: 6px;
  background: var(--surface-2);
  white-space: pre-wrap;
  font-size: 0.8rem;
  line-height: 1.5;
}

/* --- Trang Kết nối ----------------------------------------------------------------------- */

.sub-steps {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 20px;
}

.sub-steps h3 {
  margin-bottom: 4px;
}

.list-title {
  margin: 24px 0 8px;
}

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

.connection {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 0;
  border-top: 1px solid var(--grid);
}

.connection .grow {
  flex: 1 1 260px;
}

.connection-name {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.connection .row-actions {
  margin: 0;
}

.key-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr));
  gap: 16px;
}

.key-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  margin: 12px 0;
}

.facts dt {
  color: var(--text-2);
}

.facts dd {
  margin: 0;
}

/* --- Đăng nhập và lỗi ------------------------------------------------------------------ */

.login {
  display: flex;
  justify-content: center;
  padding: 40px 0;
}

.login-card {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 28px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.login-brand h1 {
  font-size: 1.3rem;
}

.error-page {
  max-width: 560px;
  margin: 40px auto;
  text-align: center;
}

.error-code {
  color: var(--text-2);
  font-weight: 600;
}

.error-page h1 {
  font-size: 1.3rem;
  margin-bottom: 16px;
}

/* --- Màn hình hẹp ---------------------------------------------------------------------- */

@media (max-width: 720px) {
  .topbar-inner {
    flex-wrap: wrap;
    gap: 8px 16px;
  }

  .nav {
    order: 3;
    flex-basis: 100%;
    flex-wrap: wrap;
  }

  .nav a {
    padding: 4px 10px;
  }

  .kpi-value {
    font-size: 1.45rem;
  }

  .videos td:first-child {
    min-width: 220px;
  }

  .video-cell img {
    width: 64px;
    height: 36px;
  }

  .logout {
    margin-left: auto;
  }

  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .form-grid > div:empty {
    display: none;
  }

  .input-row {
    flex-direction: column;
  }

  .card {
    padding: 16px;
  }

  .table-wrap {
    margin: 0 -16px;
    padding: 0 16px;
  }

  h1 {
    font-size: 1.35rem;
  }
}

@media (forced-colors: active) {
  progress,
  .status-icon,
  .notice-icon,
  .step-mark {
    forced-color-adjust: none;
    border: 1px solid CanvasText;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
