/* File: modules/core/web/static/style.css */
/* "Muqarnas" design (issue #130): deep bottle-green + brass accents,
   Amiri (serif) + Mada (bilingual Arabic/Latin sans) -- applied entirely
   through the class names templates already emit, plus the first real
   mobile breakpoints this dashboard has had. */

:root {
    --paper: #F6F1E6;
    --paper-2: #EFE7D3;
    --ink: #16241F;
    --ink-dim: #5B6B60;
    --line: #D8CBA8;
    --green: #0F4C3A;
    --green-dark: #0B3A2C;
    --green-soft: #E2ECE6;
    --brass: #A9782F;
    --bad: #8C3B2E;
    --bad-soft: #F5E7E2;
    --warn-soft: #F6EEDD;
    --white: #FFFFFF;
    --serif: 'Amiri', serif;
    --sans: 'Mada', -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    font-family: var(--sans);
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    line-height: 1.5;
}

h1, h2, h3 {
    font-family: var(--serif);
    font-weight: 700;
    color: var(--green);
}

h1 {
    font-size: 1.9rem;
    margin: 0 0 1.25rem;
}

h2 {
    font-size: 1.3rem;
    margin: 1.75rem 0 0.9rem;
}

a {
    color: var(--green);
}

/* Topbar -- shared via base.html, so this alone gives every page a
   consistent identity. A subtle repeating dot pattern nods to Islamic
   geometric ornamentation without needing an image asset. */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    background:
        radial-gradient(circle at 10px 10px, rgba(169, 120, 47, 0.16) 0 2px, transparent 2px),
        linear-gradient(135deg, var(--green) 0%, var(--green-dark) 100%);
    background-size: 24px 24px, cover;
    color: #F3EEDF;
    padding: 0.85rem 1.5rem;
    border-bottom: 3px solid var(--brass);
}

.topbar nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.4rem;
}

.topbar nav a {
    color: rgba(243, 238, 223, 0.82);
    text-decoration: none;
    font-weight: 500;
    padding-bottom: 2px;
}

.topbar nav a:hover {
    color: #F3EEDF;
    text-decoration: none;
    border-bottom: 2px solid var(--brass);
}

.logout-form {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: rgba(243, 238, 223, 0.82);
    font-size: 0.9rem;
}

.logout-form button {
    background: transparent;
    color: #F3EEDF;
    border: 1px solid rgba(243, 238, 223, 0.4);
    padding: 0.35rem 0.75rem;
    border-radius: 2px;
    cursor: pointer;
    font-family: var(--sans);
}

.logout-form button:hover {
    border-color: var(--brass);
}

main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.75rem 2rem;
}

.login-box {
    max-width: 340px;
    margin: 4rem auto;
    background: var(--white);
    padding: 2.25rem 2rem;
    border-radius: 2px;
    border: 1px solid var(--line);
    box-shadow: 0 2px 10px rgba(15, 76, 58, 0.08);
}

.login-box h1 {
    text-align: center;
    margin-bottom: 1.5rem;
}

.login-box form {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.login-box label {
    font-size: 0.85rem;
    color: var(--ink-dim);
    margin-top: 0.4rem;
}

.login-box input, .login-box button {
    padding: 0.55rem 0.65rem;
    font-size: 1rem;
    font-family: var(--sans);
    border: 1px solid var(--line);
    border-radius: 2px;
}

.login-box button {
    background: var(--green);
    color: var(--white);
    border: none;
    border-radius: 2px;
    cursor: pointer;
    margin-top: 0.9rem;
    font-weight: 600;
}

.login-box button:hover {
    background: var(--green-dark);
}

.error {
    color: var(--bad);
}

.success {
    color: var(--green);
    font-weight: 500;
}

/* Tables -- shared by dashboard/sermons/runs/settings. A brass double
   rule under the header and warm zebra striping instead of flat grey. */
.table-scroll {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--white);
    margin-top: 1rem;
    border: 1px solid var(--line);
}

th, td {
    text-align: left;
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--line);
    overflow-wrap: break-word;
}

/* `anywhere` (not `break-word`) on body cells: only `anywhere` lets the
   browser count a mid-token break when computing a column's *minimum*
   width, so a long unbroken string (a URL inside an error message or
   activity line) can no longer force its column -- and the whole table
   -- wider than the container. */
td {
    overflow-wrap: anywhere;
}

/* The runs table has ten columns, two of them free text (Error,
   Activity) -- under auto layout the free-text columns hog whatever
   the longest message wants, the rest get crushed to one word per line,
   and the Actions column ends up off-screen. Fixed layout + the
   <colgroup> widths in runs.html make every column fit the container
   and wrap inside itself instead. The min-width keeps narrow-desktop
   viewports scrolling sideways (which .table-scroll supports) rather
   than squeezing the short columns below one word wide. */
.runs-table {
    table-layout: fixed;
    min-width: 64rem;
}

.runs-table th, .runs-table td {
    padding: 0.6rem 0.6rem;
}

.runs-table details summary {
    cursor: pointer;
}

.runs-table [data-field="recent-log"] {
    margin: 0.3rem 0 0;
    padding-left: 1.1rem;
    font-size: 0.85rem;
    color: var(--ink-dim);
}

th {
    background: var(--paper-2);
    font-weight: 600;
    color: var(--ink);
    border-bottom: 2px solid var(--brass);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

tbody tr:nth-child(even) {
    background: var(--paper-2);
}

tbody tr:hover {
    background: var(--green-soft);
}

/* Stat cards -- hexagonal tiles echoing the honeycomb/muqarnas motif. */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--line);
    padding: 1.1rem 1.3rem 1.3rem;
    clip-path: polygon(6% 0, 94% 0, 100% 18%, 100% 82%, 94% 100%, 6% 100%, 0 82%, 0 18%);
}

.stat-card h3 {
    margin: 0 0 0.3rem;
    font-size: 0.85rem;
    font-family: var(--sans);
    font-weight: 500;
    color: var(--ink-dim);
}

.stat-number {
    font-family: var(--serif);
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--green);
    margin: 0.15rem 0;
}

.stat-label {
    color: var(--ink-dim);
    margin: 0;
    font-size: 0.85rem;
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    margin: 1rem 0;
    background: var(--white);
    border: 1px solid var(--line);
    padding: 0.9rem 1rem;
}

.filter-form label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--ink-dim);
}

select, input[type="text"], input[type="search"], input[type="number"],
input[type="date"], input[type="time"], input[type="password"] {
    padding: 0.45rem 0.6rem;
    font-size: 0.95rem;
    font-family: var(--sans);
    border: 1px solid var(--line);
    border-radius: 2px;
    background: var(--white);
    color: var(--ink);
}

button, input[type="submit"] {
    font-family: var(--sans);
}

button:not(.logout-form button):not(.login-box button) {
    background: var(--green);
    color: var(--white);
    border: none;
    border-radius: 2px;
    padding: 0.5rem 1.1rem;
    cursor: pointer;
    font-weight: 600;
}

button:not(.logout-form button):not(.login-box button):hover {
    background: var(--green-dark);
}

.id-lookup {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.id-lookup label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--ink-dim);
}

.meta-list {
    display: grid;
    grid-template-columns: 190px 1fr;
    row-gap: 0.55rem;
    background: var(--white);
    border: 1px solid var(--line);
    padding: 1.1rem 1.3rem;
    max-width: 900px;
}

.meta-list dt {
    font-family: var(--serif);
    font-weight: 700;
    color: var(--green);
}

.meta-list dd {
    margin: 0;
}

.sermon-content pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    background: var(--white);
    border: 1px solid var(--line);
    padding: 1.2rem;
    border-radius: 2px;
    line-height: 1.85;
    font-family: var(--sans);
    max-width: 900px;
}

.status-failed {
    background: var(--bad-soft) !important;
}

.status-running {
    background: var(--warn-soft) !important;
}

.settings-section {
    background: var(--white);
    border: 1px solid var(--line);
    padding: 1.2rem 1.4rem;
    margin: 1.25rem 0;
}

.settings-section h2 {
    margin-top: 0;
}

.settings-form {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    background: var(--white);
    padding: 1.1rem 1.4rem;
    border: 1px solid var(--line);
    margin: 1rem 0;
    max-width: 480px;
}

/* Nested inside a .settings-section, the section itself already
   provides the card chrome -- avoid a card-in-a-card look. */
.settings-section .settings-form {
    background: none;
    padding: 0;
    border: none;
    margin: 0;
    max-width: none;
}

.settings-form label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: 100%;
    color: var(--ink-dim);
    font-size: 0.9rem;
}

/* A checkbox-driven label ("Enabled", "Always run as a full backfill",
   each day chip below) reads left-to-right like any other checkbox,
   not stacked -- only a label whose child is a real value input
   ("Display name" etc.) benefits from stacking the description above
   its control. */
.settings-form label:has(> input[type="checkbox"]) {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    width: auto;
}

.settings-form input[type="checkbox"] {
    width: auto;
    accent-color: var(--green);
}

.settings-form fieldset {
    border: 1px solid var(--line);
    border-radius: 2px;
    padding: 0.9rem 1rem 1.1rem;
    margin: 0;
    width: 100%;
}

.settings-form legend {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--ink-dim);
    font-weight: 600;
    padding: 0 0.4rem;
}

.day-picker, .time-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.day-picker label {
    border: 1px solid var(--line);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    cursor: pointer;
    background: var(--paper);
}

.day-picker label:has(input:checked) {
    background: var(--green);
    border-color: var(--green);
    color: var(--white);
}

.settings-form input, .settings-form select {
    padding: 0.45rem 0.6rem;
    font-size: 1rem;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin: 0.5rem 0 1rem;
}

.pagination a {
    color: var(--green);
    font-weight: 500;
    text-decoration: none;
}

.pagination a:hover {
    color: var(--brass);
    text-decoration: underline;
}

.pagination-current {
    background: var(--green);
    color: var(--white);
    border-radius: 2px;
    padding: 0.1rem 0.55rem;
    font-weight: 700;
}

.pagination-ellipsis {
    color: var(--ink-dim);
}

.jump-to-page {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.jump-to-page input[type="number"] {
    width: 4.5rem;
}

.schedule-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.config-field {
    border-bottom: 1px solid var(--line);
    padding-bottom: 0.9rem;
    width: 100%;
}

.config-field:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.config-description {
    color: var(--ink-dim);
    font-size: 0.82rem;
    margin: 0.3rem 0 0;
}

.config-label {
    color: var(--ink-dim);
    font-size: 0.9rem;
}

.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.35rem;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid var(--line);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    cursor: pointer;
    background: var(--paper);
    font-size: 0.9rem;
}

.radio-option:has(input:checked) {
    background: var(--green);
    border-color: var(--green);
    color: var(--white);
}

.radio-option input[type="radio"] {
    accent-color: var(--green);
}

.ocr-compare-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
    gap: 1rem;
}

.ocr-compare-method {
    border: 1px solid var(--line);
    padding: 1rem;
}

.ocr-compare-method pre {
    max-height: 30rem;
    overflow-y: auto;
}

/* Responsive -- this dashboard had no breakpoints at all before #130. */
@media (max-width: 820px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .filter-form, .settings-form {
        flex-direction: column;
        align-items: stretch;
    }

    .meta-list {
        grid-template-columns: 1fr;
    }

    .meta-list dt {
        margin-top: 0.5rem;
    }

    /* Tables become stacked cards instead of scrolling sideways --
       label-above-value (not side-by-side) since some cells hold rich
       content (buttons, the runs table's nested activity log), not
       just short text, which a flex "label left, value right" row
       can't handle cleanly. */
    table {
        display: block;
        border: none;
    }

    .runs-table {
        min-width: 0;
    }

    thead {
        display: none;
    }

    tbody, tr {
        display: block;
    }

    tr {
        border: 1px solid var(--line);
        margin-bottom: 0.75rem;
        padding: 0.6rem 0.85rem;
        background: var(--white);
    }

    tbody tr:nth-child(even) {
        background: var(--white);
    }

    td {
        display: block;
        border: none;
        padding: 0.3rem 0;
    }

    td::before {
        content: attr(data-label);
        display: block;
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--ink-dim);
        font-weight: 600;
        margin-bottom: 0.1rem;
    }

    td:not([data-label]) {
        text-align: center;
    }
}

@media (max-width: 520px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .topbar {
        padding: 0.75rem 1rem;
    }

    main {
        padding: 1.25rem 1rem;
    }

    .login-box {
        margin: 2rem 1rem;
        padding: 1.75rem 1.25rem;
    }

    h1 {
        font-size: 1.5rem;
    }
}
