/* ===== CSS Custom Properties ===== */
:root {
  --green:        #2E7D32;
  --green-dark:   #1B5E20;
  --green-light:  #4CAF50;
  --green-pale:   #E8F5E9;
  --accent:       #FF6F00;
  --bg:           #F0F2F5;
  --surface:      #FFFFFF;
  --border:       #E0E0E0;
  --text:         #1A1A1A;
  --text-med:     #555555;
  --text-light:   #888888;
  --danger:       #C62828;
  --danger-light: #FFEBEE;
  --shadow:       0 2px 8px rgba(0,0,0,0.10);
  --shadow-md:    0 4px 16px rgba(0,0,0,0.14);
  --radius:       12px;
  --radius-sm:    8px;
  --header-h:     56px;
  --bottom-nav-h: 60px;
  --sidebar-w:    280px;
  --transition:   0.22s ease;
  --font:         'Inter', system-ui, sans-serif;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; overflow-x: hidden; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, select, textarea { font-family: inherit; }
a { text-decoration: none; color: inherit; }
ul { list-style: none; }

/* ===== Utilities ===== */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-2 { margin-bottom: 16px; }
.w-full { width: 100%; }
.text-sm { font-size: 0.85rem; }
.text-center { text-align: center; }
.text-green { color: var(--green); }
.text-danger { color: var(--danger); }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }

/* ===== Splash ===== */
#splash {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--green-dark);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: white; gap: 12px;
  transition: opacity 0.4s ease;
}
#splash img { width: 90px; height: 90px; border-radius: 20px; }
#splash h1 { font-size: 2rem; font-weight: 700; letter-spacing: 1px; }
#splash p { font-size: 0.95rem; opacity: 0.8; }
#splash.fade-out { opacity: 0; pointer-events: none; }

.splash-spinner {
  width: 36px; height: 36px; margin-top: 16px;
  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); } }

/* ===== App Shell ===== */
#app { display: flex; flex-direction: column; min-height: 100vh; }

/* ===== Header ===== */
#app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  background: var(--green-dark);
  color: white;
  display: flex; align-items: center; padding: 0 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
#app-header h1 { flex: 1; font-size: 1.1rem; font-weight: 600; margin-left: 8px; }
#header-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; color: white;
  transition: background var(--transition);
}
.icon-btn:hover, .icon-btn:active { background: rgba(255,255,255,0.15); }
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }

/* ===== Sidebar ===== */
#sidebar-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.5);
  transition: opacity var(--transition);
}
#sidebar-overlay.hidden { opacity: 0; pointer-events: none; }

#sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 201;
  width: var(--sidebar-w);
  background: var(--surface);
  transform: translateX(-100%);
  transition: transform var(--transition);
  overflow-y: auto;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-md);
}
#sidebar.open { transform: translateX(0); }

.sidebar-header {
  background: var(--green-dark); color: white;
  padding: 48px 16px 20px;
  display: flex; align-items: center; gap: 12px;
}
.sidebar-header img { width: 48px; height: 48px; border-radius: 12px; }
.sidebar-header strong { display: block; font-size: 1rem; }
.sidebar-header small { font-size: 0.8rem; opacity: 0.8; }

.sidebar-menu { flex: 1; padding: 8px 0; }
.sidebar-menu a {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px;
  font-size: 0.95rem; font-weight: 500;
  color: var(--text);
  transition: background var(--transition);
}
.sidebar-menu a:hover, .sidebar-menu a.active { background: var(--green-pale); color: var(--green); }
.sidebar-menu a svg { width: 22px; height: 22px; fill: currentColor; flex-shrink: 0; }
.sidebar-separator { height: 1px; background: var(--border); margin: 6px 16px; }

/* ===== Page Content ===== */
#page-content {
  margin-top: var(--header-h);
  margin-bottom: var(--bottom-nav-h);
  min-height: calc(100vh - var(--header-h) - var(--bottom-nav-h));
  padding: 16px;
}

/* ===== Bottom Nav ===== */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: var(--bottom-nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(4, 1fr);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
}
.bottom-nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 6px 4px;
  color: var(--text-light); font-size: 0.68rem; font-weight: 500;
  transition: color var(--transition);
}
.bottom-nav-item svg { width: 22px; height: 22px; fill: currentColor; }
.bottom-nav-item.active { color: var(--green); }

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.card-title { font-size: 0.8rem; font-weight: 600; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 12px; }

/* ===== Buttons ===== */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--green); color: white;
  border-radius: var(--radius-sm); padding: 12px 20px;
  font-size: 0.95rem; font-weight: 600;
  transition: background var(--transition), transform 0.1s;
  width: 100%;
}
.btn-primary:hover { background: var(--green-light); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary svg { width: 20px; height: 20px; fill: white; }

.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: white; color: var(--green);
  border: 2px solid var(--green);
  border-radius: var(--radius-sm); padding: 10px 20px;
  font-size: 0.95rem; font-weight: 600;
  transition: background var(--transition);
  width: 100%;
}
.btn-secondary:hover { background: var(--green-pale); }

.btn-danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--danger); color: white;
  border-radius: var(--radius-sm); padding: 10px 20px;
  font-size: 0.9rem; font-weight: 600;
  transition: background var(--transition);
}
.btn-text { background: none; color: var(--green); font-weight: 600; font-size: 0.9rem; padding: 8px; }
.btn-sm { padding: 8px 14px !important; font-size: 0.85rem !important; }
.btn-icon-label {
  display: flex; align-items: center; gap: 8px;
  background: var(--green-pale); color: var(--green);
  border-radius: var(--radius-sm); padding: 10px 16px;
  font-weight: 600; font-size: 0.9rem;
}
.btn-icon-label svg { width: 20px; height: 20px; fill: currentColor; }

/* ===== Form Elements ===== */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 0.82rem; font-weight: 600;
  color: var(--text-med); margin-bottom: 6px; letter-spacing: 0.3px;
}
.form-label .required { color: var(--danger); }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem; color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition);
  -webkit-appearance: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(46,125,50,0.12);
}
.form-input.error, .form-select.error { border-color: var(--danger); }
.form-textarea { resize: vertical; min-height: 90px; }
.form-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23555' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 20px; padding-right: 36px; }
.form-hint { font-size: 0.78rem; color: var(--text-light); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.input-group { display: flex; }
.input-group .form-input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group-btn {
  padding: 0 14px; background: var(--border); border: 1.5px solid var(--border);
  border-left: none; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-med);
}

/* Calculated field */
.form-input[readonly] { background: #F8F9FA; color: var(--text-med); }

/* ===== Chips / Multi-select ===== */
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 20px;
  border: 1.5px solid var(--border);
  font-size: 0.85rem; cursor: pointer;
  transition: all var(--transition);
  background: white;
}
.chip.selected { background: var(--green-pale); border-color: var(--green); color: var(--green); font-weight: 600; }
.chip .chip-remove { font-size: 1.1rem; line-height: 1; }

/* ===== Toggle Switch ===== */
.toggle-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-info strong { display: block; font-size: 0.95rem; }
.toggle-info small { font-size: 0.8rem; color: var(--text-light); }
.toggle {
  position: relative; width: 48px; height: 28px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: #ccc; border-radius: 28px;
  cursor: pointer; transition: background var(--transition);
}
.toggle-slider::before {
  content: ''; position: absolute;
  height: 22px; width: 22px; left: 3px; bottom: 3px;
  background: white; border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle input:checked + .toggle-slider { background: var(--green); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ===== Photo Upload ===== */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.photo-item {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  background: var(--bg);
}
.photo-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-item .photo-remove {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px;
  background: rgba(0,0,0,0.6); color: white;
  border-radius: 50%; font-size: 0.75rem;
  display: flex; align-items: center; justify-content: center;
}
.photo-add {
  aspect-ratio: 1;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; color: var(--text-light); cursor: pointer; font-size: 0.8rem;
  transition: border-color var(--transition), color var(--transition);
}
.photo-add:hover { border-color: var(--green); color: var(--green); }
.photo-add svg { width: 28px; height: 28px; fill: currentColor; }

/* ===== Signature Preview ===== */
.signature-preview {
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  min-height: 100px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; overflow: hidden; background: #FAFAFA;
  transition: border-color var(--transition);
}
.signature-preview:hover { border-color: var(--green); }
.signature-preview img { max-height: 100px; }
.signature-placeholder { color: var(--text-light); font-size: 0.9rem; text-align: center; padding: 20px; }
.signature-placeholder svg { width: 36px; height: 36px; fill: currentColor; display: block; margin: 0 auto 8px; }

/* ===== Signature Modal ===== */
#signature-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end;
}
#signature-overlay.hidden { display: none; }
.signature-modal {
  width: 100%; background: white; border-radius: 20px 20px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.signature-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 8px;
  border-bottom: 1px solid var(--border);
}
.signature-header span { font-weight: 600; font-size: 1rem; }
.signature-header div { display: flex; align-items: center; gap: 8px; }
#signature-canvas { width: 100%; height: 280px; touch-action: none; display: block; }

/* ===== Report List Item ===== */
.report-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  cursor: pointer;
  transition: box-shadow var(--transition);
}
.report-item:hover { box-shadow: var(--shadow-md); }
.report-icon {
  width: 44px; height: 44px;
  background: var(--green-pale); color: var(--green);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.report-icon svg { width: 24px; height: 24px; fill: currentColor; }
.report-info { flex: 1; min-width: 0; }
.report-info strong { display: block; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.report-info span { font-size: 0.8rem; color: var(--text-med); }
.report-actions { display: flex; gap: 4px; }
.report-actions button {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-light);
  transition: background var(--transition), color var(--transition);
}
.report-actions button:hover { background: var(--bg); color: var(--green); }
.report-actions button svg { width: 18px; height: 18px; fill: currentColor; }

/* ===== Worker / Category Items ===== */
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
}
.list-item-info strong { display: block; font-size: 0.95rem; }
.list-item-info span { font-size: 0.8rem; color: var(--text-light); }
.list-item-actions { display: flex; gap: 4px; }
.list-item-actions button {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-light);
  transition: background var(--transition);
}
.list-item-actions button:hover { background: var(--bg); }
.list-item-actions button svg { width: 20px; height: 20px; fill: currentColor; }
.list-item-actions .btn-del:hover { color: var(--danger); }

/* ===== FAB ===== */
.fab {
  position: fixed; bottom: calc(var(--bottom-nav-h) + 16px); right: 16px; z-index: 50;
  width: 56px; height: 56px;
  background: var(--green); color: white;
  border-radius: 50%; box-shadow: 0 4px 12px rgba(46,125,50,0.4);
  display: flex; align-items: center; justify-content: center;
  transition: transform var(--transition), box-shadow var(--transition);
}
.fab:hover { transform: scale(1.08); box-shadow: 0 6px 16px rgba(46,125,50,0.5); }
.fab svg { width: 28px; height: 28px; fill: white; }

/* ===== Stats / Dashboard ===== */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-card .stat-num { font-size: 2rem; font-weight: 700; color: var(--green); line-height: 1; }
.stat-card .stat-label { font-size: 0.78rem; color: var(--text-light); margin-top: 4px; }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.quick-action {
  background: var(--green);
  color: white;
  border-radius: var(--radius);
  padding: 18px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  box-shadow: 0 3px 10px rgba(46,125,50,0.25);
  transition: transform var(--transition), box-shadow var(--transition);
  font-size: 0.88rem; font-weight: 600; text-align: center;
}
.quick-action:nth-child(2) { background: var(--green-dark); }
.quick-action svg { width: 28px; height: 28px; fill: white; }
.quick-action:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(46,125,50,0.3); }

/* ===== Login / Auth Pages ===== */
.auth-page {
  min-height: calc(100vh - var(--header-h) - var(--bottom-nav-h));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.auth-logo { margin-bottom: 24px; text-align: center; }
.auth-logo img { width: 80px; height: 80px; border-radius: 18px; margin: 0 auto 12px; }
.auth-logo h2 { font-size: 1.5rem; font-weight: 700; }
.auth-logo p { color: var(--text-med); font-size: 0.9rem; }
.auth-card { width: 100%; max-width: 420px; }
.auth-footer { margin-top: 20px; text-align: center; font-size: 0.88rem; color: var(--text-med); }
.auth-footer a { color: var(--green); font-weight: 600; }

/* ===== Section Header ===== */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.section-header h2 { font-size: 1rem; font-weight: 700; }

/* ===== Empty State ===== */
.empty-state {
  text-align: center; padding: 48px 24px;
  color: var(--text-light);
}
.empty-state svg { width: 64px; height: 64px; fill: var(--border); margin: 0 auto 16px; display: block; }
.empty-state h3 { font-size: 1rem; color: var(--text-med); margin-bottom: 8px; }
.empty-state p { font-size: 0.85rem; }

/* ===== Toast ===== */
#toast {
  position: fixed; bottom: calc(var(--bottom-nav-h) + 16px); left: 50%; z-index: 999;
  transform: translateX(-50%) translateY(20px);
  background: #333; color: white;
  padding: 12px 20px; border-radius: 24px;
  font-size: 0.88rem; font-weight: 500;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.success { background: var(--green); }
#toast.error { background: var(--danger); }

/* ===== Modal ===== */
#modal-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
#modal-overlay.hidden { display: none; }
#modal { background: white; border-radius: var(--radius); width: 100%; max-width: 420px; overflow: hidden; box-shadow: var(--shadow-md); }
#modal-content { padding: 24px; }
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 12px; }
.modal-text { color: var(--text-med); font-size: 0.9rem; margin-bottom: 20px; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-actions button { padding: 10px 20px; border-radius: var(--radius-sm); font-weight: 600; font-size: 0.9rem; }
.modal-cancel { background: var(--bg); color: var(--text); }
.modal-confirm { background: var(--danger); color: white; }
.modal-confirm.green { background: var(--green); }

/* ===== Settings Page ===== */
.settings-section { margin-bottom: 20px; }
.settings-section-title {
  font-size: 0.78rem; font-weight: 700; color: var(--green);
  text-transform: uppercase; letter-spacing: 0.6px;
  padding: 0 4px; margin-bottom: 8px;
}

/* ===== Profile Avatar ===== */
.avatar-block { text-align: center; padding: 20px 0; }
.avatar {
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--green); color: white;
  font-size: 2rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 8px;
}

/* ===== Divider ===== */
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ===== Loading Spinner ===== */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 32px auto;
}

/* ===== Checklist ===== */
.checklist-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.checklist-item:last-child { border-bottom: none; }
.checklist-item input[type="checkbox"] {
  width: 20px; height: 20px; accent-color: var(--green); flex-shrink: 0;
}
.checklist-item label { font-size: 0.92rem; flex: 1; }
.checklist-add { display: flex; gap: 8px; margin-top: 10px; }
.checklist-add .form-input { flex: 1; }
.checklist-add button { padding: 0 16px; background: var(--green); color: white; border-radius: var(--radius-sm); font-weight: 600; flex-shrink: 0; }

/* ===== Time Report ===== */
.time-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.time-row:last-child { border-bottom: none; }
.time-row .date { font-size: 0.85rem; color: var(--text-med); }
.time-row .hours { font-weight: 700; color: var(--green); font-size: 1rem; }
.time-total {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px; background: var(--green-pale); border-radius: var(--radius-sm);
  margin-top: 12px;
}
.time-total strong { color: var(--green); font-size: 1.1rem; }

/* ===== Responsive tweaks ===== */
@media (min-width: 600px) {
  #page-content { max-width: 640px; margin-left: auto; margin-right: auto; }
  .photo-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-color-scheme: dark) {
  /* Basic dark mode hints — optional, can be expanded */
}
