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

:root {
    --bg: #f8f9fa;
    --surface: #ffffff;
    --text: #1a1a2e;
    --text-secondary: #6c757d;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --success: #16a34a;
    --error: #dc2626;
    --warning: #f59e0b;
    --border: #e5e7eb;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html { font-size: 16px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

/* === Registration Wizard Layout === */
.wizard-container {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 0 20px;
}

.wizard-header {
    text-align: center;
    padding: 32px 0 16px;
}

.wizard-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.wizard-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 4px;
}

/* Progress bar */
.progress-bar {
    display: flex;
    gap: 6px;
    padding: 12px 0 24px;
}

.progress-step {
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    transition: background 0.3s ease;
}

.progress-step.active {
    background: var(--accent);
}

.progress-step.completed {
    background: var(--success);
}

/* Steps */
.step {
    display: none;
    flex: 1;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
}

.step.active {
    display: flex;
}

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

.step-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.step-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

/* === Form Elements === */
.input-group {
    margin-bottom: 16px;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text);
}

.input-group input[type="text"],
.input-group input[type="number"],
.input-group input[type="tel"] {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: var(--font);
    transition: border-color 0.2s;
    background: var(--surface);
    appearance: none;
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.input-group input.error {
    border-color: var(--error);
}

.error-msg {
    color: var(--error);
    font-size: 0.8rem;
    margin-top: 6px;
    display: none;
}

.error-msg.visible {
    display: block;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 16px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s;
    min-height: 52px;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled {
    background: var(--border);
    color: var(--text-secondary);
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 2px solid var(--border);
}

.btn-secondary:hover { background: var(--bg); }

.btn-success {
    background: var(--success);
    color: white;
}

.btn-danger {
    background: var(--error);
    color: white;
}

/* Role selector */
.role-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.role-option {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px 20px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
    font-weight: 500;
}

.role-option:hover {
    border-color: var(--accent);
    background: #f0f5ff;
}

.role-option .role-icon {
    font-size: 1.5rem;
}

/* Camera */
.camera-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.camera-preview {
    width: 100%;
    aspect-ratio: 1 / 1;
    max-height: 70vh;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
}

.camera-preview video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-preview canvas { display: none; }

.camera-instructions {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 8px;
}

.camera-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.upload-alt {
    text-align: center;
    margin-top: 8px;
}

.upload-alt label {
    color: var(--accent);
    font-weight: 500;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: underline;
}

.upload-alt input { display: none; }

/* Summary */
.summary-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.summary-row:last-child { border-bottom: none; }

.summary-row .label { color: var(--text-secondary); }
.summary-row .value { font-weight: 500; text-align: right; }

.summary-photo {
    text-align: center;
    padding: 16px 0;
}

.summary-photo img {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--border);
}

/* Result */
.result-container {
    text-align: center;
    padding: 40px 0;
}

.result-icon {
    font-size: 4rem;
    margin-bottom: 16px;
}

.result-title {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.result-message {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 32px;
    line-height: 1.6;
}

.error-details {
    text-align: left;
    margin: 16px 0;
}

.error-details summary {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.error-details pre {
    background: var(--bg);
    padding: 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    overflow-x: auto;
    margin-top: 8px;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.loading-card {
    background: var(--surface);
    padding: 32px;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.loading-card .spinner {
    border-color: var(--border);
    border-top-color: var(--accent);
    width: 40px;
    height: 40px;
}

.loading-card p {
    margin-top: 16px;
    font-weight: 500;
}

/* Links */
.text-link {
    display: block;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 12px;
    cursor: pointer;
    text-decoration: underline;
}

.text-link:hover { color: var(--text); }

/* Bottom spacer for buttons */
.step-actions {
    padding: 16px 0 32px;
    margin-top: auto;
}

/* Confirmation apt highlight */
.apt-highlight {
    display: inline-block;
    background: #f0f5ff;
    color: var(--accent);
    font-weight: 700;
    font-size: 1.5rem;
    padding: 12px 24px;
    border-radius: var(--radius);
    border: 2px solid var(--accent);
    margin: 16px 0;
}

/* === ADMIN STYLES === */
.admin-layout {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}

.admin-header h1 {
    font-size: 1.3rem;
    font-weight: 700;
}

.admin-nav {
    display: flex;
    gap: 12px;
    align-items: center;
}

.admin-nav a {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding: 8px 12px;
    border-radius: 8px;
    transition: all 0.2s;
}

.admin-nav a:hover, .admin-nav a.active {
    background: var(--bg);
    color: var(--text);
}

/* Stats */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.stat-card .number {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-card .label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Apartment grid */
.apt-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.apt-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: all 0.2s;
    cursor: pointer;
    text-decoration: none;
    color: var(--text);
    display: block;
}

.apt-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--accent);
}

.apt-card .apt-number {
    font-size: 1.3rem;
    font-weight: 700;
}

.apt-card .apt-code {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
    font-family: monospace;
}

.apt-card .apt-count {
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: #dcfce7; color: var(--success); }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-error { background: #fee2e2; color: var(--error); }
.badge-info { background: #dbeafe; color: var(--accent); }

/* Admin table */
.admin-table-wrap {
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.admin-table th {
    text-align: left;
    padding: 12px;
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    white-space: nowrap;
}

.admin-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.admin-table tr:hover td { background: var(--bg); }

.resident-photo-sm {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

/* Admin actions */
.action-btn {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
    white-space: nowrap;
}

.action-btn:hover { background: var(--bg); }
.action-btn.danger { color: var(--error); border-color: var(--error); }
.action-btn.danger:hover { background: #fee2e2; }

/* Code copy */
.code-copy {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    padding: 6px 12px;
    border-radius: 6px;
    font-family: monospace;
    font-size: 0.9rem;
}

.code-copy button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--accent);
}

/* Login */
.login-container {
    max-width: 380px;
    margin: 80px auto;
    padding: 0 20px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
}

.login-card h2 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 1.2rem;
}

.login-card .input-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: var(--font);
}

.login-card .input-group input:focus {
    outline: none;
    border-color: var(--accent);
}

.login-error {
    background: #fee2e2;
    color: var(--error);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 16px;
    text-align: center;
}

/* Search/filter bar */
.filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-bar input,
.filter-bar select {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: var(--font);
    background: var(--surface);
}

.filter-bar input { flex: 1; min-width: 200px; }

/* Section header with action */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

/* Responsive */
@media (max-width: 600px) {
    .admin-layout { padding: 12px; }
    .admin-header { flex-direction: column; gap: 12px; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .filter-bar { flex-direction: column; }
    .filter-bar input { min-width: unset; }
}
