/* --------------------------------------------------------
   Knyle Share shared styles
   -------------------------------------------------------- */

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

:root {
  --color-bg: #ffffff;
  --color-surface: #fafafa;
  --color-border: #e5e5e5;
  --color-text: #171717;
  --color-muted: #737373;
  --color-accent: #2563eb;
  --color-accent-hover: #1d4ed8;
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-success: #16a34a;
  --color-warning: #ca8a04;
  --color-badge-bg: #f4f4f5;
  --color-badge-text: #3f3f46;
  --color-badge-protected-bg: #dbeafe;
  --color-badge-protected-text: #1e40af;
  --color-badge-public-bg: #f0fdf4;
  --color-badge-public-text: #166534;
  --color-badge-disabled-bg: #fef2f2;
  --color-badge-disabled-text: #991b1b;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0a0a0a;
    --color-surface: #111111;
    --color-border: #262626;
    --color-text: #ededed;
    --color-muted: #a3a3a3;
    --color-accent: #3b82f6;
    --color-accent-hover: #60a5fa;
    --color-danger: #ef4444;
    --color-danger-hover: #f87171;
    --color-success: #22c55e;
    --color-warning: #eab308;
    --color-badge-bg: #27272a;
    --color-badge-text: #d4d4d8;
    --color-badge-protected-bg: #1e3a5f;
    --color-badge-protected-text: #93c5fd;
    --color-badge-public-bg: #14532d;
    --color-badge-public-text: #86efac;
    --color-badge-disabled-bg: #450a0a;
    --color-badge-disabled-text: #fca5a5;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

html {
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
  color: var(--color-text);
  background-color: var(--color-bg);
}

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

a:hover {
  text-decoration: underline;
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.3;
}

h3 {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
}

small,
.text-muted {
  color: var(--color-muted);
  font-size: 0.87rem;
}

code,
.mono {
  font-family: "SF Mono", SFMono-Regular, ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.87em;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1.25rem;
  width: 100%;
}

main {
  flex: 1;
  padding: 2rem 0;
}

.page-centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.25rem;
}

.centered-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-md);
}

.centered-card.wide {
  max-width: 520px;
}

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.87rem;
  font-weight: 500;
  line-height: 1;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 120ms ease;
}

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

.btn.is-disabled,
.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--color-accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--color-accent-hover);
}

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

.btn-secondary:hover {
  background: var(--color-badge-bg);
}

.btn-danger {
  background: var(--color-danger);
  color: #ffffff;
}

.btn-danger:hover {
  background: var(--color-danger-hover);
}

.page-title {
  margin-bottom: 1.5rem;
}

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

.count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6rem;
  height: 1.6rem;
  border-radius: 999px;
  background: var(--color-badge-bg);
  color: var(--color-badge-text);
  font-size: 0.8rem;
}

.card,
.detail-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
}

.bundle-list {
  list-style: none;
}

.bundle-list li + li {
  border-top: 1px solid var(--color-border);
}

.bundle-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem 0;
  color: inherit;
}

.bundle-item:hover {
  text-decoration: none;
}

.bundle-item.is-disabled {
  opacity: 0.6;
}

.bundle-name {
  font-weight: 600;
  color: var(--color-text);
}

.bundle-slug {
  margin-top: 0.2rem;
  color: var(--color-muted);
  font-size: 0.87rem;
}

.bundle-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.45rem;
}

.bundle-stats {
  text-align: right;
  color: var(--color-muted);
  font-size: 0.87rem;
  flex-shrink: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--color-badge-bg);
  color: var(--color-badge-text);
  border-radius: 999px;
  padding: 0.22rem 0.55rem;
  font-size: 0.76rem;
  font-weight: 500;
}

.badge-protected {
  background: var(--color-badge-protected-bg);
  color: var(--color-badge-protected-text);
}

.badge-public {
  background: var(--color-badge-public-bg);
  color: var(--color-badge-public-text);
}

.badge-active {
  color: var(--color-success);
}

.badge-disabled {
  background: var(--color-badge-disabled-bg);
  color: var(--color-badge-disabled-text);
}

.breadcrumb {
  margin-bottom: 1rem;
  font-size: 0.87rem;
  color: var(--color-muted);
}

.bundle-url {
  margin-top: 0.4rem;
  color: var(--color-muted);
}

.flash-stack {
  position: sticky;
  top: 0;
  z-index: 30;
}

.flash {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
}

.flash-notice {
  background: rgba(22, 163, 74, 0.12);
  color: var(--color-text);
}

.flash-alert {
  background: rgba(220, 38, 38, 0.12);
  color: var(--color-text);
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* --------------------------------------------------------
   Markdown document
   -------------------------------------------------------- */

.markdown-document {
  max-width: 72ch;
  margin: 0 auto;
  padding: 0 1.25rem;
  width: 100%;
}

.markdown-body {
  font-family: "SF Mono", SFMono-Regular, ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 1.07rem;
  line-height: 1.7;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-family: inherit;
  line-height: 1.3;
  margin-top: 2em;
  margin-bottom: 0.5em;
}

.markdown-body h1 {
  font-size: 1.4em;
  font-weight: 700;
}

.markdown-body h2 {
  font-size: 1.2em;
  font-weight: 700;
}

.markdown-body h3 {
  font-size: 1.05em;
  font-weight: 700;
}

.markdown-body h1:first-child,
.markdown-body h2:first-child,
.markdown-body h3:first-child {
  margin-top: 0;
}

.markdown-body p {
  margin-bottom: 1em;
}

.markdown-body ol,
.markdown-body ul {
  margin-bottom: 1em;
  padding-left: 2em;
}

.markdown-body li {
  margin-bottom: 0.5em;
}

.markdown-body li p {
  margin-bottom: 0.5em;
}

.markdown-body blockquote {
  border-left: 3px solid var(--color-border);
  padding-left: 1em;
  margin-bottom: 1em;
  color: var(--color-muted);
}

.markdown-body pre {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1em;
  margin-bottom: 1em;
  overflow-x: auto;
  font-size: 0.9em;
}

.markdown-body code {
  font-family: inherit;
  font-size: inherit;
}

.markdown-body :not(pre) > code {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.15em 0.35em;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 2em 0;
}

.markdown-body strong {
  font-weight: 700;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1em;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--color-border);
  padding: 0.5em 0.75em;
  text-align: left;
}

.markdown-body th {
  font-weight: 700;
  background: var(--color-surface);
}

.markdown-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

/* --------------------------------------------------------
   Image display
   -------------------------------------------------------- */

.image-display {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.image-display-viewport {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.image-display-viewport img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-display-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem;
  border-top: 1px solid var(--color-border);
}

.image-display-actions h1 {
  font-size: 1rem;
  margin-bottom: 0.15rem;
}

/* --------------------------------------------------------
   Video display
   -------------------------------------------------------- */

.video-display {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: #000;
}

.video-display-viewport {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.video-display-viewport video {
  max-width: 100%;
  max-height: 100%;
}

.video-display-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
}

.video-display-actions h1 {
  font-size: 1rem;
  margin-bottom: 0.15rem;
}

/* --------------------------------------------------------
   PDF display
   -------------------------------------------------------- */

.pdf-display {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.pdf-display-viewport {
  flex: 1;
  min-height: 0;
  border: none;
  width: 100%;
}

.pdf-display-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem;
  border-top: 1px solid var(--color-border);
}

.pdf-display-actions h1 {
  font-size: 1rem;
  margin-bottom: 0.15rem;
}

/* --------------------------------------------------------
   Audio display
   -------------------------------------------------------- */

.audio-display {
  width: 100%;
  max-width: 520px;
  padding: 2rem;
}

.audio-display h1 {
  font-size: 1.25rem;
  margin-bottom: 0.15rem;
}

.audio-display-waveform {
  width: 100%;
  height: 120px;
  margin: 1.5rem 0 1rem;
  cursor: pointer;
  border-radius: var(--radius-md);
}

.audio-display-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.audio-display-time {
  font-family: "SF Mono", SFMono-Regular, ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.87rem;
  color: var(--color-muted);
}

@media (max-width: 720px) {
  .bundle-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .bundle-stats {
    text-align: left;
  }

  .image-display-actions,
  .video-display-actions,
  .pdf-display-actions {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Shared interaction primitives. These also serve protected/public viewers. */
[hidden] { display: none !important; }
:root { color-scheme: light dark; }
:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 3px; }
button, .btn { min-height: 44px; transition: background-color 120ms ease, border-color 120ms ease; }
input, select, textarea { font-size: 16px; }
fieldset { border: 0; min-width: 0; }
legend { font-weight: 600; margin-bottom: .5rem; }
.stack-form, .field-group { display: grid; gap: .6rem; }
.stack-form { gap: 1rem; }
.text-input { width: 100%; min-width: 0; font: inherit; font-size: 16px; color: var(--color-text); background: var(--color-bg); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: .75rem .9rem; }
textarea.text-input { resize: vertical; }
.field-note { font-size: .85rem; color: var(--color-muted); overflow-wrap: anywhere; }
.field-error { color: var(--color-danger); }
.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; }
.link-button { display: inline; min-height: 44px; padding: .4rem 0; background: transparent; color: var(--color-accent); text-decoration: underline; text-align: left; justify-self: start; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mb-2 { margin-bottom: 1rem; }
h1, .bundle-name, .bundle-slug, .bundle-url, .breadcrumb, .file-selected, .detail-value { overflow-wrap: anywhere; min-width: 0; }
.bundle-item > div { min-width: 0; }
.bundle-item:hover .bundle-name { color: var(--color-accent); }
.btn-ghost { color: var(--color-text); background: transparent; border-color: var(--color-border); }
.badge-active { color: #15803d; }
.copy-field { display: grid; gap: .5rem; margin-top: 1rem; }
.copy-field label { font-weight: 500; }
.copy-field-controls { display: flex; gap: .5rem; }
.copy-field-controls .btn { flex-shrink: 0; }
.copy-field .mono { font-size: .85rem; }
.pagination { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; justify-content: center; margin: 1.5rem 0; }
.audio-display audio { display: block; width: 100%; margin: 1.5rem 0; }
.audio-display select { max-width: 9rem; }
.image-display, .video-display, .pdf-display { height: 100dvh; min-height: 420px; }
.image-display-viewport.is-actual-size { display: block; overflow: auto; }
.image-display-viewport.is-actual-size img { max-width: none; max-height: none; }
.image-display-actions, .video-display-actions, .pdf-display-actions { flex-shrink: 0; padding-bottom: max(1rem, env(safe-area-inset-bottom)); }
.image-display-actions .button-row { justify-content: flex-end; }
.reading-controls { display: flex; justify-content: flex-end; margin-bottom: 1rem; }
.reading-font .markdown-body { font-family: Georgia, 'Times New Roman', serif; font-size: 1.2rem; line-height: 1.75; }
.reading-font .markdown-body code, .reading-font .markdown-body pre { font-family: ui-monospace, monospace; font-size: .95rem; }
.markdown-body { overflow-wrap: anywhere; }
.table-scroll { overflow-x: auto; margin-bottom: 1rem; }
.table-scroll table { margin-bottom: 0; }
.code-copy { margin-bottom: .35rem; }
progress { width: 100%; accent-color: var(--color-accent); margin: 1rem 0; }
@media (prefers-color-scheme: dark) {
  :root { --color-accent: #2563eb; --color-accent-hover: #1d4ed8; --color-danger: #b91c1c; --color-danger-hover: #991b1b; }
  a, .link-button { color: #93c5fd; }
  .btn-primary, .btn-danger { color: white; }
  .field-error { color: #fca5a5; }
  .badge-active { color: #86efac; }
}
@media (max-width: 720px) {
  .copy-field-controls { flex-wrap: wrap; }
  .copy-field-controls input { flex: 1 1 200px; }
  .image-display-actions .button-row { justify-content: flex-start; }
  .image-display-actions, .video-display-actions, .pdf-display-actions { gap: .65rem; padding: .85rem 1.25rem; }
  .audio-display { padding: 1rem; }
  .centered-card { padding: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }
