/* ============================================================
   CASEFILE — Personal Security Knowledgebase
   Design language: field-notebook / evidence-log aesthetic.
   Every entry is a "tagged" note, not a wiki article.
   ============================================================ */

:root {
  /* Palette */
  --bg:            #14171A;
  --bg-panel:      #1A1E22;
  --bg-elevated:   #20262B;
  --bg-hover:      #262D33;
  --ink:           #E8E6DF;
  --ink-dim:       #C7C4BB;
  --muted:         #83898F;
  --border:        #2A3138;
  --border-bright: #3A434B;

  --amber:         #FFB454;
  --amber-dim:     #8A6A32;
  --teal:          #4FD1C5;
  --teal-dim:      #2C6B65;
  --danger:        #E8685D;
  --danger-dim:    #5A2E2A;

  --font-display: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;
  --font-body:    'IBM Plex Sans', -apple-system, sans-serif;
  --font-code:    'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;

  --radius: 3px;
  --sidebar-w: 300px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(circle at 20% 0%, rgba(255,180,84,0.03), transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(79,209,197,0.03), transparent 40%);
}

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

::selection { background: var(--amber-dim); color: var(--ink); }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* Focus visibility */
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

/* ============= LAYOUT ============= */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 50;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 20px 0 40px rgba(0,0,0,.5);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-flex !important; }
}

/* ============= SIDEBAR ("case cabinet") ============= */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
}

.sidebar-header {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.brand .dot { color: var(--amber); }
.brand-tagline {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.5;
}

.sidebar-search {
  margin: 14px 18px;
}
.sidebar-search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-family: var(--font-code);
  font-size: 13px;
}
.sidebar-search-box:focus-within { border-color: var(--amber); }
.sidebar-search-box .prompt { color: var(--amber); user-select: none; }
.sidebar-search-box input {
  background: none;
  border: none;
  outline: none;
  color: var(--ink);
  font-family: var(--font-code);
  font-size: 13px;
  width: 100%;
}
.sidebar-search-box input::placeholder { color: var(--muted); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 20px;
}

.nav-cat { margin-bottom: 2px; }
.nav-cat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 8px;
  cursor: pointer;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink-dim);
  user-select: none;
}
.nav-cat-head:hover { background: var(--bg-hover); }
.nav-cat-head .chevron {
  font-size: 10px;
  color: var(--muted);
  transition: transform .15s ease;
  width: 10px;
  flex-shrink: 0;
}
.nav-cat.open > .nav-cat-head .chevron { transform: rotate(90deg); }
.nav-cat-head .tab-swatch {
  width: 3px;
  align-self: stretch;
  border-radius: 2px;
  flex-shrink: 0;
}
.nav-cat-count {
  margin-left: auto;
  font-family: var(--font-code);
  font-size: 10.5px;
  color: var(--muted);
  background: var(--bg-elevated);
  padding: 1px 6px;
  border-radius: 8px;
}

.nav-pages {
  display: none;
  padding-left: 17px;
  border-left: 1px solid var(--border);
  margin-left: 16px;
}
.nav-cat.open > .nav-pages { display: block; }

.nav-page-item { }
.nav-page-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--muted);
  border-radius: var(--radius);
  cursor: pointer;
  line-height: 1.4;
}
.nav-page-link:hover { background: var(--bg-hover); color: var(--ink-dim); text-decoration: none; }
.nav-page-link.active { background: var(--bg-elevated); color: var(--amber); }
.nav-page-link .status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  flex-shrink: 0;
  background: var(--border-bright);
}
.nav-page-link.has-content .status-dot { background: var(--teal); }

.nav-children {
  padding-left: 14px;
  border-left: 1px solid var(--border);
  margin-left: 14px;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  color: var(--muted);
  font-family: var(--font-code);
}
.sidebar-footer a { color: var(--muted); }
.sidebar-footer a:hover { color: var(--amber); }

/* ============= MAIN ============= */
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  position: sticky;
  top: 0;
  z-index: 10;
}
@media (max-width: 860px) { .topbar { display: flex; } }

.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  cursor: pointer;
  font-family: var(--font-code);
}

.content {
  flex: 1;
  padding: 40px 56px 100px;
  max-width: 900px;
}
@media (max-width: 640px) { .content { padding: 24px 20px 80px; } }

/* Home hero */
.hero {
  padding: 8px 0 30px;
}
.hero-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-code);
  font-size: 12px;
  color: var(--amber);
  border: 1px dashed var(--amber-dim);
  padding: 4px 10px;
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.hero h1 {
  font-family: var(--font-display);
  font-size: 34px;
  margin: 0 0 12px;
  letter-spacing: -0.3px;
}
.hero p.lead {
  color: var(--ink-dim);
  font-size: 16px;
  max-width: 60ch;
  margin: 0 0 30px;
}
.hero-stats {
  display: flex;
  gap: 28px;
  flex-wrap: wrap;
  margin: 30px 0 10px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.hero-stat .num {
  font-family: var(--font-display);
  font-size: 26px;
  color: var(--teal);
}
.hero-stat .label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 30px;
}
.cat-card {
  border: 1px solid var(--border);
  background: var(--bg-panel);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.cat-card:hover { border-color: var(--border-bright); background: var(--bg-elevated); }
.cat-card::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--card-color, var(--amber));
}
.cat-card h3 {
  font-family: var(--font-display);
  font-size: 14.5px;
  margin: 0 0 6px;
  font-weight: 500;
}
.cat-card .count {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--font-code);
}

/* Page (evidence entry) header */
.entry-header {
  margin-bottom: 30px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.breadcrumb {
  font-family: var(--font-code);
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--teal); }
.breadcrumb .sep { opacity: 0.5; }

.entry-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.entry-title-row h1 {
  font-family: var(--font-display);
  font-size: 28px;
  margin: 0;
  letter-spacing: -0.2px;
  max-width: 46ch;
}

.tag-stamp {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--amber);
  border: 1px dashed var(--amber-dim);
  padding: 5px 10px;
  border-radius: var(--radius);
  white-space: nowrap;
  transform: rotate(1.2deg);
  flex-shrink: 0;
}

.entry-meta {
  display: flex;
  gap: 14px;
  margin-top: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--font-code);
  align-items: center;
}
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 10px;
  font-size: 11px;
  border: 1px solid var(--border-bright);
}
.status-badge.complete { color: var(--teal); border-color: var(--teal-dim); background: rgba(79,209,197,0.07); }
.status-badge.empty { color: var(--muted); }
.status-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Markdown-rendered body */
.entry-body {
  font-size: 15px;
  color: var(--ink-dim);
}
.entry-body h1, .entry-body h2, .entry-body h3, .entry-body h4 {
  font-family: var(--font-display);
  color: var(--ink);
  font-weight: 600;
  margin: 34px 0 14px;
  letter-spacing: -0.2px;
}
.entry-body h1 { font-size: 22px; }
.entry-body h2 { font-size: 19px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.entry-body h3 { font-size: 16px; color: var(--amber); }
.entry-body h4 { font-size: 14px; }
.entry-body p { margin: 14px 0; }
.entry-body ul, .entry-body ol { margin: 14px 0; padding-left: 24px; }
.entry-body li { margin: 5px 0; }
.entry-body li.checklist-item { list-style: none; margin-left: -24px; padding-left: 28px; position: relative; }
.entry-body li.checklist-item::before {
  content: "☐";
  position: absolute; left: 0; color: var(--muted); font-family: var(--font-code);
}
.entry-body li.checklist-item.checked::before { content: "☑"; color: var(--teal); }

.entry-body code {
  font-family: var(--font-code);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.88em;
  color: var(--amber);
}
.entry-body pre {
  background: #0F1214;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  overflow-x: auto;
  margin: 16px 0;
  position: relative;
}
.entry-body pre code {
  background: none;
  border: none;
  padding: 0;
  color: #D7E4DC;
  font-size: 13.2px;
  line-height: 1.6;
}
.copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--font-code);
  font-size: 10.5px;
  padding: 3px 8px;
  border-radius: 3px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .12s ease;
}
.entry-body pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--amber); border-color: var(--amber-dim); }

.entry-body blockquote {
  margin: 16px 0;
  padding: 4px 16px;
  border-left: 3px solid var(--amber-dim);
  color: var(--muted);
  font-style: italic;
}
.entry-body hr { border: none; border-top: 1px solid var(--border); margin: 30px 0; }
.entry-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 13.5px;
}
.entry-body th, .entry-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.entry-body th {
  background: var(--bg-elevated);
  font-family: var(--font-code);
  font-size: 12px;
  color: var(--amber);
  font-weight: 500;
}
.entry-body tr:nth-child(even) td { background: rgba(255,255,255,0.015); }
.entry-body a { border-bottom: 1px dotted var(--teal-dim); }
.entry-body strong { color: var(--ink); font-weight: 600; }

.empty-state {
  border: 1px dashed var(--border-bright);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  color: var(--muted);
  margin-top: 10px;
}
.empty-state .stamp {
  font-family: var(--font-display);
  color: var(--danger);
  border: 1px dashed var(--danger-dim);
  display: inline-block;
  padding: 4px 10px;
  transform: rotate(-2deg);
  margin-bottom: 14px;
  font-size: 12px;
}
.empty-state a.btn { margin-top: 12px; display: inline-block; }

.btn {
  font-family: var(--font-code);
  font-size: 12.5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none !important;
}
.btn:hover { border-color: var(--amber); color: var(--amber); }
.btn.primary { background: var(--amber); border-color: var(--amber); color: #1A1200; font-weight: 600; }
.btn.primary:hover { color: #1A1200; opacity: 0.9; }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }

/* Search results overlay */
.search-results {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  margin-top: 6px;
  max-height: 60vh;
  overflow-y: auto;
  z-index: 30;
  display: none;
  box-shadow: 0 12px 30px rgba(0,0,0,.5);
}
.search-results.show { display: block; }
.search-result-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--bg-hover); }
.search-result-item .path { font-size: 10.5px; color: var(--muted); font-family: var(--font-code); margin-top: 3px; }
.search-empty { padding: 14px; color: var(--muted); font-size: 13px; }

.sidebar-search { position: relative; }

/* Admin-specific bits (loaded on admin.html too) */
.admin-badge {
  font-family: var(--font-code);
  font-size: 10px;
  color: var(--danger);
  border: 1px solid var(--danger-dim);
  padding: 2px 6px;
  border-radius: 3px;
}
