:root {
    --ink: #102a43;
    --muted: #567187;
    --paper: #f3f9ff;
    --panel: #ffffff;
    --line: #d7e7f3;
    --blue: #0176d3;
    --blue-dark: #0b2e4a;
    --blue-soft: #ddf2ff;
    --yellow: #ffd13b;
    --green: #2e844a;
    --green-soft: #effaf3;
    --red: #b83238;
    --shadow: 0 18px 54px rgba(8, 39, 62, 0.12);
    color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; scroll-behavior: smooth; background: var(--paper); }
body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 10% 3%, rgba(116, 198, 247, 0.28), transparent 28rem),
        radial-gradient(circle at 92% 9%, rgba(255, 209, 59, 0.2), transparent 26rem),
        linear-gradient(180deg, var(--paper), #fff 48%, #fff9e8);
    font: 16px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
:focus-visible { outline: 3px solid rgba(1, 118, 211, 0.38); outline-offset: 3px; }

.skip-link {
    position: fixed;
    z-index: 100;
    top: 8px;
    left: 8px;
    padding: 10px 14px;
    border-radius: 10px;
    color: white;
    background: var(--blue-dark);
    transform: translateY(-150%);
}
.skip-link:focus { transform: none; }

.portal-header {
    position: sticky;
    z-index: 20;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 74px;
    padding: 12px clamp(18px, 4vw, 56px);
    border-bottom: 1px solid rgba(191, 212, 230, 0.8);
    background: rgba(243, 249, 255, 0.92);
    backdrop-filter: blur(18px);
}
.portal-brand { display: inline-flex; gap: 12px; align-items: center; text-decoration: none; }
.portal-brand img { width: 46px; height: 46px; border-radius: 13px; object-fit: cover; }
.portal-brand span { display: grid; line-height: 1.15; }
.portal-brand strong { font-size: 19px; }
.portal-brand small { margin-top: 4px; color: var(--muted); font-size: 13px; }
.portal-header nav { display: flex; gap: 7px; align-items: center; }
.portal-header nav a, .sign-out-button {
    min-height: 40px;
    padding: 9px 13px;
    border: 0;
    border-radius: 999px;
    color: var(--muted);
    background: transparent;
    font-weight: 800;
    text-decoration: none;
}
.portal-header nav a:hover, .sign-out-button:hover { color: var(--blue-dark); background: var(--blue-soft); }
.sign-out-form { margin: 0; }

main { width: min(1240px, 100%); margin: 0 auto; padding: clamp(26px, 5vw, 64px) clamp(18px, 4vw, 50px) 90px; }
.portal-hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(250px, 340px); gap: 34px; align-items: end; }
.eyebrow { margin: 0 0 8px; color: var(--blue); font-size: 12px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
h1, h2, h3, h4, p { margin-top: 0; }
h1 { max-width: 790px; margin-bottom: 16px; font-size: clamp(42px, 6.5vw, 76px); line-height: .96; letter-spacing: -.055em; }
h2 { margin-bottom: 10px; font-size: clamp(30px, 4vw, 48px); line-height: 1; letter-spacing: -.04em; }
h3 { margin-bottom: 8px; font-size: 23px; line-height: 1.18; }
h4 { margin: 28px 0 12px; font-size: 17px; }
.hero-copy, .section-heading p { max-width: 760px; margin-bottom: 0; color: var(--muted); font-size: 18px; }
.customer-card { display: grid; gap: 4px; padding: 22px; border: 1px solid var(--line); border-radius: 22px; background: rgba(255,255,255,.82); box-shadow: var(--shadow); }
.customer-card > span, .customer-card small { color: var(--muted); font-size: 13px; }
.customer-card > strong { font-size: 21px; }
.open-count { display: flex; gap: 9px; align-items: baseline; margin-top: 15px; padding-top: 15px; border-top: 1px solid var(--line); }
.open-count b { color: var(--blue); font-size: 31px; line-height: 1; }
.open-count span { color: var(--muted); font-weight: 700; }

.portal-section { margin-top: 64px; scroll-margin-top: 94px; }
.split-heading { display: flex; gap: 24px; align-items: end; justify-content: space-between; margin-bottom: 23px; }
.button { display: inline-flex; min-height: 46px; align-items: center; justify-content: center; padding: 10px 18px; border: 1px solid transparent; border-radius: 999px; font-weight: 900; cursor: pointer; }
.button:disabled { cursor: wait; opacity: .58; }
.button-primary { color: white; background: var(--blue); box-shadow: 0 10px 30px rgba(1,118,211,.2); }
.button-secondary { color: var(--blue-dark); border-color: var(--line); background: white; }
.text-button { border: 0; color: var(--blue); background: transparent; font-weight: 800; cursor: pointer; }

.ticket-layout { display: grid; grid-template-columns: minmax(270px, 36%) minmax(0, 1fr); min-height: 570px; overflow: hidden; border: 1px solid var(--line); border-radius: 24px; background: var(--panel); box-shadow: var(--shadow); }
.ticket-list-panel { padding: 18px; border-right: 1px solid var(--line); background: #f7fbfe; }
.ticket-list { display: grid; gap: 10px; }
.ticket-button { width: 100%; padding: 15px; border: 1px solid var(--line); border-radius: 15px; color: inherit; background: white; text-align: left; cursor: pointer; }
.ticket-button:hover, .ticket-button[aria-current="true"] { border-color: var(--blue); background: var(--blue-soft); }
.ticket-button-head { display: flex; gap: 12px; justify-content: space-between; margin-bottom: 5px; }
.ticket-button strong { display: block; }
.ticket-button p { margin: 0; color: var(--muted); font-size: 14px; }
.ticket-detail-panel { padding: clamp(22px, 4vw, 42px); }
.empty-detail { max-width: 440px; margin: 100px auto; color: var(--muted); text-align: center; }
.ticket-toolbar, .form-actions { display: flex; gap: 16px; align-items: center; justify-content: space-between; }
.status-pill { display: inline-flex; padding: 7px 11px; border-radius: 999px; color: #17603d; background: var(--green-soft); font-size: 13px; font-weight: 900; text-transform: capitalize; }
.ticket-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 22px 0; }
.ticket-facts div { padding: 13px; border-radius: 13px; background: #f7fbfe; }
.ticket-facts dt { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.ticket-facts dd { margin: 3px 0 0; font-weight: 750; }
.ticket-notes { display: grid; gap: 11px; margin: 0; padding: 0; list-style: none; }
.ticket-note { padding: 16px; border-left: 4px solid var(--blue); border-radius: 0 14px 14px 0; background: #f7fbfe; }
.ticket-note p { white-space: pre-wrap; overflow-wrap: anywhere; }
.ticket-note small { color: var(--muted); }
.reply-form, .new-ticket-form { display: grid; gap: 10px; }
.reply-form { margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--line); }
.reply-recovery-actions { display: grid; gap: 4px; justify-items: end; text-align: right; }
label { font-weight: 850; }
input, select, textarea { width: 100%; padding: 12px 13px; border: 1px solid #b7cad8; border-radius: 12px; color: var(--ink); background: white; }
textarea { resize: vertical; }
.safe-input { color: var(--muted); font-size: 13px; }
.empty-list { padding: 22px; border: 1px dashed #a9c6da; border-radius: 15px; color: var(--muted); text-align: center; }

.proof-section { padding: clamp(24px, 4vw, 44px); border: 1px solid #eed887; border-radius: 26px; background: rgba(255, 249, 232, .8); box-shadow: var(--shadow); }
.proof-current { margin-top: 22px; }
.proof-card { padding: 23px; border: 1px solid var(--line); border-radius: 18px; background: white; }
.proof-card-head { display: flex; gap: 16px; justify-content: space-between; align-items: start; }
.proof-statement { margin: 16px 0 0; padding: 10px 12px; border-left: 4px solid var(--blue); color: var(--ink); background: var(--blue-soft); font-weight: 850; }
.proof-badge { display: inline-flex; padding: 6px 10px; border-radius: 999px; color: #17603d; background: var(--green-soft); font-size: 12px; font-weight: 900; text-transform: uppercase; }
.proof-provenance { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.proof-provenance-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0; }
.proof-provenance-summary div { padding: 12px; border-radius: 12px; background: #f7fbfe; }
.proof-provenance-summary dt { color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.proof-provenance-summary dd { margin: 3px 0 0; font-weight: 750; }
.proof-receipts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.proof-receipt { min-width: 0; padding: 13px; border: 1px solid var(--line); border-radius: 13px; }
.proof-receipt-head { display: flex; gap: 10px; align-items: baseline; justify-content: space-between; }
.proof-receipt-head span, .proof-receipt small, .proof-receipt-hash span { color: var(--muted); font-size: 12px; }
.proof-receipt small { display: block; margin-top: 4px; }
.proof-receipt-hash { display: grid; gap: 3px; margin-top: 10px; }
.proof-receipt-hash code { overflow: auto; padding: 7px; border-radius: 7px; background: #eef6fb; font-size: 11px; white-space: nowrap; }
.proof-receipt .text-button { margin-top: 7px; padding: 0; }
.proof-sections { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.proof-metric { padding: 14px; border-radius: 14px; background: #f7fbfe; }
.proof-metric strong { display: block; font-size: 22px; }
.proof-metric span, .proof-card small { color: var(--muted); font-size: 13px; }
.proof-history-wrap { margin-top: 30px; }
.proof-history { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.proof-history-button { padding: 15px; border: 1px solid var(--line); border-radius: 14px; color: inherit; background: white; text-align: left; cursor: pointer; }
.proof-history-button strong, .proof-history-button span { display: block; }
.proof-history-button span { color: var(--muted); font-size: 13px; }

.loading-panel { max-width: 680px; margin: 10vh auto; padding: clamp(28px, 5vw, 52px); border: 1px solid var(--line); border-radius: 25px; background: rgba(255,255,255,.9); box-shadow: var(--shadow); text-align: center; }
.loading-mark { width: 52px; height: 52px; margin: 0 auto 24px; border: 6px solid var(--blue-soft); border-top-color: var(--blue); border-radius: 50%; animation: spin .9s linear infinite; }
.loading-panel h1 { margin: 0 auto 15px; font-size: clamp(34px, 6vw, 55px); }
.loading-status { color: var(--muted); }
.loading-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 24px; }
.startup-watchdog { margin-top: 24px; padding: 16px; border-radius: 14px; color: #6b5315; background: #fff4c2; }
.startup-watchdog p { margin: 6px 0; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; z-index: 40; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px)); padding: 14px 17px; border-radius: 14px; color: white; background: var(--blue-dark); box-shadow: var(--shadow); }
.toast.error { background: var(--red); }

@media (max-width: 850px) {
    .portal-header nav > a { display: none; }
    .portal-hero, .ticket-layout { grid-template-columns: 1fr; }
    .ticket-list-panel { border-right: 0; border-bottom: 1px solid var(--line); }
    .ticket-layout { min-height: 0; }
    .ticket-facts, .proof-sections { grid-template-columns: 1fr 1fr; }
    .proof-history { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
    .portal-header { padding: 10px 14px; }
    .portal-brand small { display: none; }
    main { padding-inline: 14px; }
    .split-heading, .proof-card-head { align-items: stretch; flex-direction: column; }
    .ticket-facts, .proof-sections, .proof-history, .proof-provenance-summary, .proof-receipts { grid-template-columns: 1fr; }
}
@media print {
    body { background: white; }
    .portal-header, .portal-hero, #supportTickets, .print-button, .skip-link, .toast { display: none !important; }
    main { width: 100%; padding: 0; }
    #monthlyProof { margin: 0; padding: 0; border: 0; box-shadow: none; background: white; }
    .proof-card, .proof-history-button { break-inside: avoid; box-shadow: none; }
}
