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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    line-height: 1.6;
}

header {
    background: #1a1a2e;
    color: #fff;
    padding: 1.5rem 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

header .subtitle {
    color: #a0a0c0;
    font-size: 0.95rem;
}

.health-badge {
    margin-left: auto;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    background: #555;
    color: #fff;
}
.health-badge.ok { background: #27ae60; }
.health-badge.degraded { background: #e67e22; }
.health-badge.error { background: #c0392b; }

main {
    max-width: 860px;
    margin: 2rem auto;
    padding: 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.card {
    background: #fff;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.card h2 {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
    color: #1a1a2e;
}

.card p {
    color: #555;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.form-row label {
    min-width: 160px;
    font-weight: 500;
    font-size: 0.95rem;
}

input[type="number"],
input[type="text"] {
    padding: 0.5rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
    width: 140px;
}

input[type="text"].wide-input {
    width: 100%;
    max-width: 500px;
}

input[type="file"] {
    font-size: 0.95rem;
    padding: 0.25rem;
}

button {
    padding: 0.5rem 1.25rem;
    border: none;
    border-radius: 4px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

#btn-setup, #btn-advise {
    background: #2563eb;
    color: #fff;
}
#btn-setup:hover, #btn-advise:hover {
    background: #1d4ed8;
}
#btn-setup:disabled, #btn-advise:disabled {
    background: #93c5fd;
    cursor: wait;
}

/* Image input toggle */
.input-toggle {
    display: flex;
    gap: 0;
    margin-bottom: 0.75rem;
}

.tab {
    background: #e5e7eb;
    color: #555;
    border-radius: 4px 4px 0 0;
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
}
.tab.active {
    background: #2563eb;
    color: #fff;
}

.image-input {
    padding: 0.5rem 0;
}

/* Results */
.result-box {
    margin-top: 1rem;
    padding: 1rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

.result-box h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.param-grid {
    display: flex;
    gap: 2rem;
    margin-bottom: 0.75rem;
}

.param {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.param-label {
    font-size: 0.8rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.param-value {
    font-size: 2rem;
    font-weight: 700;
    color: #1a1a2e;
}

.detail-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    font-size: 0.85rem;
    color: #555;
}

.tolerance-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}
.tolerance-badge.good { background: #d1fae5; color: #065f46; }
.tolerance-badge.close { background: #fef3c7; color: #92400e; }
.tolerance-badge.far { background: #fee2e2; color: #991b1b; }

/* History table */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

thead th {
    background: #f1f5f9;
    padding: 0.5rem;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #e2e8f0;
}

tbody td {
    padding: 0.5rem;
    border-bottom: 1px solid #f1f5f9;
}

tbody tr:hover {
    background: #f8fafc;
}

/* History thumbnails */
.history-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    transition: transform 0.15s;
}
.history-thumb:hover {
    transform: scale(3);
    z-index: 10;
    position: relative;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.thumb-cell {
    width: 56px;
    text-align: center;
}

.muted {
    color: #999;
    font-size: 0.85rem;
    font-style: italic;
}

.hidden {
    display: none;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #fff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 0.5rem;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

footer {
    text-align: center;
    padding: 2rem 1rem;
    color: #999;
    font-size: 0.8rem;
}
