/*
 * Preview — admin UI + global flash
 */

:root {
  color-scheme: light dark;
  --canvas: #f3f4f6;
  --surface: #ffffff;
  --fg: #111827;
  --fg-secondary: #4b5563;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-muted: rgba(29, 78, 216, 0.08);
  --danger: #b91c1c;
  --danger-surface: rgba(185, 28, 28, 0.06);
  --success-surface: rgba(22, 163, 74, 0.1);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", monospace;
  --header-h: 3.25rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #0c0c0e;
    --surface: #18181b;
    --fg: #f4f4f5;
    --fg-secondary: #a1a1aa;
    --muted: #71717a;
    --border: #27272a;
    --border-strong: #3f3f46;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --accent-muted: rgba(96, 165, 250, 0.12);
    --danger: #f87171;
    --danger-surface: rgba(248, 113, 113, 0.1);
    --success-surface: rgba(74, 222, 128, 0.1);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  }
}

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 0.9375rem;
  background: var(--canvas);
  color: var(--fg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Global flash (non-admin layouts) */
.flash {
  margin: 0;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.flash--notice {
  background: var(--success-surface);
  color: var(--fg);
}

.flash--alert {
  background: var(--danger-surface);
  color: var(--fg);
}

/* ——— Admin shell ——— */
.admin-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.admin-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
}

.admin-header__inner {
  max-width: 68rem;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.admin-brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--fg);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.admin-brand__badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--accent-muted);
  color: var(--accent);
}

.admin-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.admin-nav__link {
  color: var(--fg-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  transition: background 0.12s ease, color 0.12s ease;
}

.admin-nav__link:hover {
  background: var(--border);
  color: var(--fg);
}

.admin-nav__link--active {
  background: var(--accent-muted);
  color: var(--accent);
}

.admin-signout {
  margin-left: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--fg-secondary);
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}

.admin-signout:hover {
  border-color: var(--muted);
  color: var(--fg);
}

.admin-flash {
  max-width: 68rem;
  margin: 0 auto;
  padding: 0.75rem 1.25rem 0;
}

.admin-flash .flash {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  box-shadow: var(--shadow);
}

.admin-main {
  flex: 1;
  max-width: 68rem;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

/* Page chrome */
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.page-head__text {
  min-width: 0;
}

.page-title {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.page-subtitle {
  margin: 0;
  font-size: 0.875rem;
  color: var(--muted);
  max-width: 36rem;
}

.page-head__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  min-height: 2.25rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.15s ease, transform 0.05s ease;
}

.button:hover {
  background: var(--accent-hover);
}

.button:active {
  transform: translateY(1px);
}

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

.button--sm {
  padding: 0.35rem 0.65rem;
  min-height: auto;
  font-size: 0.8125rem;
  font-weight: 500;
  box-shadow: none;
}

.button--ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--border-strong);
  box-shadow: none;
}

.button--ghost:hover {
  background: var(--accent-muted);
  border-color: transparent;
}

.button--danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--border-strong);
  box-shadow: none;
}

.button--danger:hover {
  background: var(--danger-surface);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

.button--danger:focus-visible {
  outline-color: var(--danger);
}

/* Panels & cards */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel--pad {
  padding: 1.25rem 1.35rem;
}

.form-section {
  padding: 1.35rem 1.35rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.form-section:last-of-type {
  border-bottom: none;
}

.form-section__title {
  margin: 0 0 1rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* Table */
.data-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

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

.data-table th {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  background: color-mix(in srgb, var(--canvas) 50%, var(--surface));
}

.data-table__th--right {
  width: 1%;
  text-align: right;
}

.data-table__date {
  white-space: nowrap;
}

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

.data-table tbody tr:hover td {
  background: color-mix(in srgb, var(--canvas) 35%, transparent);
}

.data-table__slug {
  font-weight: 600;
  font-family: var(--mono);
  font-size: 0.8125rem;
}

.data-table__slug a {
  color: var(--fg);
  text-decoration: none;
}

.data-table__slug a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.data-table__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  justify-content: flex-end;
}

.data-table__actions form.button_to {
  display: inline;
  margin: 0;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}

.empty-state__title {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.empty-state__text {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 22rem;
  margin-left: auto;
  margin-right: auto;
}

/* Forms */
.stack-form .field {
  margin-bottom: 0;
}

.stack-form label,
.stack-form .label {
  display: block;
  font-weight: 600;
  font-size: 0.8125rem;
  margin-bottom: 0.4rem;
  color: var(--fg);
}

.stack-form input[type="text"],
.stack-form input[type="url"],
.stack-form textarea {
  width: 100%;
  max-width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.875rem;
  background: var(--surface);
  color: var(--fg);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.stack-form input:hover,
.stack-form textarea:hover {
  border-color: var(--muted);
}

.stack-form input:focus-visible,
.stack-form textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.stack-form textarea.monospace {
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.5;
  min-height: 11rem;
  resize: vertical;
}

.field-hint {
  margin: 0 0 0.5rem;
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.45;
}

.field-hint code {
  font-size: 0.78em;
}

.bg-choice {
  display: grid;
  gap: 1rem;
}

@media (min-width: 640px) {
  .bg-choice {
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
  }

  .bg-choice__divider {
    display: none;
  }
}

.bg-choice__box {
  padding: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--canvas) 40%, var(--surface));
}

.bg-choice__label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.65rem;
}

.file-input {
  position: relative;
}

.file-input input[type="file"] {
  width: 100%;
  max-width: 100%;
  padding: 0.45rem 0;
  font-size: 0.8125rem;
  color: var(--fg-secondary);
}

.thumb-preview {
  display: block;
  max-width: 100%;
  width: auto;
  max-height: 10rem;
  margin-top: 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.form-errors {
  padding: 1rem 1.1rem;
  margin-bottom: 1.25rem;
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border));
  border-radius: var(--radius);
  background: var(--danger-surface);
}

.form-errors p {
  margin: 0 0 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
}

.form-errors ul {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.875rem;
  color: var(--fg-secondary);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  padding: 1.15rem 1.35rem 1.35rem;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--canvas) 25%, var(--surface));
}

/* Detail (show) */
.detail-grid {
  display: grid;
  gap: 1rem;
}

.detail-block {
  padding: 1rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
}

.detail-block dt {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 0.35rem;
}

.detail-block dd {
  margin: 0;
  font-size: 0.9rem;
}

.url-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.url-line code {
  flex: 1;
  min-width: 0;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--canvas) 60%, var(--surface));
  border: 1px solid var(--border);
  font-size: 0.8rem;
  word-break: break-all;
}

.embed-preview {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.5;
  background: color-mix(in srgb, var(--canvas) 50%, var(--surface));
  max-height: 16rem;
  overflow: auto;
}

.text-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
}

.text-link:hover {
  text-decoration: underline;
}

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

code {
  font-family: var(--mono);
  font-size: 0.88em;
}
