/* style.css */
:root {
    --black: #000000;
    --burgundy: #4a0404;
    --marine: #0c1a3d;
    --forest: #052e16;
    --moss: #333d29;
    --bone: #e0e0e0;

    --theme-bg: var(--black);
    --theme-text: var(--bone);
}

body.theme-burgundy { --theme-bg: var(--burgundy); }
body.theme-marine { --theme-bg: var(--marine); }
body.theme-forest { --theme-bg: var(--forest); }
body.theme-black { --theme-bg: var(--black); }

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body, html {
    height: 100%;
    font-family: 'Book Antiqua', Palatino, serif;
    display: flex;
    flex-direction: column;
    background-color: #ffffff;
    color: #111111;
}

/* Header & Navigering */
#main-header {
    background-color: var(--theme-bg);
    color: var(--theme-text);
    padding: 15px 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

#site-title {
    font-size: 1.5rem;
    margin-bottom: 10px;
    text-align: center;
    border-bottom: 1px solid var(--moss);
    padding-bottom: 10px;
}

#site-title a {
    color: var(--theme-text);
    text-decoration: none;
}

#main-menu {
    list-style: none;
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

#main-menu a {
    color: var(--theme-text);
    text-decoration: none;
    font-weight: bold;
    padding: 5px 10px;
    border: 1px solid transparent;
    border-radius: 4px;
}

#main-menu a:hover {
    border-color: var(--moss);
    background-color: rgba(255,255,255,0.1);
}

#main-menu a.active {
    border-color: var(--bone);
}

/* Huvudinnehåll */
#main-container {
    flex: 1;
    padding: 20px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

/* Inloggningsgrind */
.login-box {
    max-width: 400px;
    margin: 50px auto;
    text-align: center;
    padding: 30px;
    border: 2px solid var(--theme-bg);
    border-radius: 6px;
    background-color: #fafafa;
}

.login-box input {
    width: 100%;
    padding: 10px;
    margin: 20px 0;
    border: 1px solid #ccc;
    font-size: 1rem;
}

/* Standardknappar */
.primary-btn {
    background-color: var(--theme-bg);
    color: var(--theme-text);
    border: 1px solid var(--moss);
    padding: 10px 20px;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 4px;
    font-family: inherit;
    width: 100%;
}

.primary-btn:hover {
    background-color: var(--moss);
}

.danger-btn {
    background-color: var(--burgundy);
    color: #ffffff;
    border: 1px solid #ff0000;
    padding: 10px 20px;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 4px;
    font-family: inherit;
    width: 100%;
}

/* Sidfot */
#main-footer {
    background-color: var(--theme-bg);
    padding: 15px 20px;
    margin-top: auto;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 800px;
    margin: 0 auto;
}

.credit-text {
    font-size: 0.85em;
    color: #888888;
}

.footer-links {
    display: flex;
    gap: 10px;
    align-items: center;
}

.divider {
    color: var(--moss);
}

.footer-links a {
    color: var(--theme-text);
    text-decoration: none;
    font-size: 0.9em;
}

.footer-links a:hover {
    text-decoration: underline;
}

.admin-link {
    color: #ffaa00 !important;
}

/* Datatabeller (Listvy) */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    font-size: 0.95em;
}

.data-table th {
    background-color: var(--theme-bg);
    color: var(--theme-text);
    text-align: left;
    padding: 10px;
    border: 1px solid var(--theme-bg);
}

.data-table td {
    padding: 10px;
    border-bottom: 1px solid #ccc;
}

.data-table tbody tr {
    cursor: pointer;
    transition: background-color 0.2s;
}

.data-table tbody tr:hover {
    background-color: #f0f0f0;
}

/* Detaljkort (Kortvy) */
.back-link {
    display: inline-block;
    margin-bottom: 20px;
    color: var(--theme-bg);
    text-decoration: none;
    font-weight: bold;
}

.back-link:hover {
    text-decoration: underline;
}

.detail-card {
    border: 2px solid var(--theme-bg);
    background-color: #fafafa;
    border-radius: 6px;
    padding: 20px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.detail-card h3 {
    border-bottom: 2px solid var(--moss);
    padding-bottom: 5px;
    margin-top: 20px;
    margin-bottom: 10px;
    color: var(--theme-bg);
}

.detail-row {
    display: flex;
    padding: 8px 0;
    border-bottom: 1px solid #ddd;
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    font-weight: bold;
    width: 150px;
    flex-shrink: 0;
    text-transform: capitalize;
}

.detail-value {
    flex-grow: 1;
}

/* Sub-tabeller inuti kortet */
.sub-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    background-color: #fff;
    border: 1px solid #ccc;
}

.sub-table th {
    background-color: #eee;
    padding: 8px;
    text-align: left;
    border-bottom: 2px solid #ccc;
}

.sub-table td {
    padding: 8px;
    border-bottom: 1px solid #eee;
}

/* Kodblock och förformaterad text */
pre {
    background-color: var(--black);
    color: var(--bone);
    padding: 15px;
    overflow-x: auto;
    border-left: 4px solid var(--theme-bg);
    font-family: 'Courier New', Courier, monospace;
    border-radius: 4px;
    margin: 20px 0;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.8);
}

pre code {
    font-family: inherit;
}

/* --- Nya tillägg för sök, sortering och ikoner --- */

.table-controls {
    margin-bottom: 15px;
}

#table-search {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--theme-bg);
    border-radius: 4px;
    font-size: 1rem;
    font-family: inherit;
    background-color: #fafafa;
}

#table-search:focus {
    outline: none;
    border-color: var(--moss);
    background-color: #ffffff;
}

/* Sorterbara rubriker */
.data-table th {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 20px;
}

.data-table th:hover {
    background-color: var(--moss);
    color: var(--bone);
}

.sort-icon {
    font-size: 0.8em;
    opacity: 0.4;
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
}

/* Booleska ikoner */
.bool-yes {
    color: #10b981; /* Skogsgrön bock */
    font-weight: bold;
    font-size: 1.2em;
}

.bool-no {
    color: #ef4444; /* Rött kryss */
    font-weight: bold;
    font-size: 1.2em;
}

.text-center {
    text-align: center;
}

/* --- LÖSER TYPSNITTET --- */
body, button, input, select, textarea {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
}

/* --- LÖSER LADDNINGSIKONEN --- */
#loading-overlay {
    display: none; /* Dold som standard tills JS triggar den */
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: white;
}
.spinner {
    border: 6px solid rgba(255,255,255,0.2);
    border-top: 6px solid #fff;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- Detaljkort och specifika element --- */
.switch input:checked + .slider { background-color: var(--moss, #333d29); }
.switch input:focus + .slider { box-shadow: 0 0 1px var(--moss, #333d29); }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
.switch input:checked + .slider:before { transform: translateX(22px); }

.sub-nav-tabs { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; border-bottom: 1px solid #ccc; padding-bottom: 15px; }
.sub-nav-tabs a { padding: 6px 14px; border-radius: 4px; text-decoration: none; font-size: 0.9em; background: #eee; color: #333; transition: 0.2s; font-weight: 500; }
.sub-nav-tabs a:hover { background: #ddd; }
.sub-nav-tabs a.active { background: var(--moss, #333d29); color: white; }

.monster-block { margin-bottom: 25px; line-height: 1.5; }
.monster-statblock { margin: 15px 0; font-size: 1.05em; }
.monster-ability { margin-bottom: 8px; }

/* Källhänvisningen (Source) */
.monster-source { text-align: right; color: #888; font-size: 0.9em; margin-top: 30px; margin-bottom: 10px; }
.monster-source a { color: inherit; text-decoration: none; border-bottom: 1px dotted #888; }
.monster-source a:hover { color: var(--moss, #333d29); border-bottom: 1px solid var(--moss, #333d29); }

/* Svenskt namn */
.swedish-name-line { color: #888; font-size: 0.95em; margin-bottom: 15px; margin-top: -5px; }
.swedish-name-line a { color: #888; text-decoration: none; border-bottom: 1px dotted #888; cursor: pointer; }
.swedish-name-line a:hover { color: var(--moss, #333d29); border-bottom: 1px solid var(--moss, #333d29); }

.monster-tags { margin-top: 15px; font-size: 0.9em; }

.md-block p:first-child { margin-top: 0; }
.md-block p:last-child { margin-bottom: 0; }

.data-table tr.clickable-row { cursor: pointer; transition: background-color 0.2s; }
.data-table tr.clickable-row:hover { background-color: rgba(0,0,0,0.05); }