/* ==========================================================================
   PasteBox - single stylesheet. Design tokens, layout, components.
   Dark theme by default; light theme via <html data-theme="light">.
   ========================================================================== */

/* --------------------------------------------------------------- tokens */
:root {
  color-scheme: dark;
  --bg: #0f1216;
  --bg-2: #161b22;
  --bg-3: #1c2430;
  --border: #262d36;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4f9cf9;
  --accent-strong: #2f81f7;
  --danger: #f85149;
  --ok: #3fb950;
  --warn: #d29922;
  --code-bg: #0b0f14;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.28);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --speed: 140ms;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f8fa;
  --bg-2: #ffffff;
  --bg-3: #eef2f6;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #59636e;
  --code-bg: #f6f8fa;
  --shadow: 0 1px 2px rgba(31, 35, 40, 0.08), 0 10px 28px rgba(31, 35, 40, 0.06);
}

/* ----------------------------------------------------------------- base */
* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 10px; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0 0 10px; }

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

img, svg { max-width: 100%; }
button { font: inherit; }

[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 156, 249, 0.2);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -56px;
  left: 12px;
  z-index: 100;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text);
  transition: top var(--speed) ease;
}
.skip-link:focus { top: 8px; text-decoration: none; }

/* --------------------------------------------------------------- layout */
.wrap {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

.wrap.page { padding-top: 20px; padding-bottom: 48px; }

.page-head { margin: 4px 0 18px; }
.page-head h1 { margin: 0 0 4px; overflow-wrap: anywhere; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
}
.section-head h2 { margin: 0; }

.recent-section, .admin-section { margin-top: 30px; }

/* --------------------------------------------------------------- header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 18px;
  height: 52px;
}

.brand {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { color: var(--accent); text-decoration: none; }

.nav { display: flex; align-items: center; gap: 2px; }

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  transition: color var(--speed) ease, background-color var(--speed) ease;
}
.nav-link:hover { color: var(--text); background: var(--bg-3); text-decoration: none; }
.nav-link.active { color: var(--accent); background: var(--bg-3); font-weight: 600; }

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

/* account menu */
.menu { position: relative; }

.menu-toggle {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.menu-toggle::-webkit-details-marker { display: none; }
.menu-toggle::after {
  content: "";
  display: inline-block;
  margin-left: 8px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
}
.menu[open] .menu-toggle { border-color: var(--accent); }

.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  min-width: 208px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-2);
  box-shadow: var(--shadow);
}

.menu-item {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover { background: var(--bg-3); text-decoration: none; }
.menu-item.active { color: var(--accent); }
.menu-form { margin: 0; }

/* --------------------------------------------------------------- footer */
.site-footer {
  margin-top: 44px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
}

.footer-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 18px;
  padding-top: 14px;
  padding-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}
.footer-line a { color: var(--muted); }
.footer-line a:hover { color: var(--text); }
.footer-site { margin-left: auto; }

/* -------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--speed) ease, border-color var(--speed) ease, color var(--speed) ease;
}
.btn:hover { border-color: var(--muted); text-decoration: none; }

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

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-3); border-color: var(--border); color: var(--text); }

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

.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 13px; }

.inline-form { display: inline-flex; margin: 0; }

/* ---------------------------------------------------------- chips/badges */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 1px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.7;
  white-space: nowrap;
  text-transform: capitalize;
}
.badge-public { color: var(--ok); border-color: rgba(63, 185, 80, 0.45); background: rgba(63, 185, 80, 0.1); }
.badge-unlisted { color: var(--warn); border-color: rgba(210, 153, 34, 0.45); background: rgba(210, 153, 34, 0.1); }
.badge-private { color: var(--danger); border-color: rgba(248, 81, 73, 0.45); background: rgba(248, 81, 73, 0.1); }

/* ---------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-size: 13px; font-weight: 600; }

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  align-items: start;
}

.field-check { align-self: end; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="url"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color var(--speed) ease, box-shadow var(--speed) ease;
}

input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.75; }

textarea { min-height: 120px; resize: vertical; }

.input-code {
  min-height: 320px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}
.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 0;
  margin: 0;
  accent-color: var(--accent-strong);
}

.field-hint { margin: 0; font-size: 12.5px; }
.field-error { margin: 0; color: var(--danger); font-size: 13px; }

.stack-form { display: flex; flex-direction: column; gap: 14px; }
.paste-form { display: flex; flex-direction: column; gap: 16px; }

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

.counter {
  margin: 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12.5px;
}

.form-note { margin: 0; font-size: 12.5px; }

.filter-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 220px) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
}

/* ---------------------------------------------------------------- cards */
.card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-2);
}
.card + .card { margin-top: 18px; }
.card > h2 { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }

.form-card h1 { margin: 0 0 16px; }

.auth-card { max-width: 440px; margin: 40px auto; }
.lock-card { max-width: 440px; margin: 48px auto; }
.lock-form { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.lock-note { margin: 12px 0 0; font-size: 12.5px; }

.auth-alt { margin: 14px 0 0; font-size: 13.5px; }

.manage-card { margin-bottom: 18px; border-left: 3px solid var(--warn); }
.manage-card h2 { font-size: 16px; }
.manage-card p { font-size: 14px; }

.manage-link, .api-key {
  display: block;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}
.api-key { margin-bottom: 14px; }

.danger-card { border-color: rgba(248, 81, 73, 0.5); }
.danger-card h2 { color: var(--danger); }
.danger-card p { font-size: 14px; }

.error-card { max-width: 560px; margin: 40px auto; }
.error-code {
  margin: 0 0 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 44px;
  font-weight: 700;
  line-height: 1;
}
.error-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

/* ------------------------------------------------------- paste listings */
.paste-list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-2);
  overflow: hidden;
}

.paste-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 2px 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background-color var(--speed) ease;
}
.paste-row:last-child { border-bottom: 0; }
.paste-row:hover { background: var(--bg-3); }

.paste-info { min-width: 0; }

.paste-title {
  display: inline-block;
  max-width: 100%;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.paste-title:hover { color: var(--accent); text-decoration: none; }

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 2px;
  font-size: 13px;
  color: var(--muted);
}
.meta a { color: var(--text); }
.meta a:hover { color: var(--accent); }
.meta-dim { color: var(--muted); }

.paste-side { text-align: right; }
.paste-side time { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ------------------------------------------------------------ code view */
.code-wrap {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--code-bg);
  overflow: hidden;
}

.gutter {
  padding: 14px 10px 14px 12px;
  border-right: 1px solid var(--border);
  background: rgba(127, 127, 127, 0.05);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  text-align: right;
  user-select: none;
  overflow: hidden;
}
.gutter span { display: block; }

.code {
  margin: 0;
  padding: 14px 16px;
  background: var(--code-bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre;
  tab-size: 4;
  overflow-x: auto;
}
.code code {
  padding: 0;
  background: none;
  color: inherit;
  font: inherit;
  white-space: pre;
}
.code-wrap .code,
.code-wrap code.hljs { background: var(--code-bg); }

.paste-head { margin: 4px 0 0; }
.paste-head h1 { margin: 0 0 6px; overflow-wrap: anywhere; }

.action-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 18px 0;
}

/* ------------------------------------------------------- flash / errors */
.flash-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.flash {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  font-size: 14px;
}
.flash-success { border-left-color: var(--ok); }
.flash-error { border-left-color: var(--danger); }
.flash-info { border-left-color: var(--accent); }
.flash-message { border-left-color: var(--accent); }

.error-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 14px;
  padding: 10px 12px 10px 28px;
  border: 1px solid rgba(248, 81, 73, 0.5);
  border-radius: var(--radius-sm);
  background: rgba(248, 81, 73, 0.08);
  color: var(--danger);
  font-size: 14px;
}

/* ---------------------------------------------------------------- pager */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}

.pager-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text);
  font-size: 14px;
}
.pager-link:hover { border-color: var(--accent); text-decoration: none; }
.pager-link.is-disabled { opacity: 0.5; }

.pager-info { color: var(--muted); font-size: 13.5px; }

/* ---------------------------------------------------------------- stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.stat {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-2);
}
.stat-value { font-size: 22px; font-weight: 700; line-height: 1.2; }
.stat-label {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* --------------------------------------------------------------- tables */
.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-2);
}

.table { width: 100%; border-collapse: collapse; font-size: 14px; }

.table th {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--bg-3); }

.slug-line { margin-top: 2px; font-family: var(--mono); font-size: 12px; }

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

/* -------------------------------------------------- admin rows / empty  */
.admin-row {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}
.admin-row:last-child { border-bottom: 0; }
.admin-row .paste-row { flex: 1 1 auto; min-width: 0; border-bottom: 0; }
.admin-row-action { margin-right: 14px; }

.empty {
  padding: 28px 18px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-2);
  color: var(--muted);
  text-align: center;
}

/* -------------------------------------------------------- responsive */
@media (max-width: 760px) {
  .header-inner {
    flex-wrap: wrap;
    height: auto;
    min-height: 52px;
    padding-top: 6px;
    padding-bottom: 6px;
    row-gap: 2px;
  }
  .nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  .nav-link { min-height: 44px; }
  .header-actions { row-gap: 4px; }
  .header-actions .btn,
  .header-actions .nav-link,
  .menu-toggle { min-height: 44px; }

  .btn-sm { min-height: 44px; }

  .brand { font-size: 16px; }
  h1 { font-size: 22px; }
  .wrap.page { padding-top: 16px; padding-bottom: 40px; }

  .filter-bar { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .field-check { align-self: start; }

  .form-footer { flex-direction: column; align-items: stretch; }
  .form-footer .btn { width: 100%; }

  .paste-row { display: block; }
  .paste-side { text-align: left; margin-top: 4px; }

  .admin-row { display: block; }
  .admin-row-action { display: inline-flex; margin: 0 14px 12px; }

  .code { font-size: 12px; padding: 12px; }
  .gutter { font-size: 11.5px; padding: 12px 8px 12px 10px; }

  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 19px; }

  .pager { flex-wrap: wrap; justify-content: center; }
  .footer-site { margin-left: 0; }
}

/* ------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
