/* ═════════════════════════════════════════════════════════════════════════════
   KuyaOps Wiki — Enhanced Stylesheet
   Features: Dark mode, code copy buttons, search, print styles
   Author: John Ian Medilo | https://kuyaops.com
   ═════════════════════════════════════════════════════════════════════════════ */

/* ─── Variables ─────────────────────────────────────────────────────────── */
:root {
  --sidebar-w:    270px;
  --toc-w:        210px;
  --topbar-h:     56px;

  --bg:           #f8f7f4;
  --bg-sidebar:   #f0efe9;
  --bg-content:   #ffffff;
  --bg-code:      #f3f2ee;
  --bg-hover:     #e8e7e0;

  --border:       #dddbd3;
  --border-light: #eceae3;

  --text:         #1c1b18;
  --text-muted:   #7a7870;
  --text-sidebar: #3d3c38;

  --accent:       #2563eb;
  --accent-bg:    #eff4ff;
  --accent-hover: #1d4ed8;

  --warn:         #92400e;
  --warn-bg:      #fffbeb;
  --warn-border:  #fbbf24;

  --tip:          #065f46;
  --tip-bg:       #f0fdf4;
  --tip-border:   #34d399;

  --info:         #1e40af;
  --info-bg:      #dbeafe;
  --info-border:  #60a5fa;

  --font-body:    'Figtree', sans-serif;
  --font-serif:   'Lora', Georgia, serif;
  --font-mono:    'JetBrains Mono', 'Courier New', monospace;

  --radius:       8px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --transition:   0.18s ease;
}

/* ─── Dark Mode ─────────────────────────────────────────────────────────── */
.dark {
  --bg:           #1a1a1e;
  --bg-sidebar:   #222228;
  --bg-content:   #16161a;
  --bg-code:      #25252c;
  --bg-hover:     #2e2e36;

  --border:       #3a3a44;
  --border-light: #2e2e38;

  --text:         #e8e6e1;
  --text-muted:   #9a9890;
  --text-sidebar: #c4c2bb;

  --accent:       #60a5fa;
  --accent-bg:    #1e293b;
  --accent-hover: #93c5fd;

  --warn:         #fbbf24;
  --warn-bg:      #3d2e10;
  --warn-border:  #f59e0b;

  --tip:          #34d399;
  --tip-bg:       #0f2e1f;
  --tip-border:   #10b981;

  --info:         #60a5fa;
  --info-bg:      #172554;
  --info-border:  #3b82f6;
}

.dark .wiki-article pre { background: #1e1e2e; border-color: #313244; color: #cdd6f4; }
.dark .badge-get    { background: #1e3a5f; color: #93c5fd; }
.dark .badge-post   { background: #1a3d2e; color: #6ee7b7; }
.dark .badge-delete { background: #5c1a1a; color: #fca5a5; }
.dark .badge-put    { background: #4a4518; color: #fde047; }
.dark .search-wrap { background: #222228; }
.dark .theme-light { display: none; }
.dark .theme-dark  { display: inline; }
html:not(.dark) .theme-dark { display: none; }

/* ─── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar-h) + 1.5rem); }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Top Bar ───────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  height: var(--topbar-h);
  background: var(--bg-content);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.2rem;
  box-shadow: var(--shadow);
}
.topbar-left  { display: flex; align-items: center; gap: .7rem; flex-shrink: 0; }
.topbar-center { flex: 1; display: flex; justify-content: center; position: relative; }
.topbar-right { display: flex; align-items: center; gap: .8rem; flex-shrink: 0; }

.sidebar-toggle {
  background: none; border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 32px; height: 32px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.sidebar-toggle:hover { background: var(--bg-hover); color: var(--text); }

.site-logo {
  display: flex; align-items: center; gap: .5rem;
  text-decoration: none; color: var(--text);
  font-family: var(--font-body); font-weight: 700; font-size: .95rem;
  white-space: nowrap;
}
.logo-icon { font-size: 1.1rem; }
.page-count {
  font-size: .7rem; color: var(--text-muted);
  border-left: 1px solid var(--border); padding-left: .7rem;
}

/* Search */
.search-wrap {
  position: relative;
  display: flex; align-items: center;
  width: min(480px, 100%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 .75rem;
  gap: .5rem;
}
.search-icon { color: var(--text-muted); flex-shrink: 0; }
.search-input {
  border: none; background: transparent;
  font-family: var(--font-body); font-size: .85rem;
  color: var(--text); flex: 1;
  outline: none; padding: .45rem 0;
}
.search-input::placeholder { color: var(--text-muted); }
.search-wrap kbd {
  font-family: var(--font-mono); font-size: .7rem;
  background: var(--border); border-radius: 4px;
  padding: .1rem .4rem; color: var(--text-muted);
  flex-shrink: 0;
}
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-content);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  max-height: 320px;
  overflow-y: auto;
  display: none;
  z-index: 300;
}
.search-result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .6rem .8rem;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
}
.search-result-item:hover {
  background: var(--bg-hover);
  text-decoration: none;
}
.search-result-label { font-weight: 500; font-size: .85rem; }
.search-result-section { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.search-no-results { padding: 1rem; text-align: center; color: var(--text-muted); font-size: .85rem; }

/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 32px; height: 32px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  color: var(--text-muted);
  transition: all var(--transition);
}
.theme-toggle:hover { background: var(--bg-hover); color: var(--text); }

.topbar-link {
  font-size: .82rem; color: var(--text-muted); text-decoration: none;
  transition: color var(--transition);
}
.topbar-link:hover { color: var(--accent); text-decoration: none; }
.topbar-cta {
  background: var(--accent); color: #fff !important;
  padding: .3rem .8rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
}
.topbar-cta:hover { background: var(--accent-hover); }

/* ─── Layout ────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--topbar-h));
}

/* ─── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.4rem 0 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  display: flex;
  flex-direction: column;
}
.sidebar-nav { padding: 0 .75rem; flex: 1; }

.nav-section { margin-bottom: .25rem; }

.nav-section-toggle {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  background: none; border: none; cursor: pointer;
  font-family: var(--font-body); font-weight: 700;
  font-size: .72rem; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-muted);
  padding: .55rem .6rem;
  border-radius: var(--radius);
  transition: background var(--transition), color var(--transition);
  user-select: none;
}
.nav-section-toggle:hover { background: var(--bg-hover); color: var(--text); }

.chevron {
  transition: transform var(--transition);
  flex-shrink: 0;
}
.nav-section.open .chevron { transform: rotate(180deg); }

.nav-submenu {
  list-style: none;
  max-height: 0;
  overflow: hidden;
  transition: max-height .28s cubic-bezier(.4,0,.2,1);
}
.nav-section.open .nav-submenu { max-height: 800px; }

.nav-item {
  display: block;
  padding: .42rem .6rem .42rem 1.2rem;
  margin: 1px 0;
  border-radius: var(--radius);
  font-size: .85rem;
  color: var(--text-sidebar);
  text-decoration: none;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  border-left: 2px solid transparent;
}
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}
.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 1rem .75rem;
  border-top: 1px solid var(--border);
  font-size: .72rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: auto;
}
.sidebar-footer p { line-height: 1.5; }

/* ─── Content area ──────────────────────────────────────────────────────── */
.content-wrap {
  flex: 1;
  display: flex;
  min-width: 0;
}

.content {
  flex: 1;
  min-width: 0;
  padding: 2.5rem clamp(1.5rem, 5vw, 3.5rem);
  max-width: 860px;
}

/* ─── Breadcrumb ────────────────────────────────────────────────────────── */
.breadcrumb {
  display: flex; align-items: center; gap: .4rem;
  font-size: .78rem; color: var(--text-muted);
  margin-bottom: 2rem;
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); text-decoration: none; }
.bc-sep { opacity: .5; }
.bc-current { color: var(--text); font-weight: 500; }

/* ─── Wiki Article ──────────────────────────────────────────────────────── */
.wiki-article { animation: fadeIn .35s ease; }

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

.wiki-article h1 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: clamp(1.7rem, 3vw, 2.2rem);
  line-height: 1.2;
  letter-spacing: -.02em;
  color: var(--text);
  margin-bottom: .6rem;
  padding-bottom: .8rem;
  border-bottom: 2px solid var(--accent);
}

.article-lead {
  font-size: 1.08rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
  line-height: 1.75;
}

.wiki-article h2 {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 1.35rem;
  margin: 2.8rem 0 .8rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
  scroll-margin-top: calc(var(--topbar-h) + 1rem);
}
.wiki-article h3 {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.05rem;
  margin: 2rem 0 .6rem;
  color: var(--text);
  scroll-margin-top: calc(var(--topbar-h) + 1rem);
}
.wiki-article h4 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: .95rem;
  margin: 1.5rem 0 .5rem;
  color: var(--text-muted);
}

.wiki-article p { margin-bottom: 1.1rem; color: var(--text); }

.wiki-article ul, .wiki-article ol {
  padding-left: 1.6rem;
  margin-bottom: 1.2rem;
}
.wiki-article li { margin-bottom: .4rem; }
.wiki-article li > code { font-size: .78em; }

.wiki-article code {
  font-family: var(--font-mono);
  font-size: .82em;
  background: var(--bg-code);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: .15em .4em;
  color: #c0392b;
}
.dark .wiki-article code { color: #f87171; }

.wiki-article pre {
  background: #1e1e2e;
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  overflow-x: auto;
  margin: 1.4rem 0;
  font-family: var(--font-mono);
  font-size: .82rem;
  line-height: 1.65;
  color: #cdd6f4;
  border: 1px solid #313244;
}
.wiki-article pre code {
  background: none; border: none; padding: 0; color: inherit; font-size: inherit;
}

/* Copy code button */
.copy-code-btn {
  position: absolute;
  top: .5rem;
  right: .5rem;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  color: #94a3b8;
  font-size: .72rem;
  font-family: var(--font-mono);
  padding: .25rem .55rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity .2s, background .2s, color .2s;
}
.wiki-article pre:hover .copy-code-btn { opacity: 1; }
.copy-code-btn:hover { background: rgba(255,255,255,0.2); color: #e2e8f0; }
.copy-code-btn.copied { background: #065f46; color: #fff; border-color: #34d399; opacity: 1; }

/* ─── Callout boxes ─────────────────────────────────────────────────────── */
.callout {
  border-left: 3px solid;
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1rem 1.2rem;
  margin: 1.5rem 0;
  font-size: .9rem;
}
.callout-warn  { background: var(--warn-bg);  border-color: var(--warn-border); color: var(--warn); }
.callout-tip   { background: var(--tip-bg);   border-color: var(--tip-border);  color: var(--tip); }
.callout-info  { background: var(--info-bg);  border-color: var(--info-border);  color: var(--info); }
.callout strong { display: block; margin-bottom: .3rem; font-size: .8rem; letter-spacing: .05em; text-transform: uppercase; }

/* ─── Table ─────────────────────────────────────────────────────────────── */
.wiki-table {
  width: 100%; border-collapse: collapse;
  font-size: .875rem; margin: 1.5rem 0;
}
.wiki-table th {
  background: var(--bg-code); font-weight: 600;
  padding: .65rem 1rem; text-align: left;
  border: 1px solid var(--border);
}
.wiki-table td {
  padding: .6rem 1rem;
  border: 1px solid var(--border-light);
  vertical-align: top;
}
.wiki-table tr:hover td { background: var(--bg); }
.wiki-table code { font-size: .78em; }

/* ─── Tags / badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: .72rem; font-weight: 600; font-family: var(--font-mono);
  padding: .15rem .55rem;
  border-radius: 999px;
}
.badge-get    { background: #dbeafe; color: #1e40af; }
.badge-post   { background: #dcfce7; color: #166534; }
.badge-delete { background: #fee2e2; color: #991b1b; }
.badge-put    { background: #fef9c3; color: #854d0e; }
.badge-beta   { background: #f3e8ff; color: #7e22ce; }
.badge-new    { background: #ccfbf1; color: #0f766e; }

.wiki-link { color: var(--accent); font-weight: 500; }

/* ─── Process Steps (numbered work instructions) ────────────────────────── */
.process-steps {
  counter-reset: step;
  list-style: none;
  padding-left: 0;
}
.process-steps li {
  position: relative;
  padding-left: 2.8rem;
  margin-bottom: 1.2rem;
  min-height: 2rem;
}
.process-steps li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 2rem;
  height: 2rem;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: .85rem;
  font-family: var(--font-mono);
}
.process-steps li h4 {
  margin-top: 0;
  margin-bottom: .3rem;
  color: var(--text);
}

/* ─── File Tree / Directory listings ────────────────────────────────────── */
.file-tree {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.4rem;
  font-family: var(--font-mono);
  font-size: .82rem;
  line-height: 1.8;
  margin: 1.2rem 0;
}
.file-tree .dir { color: var(--accent); font-weight: 500; }
.file-tree .file { color: var(--text-muted); }
.dark .file-tree .file { color: #a3a3a3; }

/* ─── Mermaid-style diagram placeholder ─────────────────────────────────── */
.diagram-container {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1.5rem 0;
  text-align: center;
}
.diagram-container img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
}
.diagram-caption {
  font-size: .82rem;
  color: var(--text-muted);
  margin-top: .75rem;
  font-style: italic;
}

/* ─── Checklist ─────────────────────────────────────────────────────────── */
.checklist {
  list-style: none;
  padding-left: 0;
}
.checklist li {
  padding-left: 1.8rem;
  position: relative;
  margin-bottom: .6rem;
}
.checklist li::before {
  content: "☐";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: bold;
}
.checklist li.checked::before { content: "☑"; }

/* ─── TOC Rail ──────────────────────────────────────────────────────────── */
.toc-rail {
  width: var(--toc-w);
  flex-shrink: 0;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 2.5rem 1rem 3rem 1.5rem;
  border-left: 1px solid var(--border-light);
}
.toc-label {
  font-size: .7rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-muted);
  margin-bottom: .8rem;
}
.toc-nav { display: flex; flex-direction: column; gap: .2rem; }
.toc-item {
  font-size: .8rem; color: var(--text-muted); text-decoration: none;
  padding: .25rem .5rem;
  border-radius: 4px;
  transition: background var(--transition), color var(--transition);
  border-left: 2px solid transparent;
}
.toc-item:hover { color: var(--accent); text-decoration: none; }
.toc-sub { padding-left: 1rem; }
.toc-active { color: var(--accent) !important; border-left-color: var(--accent); background: var(--accent-bg); }

.toc-meta {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
}
.toc-meta-label {
  font-size: .65rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-muted);
  margin-bottom: .4rem;
}
.toc-meta-item {
  font-size: .78rem; color: var(--text-muted); margin-bottom: .2rem;
}

/* ─── Hero / Welcome section on intro ───────────────────────────────────── */
.wiki-hero {
  background: linear-gradient(135deg, var(--accent-bg) 0%, var(--bg-code) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.2rem;
  margin-bottom: 2rem;
}
.wiki-hero h2 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  margin: 0 0 .5rem;
  border: none;
  color: var(--text);
}
.wiki-hero p {
  margin: 0;
  color: var(--text-muted);
}
.wiki-hero .hero-stats {
  display: flex;
  gap: 2rem;
  margin-top: 1.2rem;
  flex-wrap: wrap;
}
.hero-stats .stat {
  text-align: center;
}
.hero-stats .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
}
.hero-stats .stat-label {
  font-size: .75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ─── Section cards on intro ────────────────────────────────────────────── */
.section-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}
.section-card {
  background: var(--bg-content);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  transition: box-shadow var(--transition), transform var(--transition);
  text-decoration: none;
  color: var(--text);
}
.section-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
  transform: translateY(-2px);
  text-decoration: none;
}
.section-card-icon { font-size: 1.8rem; margin-bottom: .5rem; }
.section-card h3 { margin: 0 0 .3rem; font-size: 1rem; }
.section-card p { margin: 0; font-size: .82rem; color: var(--text-muted); }

/* ─── Footer ────────────────────────────────────────────────────────────── */
.wiki-footer {
  border-top: 1px solid var(--border);
  padding: 1.1rem 1.5rem;
  font-size: .8rem;
  color: var(--text-muted);
  display: flex;
  gap: .6rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.footer-sep { opacity: .4; }
.wiki-footer a { color: var(--text-muted); }
.wiki-footer a:hover { color: var(--accent); text-decoration: none; }

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .toc-rail { display: none; }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    height: calc(100vh - var(--topbar-h));
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 150;
    box-shadow: 4px 0 24px rgba(0,0,0,.12);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar-right .topbar-link:not(.topbar-cta) { display: none; }
  .content { padding: 1.5rem 1.2rem; }
  .page-count { display: none; }
  .search-wrap { width: 100%; }
}

@media (max-width: 480px) {
  .topbar-center { display: none; }
  .section-cards { grid-template-columns: 1fr; }
  .hero-stats { gap: 1rem; }
}

/* ─── Print styles ──────────────────────────────────────────────────────── */
@media print {
  .sidebar, .toc-rail, .topbar, .wiki-footer,
  .sidebar-toggle, .theme-toggle, .copy-code-btn {
    display: none !important;
  }
  .content { max-width: 100%; padding: 0; }
  .wiki-article pre { white-space: pre-wrap; word-break: break-word; }
  body { background: #fff; color: #000; }
  a { color: #000; text-decoration: none; }
  .wiki-article h1 { border-bottom-color: #999; }
  .callout { border-left-width: 3px !important; }
}
