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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 30px;
}

header {
    text-align: left;
    margin-bottom: 25px;
}

h1 {
    font-size: 1.8em;
    color: #333;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.controls-row {
    display: flex;
    align-items: center;
    gap: 25px;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.hidden {
    display: none;
}

.mode-selector {
    display: flex;
    gap: 15px;
    align-items: center;
}

.mode-selector label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.95em;
}

.mode-selector input[type="radio"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.config-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.config-group label {
    font-weight: 500;
    color: #555;
    font-size: 0.95em;
}

.config-group select {
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.95em;
    cursor: pointer;
    background: white;
}

.config-group select:focus {
    outline: none;
    border-color: #4a90e2;
}

.calibration-panel {
    margin-bottom: 24px;
    padding: 14px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: #fafafa;
}

.calibration-panel label {
    display: block;
    font-size: 0.9em;
    font-weight: 600;
    margin-bottom: 8px;
}

.spoke-preset-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.spoke-preset-row label {
    font-weight: 500;
    font-size: 0.9em;
    color: #555;
    white-space: nowrap;
    margin-bottom: 0;
}

.spoke-preset-row select {
    padding: 6px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
    cursor: pointer;
    background: white;
}

.spoke-preset-row select:focus {
    outline: none;
    border-color: #4a90e2;
}

.calibration-panel textarea {
    width: 100%;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    padding: 10px;
    font-size: 0.9em;
    line-height: 1.3;
    resize: vertical;
    min-height: 90px;
    background: white;
    color: #333;
}

.calibration-panel textarea:focus {
    outline: none;
    border-color: #4a90e2;
}

.calibration-status {
    margin-top: 8px;
    font-size: 0.85em;
    color: #666;
}

.calibration-status.error {
    color: #ef4444;
}

.calibration-status.ok {
    color: #22c55e;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 30px;
}

.tables-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.spoke-table-container {
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.table-header {
    background: #f5f5f5;
    padding: 12px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.table-header h2 {
    font-size: 1em;
    font-weight: 600;
    color: #333;
    flex: 1;
}

.target-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 120px;
}

.target-group label {
    font-size: 0.75em;
    text-transform: uppercase;
    color: #666;
    letter-spacing: 0.3px;
    font-weight: 600;
}

.target-group input {
    padding: 5px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
    background: white;
}

.target-group input:focus {
    outline: none;
    border-color: #4a90e2;
}

.table-header h2:first-of-type {
    color: #4a90e2;
}

.spoke-table-container:nth-child(2) .table-header h2 {
    color: #f97316;
}

.spoke-count-selector select {
    padding: 4px 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    background: white;
}

.spoke-table {
    width: 100%;
    border-collapse: collapse;
}

.spoke-table thead {
    background: #e8e8e8;
}

.spoke-table th {
    padding: 10px 8px;
    text-align: center;
    font-size: 0.75em;
    font-weight: 600;
    color: #333;
    border: 1px solid #d0d0d0;
}

.th-short { display: none; }

.spoke-table tbody tr {
    background: white;
}

.spoke-table tbody tr:nth-child(even) {
    background: #f9f9f9;
}

.spoke-table td {
    padding: 8px;
    text-align: center;
    border: 1px solid #e8e8e8;
    font-size: 0.9em;
}

.spoke-table td:first-child {
    font-weight: 500;
    color: #666;
}

.spoke-table input[type="number"] {
    padding: 6px;
    border: 1px solid #d0d0d0;
    border-radius: 3px;
    text-align: center;
    font-size: 0.9em;
    width: 100%;
}

.spoke-table input[type="number"]:focus {
    outline: none;
    border-color: #4a90e2;
}

.tension-value {
    font-weight: 500;
    color: #333;
}

.within-limit {
    font-weight: 600;
}

.within-limit.yes {
    color: #22c55e;
}

.within-limit.no {
    color: #ef4444;
}

.target-delta {
    font-weight: 600;
}

.target-delta.good {
    color: #22c55e;
}

.target-delta.high,
.target-delta.low {
    color: #ef4444;
}

.chart-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.controls-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.save-status {
    font-size: 0.85em;
    color: #22c55e;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.3s;
}

.save-status.visible {
    opacity: 1;
}

.btn {
    padding: 10px 18px;
    border: none;
    border-radius: 4px;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-primary {
    background: #4a90e2;
    color: white;
}

.btn-primary:hover {
    background: #3a7bc8;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.chart-container {
    position: relative;
    height: 500px;
    padding: 20px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}

.summary-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.summary-card {
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 12px;
    font-size: 0.9em;
    line-height: 1.5;
}

.summary-card h3 {
    margin-bottom: 8px;
    font-size: 0.9em;
    font-weight: 700;
}

@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 12px;
    }

    .tables-section {
        grid-template-columns: 1fr;
    }

    .controls-row {
        flex-wrap: wrap;
        gap: 12px;
    }

    /* Prevent iOS from zooming in on input focus */
    .spoke-table input[type="number"],
    .target-group input,
    .calibration-panel textarea,
    .spoke-preset-row select,
    .config-group select,
    .spoke-count-selector select {
        font-size: 16px;
    }

    /* Proper touch targets for spoke inputs */
    .spoke-table input[type="number"] {
        min-height: 44px;
        padding: 8px 4px;
    }

    /* Tighter table cells to fit 4 columns at 375px */
    .spoke-table th,
    .spoke-table td {
        padding: 6px 4px;
        font-size: 0.8em;
    }

    .th-long { display: none; }
    .th-short { display: inline; }

    /* Hide WITHIN LIMIT column — redundant with colour-coded TARGET DELTA */
    .spoke-table th:nth-child(5),
    .spoke-table td:nth-child(5) {
        display: none;
    }

    .table-header {
        flex-wrap: wrap;
        gap: 8px;
    }

    .table-header h2 {
        font-size: 0.95em;
    }

    .target-group {
        min-width: 0;
        width: 100%;
    }

    .target-group input {
        min-height: 44px;
    }

    /* Taller touch targets for buttons */
    .btn {
        min-height: 44px;
    }

    .chart-container {
        height: 300px;
        padding: 10px;
    }

    .summary-section {
        grid-template-columns: 1fr;
    }

    /* Spoke preset row stacks on very narrow screens */
    .spoke-preset-row {
        flex-wrap: wrap;
    }

    .spoke-preset-row select {
        flex: 1;
        min-height: 44px;
    }
}
