:root {
    /* Material Design 3 Dark Theme Colors */
    --md-sys-color-background: #1c1b1f;
    --md-sys-color-on-background: #e6e1e5;
    --md-sys-color-surface: #2b2930;
    --md-sys-color-surface-variant: #49454f;
    --md-sys-color-on-surface: #e6e1e5;
    --md-sys-color-on-surface-variant: #cac4d0;
    --md-sys-color-primary: #d0bcff;
    --md-sys-color-on-primary: #381e72;
    --md-sys-color-primary-container: #4f378b;
    --md-sys-color-on-primary-container: #eaddff;
    --md-sys-color-error: #ffb4ab;
    --md-sys-color-error-container: #93000a;
    --md-sys-color-on-error: #690005;
    --md-sys-color-on-error-container: #ffdad6;
    --md-sys-color-outline: #938f99;

    --elevation-1: 0px 1px 3px 1px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.3);
    --elevation-2: 0px 2px 6px 2px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.3);
    
    font-family: 'Roboto', sans-serif;
}

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

body {
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 2rem 1rem;
    line-height: 1.5;
}

.app-container {
    max-width: 900px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.app-container-wide {
    max-width: 1200px;
}

.header {
    text-align: center;
}

.header h1 {
    font-size: 2rem;
    font-weight: 500;
    color: var(--md-sys-color-primary);
    margin-bottom: 0.25rem;
}

.header .subtitle {
    font-size: 1rem;
    color: var(--md-sys-color-on-surface-variant);
}

.card {
    background-color: var(--md-sys-color-surface);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--elevation-1);
    overflow: hidden;
}

.content-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
    align-items: flex-start;
}

.table-container {
    overflow-x: auto;
    flex: 1 1 500px;
}

/* CG Chart Styles */
.chart-container {
    flex: 1 1 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chart-title {
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--md-sys-color-primary);
    margin-bottom: 1rem;
}

.svg-wrapper {
    width: 100%;
    max-width: 500px;
    aspect-ratio: 1;
}

svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

.axis-line {
    stroke: var(--md-sys-color-outline);
    stroke-width: 2;
}

.grid-line {
    stroke: rgba(255, 255, 255, 0.05);
    stroke-width: 1;
}

.axis-label {
    fill: var(--md-sys-color-on-surface-variant);
    font-size: 14px;
    font-weight: 500;
}

.tick-label {
    fill: var(--md-sys-color-on-surface-variant);
    font-size: 12px;
}

.envelope-shape {
    fill: var(--md-sys-color-primary);
    fill-opacity: 0.15;
}

.envelope-border {
    stroke: var(--md-sys-color-primary);
    stroke-width: 2;
    fill: none;
}

.point {
    stroke: var(--md-sys-color-surface);
    stroke-width: 2;
    transition: all 0.3s ease;
}

.takeoff-point {
    fill: #ffb4ab;
}

.landing-point {
    fill: #81c995;
}

.point-label {
    fill: var(--md-sys-color-on-surface);
    font-size: 12px;
    font-weight: 500;
    pointer-events: none;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    padding: 1rem 0.5rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    border-bottom: 1px solid var(--md-sys-color-surface-variant);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    padding: 0.75rem 0.5rem;
    vertical-align: middle;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

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

.item-name {
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    width: 30%;
}

.limit-badge {
    display: inline-block;
    margin-left: 0.5rem;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    background-color: var(--md-sys-color-surface-variant);
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.75rem;
    font-weight: 400;
}

/* Inputs */
input[type="number"], input[type="text"] {
    width: 100%;
    background-color: transparent;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 4px;
    color: var(--md-sys-color-on-surface);
    padding: 0.5rem 0.75rem;
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.2s ease;
}

input[type="number"]:focus, input[type="text"]:focus {
    outline: none;
    border-color: var(--md-sys-color-primary);
    box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

/* Hide number spin buttons */
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
    -webkit-appearance: none; 
    margin: 0; 
}
input[type=number] {
    -moz-appearance: textfield;
}

/* Computed Values */
.calc-val {
    font-family: 'Roboto Mono', monospace;
    font-size: 1rem;
    color: var(--md-sys-color-on-surface);
    padding: 0.5rem 0.75rem;
}

.fixed-val {
    color: var(--md-sys-color-on-surface-variant);
}

.negative {
    color: var(--md-sys-color-error);
}

.total-row {
    background-color: rgba(208, 188, 255, 0.08); /* primary with opacity */
}

.total-row .item-name {
    color: var(--md-sys-color-primary);
}

.total-row .calc-val {
    font-weight: 700;
    color: var(--md-sys-color-primary);
}

/* Burn Inputs Container */
.burn-inputs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.burn-inputs input {
    width: 70px;
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

.burn-inputs span {
    color: var(--md-sys-color-on-surface-variant);
    font-size: 0.875rem;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Error States */
tr.is-error {
    background-color: rgba(255, 180, 171, 0.1); /* error with opacity */
}

tr.is-error .item-name,
tr.is-error .calc-val,
tr.is-error .limit-badge {
    color: var(--md-sys-color-error);
}

tr.is-error .limit-badge {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
}

input.is-error {
    border-color: var(--md-sys-color-error) !important;
    color: var(--md-sys-color-error);
}
input.is-error:focus {
    box-shadow: inset 0 0 0 1px var(--md-sys-color-error) !important;
}

/* Distance Section */
.distance-section {
    width: 100%;
    margin-top: 2rem;
}

.distance-inputs {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-size: 0.875rem;
    color: var(--md-sys-color-on-surface-variant);
}

.input-group input {
    width: 180px;
}

.btn-primary {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
    height: 38px;
}

.btn-primary:hover {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.distance-results {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

.result-card {
    flex: 1 1 300px;
    background-color: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--md-sys-color-surface-variant);
}

.result-card h3 {
    color: var(--md-sys-color-primary);
    margin-bottom: 1rem;
    font-size: 1.125rem;
}

.weather-data, .perf-data {
    margin-bottom: 1rem;
}

.data-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.data-row .label {
    font-weight: 500;
}

.data-row .value {
    text-align: right;
    white-space: nowrap;
}

input.altim-input {
    width: 45px !important;
    min-width: 45px !important;
    max-width: 45px !important;
    text-align: right;
    background: transparent;
    border: 1px solid transparent;
    border-bottom: 1px solid var(--md-sys-color-surface-variant);
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    padding: 0 !important;
    margin: 0 4px 0 0 !important;
    box-sizing: border-box !important;
    -moz-appearance: textfield;
}

input.altim-input::-webkit-outer-spin-button,
input.altim-input::-webkit-inner-spin-button {
    -webkit-appearance: none !important;
    margin: 0 !important;
}

input.altim-input:focus {
    outline: none;
    border-bottom-color: var(--md-sys-color-primary);
}

.perf-data {
    border-top: 1px solid var(--md-sys-color-surface-variant);
    padding-top: 1rem;
}

.perf-data .data-row {
    color: var(--md-sys-color-primary);
    font-size: 1rem;
}

.poh-reference h3 {
    margin-bottom: 1rem;
    color: var(--md-sys-color-primary);
}

.poh-images {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
}

.poh-images figure {
    flex: 0 0 auto;
    width: 400px;
}

.poh-images img {
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--md-sys-color-surface-variant);
}

.poh-images figcaption {
    font-size: 0.875rem;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 0.5rem;
    text-align: center;
}

@media (max-width: 600px) {
    th, td {
        padding: 0.5rem 0.25rem;
    }
    .item-name {
        font-size: 0.875rem;
    }
    input[type="number"], input[type="text"] {
        padding: 0.4rem;
        font-size: 0.875rem;
    }
    .burn-inputs {
        flex-wrap: wrap;
    }
}
