* {
    box-sizing: border-box;
    outline: none;
}
:focus,
:focus-within,
:focus-visible,
:active,
:target,
:hover {
    opacity: 1;
    transition: opacity 0.2s ease-in-out;
}

/* Default: Dark theme */
:root {
    --accent: #eea46d;
    --background: #1e1e1e;
    --default: #ccc;
    --item: #262728;
    --separator: #1e1e1e;
    --form-bg: #554840;
    --font-family: Sans-serif;
    --error: #ff0000;
    --disabled: #f5b88d;
}

/* System preference: Light theme (when JavaScript is disabled or no override) */
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --accent: #d4732a;
        --background: #ffffff;
        --default: #333333;
        --item: #f5f5f5;
        --separator: #e0e0e0;
        --form-bg: #e8dcc8;
    }
}

/* JavaScript override: Light theme */
:root[data-theme="light"] {
    --accent: #d4732a;
    --background: #ffffff;
    --default: #333333;
    --item: #f5f5f5;
    --separator: #e0e0e0;
    --form-bg: #e8dcc8;
}

/* JavaScript override: Dark theme */
:root[data-theme="dark"] {
    --accent: #eea46d;
    --background: #1e1e1e;
    --default: #ccc;
    --item: #262728;
    --separator: #1e1e1e;
    --form-bg: #554840;
}

body {
    background: var(--background);
    color: var(--default);
    display: grid;
    font-family: var(--font-family);
    font-size: 14px;
    grid-template-columns: 1fr;
    margin: 0;
    padding: 0;
}

@media (min-width: 1240px) {
    body {
        grid-template-columns: minmax(0, 580px) 25em;
        gap: 20px;
        justify-content: center;
    }
}

a,
a:visited,
a:active {
    color: var(--accent);
    text-decoration: none;
    opacity: 0.9;
}

h1 {
    font-size: 1.5em;
    font-weight: bold;
    margin: 0.67em 0;
}

h2 {
    font-size: 1.3em;
    font-weight: bold;
    margin: 0.75em 0;
}

h3 {
    font-size: 1.17em;
    font-weight: bold;
    margin: 0.83em 0;
}

h4 {
    font-size: 1em;
    font-weight: bold;
    margin: 1em 0;
}

h5 {
    font-size: 0.83em;
    font-weight: bold;
    margin: 1.17em 0;
}

p {
    margin: 0.5em 0;
}

ul,
ol {
    margin: 0.5em 0;
    padding-left: 2em;
    list-style-position: outside;
}

ul {
    list-style-type: disc;
}

ol {
    list-style-type: decimal;
}

li {
    margin: 0.25em 0;
    display: list-item;
}

code {
    background: var(--background);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: monospace;
}

pre {
    background: var(--background);
    padding: 1em;
    border-radius: 3px;
    overflow-x: auto;
    margin: 0.5em 0;
}

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

blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 1em;
    margin: 0.5em 0;
    opacity: 0.8;
}

table {
    border-collapse: collapse;
    margin: 0.5em 0;
    width: 100%;
}

th,
td {
    border: 1px solid var(--separator);
    padding: 0.5em;
    text-align: left;
}

th {
    background: var(--item);
    font-weight: bold;
}

hr {
    border: none;
    border-top: 1px solid var(--separator);
    margin: 1em 0;
    opacity: 0.3;
}

body > * {
    max-width: 100%;
    overflow: hidden;
    position: relative;
}

@media (min-width: 768px) {
    body > * {
        max-width: 580px;
    }
}

header {
    grid-column: 1;
    grid-row: 1;
    height: fit-content;
    margin: 16px auto;
    position: relative;
    top: 0;
    width: 100%;
}

/* Mobile menu toggle */
.mobile-menu-toggle {
    display: none;
}

.mobile-menu-button {
    display: none;
    background: var(--item);
    color: var(--accent);
    padding: 10px 15px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 20px;
    margin-top: 10px;
    text-align: center;
    user-select: none;
}

.mobile-menu {
    display: block;
}

@media (max-width: 767px) {
    .mobile-menu-button {
        display: block;
    }

    .mobile-menu {
        display: none;
        margin-top: 10px;
    }

    .mobile-menu-toggle:checked ~ .mobile-menu {
        display: block;
    }

    .mobile-menu-toggle:checked ~ .mobile-menu-button {
        opacity: 1;
    }
}

@media (min-width: 1240px) {
    header {
        grid-column: 2;
        position: sticky;
        top: 16px;
    }
}

header > a,
header > a:active,
header > a:hover,
header > a:visited {
    color: var(--default);
    font-size: 24px;
}

header > a .accent-text {
    color: var(--accent);
}

/* Theme toggle button */
.theme-toggle {
    background: var(--item);
    border: none;
    border-radius: 3px;
    color: var(--accent);
    cursor: pointer;
    font-size: 16px;
    padding: 6px;
    opacity: 0.9;
    user-select: none;
    float: right;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    opacity: 1;
}

header > p {
    font-size: small;
    margin-top: 3px;
}

.mobile-menu > div {
    font-size: small;
    margin-top: 12px;
    text-align: center;
}

.mobile-menu > div > code:not(:last-child)::after {
    content: "|";
    margin: 0 6px;
}

header form {
    border-top: 1px solid var(--item);
    margin-top: 10px;
}

header form > input {
    background: var(--item);
    border-color: var(--item);
    border-radius: 3px;
    border-style: solid;
    border-width: 1px;
    color: var(--default);
    margin-top: 16px;
    opacity: 0.9;
}

form > input:hover {
    opacity: 1;
}

header form > input[type="text"] {
    padding: 6px 8px;
}

header form > input[type="text"]:focus,
form textarea:focus {
    border-color: var(--item);
}

header form > input[type="submit"] {
    cursor: pointer;
    margin-left: 8px;
    padding: 6px 16px;
}

main {
    grid-column: 1;
    grid-row: 2;
    margin: 16px auto;
    min-width: auto;
    width: 100%;
    padding: 0 8px;
}

@media (min-width: 768px) {
    main {
        min-width: 580px;
        padding: 0;
    }
}

@media (min-width: 1240px) {
    main {
        grid-column: 1;
        grid-row: 1;
        padding: 0;
    }
}

main > form {
    background-color: var(--form-bg);
    border-radius: 3px;
    margin-bottom: 8px;
    overflow: hidden;
    padding: 0 8px 8px;
}

main > form > textarea {
    background: var(--item);
    border-color: var(--item);
    border-radius: 3px;
    border-style: solid;
    border-width: 1px;
    color: var(--default);
    font-family: var(--font-family);
    font-size: 16px;
    margin: 8px 0;
    max-width: 100%;
    min-width: 100%;
    opacity: 0.9;
    padding: 8px;
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
}

main > form > input {
    background: var(--item);
    border-radius: 3px;
    border-width: 1px;
    color: var(--accent);
    cursor: pointer;
    /*font-weight: bold;*/
    opacity: 0.9;
    padding: 7px 16px;
}

.form-actions input[type="submit"] {
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 3px;
    color: #000;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    padding: 6px 12px;
}
.form-actions input[type="submit"]:disabled {
    background: var(--disabled);
    border: 1px solid var(--default);
    color: gray;
    cursor: not-allowed;
    /*pointer-events: none;*/
}

.form-actions input[type="submit"]:hover {
    opacity: 0.9;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    flex-wrap: wrap;
}

@media (max-width: 480px) {
    .form-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .form-actions input[type="submit"],
    .form-actions .save-draft-btn {
        width: 100%;
        text-align: center;
    }

    .draft-status {
        text-align: center;
    }
}

.save-draft-btn {
    background: var(--item);
    border: 1px solid var(--default);
    border-radius: 3px;
    color: var(--default);
    cursor: pointer;
    font-size: 14px;
    font-weight: normal;
    opacity: 0.7;
    padding: 6px 12px;
    transition: opacity 0.2s ease;
}

.save-draft-btn:hover {
    opacity: 0.9;
}

.draft-status {
    color: var(--default);
    font-size: 12px;
    opacity: 0.6;
    font-style: italic;
}

.character-count {
    color: var(--default);
    font-size: 12px;
    opacity: 0.6;
    font-style: italic;
    margin-left: auto;
    margin-right: 1em;
}

/* pagination */
main > a {
    background: var(--item);
    border-radius: 3px;
    float: right;
    font-size: small;
    /*font-weight: bold;*/
    margin-left: 8px;
    opacity: 0.9;
    padding: 8px 16px;
}

/* item row */
main > div {
    background-color: var(--item);
    border-radius: 3px;
    margin-bottom: 8px;
    opacity: 0.9;
    padding: 16px;
}

main > div:first-child {
    font-size: 116%;
    opacity: 1;
}

/* item row meta, controls */
main > div > div {
    border-top: 1px solid var(--separator);
    font-size: small;
    margin-top: 16px;
    overflow: hidden;
    padding-top: 16px;
}

/* Meta list items (time, etc) - only for the metadata section */
main > div > div:last-child > ul {
    list-style: none;
    padding-left: 0;
}

main > div > div:last-child > ul > li {
    cursor: default;
    float: left;
    display: inline;
}

main > div > div:last-child > ul > li:not(:last-child)::after {
    content: "•";
    margin: 0 6px;
}

/* control actions */
main > div > div > div {
    float: right;
    /*opacity: 0;*/
}

/*main > div:hover > div > div {
    opacity: 1;
}*/

main > div > div > div > a {
    background-position: center;
    background-repeat: no-repeat;
    display: inline-block;
}

/* pagination info */
main > span {
    float: right;
    font-size: small;
    padding: 8px 4px;
}

@media (max-width: 767px) {
    body {
        font-size: 16px;
    }

    header > a,
    header > a:active,
    header > a:hover,
    header > a:visited {
        font-size: 32px;
    }

    header form > input[type="text"],
    header form > input[type="submit"] {
        width: 100%;
        margin: 8px 0;
        font-size: 16px;
    }

    .mobile-menu > div {
        position: static;
        margin-top: 16px;
    }

    main > div > div > ul > li {
        float: none;
        display: block;
    }

    main > div > div > ul > li:not(:last-child)::after {
        content: "";
        margin: 0;
    }
}

@media (min-width: 768px) and (max-width: 1239px) {
    header {
        padding: 0 16px;
    }
    header form {
        padding-right: 96px;
    }
    .mobile-menu > div {
        bottom: 8px;
        position: absolute;
        right: 8px;
    }
}

/* Admin pages styling (/about, /logs) */
body:has(.admin-page) {
    display: block;
    max-width: 100%;
}

body:has(.admin-page) header {
    max-width: 1200px;
    margin: 16px auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: static;
}

body:has(.admin-page) header > a {
    order: 1;
}

body:has(.admin-page) .theme-toggle {
    position: static;
    float: none;
    order: 2;
}

body:has(.admin-page) main {
    max-width: 1200px;
    margin: 16px auto;
    padding: 0 16px;
}

/* Logs page gets even wider */
body:has(.logs-filter-form) header {
    max-width: 1600px;
}

body:has(.logs-filter-form) main {
    max-width: 1600px;
}

.admin-page {
    background: var(--item);
    border-radius: 3px;
    padding: 24px;
    opacity: 0.9;
    width: 100%;
}

.admin-page h1 {
    color: var(--accent);
    margin-top: 0;
}

.admin-page h2 {
    color: var(--accent);
    margin-top: 1.5em;
}

.admin-page h3 {
    color: var(--default);
    opacity: 0.9;
    margin-top: 1em;
}

.info-section {
    background: var(--background);
    padding: 15px;
    border-radius: 6px;
    border: 1px solid var(--separator);
    margin-bottom: 20px;
}

.version-badge {
    font-size: 2em;
    color: var(--accent);
    font-weight: bold;
    margin-bottom: 0.5em;
}

.admin-nav {
    margin: 1em 0;
}

.admin-nav a {
    display: inline-block;
    margin-right: 1em;
    opacity: 0.9;
}

.admin-nav a:hover {
    opacity: 1;
}

.stat-list {
    margin: 1em 0;
}

.stat-list dt {
    color: var(--default);
    opacity: 0.7;
    font-weight: normal;
    margin-top: 0.5em;
}

.stat-list dd {
    color: var(--default);
    font-weight: bold;
    margin-left: 1em;
    margin-bottom: 0.5em;
}

.config-display {
    background: var(--background);
    color: var(--default);
    padding: 15px;
    overflow-x: auto;
    border: 1px solid var(--separator);
    border-radius: 6px;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: monospace;
    font-size: 13px;
    line-height: 1.5;
}

/* Config syntax highlighting */
.config-section {
    color: var(--default);
    font-weight: bold;
    font-size: 1.1em;
    display: block;
    margin-top: 1em;
    margin-bottom: 0.25em;
    opacity: 0.6;
}

.config-key {
    color: var(--accent);
    font-weight: normal;
    opacity: 0.85;
}

.config-string {
    color: var(--default);
    opacity: 0.9;
}

.config-number {
    color: var(--accent);
    opacity: 1;
    font-weight: bold;
}

.config-boolean {
    color: var(--accent);
    font-weight: bold;
    opacity: 1;
}

.config-none {
    color: var(--default);
    opacity: 0.4;
    font-style: italic;
}

.config-redacted {
    /*color: var(--accent);
    font-weight: bold;*/
    text-decoration: line-through;
    opacity: 0.8;
}

/* Logs page specific styles */
.logs-filter-form {
    background: var(--background);
    padding: 15px;
    border-radius: 6px;
    border: 1px solid var(--separator);
    margin-bottom: 20px;
}

.filter-controls {
    margin-top: 1em;
}

.filter-row {
    margin: 0.75em 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5em;
}

.filter-row label {
    color: var(--default);
    opacity: 0.8;
}

.logs-filter-form input,
.logs-filter-form select,
.logs-filter-form button {
    background: var(--item);
    color: var(--default);
    border: 1px solid var(--separator);
    border-radius: 3px;
    padding: 6px 10px;
    font-family: var(--font-family);
    font-size: 14px;
}

.logs-filter-form input:focus,
.logs-filter-form select:focus {
    border-color: var(--accent);
    outline: none;
}

.logs-filter-form button {
    background: var(--accent);
    color: var(--background);
    font-weight: bold;
    cursor: pointer;
    padding: 6px 16px;
}

.logs-filter-form button:hover {
    opacity: 0.9;
}

.logs-info {
    color: var(--default);
    opacity: 0.7;
    margin-bottom: 1em;
    font-size: 14px;
}

.logs-content {
    background: var(--background);
    color: var(--default);
    padding: 15px;
    overflow-x: auto;
    border: 1px solid var(--separator);
    border-radius: 6px;
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.5;
    font-family: monospace;
    font-size: 13px;
}

/* Log level styling */
.log-timestamp {
    opacity: 0.6;
}

.log-target {
    opacity: 0.7;
}

.log-level-ERROR {
    color: #f85149;
    font-weight: bold;
}

.log-level-WARN {
    color: #d29922;
    font-weight: bold;
}

.log-level-INFO {
    color: #3fb950;
    font-weight: bold;
}

.log-level-DEBUG {
    color: #58a6ff;
    font-weight: bold;
}

.log-level-TRACE {
    color: #bc8cff;
    font-weight: bold;
}

.search-highlight {
    background-color: var(--accent);
    color: var(--background);
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: bold;
}

/* Logs table */
.logs-table {
    width: 100%;
    border-collapse: collapse;
    font-family: monospace;
    font-size: 0.8125rem;
    background: var(--item);
    border-radius: 0.25rem;
    overflow: hidden;
}

.logs-table thead {
    background: var(--background);
    position: sticky;
    top: 0;
    z-index: 1;
}

.logs-table th {
    padding: 0.5rem 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--accent);
    border-bottom: 2px solid var(--separator);
}

.logs-table tbody tr {
    border-bottom: 1px solid var(--separator);
}

.logs-table tbody tr:hover {
    background: var(--background);
}

.logs-table td {
    padding: 0.25rem 0.75rem;
    vertical-align: top;
}

.log-timestamp {
    white-space: nowrap;
    color: var(--default);
    opacity: 0.7;
    width: 11.25rem;
}

.log-target {
    color: var(--default);
    opacity: 0.6;
    font-size: 0.6875rem;
    width: 12.5rem;
    word-break: break-word;
}

.log-level {
    font-weight: bold;
    text-align: center;
    width: 5rem;
}

.log-message {
    color: var(--default);
    word-break: break-word;
}

/* Mobile responsiveness for admin pages */
@media (max-width: 767px) {
    body:has(.admin-page) header,
    body:has(.admin-page) main {
        padding: 0 8px;
    }

    .admin-page {
        padding: 16px;
    }

    .filter-row {
        flex-direction: column;
        align-items: stretch;
    }

    .logs-filter-form input,
    .logs-filter-form select,
    .logs-filter-form button {
        width: 100%;
    }

    .admin-nav a {
        display: block;
        margin: 0.5em 0;
    }

    /* Stack table columns on mobile */
    .logs-table,
    .logs-table thead,
    .logs-table tbody,
    .logs-table tr,
    .logs-table td {
        display: block;
    }

    .logs-table thead {
        display: none;
    }

    .logs-table tr {
        margin-bottom: 1rem;
        border: 1px solid var(--separator);
        border-radius: 0.25rem;
        padding: 0.5rem;
    }

    .logs-table td {
        border: none;
        padding: 0.25rem 0;
    }

    .log-timestamp::before {
        content: "Time: ";
        font-weight: bold;
    }

    .log-target::before {
        content: "Module: ";
        font-weight: bold;
    }

    .log-level::before {
        content: "Level: ";
        font-weight: bold;
    }

    .log-message::before {
        content: "Message: ";
        font-weight: bold;
        display: block;
    }

    .log-timestamp,
    .log-target,
    .log-level {
        width: auto;
        max-width: none;
    }
}

@media (min-width: 768px) {
    .admin-page {
        padding: 32px;
    }
}

/* ============================================
   Login Page Styles
   ============================================ */

.login-page {
    background: var(--background);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-container {
    background: var(--item);
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 400px;
}

.login-container h1 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--default);
}

.login-container .subtitle {
    color: var(--default);
    opacity: 0.7;
    margin-bottom: 30px;
    font-size: 14px;
}

.login-container .form-group {
    margin-bottom: 20px;
}

.login-container label {
    display: block;
    margin-bottom: 8px;
    color: var(--default);
    font-weight: 500;
    font-size: 14px;
}

.login-container input[type="text"],
.login-container input[type="password"] {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--separator);
    border-radius: 4px;
    font-size: 14px;
    background: var(--background);
    color: var(--default);
    transition: border-color 0.2s;
}

.login-container input[type="text"]:focus,
.login-container input[type="password"]:focus {
    outline: none;
    border-color: var(--accent);
}

.login-container button[type="submit"] {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: var(--background);
    border: none;
    border-radius: 4px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
}

.login-container button[type="submit"]:hover {
    opacity: 0.9;
}

.login-container button[type="submit"]:active {
    opacity: 0.8;
}

.login-container .error-message {
    background: rgba(204, 51, 51, 0.1);
    color: #c33;
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 20px;
    font-size: 14px;
    border: 1px solid rgba(204, 51, 51, 0.3);
}

.login-container .back-link {
    text-align: center;
    margin-top: 20px;
}

.login-container .back-link a {
    color: var(--default);
    opacity: 0.7;
    text-decoration: none;
    font-size: 14px;
}

.login-container .back-link a:hover {
    opacity: 1;
    text-decoration: underline;
}

.login-container .footer {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--separator);
    color: var(--default);
    opacity: 0.5;
    font-size: 12px;
}
