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

:root {
    --bg: #0f0f1a;
    --bg-card: #1a1a2e;
    --bg-input: #16213e;
    --border: #2a2a4a;
    --text: #e8e8f0;
    --text-muted: #8888aa;
    --primary: #4a90d9;
    --primary-hover: #5a9ee6;
    --danger: #d94a4a;
    --success: #4ad97a;
    --accent: #d9a04a;
    --radius: 12px;
    --radius-sm: 8px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { font-size: 16px; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

/* Nav */
.app-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(var(--safe-top) + 8px) 16px 8px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    text-decoration: none;
}
.nav-right { display: flex; align-items: center; gap: 12px; font-size: 0.85rem; }
.nav-user { color: var(--text-muted); }
.nav-link { color: var(--text-muted); text-decoration: none; }
.nav-link:hover { color: var(--text); }

/* Main */
.app-main { padding: 16px; max-width: 960px; margin: 0 auto; padding-bottom: calc(var(--safe-bottom) + 24px); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }
.form-group input, .form-group textarea, .form-group select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
    outline: none;
    border-color: var(--primary);
}
.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.form-actions .btn { flex: 1; }

.input-row { display: flex; gap: 8px; }
.input-row input { flex: 2; }
.input-row select { flex: 1; }

.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input { padding: 6px 10px; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-size: 0.9rem; }

.checkbox-label {
    display: flex; align-items: center; gap: 8px; padding: 8px 0; cursor: pointer; font-size: 0.9rem;
}
.checkbox-label input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--success); }

/* Alerts */
.alert { padding: 10px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 0.9rem; background: var(--bg-input); border: 1px solid var(--border); }
.alert-error { border-color: var(--danger); color: #ff8888; }

/* Cards */
.card { background: var(--bg-card); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; border: 1px solid var(--border); }
.card h2 { font-size: 1rem; margin-bottom: 12px; }

/* Badge */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 0.7rem; background: var(--primary); color: #fff; font-weight: 600; }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.login-card { width: 100%; max-width: 360px; }
.login-logo { text-align: center; margin-bottom: 32px; color: var(--primary); }
.login-logo h1 { font-size: 1.5rem; margin-top: 12px; color: var(--text); }

/* Home */
.home-actions { display: flex; gap: 16px; margin-bottom: 24px; }
.action-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 24px 16px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
}
.action-btn:active { transform: scale(0.97); }
.action-camera { border-color: var(--primary); }
.action-camera:hover { border-color: var(--primary-hover); background: rgba(74, 144, 217, 0.05); }
.action-camera svg { color: var(--primary); }
.action-search { border-color: var(--accent); }
.action-search:hover { border-color: #e6ad5a; background: rgba(217, 160, 74, 0.05); }
.action-search svg { color: var(--accent); }

.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-header h2 { font-size: 1.1rem; }

/* Project feed */
.project-feed { display: flex; flex-direction: column; gap: 12px; }
.project-card {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.15s;
}
.project-card:hover { border-color: var(--primary); }
.project-thumb {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-input);
    flex-shrink: 0;
}
.project-thumb img { width: 100%; height: 100%; object-fit: cover; }
.project-thumb-empty {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); font-size: 0.7rem;
}
.project-details { flex: 1; min-width: 0; }
.project-details .company { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.project-details .name { font-weight: 600; font-size: 1rem; margin: 2px 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-details .meta { font-size: 0.8rem; color: var(--text-muted); display: flex; gap: 12px; }

/* Swipe container */
.swipe-container {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
}
.swipe-actions {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    z-index: 0;
}
.swipe-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 75px;
    border: none;
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 600;
    font-family: inherit;
    color: #fff;
}
.swipe-archive, .swipe-unarchive { background: var(--accent); }
.swipe-delete { background: var(--danger); }
.swipe-card {
    position: relative;
    z-index: 1;
    will-change: transform;
    touch-action: pan-y;
}

/* Archive link */
.archive-link-wrap {
    text-align: center;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.archive-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
}
.archive-link:hover { color: var(--text); }
.archive-link svg { flex-shrink: 0; }

.loading, .empty-state { text-align: center; padding: 40px; color: var(--text-muted); }

/* Search */
.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.search-bar svg { color: var(--text-muted); flex-shrink: 0; }
.search-bar input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
}

/* Project page */
.project-header { margin-bottom: 20px; }
.back-link { color: var(--text-muted); text-decoration: none; font-size: 0.85rem; display: inline-block; margin-bottom: 8px; }
.back-link:hover { color: var(--text); }
.project-meta .company-name { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.project-meta h1 { font-size: 1.4rem; margin: 4px 0; }
.project-notes { color: var(--text-muted); font-size: 0.9rem; margin: 8px 0; }
.project-date { font-size: 0.8rem; color: var(--text-muted); }
.project-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.photo-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 24px; }
@media (min-width: 600px) { .photo-grid { grid-template-columns: repeat(2, 1fr); } }
.photo-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.photo-thumb { position: relative; aspect-ratio: 4/3; background: var(--bg-input); }
.photo-thumb img, .photo-thumb canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.dim-badge {
    position: absolute; top: 8px; right: 8px;
    background: rgba(0,0,0,0.7); color: #fff;
    padding: 3px 8px; border-radius: 10px; font-size: 0.75rem; font-weight: 600;
}
.photo-edit-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.6);
    border-radius: 50%;
    color: #fff;
    text-decoration: none;
    transition: background 0.15s;
}
.photo-edit-btn:hover { background: rgba(0,0,0,0.85); }

.photo-info { padding: 10px; }
.photo-notes-wrap { margin-bottom: 8px; }
.photo-notes {
    width: 100%;
    padding: 6px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
    min-height: 32px;
    max-height: 120px;
}
.photo-notes:focus { outline: none; border-color: var(--primary); }
.photo-notes::placeholder { color: var(--text-muted); }
.photo-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.download-section {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; text-align: center;
}
.download-section h3 { margin-bottom: 4px; }
.download-section p { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 16px; }
.download-options { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Editor */
.capture-page { position: relative; }

/* Camera view */
.camera-view {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 60;
    display: flex;
    flex-direction: column;
}
.camera-view video {
    flex: 1;
    width: 100%;
    object-fit: cover;
}
.thirds-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}
.thirds-line {
    position: absolute;
    background: rgba(255,255,255,0.45);
    box-shadow: 0 0 2px rgba(0,0,0,0.3);
}
.thirds-h { left: 0; right: 0; height: 1px; }
.thirds-v { top: 0; bottom: 0; width: 1px; }
.center-crosshair {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 28px; height: 28px;
}
.center-crosshair::before, .center-crosshair::after {
    content: '';
    position: absolute;
    background: rgba(255,255,255,0.8);
    box-shadow: 0 0 3px rgba(0,0,0,0.5);
}
.center-crosshair::before { top: 0; bottom: 0; left: 50%; width: 1.5px; transform: translateX(-50%); }
.center-crosshair::after { left: 0; right: 0; top: 50%; height: 1.5px; transform: translateY(-50%); }

.camera-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 20px 24px calc(var(--safe-bottom) + 20px);
    background: linear-gradient(transparent, rgba(0,0,0,0.6));
    z-index: 2;
}
.cam-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 12px;
}
.cam-shutter {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    border: 3px solid #fff;
    padding: 0;
    position: relative;
}
.shutter-ring {
    display: block;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #fff;
    margin: auto;
    transition: transform 0.1s;
}
.cam-shutter:active .shutter-ring { transform: scale(0.9); }
.cam-gallery, .cam-flip { opacity: 0.85; }
.cam-gallery:hover, .cam-flip:hover { opacity: 1; }

/* Landscape: move camera controls to right side */
@media (orientation: landscape) {
    .camera-controls {
        bottom: auto; left: auto;
        top: 0; right: 0;
        width: auto; height: 100%;
        flex-direction: column;
        padding: 24px 20px 24px calc(env(safe-area-inset-right, 0px) + 20px);
        background: linear-gradient(to right, transparent, rgba(0,0,0,0.6));
    }
}

.camera-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-muted);
    background: var(--bg);
}

/* Hide nav when camera or editor is fullscreen */
body.camera-active .app-nav { display: none; }
body.camera-active .app-main { padding: 0; }
body.camera-active { overflow: hidden; }

/* Fullscreen editor mode */
body.editor-fullscreen .app-nav { display: none; }
body.editor-fullscreen .app-main { padding: 0; max-width: none; }
body.editor-fullscreen { overflow: hidden; }
body.editor-fullscreen .capture-page { position: fixed; inset: 0; z-index: 50; }
body.editor-fullscreen .editor-container {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
}

.editor-container { position: relative; }

.editor-toolbar {
    display: flex;
    gap: 4px;
    padding: 6px 10px;
    background: rgba(15, 15, 26, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    padding-top: calc(var(--safe-top) + 6px);
}
.toolbar-spacer { flex: 1; }

.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
    flex-shrink: 0;
}
.tool-btn:hover, .tool-btn.active { background: rgba(255,255,255,0.1); color: var(--text); }
.tool-btn.active { color: var(--primary); }
.tool-btn-cancel { color: var(--danger) !important; }
.tool-btn-cancel:hover { background: rgba(217,74,74,0.15); }
.tool-btn-done { color: var(--success) !important; }
.tool-btn-done:hover { background: rgba(74,217,122,0.15); }

.canvas-wrap {
    position: relative;
    width: 100%;
    flex: 1;
    background: #000;
    overflow: hidden;
    touch-action: none;
    cursor: crosshair;
}
body:not(.editor-fullscreen) .canvas-wrap {
    aspect-ratio: 4/3;
    border-radius: var(--radius);
    background: var(--bg-input);
}
.canvas-wrap canvas { width: 100%; height: 100%; display: block; }
.canvas-wrap.panning { cursor: grab; }
.canvas-wrap.panning:active { cursor: grabbing; }

/* Save form */
.save-form { max-width: 500px; margin: 0 auto; }
.save-form h2 { margin-bottom: 16px; }
.photo-preview { margin-bottom: 16px; border-radius: var(--radius); overflow: hidden; background: var(--bg-input); cursor: pointer; position: relative; }
.photo-preview canvas { width: 100%; display: block; }
.photo-preview::after {
    content: 'Tap to edit';
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 6px;
    pointer-events: none;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
}
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 380px;
}
.modal h3 { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }
.modal-actions-3 { justify-content: flex-end; }
.modal-actions-3 .btn:first-child { margin-right: auto; }

/* Option row (thickness, endpoint selectors) */
.option-row {
    display: flex;
    gap: 6px;
}
.opt-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.opt-btn:hover { border-color: var(--text-muted); }
.opt-btn.active { border-color: var(--primary); color: var(--text); background: rgba(74,144,217,0.1); }
.opt-btn svg { width: 20px; height: 20px; }
.thick-line {
    display: block;
    width: 24px;
    background: currentColor;
    border-radius: 1px;
}

/* Danger zone (bottom of project page) */
.danger-zone {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    text-align: center;
}

/* Color swatches */
.color-row { display: flex; gap: 10px; padding: 4px 0; }
.color-swatch {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid var(--border);
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
    padding: 0;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary); }
.color-swatch[data-val="#000000"] { border-color: #555; }
.color-swatch[data-val="#000000"].active { border-color: var(--primary); }
.color-swatch[data-val="#ffffff"] { border-color: #666; }
.color-swatch[data-val="#ffffff"].active { border-color: var(--primary); }

/* Admin */
.admin-page h1 { font-size: 1.3rem; margin-bottom: 16px; }
.user-list { display: flex; flex-direction: column; gap: 10px; }
.user-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 8px;
}
.user-info small { display: block; color: var(--text-muted); font-size: 0.8rem; }
.user-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.toggle-label { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle-label input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }
.setting-hint { color: var(--text-muted); font-size: 0.8rem; margin-top: 6px; }

/* Desktop */
@media (min-width: 768px) {
    .home-actions { max-width: 500px; }
    .action-btn { padding: 32px 20px; }
    .canvas-wrap { aspect-ratio: 16/10; }
}

/* Utility */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
