/* Command Builder UI styles. Dark/light theme with WCAG-AA contrast. */

:root {
  --bg: #ffffff;
  --bg-elev: #f7f8fa;
  --bg-elev-2: #eef0f3;
  --border: #d8dce3;
  --fg: #14181f;
  --fg-muted: #57606a;
  --accent: #0b6bcb;
  --accent-fg: #ffffff;
  --code-bg: #f4f4f6;
  --code-fg: #1f2328;
  --warn: #b25e09;
  --danger: #b5121b;
  --good: #1a7f37;
  --shadow: 0 8px 32px rgba(20, 24, 31, 0.12);
  --radius: 6px;
  --radius-lg: 10px;
  --header-h: 56px;
  --sidebar-w: 260px;
  --maxw: 980px;
}

[data-theme="dark"], [data-theme="system"] {
  color-scheme: dark light;
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg: #0f1217;
    --bg-elev: #161a22;
    --bg-elev-2: #1d212b;
    --border: #2a2f3a;
    --fg: #e6e9ef;
    --fg-muted: #9ba3af;
    --accent: #5fa8ff;
    --accent-fg: #0f1217;
    --code-bg: #181c25;
    --code-fg: #e6e9ef;
    --warn: #f0a55a;
    --danger: #ff8a8e;
    --good: #6fcf83;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  }
}

[data-theme="dark"] {
  --bg: #0f1217;
  --bg-elev: #161a22;
  --bg-elev-2: #1d212b;
  --border: #2a2f3a;
  --fg: #e6e9ef;
  --fg-muted: #9ba3af;
  --accent: #5fa8ff;
  --accent-fg: #0f1217;
  --code-bg: #181c25;
  --code-fg: #e6e9ef;
  --warn: #f0a55a;
  --danger: #ff8a8e;
  --good: #6fcf83;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

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

kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  font: 11px ui-monospace, Menlo, monospace;
  color: var(--fg-muted);
}

button, select, input[type="search"] {
  font: inherit;
  color: inherit;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
}

button:hover, select:hover { background: var(--bg-elev-2); }

button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="search"] { cursor: text; }

code, pre, .mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace;
  background: var(--code-bg);
  color: var(--code-fg);
}

code { padding: 1px 5px; border-radius: 3px; font-size: 0.92em; }
pre {
  padding: 12px 14px;
  border-radius: var(--radius);
  overflow-x: auto;
  border: 1px solid var(--border);
}

.skip-link {
  position: absolute;
  top: -100px; left: 8px;
  padding: 8px 12px;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: var(--radius);
  z-index: 100;
}
.skip-link:focus { top: 8px; }

/* Header */
header {
  position: sticky;
  top: 0;
  z-index: 5;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-mark {
  font-family: ui-monospace, monospace;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.brand-name { font-weight: 600; }
.brand-meta { color: var(--fg-muted); font-size: 0.85em; }

.search-trigger {
  flex: 1;
  max-width: 480px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  text-align: left;
  color: var(--fg-muted);
}
.search-trigger kbd { margin-left: auto; }

.header-actions { display: flex; gap: 8px; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: calc(100vh - var(--header-h));
}

aside {
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 18px 12px;
  overflow-y: auto;
  height: calc(100vh - var(--header-h));
  position: sticky;
  top: var(--header-h);
}

aside h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
  margin: 18px 6px 6px;
  font-weight: 600;
}
aside h2:first-child { margin-top: 0; }

aside nav { display: flex; flex-direction: column; gap: 1px; }
aside nav a, aside nav button {
  display: block;
  padding: 6px 10px;
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--fg);
  text-align: left;
  width: 100%;
}
aside nav a:hover, aside nav button:hover {
  background: var(--bg-elev-2);
  text-decoration: none;
}
aside nav a.active {
  background: var(--accent);
  color: var(--accent-fg);
}
aside nav .count {
  float: right;
  color: var(--fg-muted);
  font-size: 0.85em;
}
aside nav a.active .count { color: var(--accent-fg); opacity: 0.85; }
aside .hint { color: var(--fg-muted); font-size: 0.85em; margin: 4px 6px; }

main {
  padding: 28px 32px;
  max-width: 100%;
  overflow-x: hidden;
}

main > #view {
  max-width: var(--maxw);
  margin: 0 auto;
}

/* Home */
.hero {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 28px 0 32px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.hero h1 { margin: 0; font-size: 2.4rem; line-height: 1.2; }
.hero p { color: var(--fg-muted); margin: 0; max-width: 60ch; }

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.tile {
  display: block;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--fg);
  transition: border-color 0.15s;
}
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile h3 {
  margin: 0 0 4px;
  font-family: ui-monospace, monospace;
  font-size: 1.05rem;
}
.tile p { margin: 0; color: var(--fg-muted); font-size: 0.9rem; }
.tile .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* Command page */
.cmd-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.cmd-header h1 {
  font-family: ui-monospace, monospace;
  margin: 0;
  font-size: 2rem;
}
.cmd-header .cat {
  background: var(--bg-elev-2);
  color: var(--fg-muted);
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 0.85em;
}
.cmd-header .actions { margin-left: auto; display: flex; gap: 6px; }

.cmd-section { margin: 28px 0; }
.cmd-section h2 {
  font-size: 1.15rem;
  letter-spacing: 0.01em;
  margin: 0 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.cmd-section h3 { font-size: 1rem; margin: 16px 0 8px; }

.tag {
  display: inline-block;
  font-size: 0.78rem;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--bg-elev-2);
  color: var(--fg-muted);
}
.tag-platform { background: var(--bg-elev-2); }
.tag-cat-common { background: rgba(11, 107, 203, 0.15); color: var(--accent); }
.tag-cat-advanced { background: rgba(178, 94, 9, 0.15); color: var(--warn); }
.tag-cat-deprecated { background: rgba(181, 18, 27, 0.15); color: var(--danger); }
.tag-difficulty { font-style: italic; }

.option {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.option:last-child { border-bottom: none; }
.option .flag {
  font-family: ui-monospace, monospace;
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 4px 8px;
  border-radius: var(--radius);
  align-self: start;
  white-space: nowrap;
  overflow-x: auto;
}
.option .meta { color: var(--fg-muted); font-size: 0.85em; margin-top: 4px; }

.example {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  background: var(--bg-elev);
}
.example .ex-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.example .ex-head h3 { margin: 0; font-size: 0.95rem; }
.example .ex-head .actions { margin-left: auto; display: flex; gap: 4px; }
.example .ex-cmd { margin: 0; border: none; border-radius: 0; }
.example .ex-explain { padding: 10px 14px; color: var(--fg-muted); border-top: 1px solid var(--border); }
.example .ex-output { margin: 0; border: none; border-top: 1px solid var(--border); border-radius: 0; opacity: 0.85; }

.feedback-btn {
  background: transparent;
  border: 1px solid var(--border);
  padding: 3px 8px;
  font-size: 0.85rem;
}
.feedback-btn.voted { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

.pitfall {
  border-left: 3px solid var(--fg-muted);
  padding: 10px 14px;
  margin-bottom: 8px;
  background: var(--bg-elev);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.pitfall.severity-warning { border-color: var(--warn); }
.pitfall.severity-danger { border-color: var(--danger); }
.pitfall h4 { margin: 0 0 4px; font-size: 0.95rem; }
.pitfall p { margin: 0; color: var(--fg-muted); }

.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.related-grid a {
  display: block;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--fg);
}
.related-grid a:hover { border-color: var(--accent); text-decoration: none; }
.related-grid .reason { color: var(--fg-muted); font-size: 0.85rem; }

/* Search overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 10vh;
  z-index: 50;
}
.overlay[hidden] { display: none; }

.search-panel {
  width: 90%;
  max-width: 720px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 70vh;
}
.search-panel input[type="search"] {
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 16px 18px;
  font-size: 1.1rem;
  background: transparent;
}
.search-panel input[type="search"]:focus-visible { outline: none; }
.search-results { flex: 1; overflow-y: auto; }
.search-result {
  display: flex;
  flex-direction: column;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.search-result.active, .search-result:hover { background: var(--bg-elev-2); }
.search-result .name {
  font-family: ui-monospace, monospace;
  font-weight: 600;
}
.search-result .desc { color: var(--fg-muted); font-size: 0.9rem; }
.search-result .meta { font-size: 0.78rem; color: var(--fg-muted); margin-top: 2px; }
.search-footer {
  display: flex;
  gap: 12px;
  padding: 8px 18px;
  background: var(--bg-elev-2);
  font-size: 0.82rem;
  color: var(--fg-muted);
}
.search-empty { padding: 20px 18px; color: var(--fg-muted); text-align: center; }

/* Compare tray */
.compare-tray {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 30;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 10px;
}
.compare-tray ul { list-style: none; padding: 0; margin: 0; display: flex; gap: 6px; }
.compare-tray ul li {
  font-family: ui-monospace, monospace;
  background: var(--bg-elev-2);
  padding: 3px 8px;
  border-radius: var(--radius);
  font-size: 0.85rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: var(--radius);
  z-index: 100;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }

/* Compare table */
.compare-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}
.compare-table th, .compare-table td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  vertical-align: top;
  text-align: left;
}
.compare-table th { background: var(--bg-elev-2); }
.compare-table td.absent { color: var(--fg-muted); font-style: italic; }
.compare-table tr.header-row td { background: var(--bg-elev); font-weight: 600; }

/* Cheatsheet builder */
.cheat-builder {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}
.cheat-builder fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.cheat-builder label { display: block; padding: 4px 0; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  aside { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  main { padding: 20px 18px; }
  .cheat-builder { grid-template-columns: 1fr; }
  .option { grid-template-columns: 1fr; }
  .header-actions select { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  * { transition: none !important; }
}
