/*
 * Samarthanam Portal — shared styles for every module.
 * Brand colours from samarthanam.org, adjusted to meet WCAG 2.2 AA contrast.
 * No build step: edit this file directly.
 */

:root {
    --red: #D21F26;          /* primary buttons, links on white (5.4:1)   */
    --red-dark: #A8181E;     /* hover / pressed                            */
    --maroon: #5A2C2E;       /* headings, organisation name (11:1)         */
    --cream: #FFEFD9;        /* title bands (never red text on cream)      */
    --charcoal: #262930;     /* footer, body text                          */
    --text: #262930;
    --muted: #555a64;        /* secondary text on white (7:1)              */
    --border: #8a8f98;       /* form field borders (3.3:1 against white)   */
    --line: #dcdfe4;         /* decorative dividers only                   */
    --bg: #ffffff;
    --surface: #f6f7f9;
    --focus: #1a56db;        /* focus ring, distinct from brand red        */
    --success-bg: #e8f5ec; --success: #1e6b34;
    --error-bg: #fdecec;   --error: #a8181e;
    --warning-bg: #fff4d6; --warning: #7a4a00;
    --radius: 6px;
    --max: 72rem;
    font-size: 100%;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: "Open Sans", "Segoe UI", Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

img { max-width: 100%; height: auto; }

a { color: var(--red); text-decoration: underline; text-underline-offset: 0.15em; }
a:hover { color: var(--red-dark); text-decoration-thickness: 2px; }

h1, h2, h3 { color: var(--maroon); line-height: 1.25; margin: 0 0 0.75rem; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; margin-top: 1.5rem; }
h3 { font-size: 1.1rem; }

/* Visible keyboard focus on everything */
:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 2px;
}

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
}

.skip-link {
    position: absolute;
    left: 1rem; top: -4rem;
    z-index: 100;
    padding: 0.75rem 1rem;
    background: var(--charcoal);
    color: #fff;
    font-weight: 700;
    border-radius: var(--radius);
}
.skip-link:focus { top: 1rem; color: #fff; }

.container { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 1rem; }

/* ---------- Header ---------- */
.site-header { background: #fff; border-bottom: 4px solid var(--red); }
.site-header .container {
    display: flex; flex-wrap: wrap; align-items: center;
    gap: 0.75rem 1.5rem; padding-top: 0.6rem; padding-bottom: 0.6rem;
}
.brand { display: flex; align-items: center; gap: 1rem; text-decoration: none; color: var(--maroon); }
.brand img { height: 68px; width: auto; display: block; }
.brand:hover { color: var(--maroon); }
.module-name {
    font-size: 1.2rem; font-weight: 700; color: var(--maroon);
    padding-left: 1rem; border-left: 2px solid var(--line);
}
.header-user { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; }
.header-user .who { color: var(--muted); }
.header-user .who strong { color: var(--text); }

/* ---------- Module menu ---------- */
.module-nav { background: var(--maroon); }
.module-nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; }
.module-nav a {
    display: block; padding: 0.7rem 1rem;
    color: #fff; text-decoration: none; font-weight: 600;
    border-bottom: 4px solid transparent;
}
.module-nav a:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.module-nav a[aria-current="page"] { border-bottom-color: #fff; background: rgba(255, 255, 255, 0.08); }
.module-nav a:focus-visible { outline-color: #fff; outline-offset: -3px; }

/* ---------- Title band and content ---------- */
main { flex: 1; outline: none; }
.title-band { background: var(--cream); padding: 1.5rem 0 1.25rem; margin-bottom: 1.5rem; }
.title-band h1 { margin: 0; }
.title-band p { margin: 0.4rem 0 0; color: var(--charcoal); }
.page { padding-bottom: 3rem; }

/* ---------- Messages ---------- */
.message {
    border-left: 6px solid; padding: 0.85rem 1rem; margin: 0 0 1.25rem;
    border-radius: var(--radius);
}
.message p { margin: 0; }
.message-success { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.message-error   { background: var(--error-bg);   border-color: var(--error);   color: var(--error); }
.message-warning { background: var(--warning-bg); border-color: var(--warning); color: var(--warning); }
.message ul { margin: 0.3rem 0 0 1.2rem; padding: 0; }

/* ---------- Buttons ---------- */
.button, button {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    min-height: 44px; padding: 0.55rem 1.2rem;
    font: inherit; font-weight: 700; line-height: 1.2;
    border: 2px solid var(--red); border-radius: var(--radius);
    background: var(--red); color: #fff;
    text-decoration: none; cursor: pointer;
}
.button:hover, button:hover { background: var(--red-dark); border-color: var(--red-dark); color: #fff; text-decoration: none; }
.button-secondary { background: #fff; color: var(--red); }
.button-secondary:hover { background: var(--cream); color: var(--red-dark); }
.button-link {
    background: none; border: none; color: var(--red); padding: 0.25rem; min-height: 44px;
    text-decoration: underline; font-weight: 600;
}
.button-link:hover { background: none; color: var(--red-dark); }
button[disabled], .button[aria-disabled="true"] {
    background: #e4e6ea; border-color: #b8bcc4; color: #555a64; cursor: not-allowed;
}

/* ---------- Forms ---------- */
.field { margin-bottom: 1.25rem; }
label, .label { display: block; font-weight: 700; margin-bottom: 0.3rem; }
.hint { display: block; color: var(--muted); font-size: 0.95rem; margin-bottom: 0.35rem; }
input[type="text"], input[type="email"], input[type="number"], input[type="date"],
input[type="search"], input[type="tel"], select, textarea {
    width: 100%; max-width: 32rem;
    min-height: 44px; padding: 0.5rem 0.65rem;
    font: inherit; color: var(--text); background: #fff;
    border: 2px solid var(--border); border-radius: var(--radius);
}
.field-error { display: block; color: var(--error); font-weight: 700; margin-bottom: 0.35rem; }
[aria-invalid="true"] { border-color: var(--error); }
.code-input { font-size: 1.6rem; letter-spacing: 0.4em; max-width: 12rem !important; text-align: center; }

/* ---------- Cards and tiles ---------- */
.card {
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
    padding: 1.25rem; margin-bottom: 1.25rem;
}
.card h2:first-child { margin-top: 0; }
.narrow { max-width: 34rem; }

.tiles { list-style: none; margin: 0 0 2rem; padding: 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.tile {
    position: relative; height: 100%;
    background: #fff; border: 2px solid var(--line); border-top: 6px solid var(--red);
    border-radius: var(--radius); padding: 1.1rem 1.2rem;
}
.tile:hover, .tile:focus-within { border-color: var(--red); }
.tile h2 { margin: 0 0 0.4rem; font-size: 1.3rem; }
/* Whole tile is clickable, but only the heading link is announced. */
.tile h2 a { color: var(--maroon); text-decoration: none; }
.tile h2 a::after { content: ""; position: absolute; inset: 0; }
.tile h2 a:focus-visible { outline: none; }
.tile:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.tile p { margin: 0 0 0.6rem; color: var(--muted); }
.tile .count { font-weight: 700; color: var(--text); margin: 0; }
/* A planned module: not a link yet, so it does not look clickable. */
.tile-planned { background: var(--surface); border-top-color: var(--border); }
.tile-planned:hover { border-color: var(--line); border-top-color: var(--border); }
.tile-planned h2 { color: var(--text); }

.empty { color: var(--muted); font-style: italic; }

/* ---------- Admin pages: toolbars, tables, status ---------- */
.optional { font-weight: 400; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem 1rem; margin-bottom: 1.25rem; }
.toolbar .field { margin-bottom: 0; }
.toolbar input, .toolbar select { max-width: 18rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 1.25rem; }

.table-wrap { overflow-x: auto; margin-bottom: 1.25rem; }
.table-wrap:focus-visible { outline: 3px solid var(--focus); }
table { border-collapse: collapse; width: 100%; background: #fff; }
caption { text-align: left; font-weight: 700; color: var(--maroon); padding: 0 0 0.5rem; font-size: 1.1rem; }
th, td { text-align: left; vertical-align: top; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--line); }
thead th { background: var(--surface); border-bottom: 2px solid var(--border); white-space: nowrap; }
tbody tr:hover { background: #fbfbfc; }
td .button, td button { min-height: 36px; padding: 0.3rem 0.8rem; }

.status { display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; font-weight: 700; font-size: 0.9rem; border: 1px solid; }
.status-active { color: var(--success); background: var(--success-bg); }
.status-inactive { color: #444851; background: #eceef1; }

dl.details { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1.5rem; margin: 0 0 1.25rem; }
dl.details dt { font-weight: 700; }
dl.details dd { margin: 0; }

fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; margin: 0 0 1.25rem; }
legend { font-weight: 700; color: var(--maroon); padding: 0 0.4rem; font-size: 1.05rem; }
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.check { display: flex; align-items: flex-start; gap: 0.6rem; min-height: 32px; }
.check input { width: 1.3rem; height: 1.3rem; margin: 0.2rem 0 0; flex: none; accent-color: var(--red); }
.check label { font-weight: 400; margin: 0; }
.columns { display: grid; gap: 0 2rem; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); }

.pagination { margin: 1rem 0; }
.pagination p { margin: 0 0 0.5rem; color: var(--muted); }
.pagination ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }
.pagination a, .pagination span { display: inline-block; min-width: 44px; min-height: 44px; padding: 0.55rem 0.75rem; text-align: center; border: 1px solid var(--line); border-radius: var(--radius); }
.pagination a[aria-current="page"] { background: var(--red); color: #fff; border-color: var(--red); text-decoration: none; }
.pagination .disabled { color: #555a64; background: var(--surface); }

.changes { margin: 0; padding-left: 1.1rem; }

.photos { list-style: none; margin: 0 0 1.25rem; padding: 0; display: flex; flex-wrap: wrap; gap: 1.25rem; }
.photos li { width: 200px; }
.photos figure { margin: 0; }
.photos img { display: block; width: 200px; height: 150px; object-fit: cover; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.photos figcaption { margin-top: 0.35rem; }
.photos figcaption .hint { display: block; font-size: 0.85rem; }

details.card > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
details.card[open] > summary { margin-bottom: 0.75rem; }

.tabs { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-wrap: wrap; gap: 0.25rem; border-bottom: 2px solid var(--line); }
.tabs a { display: block; padding: 0.6rem 1rem; text-decoration: none; font-weight: 600; border: 2px solid transparent; border-bottom: none; border-radius: var(--radius) var(--radius) 0 0; }
.tabs a[aria-current="page"] { background: var(--cream); border-color: var(--line); color: var(--maroon); }
.nowrap { white-space: nowrap; }


/* ---------- Events ---------- */
.event-list { list-style: none; margin: 0 0 1.25rem; padding: 0; }
.event-list > li { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: flex-start; padding: 1rem 0; border-bottom: 1px solid var(--line); }
.event-thumb { flex: none; display: block; width: 200px; height: 150px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); text-decoration: none; }
.event-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.event-thumb-name { display: flex; align-items: center; justify-content: center; height: 100%; padding: 0.75rem; text-align: center; font-weight: 700; color: var(--maroon); overflow-wrap: anywhere; }
.event-details { flex: 1 1 16rem; margin: 0; }
.invitation { display: block; max-width: 100%; max-height: 40rem; height: auto; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1.25rem; }
.write-up { max-width: 48rem; margin-bottom: 1.5rem; }
.write-up p { margin: 0 0 0.9rem; }
.videos { list-style: none; margin: 0 0 1.25rem; padding: 0; display: grid; gap: 1.5rem; }
.videos iframe, .videos video { display: block; width: 100%; max-width: 48rem; aspect-ratio: 16 / 9; height: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #000; }
.video-files { margin: 1rem 0 1.25rem; padding-left: 1.2rem; }
.video-files li { margin-bottom: 0.4rem; }
.inline-form { display: inline; margin-left: 0.5rem; }
.upload-progress { margin-top: 1rem; max-width: 34rem; }
.upload-progress progress { width: 100%; height: 1.25rem; accent-color: var(--red); }
.photo-edit li { width: 220px; }
.photo-edit figcaption label { display: block; font-size: 0.9rem; margin-top: 0.25rem; }
.photo-edit figcaption input[type="text"] { width: 100%; }
.danger-zone { margin-top: 2.5rem; padding: 1rem 1.25rem; border: 2px solid var(--error); border-radius: var(--radius); background: var(--error-bg); }
.danger-zone h2 { margin-top: 0; color: var(--error); }
button.button-danger, .button-danger { background: var(--error); border-color: var(--error); color: #fff; }
button.button-danger:hover, .button-danger:hover { background: #7d1216; }

/* ---------- Footer ---------- */
.site-footer { background: var(--charcoal); color: #fff; padding: 1.25rem 0; margin-top: auto; }
.site-footer .container { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; align-items: center; }
.site-footer a { color: #fff; display: inline-block; padding: 0.35rem 0; }
.site-footer a:hover { color: var(--cream); }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; }
.site-footer .org { margin: 0 0 0 auto; }

/* ---------- Developer / environment banner ---------- */
.env-banner { background: var(--warning-bg); color: var(--warning); border-bottom: 2px solid var(--warning); padding: 0.4rem 0; font-weight: 700; }
.env-banner p { margin: 0; }

/* ---------- Inactivity dialog ---------- */
dialog.timeout {
    border: 3px solid var(--maroon); border-radius: var(--radius);
    padding: 1.5rem; max-width: 30rem; width: calc(100% - 2rem);
}
dialog.timeout::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog.timeout h2 { margin-top: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.25rem; }

/* ---------- Login page ---------- */
.password-wrap { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: stretch; max-width: 32rem; }
.password-wrap input { flex: 1 1 14rem; width: auto; min-height: 44px; padding: 0.5rem 0.65rem; font: inherit; border: 2px solid var(--border); border-radius: var(--radius); }
.password-wrap button { white-space: nowrap; }
.login-box { max-width: 30rem; }
.or { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); margin: 1.5rem 0; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* ---------- Responsive ---------- */
@media (max-width: 40rem) {
    .module-name { border-left: none; padding-left: 0; width: 100%; }
    .header-user { margin-left: 0; width: 100%; }
    .site-footer .org { margin-left: 0; }
    h1 { font-size: 1.5rem; }
}

/* Respect "reduce motion" */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* Windows High Contrast / forced colours */
@media (forced-colors: active) {
    .tile, .card, .button, button { border: 2px solid CanvasText; }
    .module-nav a[aria-current="page"] { border-bottom-color: Highlight; }
}

@media print {
    .skip-link, .module-nav, .header-user, .site-footer, .env-banner, dialog { display: none !important; }
}

/* Tick-box asset lists (lots) */
.picker .table-wrap { margin-top: 0.5rem; }
.picker td:first-child { width: 2.5rem; }
.picker input.row-check { width: 1.3rem; height: 1.3rem; accent-color: var(--red); }
tr.muted td, tr.muted th { color: var(--muted); }
.lot-values input { max-width: 10rem; }


/* Small button next to a value, e.g. "Renewal completion" beside a date */
.button.button-small { padding: 0.25rem 0.6rem; font-size: 0.9rem; min-height: 0; margin-left: 0.4rem; }
