:root {
  --brand: #1e6b4f;
  --brand-dark: #14523c;
  --bg: #f5f6f4;
  --card: #ffffff;
  --border: #dfe3e0;
  --text: #202826;
  --muted: #667069;
  --danger: #b3261e;
  --warn: #9a6b00;
  --ok: #1e6b4f;
  --radius: 8px;
}
* { 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);
  font-size: 15px;
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; }

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "topbar topbar" "nav content";
  min-height: 100vh;
}
.topbar {
  grid-area: topbar;
  background: var(--brand-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
}
.brand { font-weight: 700; letter-spacing: .02em; }
.role-badge {
  background: rgba(255,255,255,.15);
  padding: 1px 8px;
  border-radius: 12px;
  font-size: 12px;
  text-transform: capitalize;
}
.user-menu a { color: #fff; }
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
}
.sidenav {
  grid-area: nav;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}
.sidenav a {
  padding: 10px 20px;
  text-decoration: none;
  color: var(--text);
  border-left: 3px solid transparent;
}
.sidenav a:hover { background: #f0f2f0; border-left-color: var(--brand); }
.content, .content-plain { grid-area: content; padding: 20px 24px 60px; max-width: 1100px; }
.content-plain { max-width: 420px; margin: 60px auto; padding: 0 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h2, .card h3 { margin-top: 0; }

.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; text-align: center; }
.stat .num { font-size: 26px; font-weight: 700; color: var(--brand-dark); }
.stat .label { color: var(--muted); font-size: 13px; }

table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .04em; }
tr:hover td { background: #fafbfa; }

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

label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; background: #fff;
}
textarea { min-height: 90px; font-family: inherit; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 16px 0; }
legend { padding: 0 6px; font-weight: 600; font-size: 13px; }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.alert-success { background: #e4f5ea; color: #14532d; }
.alert-error { background: #fdecea; color: #7f1d1d; }
.alert-info { background: #eaf2fb; color: #1e3a5f; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.badge-lead, .badge-site_visit { background: #eee; color: #555; }
.badge-quote_sent, .badge-quote_accepted { background: #eaf2fb; color: #1e3a5f; }
.badge-contract_sent, .badge-contract_signed { background: #fdf3e0; color: #7a5200; }
.badge-deposit_pending, .badge-scheduled { background: #f4e9fb; color: #5b1e7a; }
.badge-in_progress { background: #fff4d6; color: #7a5b00; }
.badge-completed, .badge-final_payment { background: #e4f5ea; color: #14532d; }
.badge-archived { background: #e6e6e6; color: #444; }
.badge-cancelled { background: #fdecea; color: #7f1d1d; }

.storage-bar { background: #eee; border-radius: 8px; overflow: hidden; height: 22px; width: 100%; }
.storage-bar-fill { height: 100%; background: var(--brand); }
.storage-bar-fill.warn { background: var(--warn); }
.storage-bar-fill.danger { background: var(--danger); }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.photo-grid a img,
.photo-grid button img { width: 100%; height: 100px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); display: block; }

.status-pipeline { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 20px; }
.status-pipeline .step { padding: 5px 10px; border-radius: 14px; background: #eee; font-size: 12px; color: #777; }
.status-pipeline .step.done { background: var(--brand); color: #fff; }
.status-pipeline .step.current { background: var(--brand-dark); color: #fff; font-weight: 700; }

.muted { color: var(--muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }

.gjm-color-swatch { width: 28px; height: 28px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); cursor: pointer; padding: 0; }

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; grid-template-areas: "topbar" "content"; }
  .nav-toggle { display: block; }
  .sidenav {
    position: fixed; top: 52px; left: 0; bottom: 0; width: 220px; z-index: 20;
    transform: translateX(-100%); transition: transform .15s ease; box-shadow: 2px 0 8px rgba(0,0,0,.1);
  }
  .sidenav.open { transform: translateX(0); }
  .form-row { grid-template-columns: 1fr; }
  .content { padding: 14px; }
}
