/* css/style.css — Mobile-first PWA-like design */

:root {
    --primary: #4F46E5;
    --primary-dark: #3730A3;
    --primary-light: #E0E7FF;
    --accent: #F59E0B;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --bg: #F3F4F6;
    --surface: #FFFFFF;
    --text: #111827;
    --text-secondary: #6B7280;
    --border: #E5E7EB;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --nav-height: 64px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans TC', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
    overflow-x: hidden;
    min-height: 100dvh;
}

/* ═══ Status Bar ═══ */
.status-bar {
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    font-size: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}
.status-bar .app-title { font-weight: 700; font-size: 0.85rem; }
.status-bar button {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

/* ═══ Bottom Navigation ═══ */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-height) + var(--safe-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    padding: 6px 0 var(--safe-bottom);
    z-index: 200;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 0.65rem;
    cursor: pointer;
    transition: color 0.2s;
    position: relative;
    min-width: 60px;
}
.nav-item .nav-icon { font-size: 1.4rem; line-height: 1; }
.nav-item.active { color: var(--primary); }
.nav-item.active::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: var(--primary);
    border-radius: 2px;
}

/* ═══ Pages ═══ */
.page {
    display: none;
    padding: 12px;
    animation: fadeIn 0.25s ease;
}
.page.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ═══ Cards ═══ */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.card-header h3 {
    font-size: 1rem;
    font-weight: 700;
}
.card-header .badge {
    background: var(--primary-light);
    color: var(--primary);
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* ═══ Form Elements ═══ */
.form-group { margin-bottom: 12px; }
.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-select, .form-input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--surface);
    color: var(--text);
    appearance: none;
    transition: border-color 0.2s;
}
.form-select:focus, .form-input:focus {
    outline: none;
    border-color: var(--primary);
}
.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236B7280' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* ═══ Buttons ═══ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    width: 100%;
    text-decoration: none;
}
.btn:active { transform: scale(0.97); }

.btn-primary   { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success   { background: var(--success); color: white; }
.btn-danger    { background: var(--danger); color: white; }
.btn-warning   { background: var(--warning); color: white; }
.btn-ghost     { background: transparent; color: var(--primary); border: 2px solid var(--primary); }
.btn-sm        { padding: 8px 14px; font-size: 0.85rem; }
.btn-icon      { width: auto; padding: 10px; }

/* ═══ Chip / Tag Select ═══ */
.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    border-radius: 20px;
    border: 2px solid var(--border);
    background: var(--surface);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}
.chip input { display: none; }
.chip.selected,
.chip:has(input:checked) {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}

/* ═══ Camera / Image Area ═══ */
.capture-area {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    background: #1F2937;
    aspect-ratio: 4/3;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}
.capture-area canvas,
.capture-area img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.capture-area .placeholder {
    color: #9CA3AF;
    text-align: center;
    padding: 20px;
}
.capture-area .placeholder .icon { font-size: 3rem; }

/* ═══ Score Display ═══ */
.score-ring {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    margin: 16px auto;
    position: relative;
}
.score-ring .score-value {
    font-size: 2.5rem;
    font-weight: 800;
    line-height: 1;
}
.score-ring .score-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.score-ring svg {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    transform: rotate(-90deg);
}
.score-ring circle {
    fill: none;
    stroke-width: 8;
    stroke-linecap: round;
}
.score-ring .bg { stroke: var(--border); }
.score-ring .fg { stroke: var(--primary); transition: stroke-dashoffset 0.8s ease; }

/* ═══ Feedback Cards ═══ */
.feedback-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    border-left: 4px solid var(--border);
}
.feedback-item.excellent { border-left-color: var(--success); background: #ECFDF5; }
.feedback-item.good      { border-left-color: #3B82F6; background: #EFF6FF; }
.feedback-item.fair       { border-left-color: var(--warning); background: #FFFBEB; }
.feedback-item.poor       { border-left-color: var(--danger); background: #FEF2F2; }

.feedback-item .emoji { font-size: 1.5rem; flex-shrink: 0; }
.feedback-item .info { flex: 1; }
.feedback-item .point-name { font-weight: 700; font-size: 0.85rem; }
.feedback-item .angle-val { font-size: 0.8rem; color: var(--text-secondary); }
.feedback-item .advice { font-size: 0.8rem; margin-top: 4px; }

/* ═══ Reference Image Strip ═══ */
.ref-strip {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
}
.ref-strip img {
    /*width: 80px;
    height: 80px;*/
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
    scroll-snap-align: start;
    flex-shrink: 0;
    cursor: pointer;
}
.ref-strip img.active { border-color: var(--primary); }

/* ═══ Chat ═══ */
.chat-window {
    max-height: 50vh;
    overflow-y: auto;
    padding: 8px;
    background: #F9FAFB;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}
.chat-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    margin-bottom: 8px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
}
.chat-bubble.user {
    background: var(--primary);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}
.chat-bubble.assistant {
    background: white;
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.chat-input-row {
    display: flex;
    gap: 8px;
}
.chat-input-row input { flex: 1; }
.chat-input-row .btn { width: auto; }

/* ═══ Progress Table ═══ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.data-table th, .data-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
.data-table th {
    background: var(--bg);
    font-weight: 700;
    position: sticky;
    top: 0;
}
.data-table tbody tr:active { background: var(--primary-light); }

/* ═══ Overlay / Modal ═══ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 500;
    align-items: flex-end;
    justify-content: center;
}
.modal-overlay.show { display: flex; }

.modal-sheet {
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 20px;
    animation: slideUp 0.3s ease;
}
@keyframes slideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}
.modal-handle {
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 16px;
}

/* ═══ Skeleton Loader ═══ */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}
@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ═══ Loading Spinner ═══ */
.spinner {
    width: 24px; height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ Toast Notification ═══ */
.toast {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: #1F2937;
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.85rem;
    z-index: 999;
    opacity: 0;
    transition: all 0.3s;
    pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ═══ Responsive ═══ */
@media (min-width: 768px) {
    .page { padding: 16px 24px; max-width: 800px; margin: 0 auto; }
    .bottom-nav { max-width: 500px; left: 50%; transform: translateX(-50%); border-radius: var(--radius) var(--radius) 0 0; }
    .capture-area { aspect-ratio: 16/10; max-height: 400px; }
}

@media (min-width: 1024px) {
    .page { max-width: 960px; }
    .desktop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
}

/* ═══ Utility ═══ */
.text-center { text-align: center; }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--text-secondary); }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* ═══════════════════════════════════════════════
   AUTH UI
   ═══════════════════════════════════════════════ */

.user-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}
.user-name {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.9);
    font-weight: 500;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.btn-logout {
    background: rgba(255,255,255,0.15);
    color: white;
    border: none;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
}
.btn-logout:hover {
    background: rgba(255,255,255,0.25);
}
.btn-status-login {
    background: rgba(255,255,255,0.15);
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-status-login:hover {
    background: rgba(255,255,255,0.25);
}

/* ═══════════════════════════════════════════════
   STATS TABLE
   ═══════════════════════════════════════════════ */

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}
.stats-table th,
.stats-table td {
    padding: 7px 8px;
    text-align: center;
    border-bottom: 1px solid var(--border, #e5e7eb);
}
.stats-table th {
    background: var(--bg, #f9fafb);
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
    font-size: 0.7rem;
    text-transform: uppercase;
    position: sticky;
    top: 0;
    z-index: 1;
}
.stats-table td:first-child {
    text-align: left;
    font-weight: 500;
    font-size: 0.72rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.stats-table tbody tr:hover {
    background: var(--bg, #f9fafb);
}

/* ═══════════════════════════════════════════════
   ROOM CARDS
   ═══════════════════════════════════════════════ */

.room-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--bg, #f9fafb);
    margin-bottom: 6px;
    border: 1px solid var(--border, #e5e7eb);
    transition: box-shadow 0.2s;
}
.room-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.room-code {
    font-weight: 700;
    color: var(--primary, #4F46E5);
    font-size: 1.1rem;
    letter-spacing: 0.5px;
}
.room-meta {
    font-size: 0.75rem;
    color: var(--text-secondary, #6b7280);
    line-height: 1.4;
}

/* ═══════════════════════════════════════════════
   STATS SKELETON CANVAS
   ═══════════════════════════════════════════════ */

#stats-canvas {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 12px;
}

#stats-skeleton-container .capture-area {
    background: #111;
    border-radius: 12px;
    overflow: hidden;
}

/* ═══════════════════════════════════════════════
   UTILITY: auth-only visibility
   ═══════════════════════════════════════════════ */

.auth-only.hidden {
    display: none !important;
}