:root {
    --bg: #fff;
    --text: #0f172a;
    --primary: #0284c7;
    --primary-light: #0ea5e9;
    --muted: #4a90b8;
    --muted-dark: #4a7fa5;
    --border: #bae6fd;
    --surface: #f0f9ff;
    --surface-2: #e0f2fe;
    --pos: #16a34a;
    --neg: #dc2626;
    --subtle: #94a3b8;
    --warn-bg: #fefce8;
    --warn-border: #eab308;
    --warn-text: #713f12;
}

html {
    font-size: 18px;
}

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

body {
    font-family: ui-monospace, "Cascadia Code", "Fira Code", monospace;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 2rem;
}

h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.subtitle {
    font-size: 0.8rem;
    color: var(--primary-light);
    margin-bottom: 2rem;
}

.subtitle a {
    color: inherit;
    text-decoration: none;
}

.subtitle a:hover {
    text-decoration: underline;
}

.privacy a {
    color: inherit;
    text-decoration: none;
}

.privacy a:hover {
    text-decoration: underline;
}

.hidden {
    display: none;
}

/* Drop zone */
#dropzone {
    border: 2px dashed var(--muted);
    border-radius: 8px;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    margin-bottom: 1.5rem;
    background: var(--bg);
}

#dropzone:hover,
#dropzone.over {
    border-color: var(--primary);
    background: var(--surface);
}

#dropzone p {
    color: var(--primary-light);
    font-size: 0.9rem;
}

#dropzone p span {
    color: var(--primary);
}

#file-input {
    display: none;
}

/* Status */
#status-line {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    min-height: 1.2em;
    margin-bottom: 1rem;
}

#status {
    font-size: 0.8rem;
    color: var(--primary-light);
}

#status.error {
    color: var(--neg);
}

#status.ok {
    color: var(--pos);
}

/* Section nav */
.section-nav {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.section-nav-btn {
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.35rem 0.85rem;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--primary);
    text-decoration: none;
    transition: background 0.12s, border-color 0.12s;
}

.section-nav-btn:hover {
    background: var(--surface-2);
    border-color: var(--primary);
}

/* Page sections */
.page-section {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    background: var(--bg);
}

.page-section-title {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted-dark);
    margin-bottom: 1.25rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--surface-2);
}

/* Output sections */
.section-divider {
    border: none;
    border-top: 2px dashed var(--border);
    margin: 2.5rem 0;
}

.section-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted-dark);
    margin-bottom: 0.6rem;
}

.section-label--subsequent {
    margin-top: 2rem;
}

/* Table */
.table-wrap {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.table-wrap+.table-wrap {
    margin-top: 2rem;
}

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

thead tr {
    background: var(--muted-dark);
    color: var(--border);
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
}

th,
td {
    padding: 0.55rem 0.85rem;
    white-space: nowrap;
}

th {
    text-align: right;
}

th:first-child,
th:nth-child(2) {
    text-align: left;
}

td {
    text-align: right;
    border-top: 1px solid var(--surface-2);
}

tbody td:first-child,
tbody td:nth-child(2) {
    text-align: left;
}

tbody tr {
    background: var(--bg);
}

tbody tr:hover {
    background: var(--surface);
}

tfoot tr {
    background: var(--surface-2);
    color: var(--text);
    font-weight: 600;
}

tfoot td {
    border-top: 2px solid var(--muted);
    text-align: right;
}

tfoot td:first-child {
    text-align: left;
}

.pos {
    color: var(--pos);
}

.neg {
    color: var(--neg);
}

.pct {
    font-size: 0.75em;
    color: var(--muted);
}

.type-buy {
    color: #64748b;
}

.type-sell {
    font-weight: 600;
}

/* Privacy note */
.privacy {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.75rem;
    color: var(--primary-light);
    background: var(--bg);
}

.privacy strong {
    color: var(--primary);
}

/* Notes */
.notes {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.note {
    padding: 0.85rem 1rem;
    border-radius: 6px;
    font-size: 0.78rem;
    line-height: 1.7;
    border-left: 3px solid transparent;
}

.note-info {
    background: var(--surface-2);
    border-color: var(--primary);
    color: var(--text);
}

.note-warn {
    background: var(--warn-bg);
    border-color: var(--warn-border);
    color: var(--warn-text);
}

.note-title {
    font-weight: 600;
    display: block;
    margin-bottom: 0.4rem;
}

.note code {
    font-family: inherit;
    background: rgba(0, 0, 0, 0.07);
    padding: 0.1em 0.35em;
    border-radius: 3px;
}

.note dl {
    margin: 0.5rem 0 0.5rem 0.5rem;
}

.note dt {
    font-weight: 600;
    float: left;
    margin-right: 0.4rem;
}

.note dd {
    margin: 0 0 0.2rem 0;
}

/* PIT-38 section fields */
.pit-section {
    margin-top: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg);
}

.pit-section-title {
    background: var(--muted-dark);
    padding: 0.55rem 1rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--border);
    border-bottom: none;
}

.pit-field {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    padding: 0.55rem 1rem;
    border-bottom: 1px solid var(--surface);
    font-size: 0.8rem;
}

.pit-field:last-child {
    border-bottom: none;
}

.pit-field.pit-total {
    background: var(--surface);
    font-weight: 600;
    border-bottom: none;
}

.pit-field.pit-muted {
    opacity: 0.4;
    pointer-events: none;
}

.pit-num {
    font-weight: 700;
    color: var(--primary);
    min-width: 2.5rem;
    flex-shrink: 0;
}

.pit-label {
    flex: 1;
    color: var(--text);
    line-height: 1.5;
}

.pit-label small {
    display: block;
    font-size: 0.7rem;
    color: var(--muted);
    margin-top: 0.1rem;
}

.pit-tag {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.1em 0.45em;
    border-radius: 3px;
    background: var(--surface-2);
    color: var(--primary);
    vertical-align: middle;
    margin-left: 0.3rem;
    white-space: nowrap;
}

.pit-value {
    font-weight: 600;
    color: var(--text);
    min-width: 8rem;
    text-align: right;
    flex-shrink: 0;
}

.pit-value.pit-zero {
    color: var(--muted);
    font-weight: 400;
}

.pit-value.pos {
    color: var(--pos);
}

.pit-value-sub {
    font-weight: 400;
    color: var(--muted);
}

.pit-note {
    font-size: 0.7rem;
    color: var(--muted);
    padding: 0.4rem 1rem 0.5rem;
    border-top: 1px dashed var(--border);
}

/* Manual lots section */
#manual-lots-section {
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

#manual-lots-section>summary {
    padding: 0.65rem 1rem;
    background: var(--surface);
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--primary);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    user-select: none;
}

#manual-lots-section>summary::-webkit-details-marker {
    display: none;
}

#manual-lots-section>summary::before {
    content: '▶';
    font-size: 0.6rem;
    transition: transform 0.15s;
    color: var(--muted);
}

#manual-lots-section[open]>summary::before {
    transform: rotate(90deg);
}

.lots-inner {
    padding: 0.75rem 1rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.lots-desc {
    font-size: 0.75rem;
    color: var(--primary-light);
    margin-bottom: 0.75rem;
    line-height: 1.6;
}

#manual-lots-table {
    margin-bottom: 0.75rem;
}

#manual-lots-table th {
    font-size: 0.68rem;
    text-align: left;
    padding: 0.35rem 0.5rem;
}

#manual-lots-table td {
    text-align: left;
    padding: 0.25rem 0.4rem;
    border-top: none;
}

#manual-lots-table input {
    font-family: inherit;
    font-size: 0.8rem;
    padding: 0.28rem 0.45rem;
    border: 1px solid var(--muted);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text);
}

#manual-lots-table input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Shared ghost button style */
.btn-ghost {
    font-family: inherit;
    font-size: 0.8rem;
    padding: 0.3rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid var(--muted);
    background: var(--surface);
    color: var(--primary);
}

.btn-ghost:hover {
    background: var(--surface-2);
}

.btn-remove-lot {
    font-family: inherit;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 0.3rem;
    line-height: 1;
}

.btn-remove-lot:hover {
    color: var(--neg);
}

#retry-btn {
    display: none;
}

#reload-link {
    display: none;
    margin-top: 0.75rem;
    font-size: 0.8rem;
    color: var(--primary);
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    font-family: inherit;
    text-decoration: underline;
}

#reload-link:hover {
    color: var(--text);
}
