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

:root {
    --pass:       #059669;
    --pass-bg:    #d1fae5;
    --pass-light: #ecfdf5;
    --attention:   #d97706;
    --attention-bg:#fef3c7;
    --fail:       #dc2626;
    --fail-bg:    #fee2e2;
    --fail-light: #fef2f2;
    --bg:         #f1f5f9;
    --card:       #ffffff;
    --text:       #0f172a;
    --muted:      #64748b;
    --light:      #94a3b8;
    --border:     #e2e8f0;
    --primary:    #4f46e5;
    --primary-dark:#4338ca;
    --primary-light:#eef2ff;
    --accent:     #06b6d4;
    --radius:     14px;
    --radius-sm:  10px;
    --shadow:     0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:  0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg:  0 10px 30px rgba(0,0,0,0.12);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

/* ── Header ───────────────────────────────────────────────── */
header {
    background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
    color: white;
    padding: 14px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 12px rgba(79, 70, 229, 0.3);
}

.logo {
    font-weight: 800;
    font-size: 1.15rem;
    color: white;
    text-decoration: none;
    letter-spacing: -0.02em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
}

.header-user {
    opacity: 0.85;
    font-weight: 500;
}

.header-logout {
    color: white;
    opacity: 0.7;
    text-decoration: none;
    font-size: 0.8rem;
    padding: 4px 10px;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    transition: all 0.15s;
}

.header-logout:hover { opacity: 1; background: rgba(255,255,255,0.1); }

main {
    padding: 20px 16px;
    max-width: 640px;
    margin: 0 auto;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
    color: white;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary { background: white; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-block { display: flex; width: 100%; }
.btn-large { padding: 16px 24px; font-size: 1.05rem; border-radius: var(--radius); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ── Dashboard ────────────────────────────────────────────── */
.dashboard h1 { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.02em; }
.dashboard h2 { font-size: 1.1rem; font-weight: 700; margin-top: 32px; margin-bottom: 12px; }
.dashboard .subtitle { color: var(--muted); font-size: 0.85rem; margin-bottom: 16px; }

.room-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.room-card {
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 10px;
    text-align: center;
    text-decoration: none;
    color: var(--text);
    transition: all 0.15s ease;
    cursor: pointer;
    box-shadow: var(--shadow);
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.room-card:active { transform: scale(0.96); }

.room-number { display: block; font-size: 1.4rem; font-weight: 800; letter-spacing: -0.02em; }
.room-type   { display: block; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; margin-top: 2px; }
.room-status { display: block; font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; margin-top: 6px; padding: 2px 8px; border-radius: 20px; display: inline-block; }

.status-dirty    { border-color: var(--fail); background: var(--fail-light); }
.status-dirty .room-status { color: white; background: var(--fail); }
.status-cleaning { border-color: var(--attention); background: #fffbeb; }
.status-cleaning .room-status { color: white; background: var(--attention); }
.status-inspecting, .status-pending_inspection { border-color: var(--accent); background: #ecfeff; }
.status-inspecting .room-status, .status-pending_inspection .room-status { color: white; background: var(--accent); }
.status-clean    { border-color: var(--pass); background: var(--pass-light); }
.status-clean .room-status { color: white; background: var(--pass); }

/* ── Inspection list ──────────────────────────────────────── */
.inspection-list { display: flex; flex-direction: column; gap: 8px; }

.inspection-row {
    display: flex;
    align-items: center;
    background: var(--card);
    border-radius: var(--radius);
    border-left: 4px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.inspection-row.result-pass { border-left-color: var(--pass); }
.inspection-row.result-needs_attention { border-left-color: var(--attention); }
.inspection-row.result-fail { border-left-color: var(--fail); }

.insp-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    text-decoration: none;
    color: var(--text);
    flex: 1;
    min-width: 0;
}

.insp-room    { font-weight: 700; min-width: 65px; font-size: 0.9rem; }
.insp-cleaner { flex: 1; color: var(--muted); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.insp-result  { font-weight: 700; font-size: 0.75rem; letter-spacing: 0.03em; }
.insp-score   { font-weight: 700; min-width: 38px; text-align: right; font-size: 0.9rem; }
.insp-time    { color: var(--light); font-size: 0.7rem; min-width: 70px; text-align: right; }

.result-pass .insp-result { color: var(--pass); }
.result-needs_attention .insp-result { color: var(--attention); }
.result-fail .insp-result { color: var(--fail); }

.btn-delete-insp {
    background: none;
    border: none;
    color: var(--light);
    font-size: 1.3rem;
    padding: 14px 14px;
    cursor: pointer;
    line-height: 1;
    transition: color 0.15s;
}
.btn-delete-insp:hover { color: var(--fail); }

.empty-state { color: var(--muted); font-size: 0.9rem; padding: 20px 0; }

/* ── Modal ────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: flex-end; justify-content: center; }
.modal.hidden { display: none !important; }

.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); }

.modal-card {
    position: relative;
    background: var(--card);
    border-radius: 20px 20px 0 0;
    padding: 24px 20px 32px;
    width: 100%;
    max-width: 640px;
    box-shadow: var(--shadow-lg);
}

.modal-card h3 { font-size: 1.2rem; font-weight: 700; }
.modal-card .subtitle { color: var(--muted); font-size: 0.85rem; margin-bottom: 16px; }

.status-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}

.btn-status {
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-status.status-dirty { border-color: var(--fail); color: var(--fail); }
.btn-status.status-dirty:hover { background: var(--fail); color: white; }
.btn-status.status-cleaning { border-color: var(--attention); color: var(--attention); }
.btn-status.status-cleaning:hover { background: var(--attention); color: white; }
.btn-status.status-pending_inspection { border-color: var(--accent); color: var(--accent); }
.btn-status.status-pending_inspection:hover { background: var(--accent); color: white; }
.btn-status.status-clean { border-color: var(--pass); color: var(--pass); }
.btn-status.status-clean:hover { background: var(--pass); color: white; }

/* ── Inspect Flow ─────────────────────────────────────────── */
.step { padding: 8px 0; }
.hidden { display: none !important; }

.inspect-hero {
    text-align: center;
    padding: 40px 20px 24px;
    background: linear-gradient(135deg, var(--primary-light) 0%, #ede9fe 100%);
    border-radius: var(--radius);
    margin-bottom: 20px;
}

.hero-room { display: block; font-size: 3rem; font-weight: 900; color: var(--primary); letter-spacing: -0.03em; }
.hero-type { display: block; font-size: 0.85rem; color: var(--muted); font-weight: 500; margin-top: 4px; }

.form-group { margin: 16px 0; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9rem; }
.form-group input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.15s;
    background: var(--card);
}
.form-group input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1); }

.subtitle { color: var(--muted); margin-bottom: 8px; font-size: 0.9rem; }
.hint     { color: var(--muted); font-size: 0.85rem; margin-top: 8px; }
.centre   { text-align: center; }

/* Capture area */
.capture-header { margin-bottom: 16px; }
.capture-header h2 { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.02em; }

.progress-bar {
    background: var(--border);
    border-radius: 20px;
    height: 8px;
    margin-top: 14px;
    overflow: hidden;
}

.progress-fill {
    background: linear-gradient(90deg, var(--primary) 0%, #7c3aed 100%);
    height: 100%;
    border-radius: 20px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }

.photo-preview {
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 16px;
    border: 2px solid var(--border);
    box-shadow: var(--shadow);
}

.photo-preview img {
    width: 100%;
    height: auto;
    display: block;
}

.capture-actions { display: flex; flex-direction: column; gap: 10px; }

.btn-capture { position: relative; }
.hidden-input {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    opacity: 0;
    cursor: pointer;
}

.upload-status {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    padding: 14px;
    color: var(--muted);
    font-size: 0.9rem;
}

/* Review grid */
.review-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 16px 0;
}

.review-item {
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 2px solid var(--border);
    position: relative;
    box-shadow: var(--shadow);
}

.review-item img {
    width: 100%;
    height: 110px;
    object-fit: cover;
    display: block;
}

.review-item .review-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    color: white;
    font-size: 0.7rem;
    padding: 16px 8px 6px;
    font-weight: 600;
}

.review-item.skipped {
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 110px;
}

.review-item.skipped .review-label {
    position: static;
    background: none;
    color: var(--light);
}

/* Assessing animation */
.assessing-animation {
    text-align: center;
    padding: 60px 20px;
}

.assessing-animation h2 { margin-top: 20px; font-weight: 700; }

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner.large { width: 52px; height: 52px; border-width: 4px; margin: 0 auto; }

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

/* ── Results Page ─────────────────────────────────────────── */
.result-banner {
    text-align: center;
    padding: 36px 20px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.result-banner.result-pass { background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%); color: #065f46; }
.result-banner.result-needs_attention { background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%); color: #92400e; }
.result-banner.result-fail { background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%); color: #991b1b; }

.result-icon { font-size: 3.5rem; line-height: 1; }
.result-banner h1 { font-size: 1.6rem; font-weight: 800; margin-top: 8px; letter-spacing: -0.02em; }
.result-room { opacity: 0.6; font-size: 0.9rem; margin-top: 4px; font-weight: 500; }
.result-score {
    font-size: 3rem;
    font-weight: 900;
    margin-top: 8px;
    letter-spacing: -0.03em;
}

.summary-card {
    background: var(--card);
    padding: 18px 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    margin-bottom: 16px;
    font-size: 0.95rem;
    line-height: 1.7;
    box-shadow: var(--shadow);
}

/* Checkpoint cards */
.checkpoint-cards { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }

.cp-card {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.cp-card.cp-pass    { border-left: 5px solid var(--pass); }
.cp-card.cp-needs_attention { border-left: 5px solid var(--attention); }
.cp-card.cp-fail    { border-left: 5px solid var(--fail); }
.cp-card.cp-pending { border-left: 5px solid var(--border); }

.cp-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    font-weight: 700;
    font-size: 0.95rem;
}

.cp-score-badge {
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
}

.cp-pass .cp-score-badge { background: var(--pass-bg); color: var(--pass); }
.cp-needs_attention .cp-score-badge { background: var(--attention-bg); color: var(--attention); }
.cp-fail .cp-score-badge { background: var(--fail-bg); color: var(--fail); }
.cp-pending .cp-score-badge { background: var(--bg); color: var(--muted); }

.cp-photo img {
    width: 100%;
    height: auto;
    display: block;
}

.cp-notes {
    padding: 12px 16px;
    font-size: 0.9rem;
    color: var(--muted);
    line-height: 1.6;
}

.cp-issues { padding: 0 16px 14px; }

.issue {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-top: 8px;
    font-size: 0.85rem;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: baseline;
}

.issue-minor    { background: #fefce8; }
.issue-moderate { background: var(--attention-bg); }
.issue-critical { background: var(--fail-bg); }

.issue-severity {
    font-weight: 700;
    font-size: 0.65rem;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.issue-minor .issue-severity    { background: var(--attention); color: white; }
.issue-moderate .issue-severity { background: #ea580c; color: white; }
.issue-critical .issue-severity { background: var(--fail); color: white; }

.issue-desc { flex: 1; }
.issue-location { font-size: 0.8rem; color: var(--muted); width: 100%; font-style: italic; }

/* Meta */
.meta-info {
    padding: 16px 0;
    font-size: 0.85rem;
    color: var(--muted);
    border-top: 1px solid var(--border);
}

.meta-info p { margin-bottom: 4px; }
.meta-tokens { font-size: 0.75rem; color: var(--light); }

.results-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
    padding-bottom: 40px;
}

/* ── Auth Pages ───────────────────────────────────────────── */
.auth-page {
    display: flex;
    justify-content: center;
    padding-top: 48px;
}

.auth-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px 28px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: var(--shadow-md);
}

.auth-card h1 { font-size: 1.6rem; font-weight: 800; margin-bottom: 4px; letter-spacing: -0.02em; }
.auth-card .subtitle { color: var(--muted); margin-bottom: 28px; }

.auth-card .form-group { text-align: left; }

.auth-error {
    background: var(--fail-bg);
    color: var(--fail);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 16px;
}

.auth-link {
    display: inline-block;
    margin-top: 16px;
    font-size: 0.85rem;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.auth-link:hover { text-decoration: underline; }

/* QR code */
.qr-container {
    display: flex;
    justify-content: center;
    margin: 24px 0;
}

.qr-code {
    width: 200px;
    height: 200px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.manual-key {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 24px;
}

.manual-key code {
    display: inline-block;
    margin-top: 6px;
    background: var(--bg);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    letter-spacing: 1.5px;
    word-break: break-all;
    font-weight: 600;
}
