:root {
    --primary-color: #2563EB;
    --primary-hover: #1d4ed8;
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --error-color: #ef4444;
    --success-color: #10b981;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --radius: 12px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
    padding-bottom: calc(80px + var(--safe-bottom));
}

.hidden { display: none !important; }

/* Header */
.app-header {
    background: linear-gradient(135deg, #2563EB, #1e40af);
    color: white;
    padding: calc(16px + var(--safe-top)) 16px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}
.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 768px;
    margin: 0 auto;
}
.app-header h1 { font-size: 1.25rem; font-weight: 600; margin: 0; flex-grow: 1; text-align: center; }
.icon-btn {
    background: none; border: none; color: inherit; cursor: pointer; padding: 8px;
    display: flex; align-items: center; justify-content: center; border-radius: 50%;
}
.google-auth { min-width: 40px; }
.avatar-img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 2px solid white; }
.offline-indicator {
    background: #f59e0b; color: #fff; text-align: center; font-size: 0.875rem;
    padding: 4px; margin-top: 8px; border-radius: 4px;
}

/* Side Menu */
.side-menu {
    position: fixed; top: 0; left: -280px; width: 280px; height: 100%;
    background: var(--card-bg); z-index: 200; box-shadow: var(--shadow-md);
    transition: transform 0.3s ease; padding-top: var(--safe-top); display: flex; flex-direction: column;
}
.side-menu.open { transform: translateX(280px); }
.menu-header { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--border-color); }
.menu-list { list-style: none; padding: 16px 0; }
.menu-list li button {
    width: 100%; text-align: left; background: none; border: none; padding: 16px 24px;
    font-size: 1rem; color: var(--text-main); cursor: pointer; transition: background 0.2s;
}
.menu-list li button:hover { background: var(--bg-color); }
.menu-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 150; }

/* Main */
.app-main { padding: 16px; max-width: 768px; margin: 0 auto; }
.card { background: var(--card-bg); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.card h2 { font-size: 1.125rem; font-weight: 600; margin-bottom: 16px; color: var(--text-main); border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.flex-row { display: flex; gap: 12px; }
.flex-1 { flex: 1; }
label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 6px; color: var(--text-muted); }
.required { color: var(--error-color); }
input[type="text"], input[type="tel"], select, textarea {
    width: 100%; padding: 12px; border: 1px solid var(--border-color); border-radius: 8px;
    font-size: 1rem; font-family: inherit; transition: border-color 0.2s; background: var(--card-bg);
}
input[readonly] { background: var(--bg-color); color: var(--text-muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-color); }
.error-msg { display: none; color: var(--error-color); font-size: 0.75rem; margin-top: 4px; }
.has-error input, .has-error select { border-color: var(--error-color); }
.has-error .error-msg { display: block; }

/* Camera Area */
.camera-capture-area {
    border: 2px dashed var(--border-color); border-radius: var(--radius); padding: 32px 16px;
    text-align: center; cursor: pointer; transition: all 0.2s; background: #fafafa;
}
.camera-capture-area:active { background: #f3f4f6; }
.camera-placeholder { color: var(--text-muted); display: flex; flex-direction: column; align-items: center; gap: 8px; }
.hidden-input { display: none; }
.image-preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 12px; margin-top: 16px; }
.img-preview-item { position: relative; padding-top: 100%; border-radius: 8px; overflow: hidden; box-shadow: var(--shadow-sm); }
.img-preview-item img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
.remove-img-btn {
    position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,0.6); color: white;
    border: none; border-radius: 50%; width: 24px; height: 24px; font-size: 14px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

/* Pill Buttons */
.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.pill-btn {
    padding: 8px 16px; border: 1px solid var(--border-color); border-radius: 9999px; background: var(--card-bg);
    color: var(--text-main); font-size: 0.875rem; cursor: pointer; transition: all 0.2s;
}
.pill-btn.active { background: var(--primary-color); border-color: var(--primary-color); color: white; }

/* Bottom Action Bar */
.bottom-action-bar {
    position: fixed; bottom: 0; left: 0; width: 100%; background: var(--card-bg);
    padding: 16px 16px calc(16px + var(--safe-bottom)); box-shadow: 0 -2px 10px rgba(0,0,0,0.05); z-index: 100;
}
.primary-btn {
    width: 100%; max-width: 768px; margin: 0 auto; display: flex; justify-content: center; align-items: center;
    background: var(--primary-color); color: white; border: none; border-radius: var(--radius);
    padding: 14px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: background 0.2s;
}
.primary-btn:active { background: var(--primary-hover); }
.primary-btn:disabled { opacity: 0.7; cursor: not-allowed; }
.spinner {
    width: 20px; height: 20px; border: 3px solid rgba(255,255,255,0.3); border-radius: 50%;
    border-top-color: white; animation: spin 1s ease-in-out infinite; margin-left: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast-container { position: fixed; top: calc(20px + var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 10px; width: 90%; max-width: 400px;}
.toast { padding: 12px 20px; border-radius: 8px; color: white; font-size: 0.875rem; box-shadow: var(--shadow-md); animation: slideDown 0.3s, fadeOut 0.3s 2.7s forwards; text-align: center; }
.toast.success { background: var(--success-color); }
.toast.error { background: var(--error-color); }
@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; visibility: hidden; } }

/* Modal */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-content { background: var(--card-bg); border-radius: var(--radius); width: 100%; max-width: 500px; max-height: 80vh; display: flex; flex-direction: column; }
.modal-header { padding: 16px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px; overflow-y: auto; }
.history-list { display: flex; flex-direction: column; gap: 12px; }
.history-item { display: flex; gap: 12px; padding: 12px; border: 1px solid var(--border-color); border-radius: 8px; }
.history-item-thumb { width: 60px; height: 60px; border-radius: 4px; object-fit: cover; }
.history-item-content { flex: 1; }
.history-item-title { font-weight: 600; font-size: 0.875rem; margin-bottom: 4px; }
.history-item-desc { font-size: 0.75rem; color: var(--text-muted); }
.status-badge { display: inline-block; padding: 2px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: 600; margin-top: 4px; }
.status-synced { background: #d1fae5; color: #065f46; }
.status-pending { background: #fef3c7; color: #92400e; }

/* Real-time Time Badge */
.time-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    border: 1px solid #bfdbfe;
    color: #1e40af;
    padding: 8px 14px;
    border-radius: 9999px;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 16px;
    width: 100%;
    box-sizing: border-box;
}

/* Select Box for Mobile Pickers */
.select-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--card-bg);
    cursor: pointer;
    font-size: 1rem;
    min-height: 48px;
    box-sizing: border-box;
    transition: border-color 0.2s, background-color 0.2s;
}
.select-box:active { background: #f9fafb; border-color: var(--primary-color); }
.select-box.disabled { background: #f3f4f6; color: #9ca3af; cursor: not-allowed; }
.select-box .placeholder { color: #9ca3af; }
.select-box .selected-val { color: var(--text-main); font-weight: 500; }
.chevron-icon { color: #9ca3af; flex-shrink: 0; }

/* Readonly Highlight Field */
.readonly-highlight {
    background: #f8fafc !important;
    color: #0369a1 !important;
    font-weight: 600;
    border-color: #cbd5e1 !important;
}

/* Location Picker Modal */
.location-modal-content {
    max-height: 85vh;
    height: 600px;
    display: flex;
    flex-direction: column;
}
.search-input-wrapper {
    position: relative;
    padding: 12px 16px;
    background: #f9fafb;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
}
.search-input-wrapper svg { color: #9ca3af; flex-shrink: 0; }
.search-input-wrapper input {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 36px 10px 12px;
    font-size: 0.95rem;
    background: #ffffff;
}
.search-input-wrapper input:focus {
    outline: none;
    border-color: var(--primary-color);
}
.clear-btn {
    position: absolute;
    right: 24px;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}
.location-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}
.location-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.location-item {
    padding: 14px 16px;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
}
.location-item:active, .location-item:hover {
    background: #eff6ff;
}
.location-item-main {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-main);
}
.location-item-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}
.location-item-badge {
    font-size: 0.75rem;
    padding: 2px 8px;
    background: #e0f2fe;
    color: #0369a1;
    border-radius: 9999px;
    font-weight: 500;
}
.location-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Normalized Address Preview */
.addr-preview {
    margin-top: 6px;
    font-size: 0.8rem;
    color: #047857;
    background: #ecfdf5;
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #a7f3d0;
    display: none;
}
