/* =========================================================
   Robert Walters Toolbox
   Brand palette sampled from Look.png:
     coral   #FF4D66   charcoal #232323
     raised  #363636   field    #E9E9E9
   Brand signatures: hard 90° corners (no radius anywhere),
   heavy tight-tracked headings, offset geometric blocks,
   coral underlines rather than coral body text.
   ========================================================= */

:root {
    /* Constants — the coral and the charcoal are the brand, so they do not
       change between themes. Only the surfaces around them do. */
    --coral: #FF4D66;
    --coral-hover: #E63A54;
    --coral-ink: #D42A44;      /* darkened for text on light surfaces */
    --charcoal: #232323;
    --charcoal-raised: #363636;

    /* Light theme */
    --bg: #FFFFFF;
    --surface: #FFFFFF;
    --surface-alt: #F4F4F4;
    --border: #E1E1E1;
    --field: #E9E9E9;
    --text: #232323;
    --text-muted: #5E5E5E;
    --success: #1F7A46;
    --success-bg: #E7F6EC;
    --success-border: #B7E0C4;
    --error: #C0392B;
    --error-bg: #FDECEA;
    --error-border: #F5C2BD;
    --code-bg: #232323;
    --code-text: #EDEDED;
    --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 10px rgba(0,0,0,.05);
    --shadow-lift: 0 10px 28px rgba(0,0,0,.14);

    --radius: 0;               /* the brand has no rounded corners */
}

/* Dark theme. Two selectors carry the same block: the media query handles
   "user hasn't chosen, follow the OS", the attribute handles an explicit
   choice from the toggle. Keep the two lists in sync when editing. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #171717;
        --surface: #212121;
        --surface-alt: #2A2A2A;
        --border: #383838;
        --field: #2F2F2F;
        --text: #F2F2F2;
        --text-muted: #A8A8A8;
        --success: #5FD08A;
        --success-bg: #17301F;
        --success-border: #2C5C3D;
        --error: #FF8A7A;
        --error-bg: #331A17;
        --error-border: #5E2E28;
        --code-bg: #101010;
        --code-text: #E4E4E4;
        --shadow: 0 1px 2px rgba(0,0,0,.5), 0 2px 10px rgba(0,0,0,.4);
        --shadow-lift: 0 10px 28px rgba(0,0,0,.6);
    }
}

:root[data-theme="dark"] {
    --bg: #171717;
    --surface: #212121;
    --surface-alt: #2A2A2A;
    --border: #383838;
    --field: #2F2F2F;
    --text: #F2F2F2;
    --text-muted: #A8A8A8;
    --success: #5FD08A;
    --success-bg: #17301F;
    --success-border: #2C5C3D;
    --error: #FF8A7A;
    --error-bg: #331A17;
    --error-border: #5E2E28;
    --code-bg: #101010;
    --code-text: #E4E4E4;
    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 2px 10px rgba(0,0,0,.4);
    --shadow-lift: 0 10px 28px rgba(0,0,0,.6);
}

/* On dark surfaces the coral is already high-contrast, so inline links can use
   the pure brand colour instead of the darkened variant. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) { --coral-ink: #FF6B80; }
}
:root[data-theme="dark"] { --coral-ink: #FF6B80; }

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system,
                 BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.15;
}

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

.accent { color: var(--coral); }

:focus-visible {
    outline: 2px solid var(--coral);
    outline-offset: 2px;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ---------- Header ---------- */

.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 18px 0;
}
.header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

/* Echoes the brand lockup: the name in weight, the qualifier in coral. */
.brand {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    font-size: 19px;
    text-decoration: none;
    letter-spacing: -0.02em;
    min-width: 0;
}
.brand-mark { font-weight: 800; color: var(--text); }
.brand-sub  { font-weight: 800; color: var(--coral); }

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.user-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 14px;
    min-width: 0;
}
.user-name {
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-signout {
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 2px solid var(--coral);
    padding-bottom: 1px;
}
.user-signout:hover { color: var(--coral-ink); }

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    flex: none;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    transition: border-color .12s ease, color .12s ease, background .12s ease;
}
.theme-toggle:hover {
    border-color: var(--coral);
    color: var(--coral);
}
/* Show the icon for the mode the button switches *to*. */
.theme-icon { display: none; }
.icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .icon-moon { display: none; }
    :root:not([data-theme="light"]) .icon-sun  { display: block; }
}
:root[data-theme="dark"] .icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun  { display: block; }
:root[data-theme="light"] .icon-sun  { display: none; }
:root[data-theme="light"] .icon-moon { display: block; }

/* ---------- Hero ---------- */

/* The coral rule on the left is lifted straight from the brand hero. */
.hero {
    padding: 40px 0 20px;
    border-left: 6px solid var(--coral);
    padding-left: 22px;
    margin-top: 32px;
}
.hero h1 { margin: 0 0 10px; font-size: 34px; }
.hero-sub { margin: 0; color: var(--text-muted); font-size: 16px; }

/* ---------- Cards ---------- */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 32px;
}

.card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow);
    transition: transform .14s ease, box-shadow .14s ease;
}
.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lift);
}

/* Charcoal panel with offset coral/grey blocks — the brand's service-card
   motif. Stays dark in both themes; it is artwork, not surface. */
.card-header {
    min-height: 150px;
    display: flex;
    align-items: flex-end;
    padding: 18px;
    background: var(--charcoal);
    position: relative;
    overflow: hidden;
}
.card-header::before,
.card-header::after {
    content: "";
    position: absolute;
    display: block;
}
.card-header::before { background: var(--coral); }
.card-header::after  { background: var(--charcoal-raised); }

/* Four arrangements, cycling — each script reads as distinct while staying
   strictly within the two brand colours. */
.card:nth-child(4n+1) .card-header::before { left: 8%;  top: 24%; width: 46%; height: 58%; }
.card:nth-child(4n+1) .card-header::after  { right: 10%; top: 8%;  width: 30%; height: 42%; }

.card:nth-child(4n+2) .card-header::before { right: 6%; bottom: 12%; width: 40%; height: 46%; }
.card:nth-child(4n+2) .card-header::after  { left: 12%; top: 10%;   width: 34%; height: 50%; }

.card:nth-child(4n+3) .card-header::before { left: 10%; top: 0;      width: 16%; height: 62%; }
.card:nth-child(4n+3) .card-header::after  { right: 8%; bottom: 8%;  width: 42%; height: 44%; }

.card:nth-child(4n+4) .card-header::before { right: 12%; top: 14%;    width: 34%; height: 40%; }
.card:nth-child(4n+4) .card-header::after  { left: 6%;   bottom: 10%; width: 44%; height: 40%; }

/* Scrim under the title. The blocks land in different places on each card, so
   without this the white text would sometimes sit on coral (~3.4:1) instead of
   charcoal. The gradient guarantees contrast whatever ends up behind it, and
   needs to be a real element because ::before/::after are both spoken for. */
.card-scrim {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 62%;
    z-index: 1;
    background: linear-gradient(to top, rgba(20,20,20,.92) 0%, rgba(20,20,20,.55) 55%, transparent 100%);
}

.card-title {
    position: relative;
    z-index: 2;
    margin: 0;
    color: #FFFFFF;
    font-size: 19px;
    font-weight: 800;
    letter-spacing: -0.02em;
    text-shadow: 0 1px 10px rgba(0,0,0,.55), 0 1px 2px rgba(0,0,0,.5);
}

.card-icon {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 2;
    width: 26px;
    height: 26px;
    filter: brightness(0) invert(1);
    opacity: .85;
}

.card-body {
    padding: 18px 20px 20px;
    display: flex;
    flex-direction: column;
    flex: 1;
}
.card-desc { margin: 0 0 18px; color: var(--text-muted); font-size: 14px; flex: 1; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
    background: var(--field);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius);
}

/* ---------- Links & page furniture ---------- */

.back-link {
    display: inline-block;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    margin: 20px 0;
}
.back-link:hover { color: var(--coral-ink); }

.upload-page, .result-page { padding: 16px 0; }
.upload-page h1, .result-page h1 { font-size: 28px; margin: 0 0 10px; }
.lede { color: var(--text-muted); margin-top: 0; }

h2 { font-size: 20px; margin: 32px 0 12px; }

/* ---------- Auth ---------- */

.auth-page {
    max-width: 440px;
    margin: 72px auto;
    padding: 40px 36px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 5px solid var(--coral);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
}
.auth-page h1 { margin: 0 0 10px; font-size: 26px; }
.auth-page .lede { margin-bottom: 28px; }

/* ---------- Forms ---------- */

.upload-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    margin-top: 24px;
    box-shadow: var(--shadow);
}
.file-label {
    display: block;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 36px;
    text-align: center;
    cursor: pointer;
    transition: border-color .12s ease, background .12s ease;
}
.file-label:hover {
    border-color: var(--coral);
    background: var(--surface-alt);
}
.file-label-text {
    display: block;
    font-weight: 700;
    margin-bottom: 6px;
}
.file-hint {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 18px;
}
.file-label input[type="file"] {
    display: block;
    margin: 0 auto;
    color: var(--text);
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-block;
    padding: 12px 24px;
    border-radius: var(--radius);
    border: 2px solid var(--text);
    background: transparent;
    color: var(--text);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    margin-top: 16px;
    transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.btn:hover {
    border-color: var(--coral);
    color: var(--coral-ink);
}
.btn-primary {
    background: var(--coral);
    color: #FFFFFF;
    border-color: var(--coral);
}
.btn-primary:hover {
    background: var(--coral-hover);
    border-color: var(--coral-hover);
    color: #FFFFFF;
}

/* ---------- Banners, flashes, output ---------- */

.banner {
    border-radius: var(--radius);
    padding: 14px 18px;
    margin: 20px 0;
    border: 1px solid transparent;
    border-left-width: 5px;
}
.banner-success {
    background: var(--success-bg);
    color: var(--success);
    border-color: var(--success-border);
}
.banner-error {
    background: var(--error-bg);
    color: var(--error);
    border-color: var(--error-border);
}

.output {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 18px;
    border-radius: var(--radius);
    border-left: 5px solid var(--coral);
    overflow: auto;
    font-family: "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
    font-size: 13px;
    white-space: pre-wrap;
}
.output-error { border-left-color: var(--error); }

.download-box {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-left: 5px solid var(--coral);
    border-radius: var(--radius);
    padding: 24px;
    margin: 28px 0;
    text-align: center;
}
.download-box p { margin: 0 0 8px; color: var(--text-muted); }

.table-wrap { overflow-x: auto; margin-top: 16px; }
.output-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.output-table th, .output-table td {
    padding: 11px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.output-table th {
    background: var(--charcoal);
    color: #FFFFFF;
    font-weight: 700;
    white-space: nowrap;
}

.flash-wrap { margin: 20px 0; }
.flash {
    padding: 12px 16px;
    border-radius: var(--radius);
    border-left: 5px solid transparent;
    margin-bottom: 8px;
    font-size: 14px;
}
.flash-error { background: var(--error-bg); color: var(--error); border-left-color: var(--error); }
.flash-info  { background: var(--surface-alt); color: var(--text); border-left-color: var(--coral); }

.empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
}

/* ---------- Error page ---------- */

.error-page {
    text-align: center;
    padding: 72px 16px;
}
.error-code {
    font-size: 84px;
    font-weight: 800;
    color: var(--coral);
    line-height: 1;
    letter-spacing: -0.04em;
    margin-bottom: 8px;
}
.error-page h1 { margin: 0 0 10px; font-size: 26px; }
.error-page .lede { max-width: 480px; margin: 0 auto 24px; }

/* ---------- Footer ---------- */

.site-footer {
    margin-top: 72px;
    padding: 28px 0;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    text-align: center;
    font-size: 13px;
}

/* ---------- Responsive ---------- */

@media (max-width: 560px) {
    .hero h1 { font-size: 27px; }
    .user-name { display: none; }   /* keep the header on one line */
    .brand { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
    .card:hover { transform: none; }
}
