/* ── Theme Variables ──────────────────────────────────────────── */
:root {
    --bg: #ffffff;
    --bg-surface: #f5f5f5;
    --border-color: #e0e0e0;
    --accent: #4A90E2;
    --accent-hover: #357ABD;
    --text-main: #333333;
    --text-muted: #666666;
    --code-bg: #f5f5f5;
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
    --bg: #1e1e1e;
    --bg-surface: #252525;
    --border-color: #3c3c3c;
    --accent: #4A90E2;
    --accent-hover: #5fa0ea;
    --text-main: #d4d4d4;
    --text-muted: #808080;
    --code-bg: #1e1e1e;
}

/* Aliases for backwards compat with older viewer.html references */
:root {
    --surface: var(--bg-surface);
    --border: var(--border-color);
    --text: var(--text-main);
}

/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text-main);
    font-family: var(--font-body);
    line-height: 1.5;
    font-size: 14px;
}

.hidden { display: none !important; }

/* ── Theme Toggle Button ──────────────────────────────────────── */
.theme-toggle {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 6px 12px;
    color: var(--text-main);
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    white-space: nowrap;
}

.theme-toggle:hover {
    border-color: var(--accent);
    background: var(--accent);
    color: white;
}

/* ── Typography ───────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-main);
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    font-weight: 600;
}

h1 {
    font-size: 2em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
    margin-top: 0;
}

h2 {
    font-size: 1.5em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
}

p { margin: 1em 0; }

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

a:hover { text-decoration: underline; }

/* ── Code ─────────────────────────────────────────────────────── */
code {
    background: var(--code-bg);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.9em;
}

pre {
    background: var(--code-bg);
    padding: 15px;
    border-radius: 4px;
    overflow-x: auto;
    border: 1px solid var(--border-color);
    margin-bottom: 1rem;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 13px;
}

pre code {
    background: none;
    padding: 0;
}

/* ── Blockquotes ──────────────────────────────────────────────── */
blockquote {
    border-left: 3px solid var(--accent);
    margin: 1em 0;
    padding: 0.5em 1em;
    color: var(--text-muted);
}

/* ── Images ───────────────────────────────────────────────────── */
img {
    max-width: 100%;
    height: auto;
}

/* ── Tables ───────────────────────────────────────────────────── */
table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

th, td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

th {
    background: var(--code-bg);
    font-weight: 600;
}

/* ── Lists ────────────────────────────────────────────────────── */
ul, ol { padding-left: 2em; }
li { margin: 0.3em 0; }

/* ── Horizontal Rule ──────────────────────────────────────────── */
hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2em 0;
}

/* ── Common Components ────────────────────────────────────────── */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 40px 20px;
}

.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.error {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 20px;
    border-radius: 4px;
    margin: 20px 0;
}

.error-msg {
    color: #ff3333;
    font-size: 0.85rem;
    min-height: 1.2rem;
}

.back-link {
    display: inline-block;
    margin-top: 40px;
    padding: 8px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-main);
}

.back-link:hover {
    border-color: var(--accent);
}

/* ── Buttons ──────────────────────────────────────────────────── */
button, .btn-primary {
    padding: 0.5rem 1rem;
    border-radius: 4px;
    border: none;
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    background: var(--accent);
    color: white;
    font-family: var(--font-body);
}

button:hover, .btn-primary:hover {
    background: var(--accent-hover);
}

/* ── Inputs ───────────────────────────────────────────────────── */
input, textarea {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.875rem;
    background: var(--bg);
    color: var(--text-main);
    font-family: var(--font-body);
    outline: none;
}

input:focus, textarea:focus {
    border-color: var(--accent);
}

/* ── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
