:root {
    --blue: #023a99;
    --blue-dark: #012c75;
    --blue-tint: #eaf0fb;
    --orange: #fe8102;
    --orange-dark: #e07200;
    --orange-tint: #fff2e3;
    --ink: #16213e;
    --muted: #64708a;
    --bg: #f4f6fb;
    --surface: #ffffff;
    --border: #e2e7f1;
    --success: #28a745;
    --success-tint: #f0fff4;
    --danger: #e74c3c;
    --danger-tint: #fee;
    --warning-bg: #fff3cd;
    --warning-fg: #856404;
    --warning-border: #ffeeba;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}
img { max-width: 100%; height: auto; }
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
    color: white;
    padding: clamp(16px, 4vw, 20px) clamp(20px, 5vw, 40px);
    box-shadow: 0 2px 12px rgba(2,58,153,0.25);
    border-bottom: 3px solid var(--orange);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}
.header-logo-wrap {
    display: inline-block;
    background: #ffffff;
    padding: clamp(8px, 1.6vw, 14px) clamp(14px, 2.4vw, 22px);
    border-radius: 12px;
    line-height: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-logo { display: block; height: clamp(48px, 8vw, 72px); width: auto; }
.header p { opacity: 0.85; margin-top: 12px; font-size: clamp(12px, 3vw, 14px); }
.header-nav { display: flex; align-items: center; gap: 16px; }
.header-nav a {
    color: white; text-decoration: none; font-size: 13px; font-weight: 600;
    opacity: 0.9; border-bottom: 1px solid transparent;
}
.header-nav a:hover { opacity: 1; border-bottom-color: var(--orange); }
/* Signed-in identity. Deliberately a pill rather than another nav link:
   it is a status readout, not somewhere to click, and it has to be
   distinguishable at a glance from Admin/Logout beside it. Empty until
   /api/me answers, so a failed/blank response shows nothing rather than a
   misleading placeholder identity. */
.current-user {
    display: none; align-items: center; gap: 6px;
    padding: 4px 12px; border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    color: white; font-size: 13px; font-weight: 600;
    max-width: 40vw; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
}
.current-user.is-shown { display: inline-flex; }
.current-user .cu-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--orange); flex: none;
}

/* Main container */
.container {
    max-width: 900px;
    width: 100%;
    margin: clamp(20px, 4vw, 32px) auto;
    padding: 0 clamp(12px, 4vw, 20px);
}
.container.narrow { max-width: 440px; }

/* Card */
.card {
    background: var(--surface);
    border-radius: 12px;
    padding: clamp(18px, 4vw, 32px);
    margin-bottom: 24px;
    box-shadow: 0 1px 3px rgba(2,58,153,0.08);
}
.card h2 {
    font-size: 18px;
    margin-bottom: 20px;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.card h2 .step-num {
    background: var(--blue);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

/* Primary button */
.generate-btn {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, var(--orange) 0%, var(--orange-dark) 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    margin-top: 8px;
    min-height: 44px;
}
.generate-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(254,129,2,0.35); }
.generate-btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.generate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Secondary button */
.secondary-btn {
    padding: 10px 18px; border: 1.5px solid var(--blue); border-radius: 8px;
    background: white; color: var(--blue); font-size: 13px; font-weight: 600;
    cursor: pointer; transition: background-color 0.15s, color 0.15s;
    min-height: 40px;
}
.secondary-btn:hover { background: var(--blue); color: white; }
.secondary-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Form fields */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.field input, .field textarea, .field select {
    padding: 10px 12px;
    border: 1.5px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.15s;
}
.field input:focus, .field textarea:focus, .field select:focus {
    outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-tint);
}

/* Simple data table (admin lists) */
.data-table-wrap { overflow-x: auto; }
table.data-table { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 480px; }
table.data-table th, table.data-table td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
table.data-table th { background: var(--blue); color: white; font-weight: 600; }
table.data-table tr:nth-child(even) td { background: var(--blue-tint); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.pill.active { background: var(--success-tint); color: #155724; }
.pill.inactive { background: var(--danger-tint); color: #c00; }
.pill.admin { background: var(--orange-tint); color: var(--orange-dark); }

/* Error / status banners */
.error-box {
    background: var(--danger-tint);
    border: 1px solid #fcc;
    border-radius: 8px;
    padding: 16px;
    color: #c00;
    margin-top: 16px;
    font-size: 14px;
}
.key-warning {
    margin-bottom: 20px;
    padding: 12px 20px;
    background: var(--warning-bg);
    color: var(--warning-fg);
    border: 1px solid var(--warning-border);
    border-radius: 8px;
    font-size: 13px;
}

.footer {
    text-align: center;
    padding: 28px 24px;
    color: #999;
    font-size: 12px;
    border-top: 1px solid #e5e5e5;
}
.footer-logo { height: 20px; opacity: 0.85; vertical-align: middle; margin-right: 6px; }
.footer-line { margin-top: 6px; }

/* ── Shared in-page dialogs (static/dialog.js) ───────────────────────────
   Used instead of window.confirm/prompt/alert, which some embedded
   browsers refuse outright. */
.ui-dialog-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.55);
    display: flex; align-items: center; justify-content: center;
    padding: 24px 16px; z-index: 2000; overflow-y: auto;
}
.ui-dialog {
    background: #fff; border-radius: 12px; max-width: 460px; width: 100%;
    padding: 24px 26px; box-shadow: 0 18px 50px rgba(0,0,0,.3);
}
.ui-dialog h3 { margin: 0 0 10px; font-size: 17px; }
.ui-dialog-body { font-size: 13.5px; color: var(--muted); margin-bottom: 18px; line-height: 1.6; }
.ui-dialog-body strong { color: inherit; }
.ui-dialog-field { margin-bottom: 18px; }
.ui-dialog-field label {
    display: block; font-size: 11px; letter-spacing: .05em; text-transform: uppercase;
    color: var(--muted); font-weight: 700; margin-bottom: 6px;
}
.ui-dialog-field input {
    width: 100%; padding: 10px 12px; border: 1.5px solid var(--border);
    border-radius: 8px; font-size: 14px;
}
.ui-dialog-field input:focus {
    outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-tint);
}
.ui-dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.ui-dialog-actions .secondary-btn.danger { border-color: #c0392b; color: #c0392b; }
.ui-dialog-actions .secondary-btn.danger:hover { background: #c0392b; color: #fff; }

/* ── Pending (unfinished) jobs ──────────────────────────────────────── */
/* Amber rather than the usual blue: this card is a "money already spent,
   don't spend it again" prompt, not another step in the normal flow. */
.pending-card { border-left: 4px solid var(--orange); }
.pending-intro { font-size: 14px; color: var(--muted); margin-bottom: 14px; }
.pending-row {
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    padding: 12px 14px; border: 1px solid #e3e8f2; border-radius: 8px;
    margin-bottom: 10px; background: var(--surface);
}
.pending-row:last-child { margin-bottom: 0; }
.pending-main { flex: 1 1 260px; min-width: 0; }
.pending-wo { font-weight: 700; color: var(--ink); font-size: 15px; }
.pending-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.pending-badge {
    display: inline-block; font-size: 11px; font-weight: 700;
    padding: 2px 8px; border-radius: 999px; margin-left: 8px;
    background: var(--orange-tint); color: var(--orange-dark);
}
.pending-badge.mine { background: var(--blue-tint); color: var(--blue); }
.pending-locked { font-size: 12.5px; color: var(--muted); font-style: italic; }

/* ── Report overlay ─────────────────────────────────────────────────── */
.report-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(12, 20, 40, 0.55);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 32px 16px; overflow-y: auto;
}
.report-panel {
    background: var(--surface); border-radius: 12px; width: 100%;
    max-width: 1000px; padding: 22px 24px 20px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}
.report-head { display: flex; align-items: center; justify-content: space-between; }
.report-head h3 { margin: 0; font-size: 19px; color: var(--ink); }
.report-close {
    background: none; border: none; font-size: 26px; line-height: 1;
    color: var(--muted); cursor: pointer; padding: 0 4px;
}
.report-close:hover { color: var(--ink); }
.report-controls {
    display: flex; justify-content: space-between; gap: 16px;
    flex-wrap: wrap; margin: 16px 0 14px;
}
.report-ranges { display: flex; gap: 8px; flex-wrap: wrap; }
.range-btn {
    border: 1px solid #d7deec; background: var(--surface); color: var(--ink);
    border-radius: 999px; padding: 6px 14px; font-size: 13px;
    font-weight: 600; cursor: pointer;
}
.range-btn:hover { border-color: var(--blue); }
.range-btn.is-active { background: var(--blue); border-color: var(--blue); color: #fff; }
.report-dates { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.report-dates label { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.report-dates input {
    border: 1px solid #d7deec; border-radius: 6px; padding: 5px 8px; font-size: 13px;
}
.report-summary { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.report-stat {
    flex: 1 1 140px; background: var(--bg); border-radius: 8px; padding: 10px 14px;
}
.report-stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.report-stat .value { font-size: 22px; font-weight: 700; color: var(--ink); }
.report-table-wrap { overflow-x: auto; }
.report-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.report-table th {
    background: var(--blue); color: #fff; text-align: left;
    padding: 9px 10px; font-size: 12px; white-space: nowrap;
}
.report-table td { padding: 8px 10px; border-bottom: 1px solid #eef1f7; vertical-align: top; }
.report-table tr:nth-child(even) td { background: #fafbfe; }
.report-empty { padding: 26px; text-align: center; color: var(--muted); }
.report-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

/* Printing: the report is the document, so everything else comes off the
   page. Without this, window.print() would print the whole app - upload
   form, buttons and all - around a scrollable table clipped to its box. */
@media print {
    body > *:not(.report-overlay) { display: none !important; }
    .report-overlay {
        position: static; background: none; padding: 0; display: block; overflow: visible;
    }
    .report-panel { box-shadow: none; max-width: none; padding: 0; }
    .report-close, .report-controls, .report-actions { display: none !important; }
    .report-table-wrap { overflow: visible; }
    .report-table th { background: #ddd !important; color: #000 !important; }
    .report-table { font-size: 11px; }
    .report-table tr { page-break-inside: avoid; }
}
