/* ==========================================================================
   ttf2.cn — Shared Base System, Modals, Context Menu, Admin Console & Mobile Sheet
   ========================================================================== */

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

:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "HarmonyOS Sans SC", "Hiragino Sans GB", "Microsoft YaHei UI", sans-serif;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  /* Default fallback tokens (overridden per edition) */
  --bg: #0a0d12;
  --bg-elevated: #131822;
  --surface: #151b26;
  --surface-hover: #1b2331;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --ink: #f1f5f9;
  --ink-secondary: #94a3b8;
  --ink-muted: #64748b;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --accent-ink: #06131f;
  --private-color: #f59e0b;
  --private-soft: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --success: #10b981;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.35);
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

/* Focus visibility for keyboard users */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Bespoke FERRO Octagonal Rotor-Core Emblem */
.ferro-emblem {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.ferro-emblem svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Shared Icon Badge */
.link-icon-box {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 600;
  font-size: 15px;
  position: relative;
  overflow: hidden;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--border);
}

.link-icon-box img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  display: block;
}

.link-icon-box svg {
  width: 18px;
  height: 18px;
}

/* Badges */
.badge-private {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--private-soft);
  color: var(--private-color);
  border: 1px solid rgba(245, 158, 11, 0.28);
  white-space: nowrap;
}

.badge-count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
}

/* Demo Notice Strip (Dismissible or 1-click purge) */
.demo-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  border: 1px solid var(--border-strong);
  font-size: 12.5px;
  color: var(--ink-secondary);
  margin-bottom: 18px;
}

.demo-banner strong {
  color: var(--ink);
}

.demo-banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Search Instant Match Dropdown / Bar Info */
.search-assist-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--ink-muted);
}

.kbd-hint {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-muted);
}

/* Mobile Touch Quick Action Button (Admin Logged-In) */
.card-more-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--ink-secondary);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 3;
  transition: background 0.15s, color 0.15s;
}

.card-more-btn:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

body.is-admin .link-card:hover .card-more-btn,
body.is-admin .dir-item:hover .card-more-btn {
  display: inline-flex;
}

@media (hover: none), (max-width: 860px) {
  body.is-admin .card-more-btn {
    display: inline-flex;
  }
}

/* Mobile Floating Quick Add FAB (Admin Logged-In) */
.mobile-fab {
  position: fixed;
  right: 18px;
  bottom: 74px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 90;
  font-size: 22px;
  font-weight: 600;
}

@media (max-width: 860px) {
  body.is-admin .mobile-fab {
    display: inline-flex;
  }
}

/* Desktop Custom Right-Click Context Menu */
.ctx-menu {
  position: fixed;
  z-index: 1200;
  min-width: 210px;
  padding: 6px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}

.ctx-menu-header {
  padding: 6px 10px 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 230px;
}

.ctx-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  text-align: left;
  transition: background 0.12s;
}

.ctx-item:hover {
  background: var(--surface-hover);
}

.ctx-item.is-danger {
  color: var(--danger);
}

.ctx-item.is-danger:hover {
  background: var(--danger-soft);
}

.ctx-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 6px;
}

/* Mobile Bottom Action Sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1150;
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.mobile-sheet {
  width: 100%;
  max-width: 520px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-strong);
  border-radius: 20px 20px 0 0;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--shadow-lg);
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 99px;
  background: var(--border-strong);
  margin: 0 auto 12px;
}

.sheet-title {
  font-size: 14px;
  font-weight: 600;
  padding: 0 6px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.sheet-btn {
  width: 100%;
  padding: 13px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-size: 15px;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-btn:active, .sheet-btn:hover {
  background: var(--surface-hover);
}

.sheet-btn.is-danger {
  color: var(--danger);
}

/* Modals & Admin Drawer */
.modal-backdrop, .drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(5, 8, 14, 0.62);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.drawer-backdrop {
  justify-content: flex-end;
  padding: 0;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.modal-card.modal-sm {
  max-width: 400px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.modal-head h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
}

.icon-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-close-btn:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

/* Form Elements */
.form-grid {
  display: grid;
  gap: 14px;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 560px) {
  .form-row-2 {
    grid-template-columns: 1fr;
  }
}

.field-label {
  display: block;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--ink-secondary);
  margin-bottom: 6px;
}

.field-input, .field-select, .field-textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  transition: border-color 0.15s;
}

.field-textarea {
  min-height: 80px;
  resize: vertical;
}

.field-input:focus, .field-select:focus, .field-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.field-check {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.field-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 550;
  transition: all 0.15s ease;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
}

.btn-primary:hover {
  filter: brightness(1.07);
  background: var(--accent);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 7px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* Admin Workspace Drawer */
.admin-drawer {
  width: min(880px, 100vw);
  height: 100vh;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.admin-drawer-head {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.admin-tab {
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-secondary);
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
}

.admin-tab.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--border-strong);
}

.admin-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 22px 24px 40px;
}

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

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

.admin-table th {
  font-size: 12px;
  color: var(--ink-muted);
  font-weight: 600;
}

.admin-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.admin-stat-card {
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.admin-stat-card .num {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--ink);
}

.admin-stat-card .lbl {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 2px;
}

/* Toast Notifications */
.toast-stack {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast-item {
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  font-weight: 550;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  animation: toastIn 0.2s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Floating Edition Preview Switcher */
.edition-switcher {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 900;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(14px);
}

.edition-pill {
  padding: 6px 11px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--ink-secondary);
  font-size: 12px;
  font-weight: 550;
  transition: all 0.15s;
}

.edition-pill.is-active {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}

/* Empty Search State */
.empty-state {
  padding: 48px 20px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  color: var(--ink-secondary);
}

/* Shared Footer Legal Row */
.site-footer {
  margin-top: 64px;
  padding: 26px 0 34px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--ink-muted);
}

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

.footer-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}

.footer-links a:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

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