/* ========== Reset & base ==========
A tiny reset for consistent rendering */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    line-height: 1.15;
}

/* Theme variables */
:root {
    --bg: #f8f8f8;
    --text: #222;
    --card: #fff;
    --muted: #666;
    --border: #d0d7de;
    --accent: #1f6feb;
    --accent-hover: #1557bd;
    --shadow1: rgba(0, 0, 0, .06);
    --shadow2: rgba(0, 0, 0, .05);
    /* Badge colors (light) */
    --badge-urgent: #d32f2f;
    /* today */
    --badge-days: #c62828;
    /* 1–6 days */
}

/* Follow system/browser preference by default (auto) */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111;
        --text: #e6edf3;
        --card: #161b22;
        --muted: #9da7b3;
        --border: #30363d;
        --accent: #2f81f7;
        --accent-hover: #1b6fdc;
        --shadow1: rgba(0, 0, 0, .3);
        --shadow2: rgba(0, 0, 0, .2);
        /* Badge colors (auto dark) – match light mode */
        --badge-urgent: #d32f2f;
        --badge-days: #c62828;
    }

    .theme-toggle .theme-icon {
        filter: invert(85%);
    }
}

[data-theme="dark"] {
    --bg: #111;
    --text: #e6edf3;
    --card: #161b22;
    --muted: #9da7b3;
    --border: #30363d;
    --accent: #2f81f7;
    --accent-hover: #1b6fdc;
    --shadow1: rgba(0, 0, 0, .3);
    --shadow2: rgba(0, 0, 0, .2);
    /* Badge colors (forced dark) – match light mode */
    --badge-urgent: #d32f2f;
    --badge-days: #c62828;
}

/* Force light, even if system prefers dark */
[data-theme="light"] {
    --bg: #f8f8f8;
    --text: #222;
    --card: #fff;
    --muted: #666;
    --border: #d0d7de;
    --accent: #1f6feb;
    --accent-hover: #1557bd;
    --shadow1: rgba(0, 0, 0, .06);
    --shadow2: rgba(0, 0, 0, .05);
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
}

img,
svg,
video {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ========== Layout ==========
Wrapper constrained to 1400px */
.wrapper {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px;
}

.main {
    border-radius: 0;
    padding: 0;
    box-shadow: none;
}

/* Header & Footer */
.site-header {
    padding: 2px 0 16px;
    margin-bottom: 16px;
}

.site-header .site-title {
    font-weight: 700;
    font-size: 1.125rem;
}

.site-footer {
    padding: 16px 0;
    margin-top: 16px;
    color: var(--muted);
    font-size: .9rem;
}

/* Flag-based language selector (top-right) */
.lang-flags {
    position: fixed;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 8px;
    z-index: 1000;
}

.lang-flags .flag {
    display: inline-flex;
    align-items: center;
    justify-content: start;
    width: 36px;
    height: 32px;
    font-size: 20px;
    text-decoration: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .9);
    border: 1px solid #d0d7de;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}

.lang-flags .flag:hover {
    background: #fff;
}

.lang-flags .flag.active {
    outline: 2px solid #1f6feb;
    outline-offset: 2px;
}

/* Language selector */
.lang-select {
    margin-left: auto;
}

.lang-select select {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--text);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.hidden {
    display: none !important;
}

/* Tabs */
.tabs {
    margin-top: 8px;
}

.tab-list {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}

.tab {
    appearance: none;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 7px 7px 0 0;
    padding: 8px 12px;
    cursor: pointer;
}

.tab.active {
    border-color: var(--accent);
    color: var(--text);
}

.tab-panel {
    padding: 0;
}

/* Tab titles as H2-ish: bold and slightly larger */
.tab .tab-title {
    display: inline-block;
    font-weight: 700;
    font-size: 1.1rem;
    /* slightly larger than base */
    line-height: 1.2;
}

/* ========== Typography ==========
Simple readable defaults */
h1 {
    font-size: clamp(1.75rem, 1.2rem + 2vw, 2.25rem);
    margin: 0 0 12px;
}

h2 {
    font-size: clamp(1.25rem, 1rem + 1vw, 1.5rem);
    margin: 24px 0 8px;
}

p {
    margin: 0 0 12px;
}

/* ========== Utilities ==========
Helpers for spacing & layout */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 16px;
}

.grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.muted {
    color: var(--muted);
}

/* Buttons */
.btn {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    padding: 10px 16px;
    border-radius: 8px;
    transition: background .2s ease;
}

.btn:hover {
    background: var(--accent-hover);
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .wrapper {
        padding: 12px;
    }

    .main {
        padding: 0;
    }

    /* Slightly smaller H1 on mobile */
    h1 {
        font-size: clamp(1.35rem, 1rem + 2.5vw, 1.75rem);
    }
}

/* Override: keep language flags within wrapper, aligned to the right */
.site-header .lang-flags {
    position: static;
    top: auto;
    right: auto;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.site-header .lang-flags .flag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* center the flag image */
    width: 32px;
    height: 24px;
    border-radius: 0;
    overflow: hidden;
    background: var(--card);
    border: none;
    /* no border on the button itself */
}

.site-header .lang-flags .flag img {
    display: block;
    width: 24px;
    height: 16px;
    box-sizing: content-box;
    /* allow padding to create space around flag */
    border: 0;
    /* default: no border on image */
    border-radius: 2px;
    background: var(--card);
}

/* Active state: blue border on the button edge (no outer outline) */
.site-header .lang-flags .flag.active {
    /* keep button borderless */
    outline: none;
    border: 0;
}

/* Show the blue border tightly around the flag image */
.site-header .lang-flags .flag.active img {
    padding: 2px;
    /* ~2px space between flag and blue border */
    border: 2px solid var(--accent);
}

/* Theme toggle button */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 24px;
    text-decoration: none;
    border-radius: 0;
    background: var(--card);
    border: none;
    box-shadow: 0 1px 2px var(--shadow2);
}

.theme-toggle .theme-icon {
    display: block;
    width: 18px;
    height: 18px;
}

[data-theme="dark"] .theme-toggle .theme-icon {
    filter: invert(85%);
}

/* ========== Cleanmessage list styling ========== */
.cleanmessage-list {
    list-style: none;
    padding: 0;
    margin: 16px 0 24px;
    display: grid;
    /* Fixed-width tracks that can shrink on small screens; align grid left */
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    justify-content: start;
    /* align tracks to left */
    justify-items: stretch;
    /* cards fill track width */
    align-content: start;
    /* avoid vertical centering */
    gap: 12px;
}


/* Card base styles (restore border and appearance) */
.cleanmessage-list li {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 14px 16px 14px 18px;
    box-shadow: 0 1px 2px var(--shadow2), 0 4px 5px var(--shadow1);
    transition: transform .12s ease, box-shadow .2s ease, border-color .2s ease;
    position: relative;
    line-height: 1.5;
    overflow-wrap: anywhere;
}



.cleanmessage-list li:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px var(--shadow2), 0 8px 20px var(--shadow1);
    border-color: var(--accent);
}

.cleanmessage-list a {
    color: var(--accent);
    text-decoration: none;
}

.cleanmessage-list a:hover {
    text-decoration: underline;
}

/* Grouped date headings spanning full width */
.message-groups {
    display: block;
}

.message-date {
    margin: 28px 0 8px;
    padding: 6px 2px;
    font-weight: 700;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

/* Logo wrapper on cards */
.card-logo {
    height: 50px;
    margin: 0 auto 6px auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-logo img {
    height: 50px;
    width: auto;
    max-width: 100%;
    display: block;
    border: 1px solid var(--border);
}

/* ========== Badge styling (hooks; inline styles currently override) ========== */
.card-badge {
    /* current inline style controls color and margin to preserve existing look */
    font-weight: 700;
    position: absolute;
    bottom: 30px;
    right: 10px;
    display: inline-block;
    transform: rotate(-12deg);
    transform-origin: right center;
    white-space: nowrap;
    z-index: 2;
    pointer-events: none;
    /* Try ribbon-like red background with white text */
    color: #fff;
    background: var(--badge-urgent);
    padding: 2px 8px;
    border-radius: 4px;
    box-shadow: 0 1px 2px var(--shadow2);
}

.card-badge.badge-urgent {
    background: var(--badge-urgent);
}

.card-badge.badge-days {
    background: var(--badge-days);
}