:root {
  --primary:        #4a7c59;
  --primary-dark:   #3a6047;
  --primary-light:  #e8f4ec;
  --secondary:      #9b7e46;
  --bg:             #f4efe6;
  --card-bg:        #ffffff;
  --input-bg:       #ffffff;
  --text:           #2d2d2d;
  --text-light:     #6b6b6b;
  --border:         #e0d8cc;
  --red:            #c0392b;
  --red-light:      #fdf0ee;
  --orange:         #d35400;
  --orange-light:   #fef3ec;
  --green:          #27ae60;
  --green-light:    #edfbf3;
  --blue:           #2980b9;
  --blue-light:     #eef5fb;
  --shadow:         0 2px 8px rgba(0,0,0,0.08);
  --radius:         8px;
}

[data-theme="dark"] {
  --primary:        #6fa57d;
  --primary-dark:   #5a8a68;
  --primary-light:  #2a3a30;
  --secondary:      #c9a876;
  --bg:             #1a1d1f;
  --card-bg:        #25292c;
  --input-bg:       #1f2326;
  --text:           #e8e6e1;
  --text-light:     #9aa0a3;
  --border:         #3a4045;
  --red-light:      #3a2422;
  --orange-light:   #3a2c1e;
  --green-light:    #1f3328;
  --blue-light:     #1e2a35;
  --shadow:         0 2px 10px rgba(0,0,0,0.4);
}
[data-theme="dark"] .badge-gray { background: #3a4045; color: #c0c4c8; }
[data-theme="dark"] .stat-card .stat-value { color: var(--primary); }
[data-theme="dark"] #plan-svg { background: #1f2326; }
[data-theme="dark"] .form-group input,
[data-theme="dark"] .form-group select,
[data-theme="dark"] .form-group textarea { background: var(--input-bg); color: var(--text); }
[data-theme="dark"] .pswatch { box-shadow: 0 0 0 1px rgba(255,255,255,0.06); }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: var(--primary);
  color: white;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 32px;
  flex-wrap: wrap;
  box-shadow: 0 3px 16px rgba(0,0,0,0.18);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  flex-shrink: 0;
}

.logo { font-size: 34px; }
.header-brand h1 { font-size: 20px; font-weight: 700; line-height: 1.2; }
.header-brand .subtitle {
  font-size: 12px;
  opacity: 0.8;
  background: rgba(255,255,255,0.18);
  padding: 1px 8px;
  border-radius: 10px;
  display: block;
}

nav {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  padding: 8px 0;
}

.nav-tab {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.72);
  padding: 8px 13px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.18s;
  white-space: nowrap;
}
.nav-tab:hover { background: rgba(255,255,255,0.14); color: white; }
.nav-tab.active { background: rgba(255,255,255,0.22); color: white; font-weight: 700; }

/* ── Main ── */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px;
}

.loading {
  text-align: center;
  padding: 80px;
  color: var(--text-light);
  font-size: 16px;
}

/* ── Section header ── */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.section-title { font-size: 20px; font-weight: 700; }

/* ── Buttons ── */
.btn {
  padding: 9px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.18s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--card-bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { background: #a93226; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

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

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: all 0.18s;
}
.stat-card:hover { box-shadow: 0 4px 16px rgba(74,124,89,0.18); border-color: var(--primary); }
.stat-card .stat-icon { font-size: 26px; }
.stat-card .stat-value { font-size: 26px; font-weight: 800; color: var(--primary); line-height: 1; }
.stat-card .stat-label { font-size: 12px; color: var(--text-light); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }

/* ── Item list ── */
.item-list { display: flex; flex-direction: column; gap: 8px; }

.item-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  box-shadow: var(--shadow);
  transition: border-color 0.18s, box-shadow 0.18s;
}
.item-card:hover { border-color: var(--primary); box-shadow: 0 2px 14px rgba(74,124,89,0.13); }
.item-card.done { opacity: 0.55; }

.item-icon { font-size: 20px; width: 26px; text-align: center; flex-shrink: 0; padding-top: 2px; }
.item-body { flex: 1; min-width: 0; }
.item-title { font-weight: 600; font-size: 15px; }
.item-meta { font-size: 12.5px; color: var(--text-light); margin-top: 4px; line-height: 1.7; }
.item-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge-red    { background: var(--red-light);    color: var(--red); }
.badge-orange { background: var(--orange-light); color: var(--orange); }
.badge-green  { background: var(--green-light);  color: var(--green); }
.badge-blue   { background: var(--blue-light);   color: var(--blue); }
.badge-gray   { background: #f0ece6;             color: #666; }

/* ── Filters ── */
.filters { display: flex; gap: 7px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-btn {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 5px 13px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.18s;
  color: var(--text);
}
.filter-btn:hover, .filter-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.22);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--card-bg);
  z-index: 1;
}
.modal-header h2 { font-size: 18px; }

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-light);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.18s;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { padding: 24px; }

/* ── Forms ── */
.form-group { margin-bottom: 15px; }
.form-group label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-light);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: white;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74,124,89,0.1);
}
.form-group textarea { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Welcome banner ── */
.welcome-banner {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 24px 28px;
  border-radius: 12px;
  margin-bottom: 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.welcome-banner h2 { font-size: 21px; margin-bottom: 4px; }
.welcome-banner p  { opacity: 0.82; font-size: 14px; }
.welcome-emoji { font-size: 52px; flex-shrink: 0; }

/* ── Dashboard grid ── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.section-widget {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.widget-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
}
.widget-title { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-light); }

.widget-item {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--bg);
  font-size: 13.5px;
}
.widget-item:last-child { border-bottom: none; }

/* ── Cost amount ── */
.cost-amount { font-weight: 800; font-size: 15px; color: var(--secondary); flex-shrink: 0; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-light); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 10px; }
.empty-state p { font-size: 15px; line-height: 1.6; }

/* ── Notes ── */
.note-content {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  margin-top: 6px;
  border-top: 1px solid var(--bg);
  padding-top: 10px;
}

/* ── Plan Editor ── */
.plan-wrap {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 64px);
  margin: -28px -24px 0;
  overflow: hidden;
}

.plan-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.plan-bar-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.plan-tools {
  display: flex;
  gap: 4px;
}

.ptool {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
  font-size: 18px;
  transition: all 0.18s;
}
.ptool:hover  { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.ptool.active { background: var(--primary); border-color: var(--primary); color: white; }

.plan-save-status {
  font-size: 12px;
  color: var(--text-light);
  white-space: nowrap;
}

.plan-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

#plan-svg {
  flex: 1;
  width: 100%;
  height: 100%;
  display: block;
  background: #f9f7f4;
  user-select: none;
}

.plan-props {
  width: 230px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--card-bg);
  padding: 14px 16px;
  overflow-y: auto;
  box-shadow: -3px 0 10px rgba(0,0,0,0.05);
}
.plan-props.hidden { display: none; }

.props-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.ppalette {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
  margin-top: 4px;
}

.pswatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 5px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
}
.pswatch:hover { transform: scale(1.15); border-color: var(--text-light); }
.pswatch.active { border-color: var(--primary); outline: 2px solid var(--primary); outline-offset: 1px; }

.marker-cats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 4px;
}

.mcat-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  border: 2px solid transparent;
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 11px;
}
.mcat-btn span { font-size: 18px; line-height: 1; }
.mcat-btn small { color: var(--text-light); font-weight: 600; text-align: center; line-height: 1.2; }
.mcat-btn:hover { background: var(--primary-light); }
.mcat-btn.active { background: var(--primary-light); transform: scale(1.05); }

.plan-hint {
  padding: 6px 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-light);
  flex-shrink: 0;
}

/* ── Header tools (search + theme) ── */
.header-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.search-wrap { position: relative; }
.search-wrap input {
  background: rgba(255,255,255,0.16);
  border: 1px solid rgba(255,255,255,0.25);
  color: white;
  padding: 7px 12px;
  border-radius: 18px;
  font-size: 13px;
  width: 200px;
  transition: all 0.18s;
  outline: none;
}
.search-wrap input::placeholder { color: rgba(255,255,255,0.7); }
.search-wrap input:focus { background: rgba(255,255,255,0.28); width: 260px; border-color: rgba(255,255,255,0.5); }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 360px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
  z-index: 200;
}
.search-results.hidden { display: none; }
.search-result {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--bg); }
.search-result-title { font-weight: 600; font-size: 14px; }
.search-result-meta  { font-size: 11.5px; color: var(--text-light); margin-top: 2px; }
.search-empty { padding: 20px; text-align: center; color: var(--text-light); font-size: 13px; }

.theme-toggle {
  background: rgba(255,255,255,0.16);
  border: 1px solid rgba(255,255,255,0.25);
  color: white;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.18s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle:hover { background: rgba(255,255,255,0.28); transform: rotate(20deg); }

/* ── Calendar ── */
.cal-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.cal-title { font-size: 18px; font-weight: 700; }
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-dow {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  text-align: center;
  padding: 6px 0;
}
.cal-cell {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 84px;
  padding: 5px 6px;
  font-size: 12px;
  position: relative;
  transition: border-color .15s;
}
.cal-cell.other { opacity: 0.4; }
.cal-cell.today { border-color: var(--primary); border-width: 2px; }
.cal-cell .cal-day { font-weight: 700; font-size: 13px; margin-bottom: 3px; }
.cal-cell.today .cal-day { color: var(--primary); }
.cal-task {
  display: block;
  background: var(--card-bg);
  border-left: 3px solid var(--primary);
  padding: 2px 5px;
  margin-bottom: 2px;
  border-radius: 3px;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-task:hover { background: var(--primary-light); }
.cal-task.done   { opacity: 0.5; text-decoration: line-through; border-left-color: var(--green); }
.cal-task.urgent { border-left-color: var(--red); }
.cal-more { font-size: 10px; color: var(--text-light); margin-top: 2px; cursor: pointer; }

/* ── Charts ── */
.chart-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.chart-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-light); margin-bottom: 12px; }
.chart-svg { width: 100%; display: block; }
.chart-tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.chart-tab {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 16px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}
.chart-tab.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ── Photo / Document upload ── */
.photo-thumb {
  width: 64px;
  height: 64px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
  cursor: pointer;
  background: var(--bg);
}
.photo-preview {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-top: 6px;
  background: var(--bg);
}
.file-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  color: var(--text-light);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.file-drop:hover { border-color: var(--primary); color: var(--primary); }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.86);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 6px; box-shadow: 0 10px 40px rgba(0,0,0,0.6); }

/* ── Meter sparkline ── */
.spark { display: block; width: 100%; height: 40px; }

/* ── Maintenance entries ── */
.maint-list {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 8px;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.maint-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 10px;
  font-size: 12.5px;
  gap: 8px;
}
.maint-row .maint-date { font-weight: 700; flex-shrink: 0; color: var(--text-light); font-size: 11.5px; }
.maint-row .maint-text { flex: 1; }
.maint-row button { background: none; border: none; cursor: pointer; color: var(--red); font-size: 14px; }

/* ── Cost period filter ── */
.cost-period {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.cost-period select, .cost-period input[type=month] {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 13px;
}
.cost-period .period-total { font-weight: 800; color: var(--secondary); margin-left: auto; }

/* ── Templates picker ── */
.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}
.tpl-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: all .15s;
}
.tpl-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.tpl-card h4 { font-size: 14px; margin-bottom: 4px; }
.tpl-card p  { font-size: 12px; color: var(--text-light); }
.tpl-card .tpl-count { font-size: 11px; margin-top: 6px; color: var(--primary); font-weight: 700; }

/* ── Responsive ── */
@media (max-width: 800px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  header { padding: 0 14px; gap: 10px; }
  nav { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
  main { padding: 18px 14px; }
  .welcome-emoji { display: none; }
  .search-wrap input { width: 150px; }
  .search-wrap input:focus { width: 200px; }
  .search-results { width: calc(100vw - 28px); right: -14px; }
  .cal-cell { min-height: 60px; font-size: 10px; }
}
