:root {
  --brand-dark: #3F6B25;
  --brand: #5C9A34;
  --brand-light: #8CC63F;
  --bg: #f6f8f3;
  --card: #ffffff;
  --border: #e0e6d8;
  --text: #24301c;
  --muted: #6b7a5e;
  --danger: #c0392b;
  --warn: #d19a1f;
  --ok: #2a8f4c;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--brand-dark);
  color: white;
  display: flex;
  align-items: center;
  padding: 10px 16px;
  flex-wrap: wrap;
  gap: 10px;
}
.topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; margin-right: 12px; }
.topbar .brand img { width: 28px; height: 28px; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a { color: #e7f2da; padding: 8px 10px; border-radius: 6px; font-size: 14px; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,0.15); text-decoration: none; }
.topbar .user { font-size: 13px; color: #d7e6c6; display: flex; align-items: center; gap: 8px; }
.topbar form { margin: 0; }
.topbar button.linklike { background: none; border: none; color: #e7f2da; cursor: pointer; font-size: 13px; padding: 6px 8px; }

.container { max-width: 1100px; margin: 0 auto; padding: 18px 16px 60px; }
.container.narrow { max-width: 720px; }

h1 { font-size: 22px; margin: 4px 0 16px; color: var(--brand-dark); }
h2 { font-size: 17px; color: var(--brand-dark); }

.page-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }

.btn {
  display: inline-block; background: var(--brand-dark); color: white; border: none;
  padding: 9px 16px; border-radius: 6px; font-size: 14px; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--brand); text-decoration: none; }
.btn.secondary { background: white; color: var(--brand-dark); border: 1px solid var(--brand-dark); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

table.data { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 8px; overflow: hidden; }
table.data th { background: #eef4e5; text-align: left; padding: 10px 12px; font-size: 12.5px; color: var(--brand-dark); border-bottom: 2px solid var(--border); }
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover { background: #fafcf7; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; color: white; background: #999; }
.badge.paid, .badge.completed, .badge.approved { background: var(--ok); }
.badge.overdue, .badge.declined { background: var(--danger); }
.badge.sent { background: var(--warn); }
.badge.draft { background: #888; }
.badge.scheduled { background: #4a7fb5; }
.badge.in_progress { background: var(--warn); }
.badge.cancelled { background: #888; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; margin-top: 12px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid #ccd6bf; border-radius: 6px; font-size: 14px;
  font-family: inherit; background: white; color: var(--text);
}
textarea { min-height: 70px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 640px) {
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .topbar nav a { padding: 7px 8px; font-size: 13px; }
  /* Bigger, thumb-friendly tap targets for technicians using a phone in the field. */
  .btn { padding: 13px 18px; font-size: 15px; min-height: 44px; }
  .btn.small { padding: 10px 14px; font-size: 13.5px; min-height: 38px; }
  .btn-row.tech-actions { flex-direction: column; }
  .btn-row.tech-actions .btn { width: 100%; text-align: center; }
}

.section-title { background: var(--brand-dark); color: white; padding: 6px 12px; border-radius: 5px; font-size: 13px; font-weight: 700; margin: 20px 0 10px; }

table.readings-input { width: 100%; border-collapse: collapse; margin-bottom: 4px; }
table.readings-input th { background: var(--brand-light); color: #1a2b0d; font-size: 11.5px; padding: 6px 8px; text-align: left; }
table.readings-input td { border: 1px solid var(--border); padding: 4px; }
table.readings-input td.item-label { font-weight: 600; font-size: 12.5px; width: 30%; }
table.readings-input td.remove { width: 34px; text-align: center; border: none; }
table.readings-input input { border: none; font-size: 12.5px; padding: 6px; width: 100%; }
table.readings-input td.item-label input { font-weight: 600; }

.items-table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.items-table th { text-align: left; font-size: 12px; color: var(--muted); padding: 4px 6px; }
.items-table td { padding: 4px 6px; }
.items-table input { font-size: 13px; padding: 6px 8px; }
.items-table td.qty, .items-table td.price, .items-table td.remove { width: 100px; }
.items-table td.remove { width: 40px; text-align: center; }
.totals-box { max-width: 320px; margin-left: auto; margin-top: 10px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; }
.totals-box .row.total { font-weight: 700; font-size: 17px; color: var(--brand-dark); border-top: 2px solid var(--brand-dark); margin-top: 4px; padding-top: 8px; }

.photo-upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 8px; }
.photo-upload-cell { border: 1px dashed #ccd6bf; border-radius: 6px; padding: 10px; text-align: center; }
.photo-upload-cell img { max-width: 100%; max-height: 140px; border-radius: 4px; margin-bottom: 6px; }
.photo-upload-cell input[type=file] { font-size: 12px; }
.photo-upload-cell input[type=text] { margin-top: 6px; font-size: 12px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 14px; text-align: center; }
.stat-card .num { font-size: 26px; font-weight: 800; color: var(--brand-dark); }
.stat-card .label { font-size: 12px; color: var(--muted); margin-top: 2px; }
@media (max-width: 640px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.muted { color: var(--muted); font-size: 13px; }
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(160deg, #f6f8f3, #eaf1e0); }
.login-card { background: white; padding: 32px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,0.08); width: 340px; text-align: center; }
.login-card img { width: 64px; height: 64px; margin-bottom: 8px; }
.error-text { color: var(--danger); font-size: 13px; margin-top: 8px; }
.success-text { color: var(--ok); font-size: 13px; margin-top: 8px; }

.email-note { position: relative; }
.email-note summary { list-style: none; }
.email-note summary::-webkit-details-marker { display: none; }
.email-note-form { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 12px; width: 280px; box-shadow: 0 6px 20px rgba(0,0,0,0.12); }
.email-note-form textarea { min-height: 70px; }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; font-size: 13px; border-radius: 6px 6px 0 0; color: var(--muted); }
.tabs a.active { color: var(--brand-dark); background: white; border: 1px solid var(--border); border-bottom: 2px solid white; margin-bottom: -2px; font-weight: 700; }

.calendar-dow-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 6px; }
.calendar-dow { font-size: 11px; font-weight: 700; color: var(--brand-dark); text-align: center; padding: 4px 0; text-transform: uppercase; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 20px; }
.calendar-day { background: var(--card); border: 1px solid var(--border); border-radius: 6px; min-height: 96px; padding: 6px; display: flex; flex-direction: column; gap: 3px; }
.calendar-day.other-month { background: #eef1e8; }
.calendar-day.other-month .calendar-day-num { color: var(--muted); }
.calendar-day.today { border-color: var(--brand-dark); border-width: 2px; }
.calendar-day-num { font-size: 12px; font-weight: 700; }
.calendar-day-num a { color: inherit; }
.cal-job { font-size: 10.5px; padding: 2px 5px; border-radius: 4px; background: #eef4e5; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; border-left: 3px solid #999; }
.cal-job:hover { text-decoration: none; background: #e2ecd4; }
.cal-job.status-scheduled { border-left-color: #4a7fb5; }
.cal-job.status-in_progress { border-left-color: var(--warn); }
.cal-job.status-completed { border-left-color: var(--ok); }
.cal-job.status-cancelled { border-left-color: #888; }
.cal-job.cal-maint { background: #f6efe0; border-left-color: var(--warn); }
.cal-job.cal-maint:hover { background: #efe4cc; }
.cal-more { font-size: 10px; color: var(--muted); }
@media (max-width: 640px) {
  .calendar-day { min-height: 60px; padding: 4px; }
  .cal-job { font-size: 9.5px; }
  .calendar-dow { font-size: 9.5px; }
}

.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-chart .bar { width: 100%; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; }
.bar-chart .bar-amount { font-size: 9px; color: var(--muted); margin-bottom: 2px; }
.bar-chart .bar-month { font-size: 9.5px; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.aging-bar { display: flex; height: 28px; border-radius: 6px; overflow: hidden; margin: 10px 0; }
.aging-bar .seg { display: flex; align-items: center; justify-content: center; color: white; font-size: 11px; font-weight: 700; }
.aging-key { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.aging-key .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.watchlist-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.watchlist-item:last-child { border-bottom: none; }
