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

:root {
    --bg: #f5f5f7;
    --text: #1d1d1f;
    --text-secondary: #6e6e73;
    --card-bg: #ffffff;
    --border: #d2d2d7;
    --border-light: #e8e8ed;
    --primary: #0071e3;
    --primary-hover: #0077ed;
    --danger: #ff3b30;
    --danger-hover: #ff453a;
    --success: #34c759;
    --warning: #ff9f0a;
    --gray: #8e8e93;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1), 0 1px 3px rgba(0,0,0,0.06);
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* === Header === */
#app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-left h1 {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled {
    background: var(--border);
    cursor: not-allowed;
}

.btn-secondary {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}
.btn-secondary:hover { background: rgba(0,113,227,0.06); }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { background: var(--danger-hover); }

.btn-icon {
    background: none;
    border: none;
    padding: 6px;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
}
.btn-icon:hover { background: var(--border-light); color: var(--text); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* === Project List === */
#project-list-view {
    padding: 24px;
    max-width: 960px;
    margin: 0 auto;
}

.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.project-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.15s;
    position: relative;
}

.project-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}

.project-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 6px;
}

.project-card .project-meta {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.project-card .card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.project-card .delete-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    font-size: 16px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s;
}
.project-card:hover .delete-btn { opacity: 1; }
.project-card .delete-btn:hover { color: var(--danger); background: rgba(255,59,48,0.08); }

.loading-text, .empty-text {
    color: var(--text-secondary);
    text-align: center;
    padding: 40px 20px;
    grid-column: 1 / -1;
}

/* === Badges === */
.badge {
    display: inline-block;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-confirmed, .badge-done { background: rgba(52,199,89,0.12); color: #248a3d; }
.badge-matched { background: rgba(255,159,10,0.12); color: #c77c00; }
.badge-unmatched, .badge-error { background: rgba(255,59,48,0.12); color: #d70015; }
.badge-pending, .badge-created { background: rgba(142,142,147,0.12); color: #636366; }
.badge-processing { background: rgba(0,113,227,0.12); color: #0071e3; }
.badge-reconstructed { background: rgba(52,199,89,0.12); color: #248a3d; }

/* === Project Detail === */
#project-detail-view {
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
}

.project-detail-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.project-detail-header h2 {
    font-size: 24px;
    font-weight: 700;
}

/* === Tabs === */
.tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--border-light);
    border-radius: var(--radius);
    margin-bottom: 24px;
    overflow-x: auto;
}

.tab {
    padding: 8px 18px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.tab:hover { color: var(--text); }
.tab.active {
    background: var(--card-bg);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* === Upload Section === */
.upload-section {
    margin-bottom: 8px;
}

.upload-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.section-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.divider {
    border: none;
    border-top: 1px solid var(--border-light);
    margin: 20px 0;
}

/* === Dropzone === */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    background: var(--card-bg);
}

.dropzone:hover, .dropzone.drag-over {
    border-color: var(--primary);
    background: rgba(0,113,227,0.04);
    color: var(--primary);
}

.dropzone .dropzone-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.dropzone .dropzone-text {
    font-size: 14px;
    font-weight: 500;
}

.dropzone .dropzone-hint {
    font-size: 12px;
    margin-top: 4px;
}

/* === Progress Bar === */
.progress-bar-container {
    width: 100%;
    height: 6px;
    background: var(--border-light);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-bar {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--primary), #40a0ff);
    background-size: 200% 100%;
    animation: progressShine 2s linear infinite;
    transition: width 0.3s ease;
    width: 0%;
}

@keyframes progressShine {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.upload-progress {
    margin-top: 12px;
}

.upload-progress .progress-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
}

.upload-file-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    margin-top: 10px;
    font-size: 13px;
}

.upload-file-info .file-name { font-weight: 500; flex: 1; }
.upload-file-info .file-size { color: var(--text-secondary); }
.upload-file-info .upload-check { color: var(--success); font-weight: 700; }

/* === Status Card === */
.status-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    margin-top: 12px;
}

.status-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.status-icon.spinning {
    border: 3px solid var(--border-light);
    border-top-color: var(--primary);
    animation: spin 1s linear infinite;
}

.status-icon.done {
    background: var(--success);
    color: #fff;
}

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

.status-info { flex: 1; min-width: 0; }
.status-text { font-size: 14px; font-weight: 500; display: block; margin-bottom: 2px; }

/* === Photo Grid === */
.photos-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.photo-count {
    font-size: 14px;
    color: var(--text-secondary);
}

.photos-layout {
    display: flex;
    gap: 20px;
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    flex: 1;
}

.photo-thumb {
    position: relative;
    aspect-ratio: 4/3;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.15s;
}

.photo-thumb:hover { border-color: var(--primary); }
.photo-thumb.selected { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(0,113,227,0.3); }

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-thumb .thumb-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 700;
    border-radius: 10px;
    color: #fff;
}

.thumb-badge.conf-high { background: var(--success); }
.thumb-badge.conf-med { background: var(--warning); }
.thumb-badge.conf-low { background: var(--danger); }
.thumb-badge.conf-none { background: var(--gray); }

.photo-thumb .thumb-number {
    position: absolute;
    bottom: 6px;
    left: 6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* === Photo Detail Panel === */
.photo-detail {
    width: 320px;
    flex-shrink: 0;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    position: sticky;
    top: 80px;
    align-self: flex-start;
}

.detail-image {
    width: 100%;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
}

.detail-fields {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 12px;
    font-size: 13px;
    margin-bottom: 16px;
}

.detail-fields label {
    font-weight: 600;
    color: var(--text-secondary);
}

.detail-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.input {
    padding: 6px 10px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    width: 100%;
    transition: border-color 0.15s;
}
.input:focus { outline: none; border-color: var(--primary); }

/* === 3D Viewer === */
.viewer-container {
    width: 100%;
    height: 600px;
    border-radius: var(--radius);
    overflow: hidden;
    background: #1a1a2e;
    position: relative;
}

.viewer-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.info-panel {
    position: absolute;
    bottom: 16px;
    left: 16px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 340px;
    z-index: 10;
}

.info-thumb {
    width: 80px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
}

.info-details { flex: 1; }
.info-filename { font-size: 13px; font-weight: 600; display: block; }
.info-confidence { font-size: 12px; color: var(--text-secondary); }
.info-close { font-size: 18px; }

/* === Floor Plan === */
.floorplan-container {
    width: 100%;
    height: 600px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
}

.floorplan-container canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
}

.floorplan-container canvas:active { cursor: grabbing; }

.floorplan-legend {
    margin-top: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 13px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--card-bg);
    border-radius: 6px;
    border: 1px solid var(--border-light);
}

.legend-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* === Export Cards === */
.export-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.export-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    text-align: center;
}

.export-icon { margin-bottom: 16px; }
.export-card h3 { font-size: 17px; margin-bottom: 8px; }
.export-card p { font-size: 13px; color: var(--text-secondary); margin-bottom: 18px; }

/* === Responsive === */
@media (max-width: 768px) {
    #app-header { padding: 12px 16px; }
    #project-list-view, #project-detail-view { padding: 16px; }
    .project-grid { grid-template-columns: 1fr; }
    .photo-grid { grid-template-columns: repeat(2, 1fr); }
    .photos-layout { flex-direction: column; }
    .photo-detail { width: 100%; position: static; }
    .tabs { gap: 2px; }
    .tab { padding: 7px 12px; font-size: 13px; }
    .viewer-container { height: 400px; }
    .floorplan-container { height: 400px; }
}

@media (max-width: 480px) {
    .photo-grid { grid-template-columns: repeat(2, 1fr); }
    .export-cards { grid-template-columns: 1fr; }
}
