/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --accent: #195785;
    --radius: 6px;
    --transition: .2s ease;
}

/* --- Dark theme (default) --- */
[data-theme="dark"] {
    --bg: #0e0e0e;
    --bg-card: #1a1a1a;
    --bg-input: #222;
    --border: #333;
    --text: #e8e8e8;
    --text-muted: #999;
    --accent-hover: #1d6a9f;
    --flash-error-bg: #3a1c1c;
    --flash-error-border: #6b2c2c;
    --flash-success-bg: #1c3a1c;
    --flash-success-border: #2c6b2c;
}

/* --- Light theme --- */
[data-theme="light"] {
    --bg: #f4f4f4;
    --bg-card: #fff;
    --bg-input: #f8f8f8;
    --border: #ddd;
    --text: #111;
    --text-muted: #666;
    --accent-hover: #124a6e;
    --flash-error-bg: #fde8e8;
    --flash-error-border: #e8aaaa;
    --flash-success-bg: #e8fde8;
    --flash-success-border: #aae8aa;
}

html { font-size: 16px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background var(--transition), color var(--transition);
}

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

/* ===== Header / Nav ===== */
header {
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
}

nav {
    max-width: 1100px;
    margin: 0 auto;
    padding: .75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand {
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent);
    letter-spacing: .02em;
}

.nav-right { display: flex; gap: .5rem; align-items: center; }

/* ===== Main ===== */
main {
    flex: 1;
    max-width: 1100px;
    width: 100%;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

/* ===== Footer ===== */
footer {
    text-align: center;
    padding: 1rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    font-size: .8rem;
}

/* ===== Two-column layout ===== */
.two-col {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 1rem;
    margin-top: 1rem;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}

.card-narrow { max-width: 420px; }
.center-card { margin: 0 auto; }

.card h1 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.card hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.25rem 0;
}

/* ===== Form elements ===== */
.field { margin-bottom: 1rem; }

.field label {
    display: block;
    font-size: .85rem;
    font-weight: 500;
    margin-bottom: .3rem;
    color: var(--text-muted);
}

input[type="text"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: .6rem .75rem;
    font-size: .95rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    transition: border var(--transition);
    font-family: inherit;
}

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

textarea { resize: vertical; min-height: 200px; }

select { cursor: pointer; }

.field-row {
    display: flex;
    gap: .75rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.field-row .field { flex: 1; min-width: 150px; }

/* ===== Search row ===== */
.search-row {
    display: flex;
    gap: .5rem;
}

.search-row input { flex: 1; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .55rem 1.1rem;
    font-size: .9rem;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    font-family: inherit;
    white-space: nowrap;
}

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

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }

.btn-block { width: 100%; }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; }

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* ===== Flashes ===== */
.flash {
    padding: .7rem 1rem;
    border-radius: var(--radius);
    font-size: .9rem;
    margin-bottom: 1rem;
}

.flash-error {
    background: var(--flash-error-bg);
    border: 1px solid var(--flash-error-border);
}

/* ===== Settings section ===== */
.settings-section { margin-bottom: 0; }

.settings-section summary {
    cursor: pointer;
    font-size: .9rem;
    font-weight: 500;
    color: var(--text-muted);
    padding: .3rem 0;
}

.settings-section summary:hover { color: var(--accent); }

.settings-body { margin-top: .75rem; }

.hint {
    font-size: .82rem;
    color: var(--text-muted);
    margin-bottom: .75rem;
    line-height: 1.5;
}

code {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: .1em .35em;
    font-size: .85em;
}

.msg {
    margin-top: .5rem;
    padding: .5rem .75rem;
    border-radius: var(--radius);
    font-size: .85rem;
}

.msg.success { background: var(--flash-success-bg); border: 1px solid var(--flash-success-border); }
.msg.error { background: var(--flash-error-bg); border: 1px solid var(--flash-error-border); }

/* ===== Result ===== */
.result {
    margin-top: 1.25rem;
    padding: 1rem;
    border-radius: var(--radius);
    background: var(--flash-success-bg);
    border: 1px solid var(--flash-success-border);
    line-height: 1.6;
}

.result.error {
    background: var(--flash-error-bg);
    border: 1px solid var(--flash-error-border);
}

.result a { font-weight: 600; }

/* ===== Loader ===== */
.loader {
    margin-top: 1.25rem;
    display: flex;
    align-items: center;
    gap: .75rem;
    font-size: .9rem;
    color: var(--text-muted);
}

.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Sidebar stack ===== */
.sidebar-stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* ===== Search results ===== */
.search-results { margin-top: .5rem; }

.search-list {
    list-style: none;
    padding: 0;
}

.search-list li {
    padding: .45rem 0;
    border-bottom: 1px solid var(--border);
    font-size: .88rem;
    line-height: 1.4;
}

.search-list li:last-child { border-bottom: none; }

.badge {
    display: inline-block;
    padding: .1rem .4rem;
    border-radius: 3px;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    background: var(--border);
    color: var(--text-muted);
    vertical-align: middle;
}

.badge-book { background: var(--accent); color: #fff; }
.badge-chapter { background: #5a4b8a; color: #fff; }
.badge-page { background: #3a6b3a; color: #fff; }
.badge-trello { background: #0079bf; color: #fff; }

/* ===== Trello card items ===== */
.trello-card-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: .5rem;
}

.trello-card-name { flex: 1; min-width: 0; }

.trello-labels { display: inline-flex; gap: .25rem; flex-wrap: wrap; }

.text-muted { color: var(--text-muted); font-size: .82rem; }

.btn-import { flex-shrink: 0; }

/* ===== Utility ===== */
.hidden { display: none !important; }

/* ===== Responsive ===== */
@media (max-width: 800px) {
    .two-col {
        grid-template-columns: 1fr;
    }
    main { margin: 1rem auto; }
    .card { padding: 1.25rem; }
    .field-row { flex-direction: column; }
}
