/* =========================================================
   Fume — Legacy stylesheet for Kobo and other WebKit 538.1
   (circa 2012) browsers.

   This file is derived from style.css with the following
   changes made for compatibility:
     1. All CSS custom properties (var(--xxx)) replaced with
        their literal values from the LIGHT theme — high
        contrast for grayscale e-ink displays.
     2. All display:flex / display:inline-flex replaced with
        block or inline-block equivalents.
     3. htmx-specific styles removed (.spinner, .htmx-request).
     4. :focus-visible replaced with :focus.
     5. No CSS grid, no CSS variables, no SameSite cookie
        concerns — those are handled server-side.
     6. No theme toggle — Kobo always uses light theme.

   Maintain in parallel with style.css. When updating
   style.css, reflect relevant changes here too.
   ========================================================= */

*, *::before, *::after {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
}

body {
    background: #f8f9fa;
    color: #212529;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ---- Focus styles ---- */

:focus {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

/* ---- Utility classes ---- */

.inline-form  { display: inline; }
.text-muted   { color: #6c757d; }
.text-upper   { text-transform: uppercase; }
.text-accent  { color: #4f46e5; }
.mt-md        { margin-top: 1.25rem; }

/* Screen-reader only */
.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;
}

/* ---- Centered page layout (login / setup) ---- */

.page-center {
    min-height: 100%;
    padding: 3rem 1.5rem;
    text-align: center;
}

.card {
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
    display: inline-block;
    text-align: left;
}

.card-header {
    text-align: center;
    margin-bottom: 2rem;
}

.logo {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #4f46e5;
    font-family: "JetBrains Mono", "Fira Code", monospace;
    text-decoration: none;
}

.subtitle {
    color: #6c757d;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.info {
    color: #6c757d;
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
    text-align: center;
}

/* ---- Alerts ---- */

.alert {
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
}

.alert-error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #dc2626;
}

.alert-success {
    background: #f0fdf4;
    color: #16a34a;
    border: 1px solid #16a34a;
}

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

.field {
    margin-bottom: 1.25rem;
}

.field label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #6c757d;
    margin-bottom: 0.375rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.field input {
    width: 100%;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    color: #212529;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.9375rem;
    padding: 0.625rem 0.875rem;
    outline: none;
}

.field input:focus {
    border-color: #4f46e5;
}

.field input::-webkit-input-placeholder {
    color: #6c757d;
}

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

.btn {
    display: inline-block;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 0.9375rem;
    font-weight: 500;
    padding: 0.625rem 1.25rem;
    text-decoration: none;
}

.btn-primary {
    background: #4f46e5;
    color: #fff;
}

.btn-primary:hover {
    background: #4338ca;
}

/* Accent button */
.btn-accent {
    background: #e8e7fe;
    color: #4f46e5;
    border: 1px solid #c7d2fe;
}

.btn-accent:hover {
    background: #ddd6fe;
    color: #3730a3;
}

/* Full-width button */
.btn-block {
    width: 100%;
    text-align: center;
}

.btn-ghost {
    background: transparent;
    color: #6c757d;
    border: 1px solid #dee2e6;
}

.btn-ghost:hover {
    color: #212529;
    border-color: #212529;
}

.btn-ghost:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Danger link button */
.btn-danger-link {
    background: none;
    border: none;
    color: #dc2626;
    opacity: 0.7;
    cursor: pointer;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    padding: 0.5rem 0.5rem;
    font-size: 0.8125rem;
    min-height: 2.5rem;
    display: inline-block;
    vertical-align: middle;
}

.btn-danger-link:hover {
    opacity: 1;
}

/* Subtle link for secondary actions */
.btn-link-subtle {
    color: #6c757d;
    font-size: 0.75rem;
    text-decoration: none;
    padding: 0.25rem 0.375rem;
    display: inline-block;
}

.btn-link-subtle:hover {
    color: #212529;
    text-decoration: underline;
}

/* ---- App layout (authenticated pages) ---- */

.app {
    min-height: 100%;
}

.app-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #dee2e6;
    background: #ffffff;
    overflow: hidden; /* clearfix */
}

.app-header:after {
    content: "";
    display: table;
    clear: both;
}

.app-header .logo {
    font-size: 1.375rem;
    float: left;
}

.app-nav {
    float: right;
}

.app-nav > * {
    display: inline-block;
    vertical-align: middle;
    margin-left: 1rem;
}

.nav-user {
    color: #6c757d;
    font-size: 0.875rem;
}

.app-main {
    padding: 2rem 1.5rem;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
}

/* ---- Placeholder ---- */

.placeholder {
    text-align: center;
    padding: 4rem 1rem;
    color: #6c757d;
}

.placeholder p + p {
    margin-top: 0.5rem;
}

.muted {
    color: #6c757d;
    font-size: 0.875rem;
}

/* ---- Tables ---- */

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    color: #6c757d;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.75rem;
    border-bottom: 1px solid #dee2e6;
}

td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid #dee2e6;
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

/* Column-specific alignment */
.col-size     { text-align: right; }
.col-uploaded { }
.col-expires  { }

/* ---- Status badges ---- */

.badge {
    display: inline-block;
    padding: 0.2em 0.55em;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

/* In-progress states */
.badge-pending,
.badge-scanning,
.badge-pending_conversion,
.badge-converting { background: #e8e7fe; color: #4f46e5; }

/* Success states */
.badge-clean,
.badge-ready { background: #dcfce7; color: #16a34a; }

/* Error states */
.badge-infected,
.badge-failed { background: #fef2f2; color: #dc2626; }

/* Neutral */
.badge-expired { background: #f3f4f6; color: #6c757d; }

/* Informational */
.badge-pdf-origin { background: #fff7ed; color: #ea580c; font-size: 0.65rem; margin-left: 0.35em; vertical-align: middle; }

/* ---- Conversion error indicator ---- */

.conversion-error {
    color: #dc2626;
    cursor: help;
    margin-left: 0.25em;
    font-size: 0.9em;
}

/* ---- Upload drop zone ---- */

.drop-zone {
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    background: transparent;
    position: relative;
}

.drop-zone input[type="file"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.drop-zone-icon {
    font-size: 2.5rem;
    line-height: 1;
    margin-bottom: 0.75rem;
    display: block;
}

.drop-zone-label {
    color: #212529;
    font-size: 1rem;
    font-weight: 500;
}

.drop-zone-hint {
    color: #6c757d;
    font-size: 0.8125rem;
    margin-top: 0.375rem;
}

/* ---- Upload progress ---- */

.upload-progress {
    margin-top: 1rem;
    display: none;
}

.upload-progress.visible {
    display: block;
}

progress {
    width: 100%;
    height: 6px;
    border: none;
    border-radius: 3px;
    background: #dee2e6;
    overflow: hidden;
    -webkit-appearance: none;
    appearance: none;
}

progress::-webkit-progress-bar {
    background: #dee2e6;
}

progress::-webkit-progress-value {
    background: #4f46e5;
    border-radius: 3px;
}

progress::-moz-progress-bar {
    background: #4f46e5;
    border-radius: 3px;
}

/* ---- Upload result ---- */

.upload-result {
    margin-top: 1.25rem;
}

/* ---- Upload options (e.g. PDF convert checkbox) ---- */

.upload-option {
    margin-top: 1rem;
}

.checkbox-label {
    display: inline;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    vertical-align: middle;
    margin-right: 0.5rem;
}

.muted.small {
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* ---- Section header ---- */

.section-header {
    overflow: hidden; /* clearfix */
    margin-bottom: 1.25rem;
}

.section-header:after {
    content: "";
    display: table;
    clear: both;
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: #212529;
    float: left;
}

.section-header .btn {
    float: right;
}

/* ---- Empty state ---- */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #6c757d;
    border: 1px dashed #dee2e6;
    border-radius: 8px;
}

.empty-state p + p {
    margin-top: 0.5rem;
}

/* ---- Link button ---- */

.btn-link {
    background: none;
    border: none;
    color: #6c757d;
    cursor: pointer;
    font-size: 0.8125rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    padding: 0;
    text-decoration: none;
}

.btn-link:hover {
    color: #dc2626;
}

.btn-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    min-height: 2.5rem;
}

/* ---- File list filename truncation ---- */

.filename-cell {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Action cell — keep buttons on one line ---- */

.actions-cell {
    white-space: nowrap;
}

/* ---- Responsive: tablet / Kobo (640px and below) ---- */

@media (max-width: 640px) {
    .col-uploaded, .col-expires { display: none; }

    td, th {
        padding: 0.5rem 0.375rem;
    }

    .filename-cell {
        max-width: 160px;
    }

    .btn-sm {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
        min-height: 2.5rem;
    }
}

/* ---- Responsive: small phones / Kobo compact list (480px and below) ---- */

@media (max-width: 480px) {
    .card {
        padding: 2rem 1.25rem;
    }

    /* Switch table to block layout for card-style rows */
    .table-wrap table,
    .table-wrap thead,
    .table-wrap tbody,
    .table-wrap th,
    .table-wrap td,
    .table-wrap tr {
        display: block;
    }

    .table-wrap thead {
        display: none;
    }

    /* ---- Compact Kobo row ---- */
    /* Each file is a tight row: title line + meta line + action line.
       Min 44px touch target for the whole row. High contrast for e-ink. */

    .table-wrap tr {
        background: #ffffff;
        border: 1px solid #212529;
        border-radius: 4px;
        padding: 0.4rem 0.6rem;
        margin-bottom: 0.375rem;
        min-height: 44px;
    }

    /* Default: hide data-label pseudo-elements */
    .table-wrap td::before {
        display: none;
    }

    /* Hide all cells by default; only show what we need */
    .table-wrap td {
        display: none;
        border-bottom: none;
        padding: 0;
    }

    /* Filename — first line, bold, truncated */
    .table-wrap td.filename-cell {
        display: block;
        font-weight: 600;
        font-size: 0.875rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
        color: #212529;
        padding-bottom: 0.2rem;
    }

    /* Status badge — show inline on second line */
    .table-wrap td.col-status {
        display: block;
        font-size: 0.75rem;
        color: #6c757d;
        padding-bottom: 0.2rem;
    }

    /* Size — show inline after status */
    .table-wrap td.col-size {
        display: inline-block;
        font-size: 0.75rem;
        color: #6c757d;
        text-align: left;
        padding-right: 0.75rem;
        padding-bottom: 0.2rem;
        vertical-align: top;
    }

    /* Actions — third line, large touch targets */
    .table-wrap td.actions-cell {
        display: block;
        padding-top: 0.3rem;
        white-space: nowrap;
    }

    .table-wrap td.actions-cell > * {
        display: inline-block;
        vertical-align: middle;
        margin-right: 0.375rem;
    }

    /* Ensure Download button is easy to tap */
    .table-wrap td.actions-cell .btn {
        min-height: 44px;
        padding: 0.5rem 0.875rem;
        font-size: 0.875rem;
    }

    .table-wrap td.actions-cell .btn-danger-link,
    .table-wrap td.actions-cell .btn-link {
        min-height: 44px;
        padding: 0.5rem 0.375rem;
    }
}
