:root {
    --bg-page: white;
    --bg-bar: #f4f6f0;
    --bg-hover: #e8e8e8;
    --bg-active: #fff;
    --bg-disabled: #eee;
    --border: #ccc;
    --text-primary: #1a1a1a;
    --text-secondary: #888;
    --accent: #16a34a;
    --accent-hover: #15803d;
    --secondary: #a36c15;
    --secondary-hover: #805511;
    --tertiary: #7c1bd1;
    --tertiary-hover: #6115a3;
    --alert: #d1241b;
    --alert-hover: #a31b15;
    --font-sm: 12px;
    --font-md: 14px;
    --font-lg: 28px;
    --radius-sm: 4px;
    --radius: 6px;
    --radius-lg: 8px;
    --gap-sm: 4px;
    --gap-md: 8px;
    --gap-lg: 12px;
    --gap-xl: 16px;
}

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

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

/* ── Base ───────────────────────────────────────────────────────── */
html,
body {
    height: 100%;
    font-family:
        system-ui,
        -apple-system,
        sans-serif;
    font-size: var(--font-md);
    color: var(--text-primary);
    background: var(--bg-page);
}

body {
    display: flex;
    flex-direction: column;
    min-width: 56em;
}

/* ── Utility classes ────────────────────────────────────────────── */
.muted {
    font-size: var(--font-sm);
    color: var(--text-secondary);
}

.monospace {
    font-family: monospace;
}

.row {
    display: flex;
    gap: var(--gap-lg);
    align-items: center;
}

.col {
    display: flex;
    flex-direction: column;
    gap: var(--gap-md);
    flex: 1;
    min-height: 0;
}

.right {
    margin-left: auto;
}

[hidden] {
    display: none !important;
}

/* ── Layout ─────────────────────────────────────────────────────── */
#top {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: row;
    border-bottom: 1px solid var(--accent-hover);
    border-top: 1px solid var(--accent-hover);
}

#bottom {
    background-color: var(--bg-page);
    max-height: 50%;
    overflow-y: auto;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

#info-panel {
    width: 260px;
    border-right: 1px solid var(--accent-hover);
    overflow-y: auto;
}

.relative {
    position: relative;
}

#plot-toggle {
    height: 2.4em;
    width: 2.4em;
    padding: 1px 1px 3px 1px;
    margin: var(--gap-sm);
    position: absolute;
    z-index: 600;
    cursor: pointer;
    right: 0px;
    border: var(--border) solid 2px;
    background-color: var(--bg-active);
}

#plot-panel {
    min-width: min(400px, 38vw);
    max-width: 33%;
    flex: 0.4;
    border-left: 1px solid var(--accent-hover);
    padding-bottom: 3px;
}

#map {
    flex: 1;
    min-height: 0;
    position: relative;
}

/* ── Tabs ──────────────────────────────────────────────────────── */
#tabs {
    display: flex;
    background: var(--bg-bar);
    border-bottom: 1px solid var(--border);
}

#tabs > button {
    padding: var(--gap-md) var(--gap-lg);
    border: none;
    border-right: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    font-size: var(--font-md);
    font-weight: 500;
    color: var(--text-primary);
}

#tabs > button[aria-selected="true"] {
    background: var(--bg-active);
    border-bottom: 2px solid var(--bg-active);
    margin-bottom: -1px;
}

#tabs > button:hover[aria-selected="false"] {
    background: var(--bg-hover);
}

#tabs > button:focus-visible {
    outline: 1px solid var(--accent);
}

.tab-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--font-sm);
}

/* ── Buttons ────────────────────────────────────────────────────── */
button.action {
    padding: 6px var(--gap-lg);
    border: none;
    border-radius: var(--radius-sm);
    font-size: var(--font-md);
    cursor: pointer;
    background: var(--accent);
    color: white;
}

button.action:hover {
    background: var(--accent-hover);
}

button.secondary {
    background: var(--secondary);
}

button.secondary:hover {
    background: var(--secondary-hover);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Forms ──────────────────────────────────────────────────────── */
fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--gap-lg) var(--gap-xl);
    margin-bottom: var(--gap-lg);
}

legend {
    font-weight: 600;
    font-size: var(--font-md);
    color: var(--text-primary);
}

.field {
    margin-bottom: var(--gap-md);
    display: flex;
    align-items: center;
    gap: var(--gap-md);
}

.field label,
.field .label {
    flex-basis: 140px;
    font-size: var(--font-md);
}

input,
select,
textarea {
    flex: 1;
    padding: var(--gap-sm) var(--gap-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--font-md);
}

.field .small {
    flex-basis: 100px;
    max-width: 200px;
}

input:disabled {
    background-color: var(--bg-disabled);
}

input:required:not(:valid) {
    border-color: var(--alert);
}

label.check {
    cursor: pointer;
}

/* ── Sidebars ───────────────────────────────────────────────────── */
aside {
    display: flex;
    flex-direction: column;
}

h1 {
    font-size: var(--font-lg);
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: var(--gap-sm);
    font-family: "Courier New", Courier, monospace;
    color: var(--accent-hover);
    position: relative;
}

.logo {
    width: 44px;
    position: absolute;
    right: -2px;
    top: -2px;
}

h3 {
    font-size: var(--font-md);
    letter-spacing: 0.4px;
    color: var(--text-secondary);
    margin-bottom: var(--gap-md);
    text-align: center;
}

.desc {
    font-size: var(--font-sm);
    color: var(--secondary-hover);
    padding-left: 1.2em;
    padding-top: var(--gap-sm);
    cursor: pointer;
}

.desc:hover,
.desc:focus {
    text-decoration: underline dotted;
}

.section {
    padding: var(--gap-lg) var(--gap-xl);
    border-bottom: 1px solid var(--border);
}

.stat {
    display: flex;
    justify-content: space-between;
    gap: var(--gap-md);
    font-size: var(--font-sm);
    padding: var(--gap-sm) 0;
}

.stat span:first-child {
    color: var(--text-secondary);
    flex-shrink: 0;
}

.stat span:last-child {
    text-align: right;
    font-weight: 500;
}

#select-point {
    justify-content: center;
    margin-top: var(--gap-md);
}

.plot {
    background-color: var(--bg-page);
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    border-bottom: 1px solid var(--border);
    padding: var(--gap-sm);
}

.plot:last-of-type {
    border-bottom: none;
}

.plot div {
    flex: 1;
    min-height: 0;
}

/* ── Tab content ───────────────────────────────────────────────────── */
.tab-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: var(--gap-xl);
    overflow-y: auto;
}

.tab-content.row {
    flex-direction: row;
}

#fix-list {
    list-style: none;
    min-width: 21em;
    flex: 0.4;
}

#fix-list li {
    padding: var(--gap-sm) 0;
}

#track-cards {
    list-style: none;
}

/* ── Loading overlay ──────────────────────────────────────────── */
#loading {
    position: fixed;
    inset: 0;
    background: rgba(255, 250, 200, 0.5);
    display: flex;
    flex-direction: column;
    gap: var(--font-sm);
    align-items: center;
    justify-content: center;
    z-index: 500;
    font-size: var(--font-md);
    color: var(--text-secondary);
    text-align: center;
    padding-bottom: 15%;
}

#loading-message {
    background: rgba(255, 255, 255, 0.95);
    padding: var(--gap-md) var(--gap-xl);
    border-radius: var(--radius);
    font-weight: 500;
    font-size: var(--font-md);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--accent);
    border-top-color: var(--secondary);
    border-radius: 50%;
    animation: spin 1.2s linear infinite;
    margin: 0 auto var(--gap-lg);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Toast notifications ───────────────────────────────────────── */
#toasts {
    position: fixed;
    top: var(--gap-xl);
    right: var(--gap-xl);
    display: flex;
    flex-direction: column;
    gap: var(--gap-md);
    z-index: 1000;
    pointer-events: none;
    max-width: 400px;
}

.toast {
    pointer-events: auto;
    background: var(--alert);
    color: #fff;
    padding: var(--gap-md) var(--gap-lg);
    border-radius: var(--radius);
    font-size: var(--font-md);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    opacity: 0;
    transform: translateX(100%);
    transition:
        opacity 0.15s,
        transform 0.15s;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

/* ── Drop zone ──────────────────────────────────────────────────── */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 10px;
    text-align: center;
    cursor: pointer;
    flex: 1;
    min-width: 17em;
}

.drop-zone:hover,
.drop-zone.dragover,
.drop-zone:focus-visible {
    border-color: var(--accent);
    background: var(--bg-bar);
}

.drop-zone .icon {
    font-size: 32px;
    margin-bottom: var(--gap-md);
}

#file-list {
    list-style: none;
    overflow: auto;
    margin-bottom: auto;
    flex: 1;
    min-width: 12em;
}

#file-list li {
    display: flex;
    font-size: var(--font-sm);
    font-family: monospace;
}

/* ── Point table ──────────────────────────────────────────────────── */
#point-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: var(--gap-lg);
    font-size: var(--font-sm);
}

th {
    font-size: var(--font-md);
    color: var(--text-secondary);
}

#point-table th {
    text-align: left;
    padding: var(--gap-md);
    padding-bottom: 0px;
    border-bottom: 2px solid var(--border);
}

#point-table td {
    padding: var(--gap-sm);
    vertical-align: middle;
}

td input {
    width: 100%;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-secondary);
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    line-height: 1;
}

.btn-icon:hover:not(:disabled) {
    color: #fff;
    background: var(--accent-hover);
}

.btn-icon:disabled {
    opacity: 0.3;
    cursor: default;
}

.btn-icon.danger:hover {
    color: #fff;
    background: var(--alert-hover);
}
