/* Grow Easy Systems — brand colours from theme.png */
:root {
  --deep-green: #0b1d16;
  --primary-green: #2e7d32;
  --light-green: #66bb6a;
  --leaf-green: #a5d66a;
  --tagline-gray: #6b6f72;
  --white: #ffffff;

  --bg: var(--white);
  --surface: var(--white);
  --surface-2: #f4f9f4;
  --text: var(--deep-green);
  --muted: var(--tagline-gray);
  --accent: var(--primary-green);
  --accent-hover: #1b5e20;
  --accent-secondary: var(--light-green);
  --accent-leaf: var(--leaf-green);
  --border: #d6e8d6;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --shadow: 0 8px 30px rgba(11, 29, 22, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background:
    radial-gradient(ellipse 80% 50% at 100% 0%, rgba(165, 214, 106, 0.22) 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 0% 100%, rgba(102, 187, 106, 0.14) 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

.muted {
  color: var(--muted);
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 2px solid var(--accent-leaf);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--deep-green);
  text-decoration: none;
  flex-shrink: 0;
}

.brand:hover {
  color: var(--deep-green);
  text-decoration: none;
}

.brand-logo {
  display: block;
  height: 36px;
  width: auto;
  object-fit: contain;
}

.brand span {
  color: var(--accent);
}

.topnav {
  display: flex;
  gap: 1rem;
  flex: 1;
  flex-wrap: wrap;
}

.topnav a {
  color: var(--text);
  text-decoration: none;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  font-weight: 500;
}

.topnav a:hover {
  background: var(--surface-2);
  text-decoration: none;
  color: var(--accent);
}

.topnav a.active {
  background: var(--accent-secondary);
  color: var(--white);
}

.nav-placeholder {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0.35rem 0.5rem;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  color: var(--text);
}

.user-badge {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  background: var(--accent);
  color: var(--white);
}

/* Auth */
.auth-card {
  max-width: 400px;
  margin: 4rem auto;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-card--wide {
  max-width: 520px;
}

.payfast-form {
  margin-top: 0.5rem;
}

.payfast-summary {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
}

.payfast-amount {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

.payfast-payer {
  margin: 0 0 1rem;
}

.auth-logo-img {
  display: block;
  max-width: 90px;
  height: auto;
  margin: 0 auto 1rem;
}

.auth-logo h1 {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
  color: var(--deep-green);
  font-weight: 700;
  text-align: center;
}

.auth-logo h1 .accent,
.accent {
  color: var(--accent);
}

.auth-subheading {
  margin: 1.25rem 0 0.5rem;
  font-size: 1rem;
  color: var(--deep-green);
  font-weight: 600;
}

.auth-tagline {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
}

.setup-title {
  color: var(--deep-green);
  text-align: center;
}

.setup-title .accent {
  color: var(--accent);
}

.auth-foot {
  margin-top: 1.5rem;
  font-size: 0.8rem;
  text-align: center;
}

.auth-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 1.25rem 0 0.5rem;
  padding: 0.25rem;
  background: var(--surface-2);
  border-radius: 8px;
}

.auth-tab {
  flex: 1;
  text-align: center;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
}

.auth-tab:hover {
  color: var(--accent);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.6);
}

.auth-tab.active {
  background: var(--white);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(11, 29, 22, 0.08);
}

.auth-switch {
  margin-top: 1rem;
  font-size: 0.9rem;
  text-align: center;
}

.auth-switch a {
  font-weight: 600;
}

/* Forms */
.form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 1.25rem;
}

label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="tel"] {
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent-secondary);
  outline-offset: 1px;
  border-color: var(--accent);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--white);
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  color: var(--white);
  text-decoration: none;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent-secondary);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent-secondary);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.btn-block {
  width: 100%;
  margin-top: 0.5rem;
}

/* Alerts */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin: 0.75rem 0;
}

.alert-error {
  background: #fef2f2;
  border: 1px solid #e57373;
  color: #b71c1c;
}

.alert-info,
.alert-success {
  background: #f1f8e9;
  border: 1px solid var(--accent-secondary);
  color: var(--deep-green);
}

/* Dashboard */
.dashboard .page-header h1 {
  margin: 0 0 0.35rem;
  color: var(--deep-green);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.stat-card.placeholder {
  border-style: dashed;
  border-color: var(--accent-leaf);
  background: linear-gradient(135deg, var(--white) 0%, var(--surface-2) 100%);
}

.stat-card h2 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 600;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  margin: 0;
  color: var(--accent);
}

.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  color: var(--deep-green);
}

.placeholder-panel {
  border-style: dashed;
  border-color: var(--light-green);
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* App shell: quick actions flush left, content to the right */
.app-layout {
  display: flex;
  width: 100%;
  align-items: flex-start;
  gap: 2rem;
}

.app-sidebar {
  flex: 0 0 300px;
  width: 300px;
  padding: 1.25rem 0 1.25rem 1.25rem;
  position: sticky;
  top: 4.5rem;
  align-self: flex-start;
}

.app-main {
  flex: 1;
  min-width: 0;
}

.page-content {
  padding: 1.5rem 1.5rem 1.5rem 0;
  max-width: none;
}

body.has-app-sidebar .footer {
  margin-top: 0;
}

.quick-actions-panel {
  margin-bottom: 0;
}

.sidebar-calendar-panel {
  margin-top: 1rem;
}

.sidebar-calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.sidebar-calendar-title {
  margin: 0;
  flex: 1;
  text-align: center;
  font-size: 0.95rem;
  color: var(--deep-green);
  font-weight: 600;
}

.sidebar-calendar-header .btn {
  flex-shrink: 0;
  min-width: 2rem;
  padding-left: 0.4rem;
  padding-right: 0.4rem;
}

.sidebar-calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 0.4rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--muted);
  text-align: center;
}

.sidebar-calendar-weekdays span {
  min-width: 0;
  line-height: 1.2;
}

.sidebar-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}

.sidebar-cal-day {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  min-height: 2.35rem;
  min-width: 0;
  padding: 0.15rem 0.1rem 0.2rem;
  font-size: 0.8rem;
  line-height: 1;
  font-weight: 500;
  color: var(--text);
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
}

button.sidebar-cal-day {
  appearance: none;
}

.sidebar-cal-day.is-empty {
  background: transparent;
  border-color: transparent;
}

.sidebar-cal-day.is-today {
  background: var(--accent);
  color: var(--white);
  border-color: var(--accent-hover);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(46, 125, 50, 0.35);
}

.sidebar-cal-day:not(.is-empty):not(.is-today):hover {
  border-color: var(--accent-secondary);
  background: rgba(165, 214, 106, 0.25);
}

.sidebar-calendar-legend {
  display: flex;
  gap: 0.75rem;
  font-size: 0.7rem;
  margin: 0.35rem 0 0.25rem;
}

.sidebar-calendar-legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.sidebar-calendar-hint {
  font-size: 0.68rem;
  margin: 0 0 0.5rem;
  line-height: 1.3;
}

.cal-day-num {
  line-height: 1;
}

.cal-day-dots {
  display: flex;
  gap: 3px;
  align-items: center;
  justify-content: center;
  min-height: 5px;
}

.cal-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  font-style: normal;
}

.cal-dot-task {
  background: var(--accent);
}

.cal-dot-meeting {
  background: #1565c0;
}

.calendar-day-menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 29, 22, 0.35);
  z-index: 100;
}

.calendar-day-menu {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 101;
  width: min(280px, calc(100vw - 2rem));
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.calendar-day-menu-title {
  margin: 0 0 1rem;
  font-weight: 600;
  color: var(--deep-green);
  font-size: 0.95rem;
}

.calendar-day-menu-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.calendar-day-menu-actions .btn {
  width: 100%;
  justify-content: center;
}

.calendar-day-menu-close {
  width: 100%;
}

.list-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.list-pagination-info {
  font-size: 0.9rem;
  color: var(--muted);
}

.list-pagination [aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

.reminder-fieldset {
  margin: 1.25rem 0 0;
  padding: 1rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.reminder-fieldset legend {
  font-weight: 600;
  color: var(--deep-green);
  padding: 0 0.35rem;
}

.reminder-fieldset p {
  margin: 0 0 0.65rem;
  line-height: 1.45;
}

.reminder-email-missing {
  padding: 0.65rem 0.75rem;
  font-size: 0.85rem;
}

.reminder-email-to {
  font-size: 0.85rem;
}

.reminder-choice {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.25rem;
  width: 100%;
}

.reminder-fieldset .reminder-radio {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  width: 100%;
  margin: 0;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  box-sizing: border-box;
}

.reminder-fieldset .reminder-radio:hover {
  background: rgba(255, 255, 255, 0.65);
  border-color: var(--border);
}

.reminder-fieldset .reminder-radio input[type="radio"] {
  width: 1rem;
  min-width: 1rem;
  height: 1rem;
  margin: 0.15rem 0 0;
  padding: 0;
  flex-shrink: 0;
  display: inline-block;
  accent-color: var(--accent);
}

.admin-form .reminder-fieldset input[type="radio"] {
  width: 1rem;
  min-width: 1rem;
  display: inline-block;
}

.reminder-radio-text {
  flex: 1;
  min-width: 0;
}

.reminder-datetime-wrap label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.reminder-hint,
.reminder-scheduled {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
}

.reminder-scheduled {
  color: var(--accent);
  font-weight: 500;
}

.admin-email-test {
  margin-bottom: 1.25rem;
}

.admin-email-test h2 {
  margin-top: 0;
}

.admin-email-test .inline-form {
  margin-top: 0.75rem;
}

.crm-form-split {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 320px);
  gap: 1.25rem 1.5rem;
  align-items: start;
}

.crm-form-main {
  min-width: 0;
}

.crm-form-reminder {
  min-width: 0;
}

.crm-form-reminder .reminder-fieldset {
  margin: 0;
  height: 100%;
}

.required-mark {
  color: #c62828;
  font-weight: 700;
}

.reminder-required-note {
  font-size: 0.8rem;
  margin: 0 0 0.5rem;
}

@media (max-width: 900px) {
  .crm-form-split {
    grid-template-columns: 1fr;
  }
}

.quick-actions-panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

.action-row-vertical {
  flex-direction: column;
  align-items: stretch;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.crm-page .page-header.admin-header,
.dashboard .page-header {
  margin-bottom: 1rem;
}

@media (max-width: 900px) {
  .app-layout {
    flex-direction: column;
  }

  .app-sidebar {
    position: static;
    flex: none;
    width: 100%;
    padding: 1rem 1.25rem 0;
  }

  .page-content {
    padding: 1rem 1.25rem 1.5rem;
  }

  .action-row-vertical {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .action-row-vertical .btn-block {
    width: auto;
  }
}

.meta-list {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
}

.meta-list dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.meta-list dd {
  margin: 0;
  color: var(--text);
}

.footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

.footer strong {
  color: var(--deep-green);
}

/* Admin */
.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.subscription-cell {
  font-size: 0.9rem;
}

.subscription-warning {
  color: #b45309;
  font-weight: 600;
}

.terms-accepted-flag {
  display: inline-block;
  margin-top: 0.15rem;
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.admin-form-panel {
  max-width: 520px;
}

.crm-form-panel {
  max-width: 960px;
  width: 100%;
}

.crm-form-panel .form {
  margin-top: 0.75rem;
}

.admin-form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]),
.admin-form select,
.admin-form textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.4;
}

.admin-form select {
  cursor: pointer;
  appearance: auto;
}

.admin-form textarea {
  min-height: 5rem;
  resize: vertical;
}

.admin-form input[type="number"] {
  appearance: textfield;
}

.admin-form input[type="date"] {
  min-height: 2.75rem;
}

.address-fieldset {
  margin: 0.5rem 0 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.address-fieldset legend {
  font-weight: 600;
  color: var(--deep-green);
  padding: 0 0.35rem;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
  font-size: 0.95rem;
}

.form-hint {
  margin: -0.25rem 0 0.5rem;
  font-size: 0.85rem;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table tbody tr:hover {
  background: var(--surface-2);
}

.row-inactive {
  opacity: 0.65;
}

.role-pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.role-superuser {
  background: var(--accent);
  color: var(--white);
}

.role-admin {
  background: var(--accent-secondary);
  color: var(--deep-green);
}

.role-sales {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.status-active {
  color: var(--accent);
  font-weight: 600;
}

.status-inactive {
  color: var(--muted);
}

.account-status-pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.account-status-pending {
  background: #fff8e1;
  color: #f57f17;
}

.account-status-active {
  background: #e8f5e9;
  color: var(--accent);
}

.account-status-rejected {
  background: #ffebee;
  color: #c62828;
}

.account-status-suspended {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.admin-user-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.admin-user-filters__field {
  flex: 1 1 160px;
  min-width: 140px;
}

.admin-user-filters__field label {
  display: block;
  margin-bottom: 0.25rem;
}

.admin-user-filters__field input,
.admin-user-filters__field select {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
}

.admin-user-filters__actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.admin-results-meta {
  margin: 0 0 0.75rem;
}

.admin-actions-cell {
  max-width: 280px;
  white-space: normal;
}

.admin-actions-cell .inline-form {
  display: inline-block;
  margin: 0.15rem 0.25rem 0.15rem 0;
}

.admin-notify-form {
  max-width: 420px;
}

.admin-user-table-wrap {
  overflow-x: auto;
}

.actions-cell {
  white-space: nowrap;
}

.inline-form {
  display: inline;
}

.btn-danger {
  background: #c62828;
  color: var(--white);
}

.btn-danger:hover:not(:disabled) {
  background: #b71c1c;
  color: var(--white);
  text-decoration: none;
}

/* CRM pages */
.crm-page .page-header h1 {
  color: var(--deep-green);
}

.panel-list {
  padding-top: 1rem;
}

.list-filters-collapse {
  margin-bottom: 0.75rem;
}

.filter-collapse,
.analytics-collapse {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.filter-collapse > summary,
.analytics-collapse > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
  border-radius: var(--radius);
}

.filter-collapse > summary::-webkit-details-marker,
.analytics-collapse > summary::-webkit-details-marker {
  display: none;
}

.filter-collapse-title,
.analytics-summary-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--deep-green);
}

.filter-collapse-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: rgba(102, 187, 106, 0.2);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  margin-right: auto;
  margin-left: 0.5rem;
}

.filter-collapse-chevron::before,
.analytics-summary-chevron::before {
  content: '▸';
  display: inline-block;
  color: var(--accent);
  font-size: 1.1rem;
  transition: transform 0.2s;
}

.filter-collapse[open] > summary .filter-collapse-chevron::before,
.analytics-collapse[open] > summary .analytics-summary-chevron::before {
  content: '▾';
}

.filter-collapse[open] > summary,
.analytics-collapse[open] > summary {
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}

.filter-collapse-body,
.analytics-body {
  padding: 1rem;
}

.list-filters {
  margin: 0;
}

.list-filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 140px;
}

.filter-search {
  flex: 1 1 220px;
  min-width: 200px;
}

.filter-field label {
  font-size: 0.8rem;
  color: var(--muted);
}

.list-filters .filter-field input[type="search"],
.list-filters .filter-field input[type="date"] {
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--white);
  font-size: 0.95rem;
  font-family: inherit;
}

.filter-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  padding-bottom: 0.1rem;
}

.list-filters-meta {
  margin: 0.65rem 0 0;
  font-size: 0.85rem;
}

.address-cell {
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text);
}

.small-meta {
  font-size: 0.8rem;
}

.nowrap {
  white-space: nowrap;
}

.data-table td {
  vertical-align: top;
}

.stat-link {
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s, box-shadow 0.15s;
}

.stat-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(11, 29, 22, 0.12);
  text-decoration: none;
}

.stat-money {
  font-size: 1.35rem !important;
}

.status-pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
  background: var(--surface-2);
  color: var(--deep-green);
}

.status-new { background: #e3f2fd; color: #1565c0; }
.status-contacted { background: #fff3e0; color: #e65100; }
.status-qualified { background: #f1f8e9; color: var(--accent); }
.status-lost { background: #ffebee; color: #c62828; }

.stage-prospecting { background: #e8f5e9; }
.stage-proposal { background: #f1f8e9; }
.stage-negotiation { background: #fff8e1; color: #f57f17; }
.stage-won { background: var(--accent); color: var(--white); }
.stage-lost { background: #ffcdd2; color: #b71c1c; }

.status-pending { background: #fff8e1; color: #f57f17; }
.status-in_progress { background: #e3f2fd; color: #1565c0; }
.status-completed { background: #f1f8e9; color: var(--accent); }
.status-cancelled { background: #eceff1; color: var(--muted); }
.status-scheduled { background: #e8f5e9; color: var(--accent-hover); }

.priority-pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.priority-low { background: #eceff1; color: var(--muted); }
.priority-medium { background: #fff3e0; color: #e65100; }
.priority-high { background: #ffebee; color: #c62828; }

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.activity-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.activity-list li:last-child {
  border-bottom: none;
}

/* Reports & charts */
.chart-style-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chart-style-form select {
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--white);
  font-weight: 600;
  color: var(--accent);
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

.chart-panel h2 {
  margin-bottom: 0.75rem;
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.chart-wrap-tall {
  height: 300px;
}

.chart-wide {
  grid-column: 1 / -1;
}

.report-summary {
  margin-bottom: 1.5rem;
}

.dashboard-charts {
  margin: 1.5rem 0 2rem;
}

.analytics-collapse > summary {
  padding: 0.85rem 1.15rem;
}

.analytics-summary-title {
  font-size: 1.1rem;
}

.analytics-body {
  padding: 1rem 1.15rem 1.15rem;
}

.analytics-style-form {
  margin-bottom: 1rem;
}

.charts-grid-compact {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.chart-panel-compact {
  padding: 0.65rem 0.75rem;
  margin-bottom: 0;
}

.chart-panel-compact h3 {
  margin: 0 0 0.4rem;
  font-size: 0.78rem;
  color: var(--deep-green);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-wrap-compact {
  height: 150px;
}

.chart-panel-monthly {
  margin-bottom: 0;
}

.chart-panel-monthly h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--deep-green);
  font-weight: 600;
}

.chart-panel h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  color: var(--deep-green);
  font-weight: 600;
}

@media (max-width: 520px) {
  .charts-grid-compact {
    grid-template-columns: 1fr;
  }

  .chart-wrap-compact {
    height: 180px;
  }
}

@media (max-width: 600px) {
  .auth-card {
    margin: 2rem auto;
    padding: 1.25rem;
  }

  .user-menu {
    width: 100%;
    justify-content: flex-end;
  }

  .actions-cell .btn {
    display: block;
    margin: 0.25rem 0;
  }

  .topnav {
    width: 100%;
  }
}

/* CRM entity edit pages — form on the left, reminder + documents stacked in a right-side aside */
.crm-edit-stack {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 320px);
  gap: 1rem 1.5rem;
  max-width: 960px;
  align-items: start;
}

.crm-edit-stack:not(:has(> aside)) {
  grid-template-columns: 1fr;
}

.crm-edit-main {
  min-width: 0;
  margin: 0;
}

.crm-edit-side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.crm-edit-side-panel {
  margin: 0;
}

.crm-edit-reminder-panel .reminder-fieldset {
  margin: 0;
  border: none;
  padding: 0;
}

.crm-edit-reminder-panel .reminder-fieldset > legend {
  padding: 0;
  margin: 0 0 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--deep-green);
}

@media (max-width: 900px) {
  .crm-edit-stack {
    grid-template-columns: 1fr;
  }
}

/* Documents (attachments) section */
.documents-panel {
  margin-top: 1rem;
}

.crm-edit-side .documents-panel {
  margin-top: 0;
}

.documents-section-head {
  margin-bottom: 0.75rem;
}

.documents-section-head h3 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  color: var(--text);
}

.documents-section-hint {
  margin: 0;
  font-size: 0.9rem;
}

.documents-empty {
  margin: 0.5rem 0 1rem;
  font-size: 0.9rem;
}

.documents-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow: hidden;
}

.documents-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: var(--white);
}

.documents-item:last-child {
  border-bottom: none;
}

.documents-item-main {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.documents-item-name {
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}

.documents-item-name:hover {
  text-decoration: underline;
  color: var(--accent-hover);
}

.documents-item-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.documents-item-size,
.documents-item-when {
  font-size: 0.8rem;
}

.documents-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  line-height: 1.4;
}

.documents-badge-document {
  background: #e8f1e8;
  color: var(--accent-hover);
}

.documents-badge-quote {
  background: #fff3cd;
  color: #8a6d1a;
}

.documents-item-actions {
  flex-shrink: 0;
}

.documents-upload-form {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  background: var(--surface-2);
}

.documents-upload-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.75rem;
}

.documents-upload-file,
.documents-upload-category {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1 1 220px;
  min-width: 0;
}

.documents-upload-category {
  flex: 0 1 180px;
}

.documents-upload-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.documents-upload-form input[type="file"],
.documents-upload-form select {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

.documents-upload-submit {
  flex: 0 0 auto;
  align-self: end;
}

.documents-upload-hint {
  margin: 0.65rem 0 0;
  font-size: 0.8rem;
}

@media (max-width: 600px) {
  .documents-item {
    flex-direction: column;
    align-items: stretch;
  }

  .documents-item-actions {
    align-self: flex-end;
  }

  .documents-upload-row {
    flex-direction: column;
    align-items: stretch;
  }

  .documents-upload-submit {
    align-self: stretch;
  }
}

/* ==========================================================================
   Mobile optimisations
   - Hamburger menu in topbar
   - Collapsible Quick-actions sidebar
   - Larger touch targets, 16px form fields (prevent iOS auto-zoom)
   - Responsive grids, tighter page padding, table scroll cues
   ========================================================================== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Hide the mobile-menu checkbox; only the label is visible */
.mobile-menu-toggle {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-left: auto;
  cursor: pointer;
  border-radius: 8px;
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--surface);
}

.mobile-menu-btn:hover {
  background: var(--surface-2);
}

.burger-icon,
.burger-icon::before,
.burger-icon::after {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.burger-icon {
  position: relative;
}

.burger-icon::before,
.burger-icon::after {
  content: '';
  position: absolute;
  left: 0;
}

.burger-icon::before { top: -7px; }
.burger-icon::after  { top:  7px; }

.mobile-menu-toggle:checked + .mobile-menu-btn .burger-icon {
  background: transparent;
}

.mobile-menu-toggle:checked + .mobile-menu-btn .burger-icon::before {
  transform: translateY(7px) rotate(45deg);
}

.mobile-menu-toggle:checked + .mobile-menu-btn .burger-icon::after {
  transform: translateY(-7px) rotate(-45deg);
}

/* Desktop: collapse wrapper is just a flex container */
.topbar-collapse {
  display: contents;
}

/* Sidebar collapse defaults to "no chrome" on desktop */
.sidebar-collapse {
  display: block;
}

.sidebar-collapse > .sidebar-collapse-summary {
  display: none;
}

.sidebar-collapse[open] > .sidebar-collapse-body,
.sidebar-collapse > .sidebar-collapse-body {
  display: block;
}

/* Tablet & smaller */
@media (max-width: 768px) {
  /* Topbar */
  .topbar {
    padding: 0.6rem 1rem;
    gap: 0.6rem;
  }

  .brand {
    font-size: 1rem;
  }

  .brand-logo {
    height: 30px;
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

  .topbar-collapse {
    display: none;
    flex-basis: 100%;
    width: 100%;
    order: 99;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.25rem;
  }

  .mobile-menu-toggle:checked ~ .topbar-collapse {
    display: flex;
  }

  .topnav {
    flex-direction: column;
    gap: 0.25rem;
    width: 100%;
  }

  .topnav a {
    padding: 0.75rem 0.85rem;
    font-size: 1rem;
    border-radius: 8px;
  }

  .user-menu {
    width: 100%;
    flex-wrap: wrap;
    margin-left: 0;
    padding-top: 0.4rem;
    border-top: 1px solid var(--border);
    gap: 0.5rem;
  }

  .user-menu .btn {
    flex: 1 1 auto;
  }

  /* Sidebar — collapsible */
  .sidebar-collapse > .sidebar-collapse-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    list-style: none;
    cursor: pointer;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-weight: 600;
    color: var(--deep-green);
    user-select: none;
  }

  .sidebar-collapse > .sidebar-collapse-summary::-webkit-details-marker {
    display: none;
  }

  .sidebar-collapse-chevron {
    transition: transform 0.2s ease;
  }

  .sidebar-collapse[open] .sidebar-collapse-chevron {
    transform: rotate(180deg);
  }

  .sidebar-collapse-body {
    margin-top: 0.75rem;
  }

  /* On mobile we want the sidebar closed by default to save space.
     The <details open> in PHP keeps it open on desktop via the rule above;
     here we explicitly override so the same markup works on phones. */
  .sidebar-collapse:not([data-keep-open]) {
    /* nothing — user expands as needed */
  }

  /* App shell tightening */
  .app-layout {
    gap: 0.75rem;
  }

  .app-sidebar {
    padding: 0.75rem 1rem 0;
  }

  .page-content {
    padding: 0.75rem 1rem 1.25rem;
  }

  .page,
  .page-auth {
    padding: 1rem;
  }

  /* Sticky topbar shouldn't shove the page when collapsed */
  .topbar {
    position: sticky;
    top: 0;
  }

  /* Headings and meta */
  .page-header h1 {
    font-size: 1.4rem;
  }

  .stat-value {
    font-size: 1.6rem;
  }

  /* Stats grid: max 2 columns at this width */
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 1rem 0;
  }

  .stat-card {
    padding: 0.9rem;
  }

  /* Panels: less padding */
  .panel {
    padding: 1rem;
  }

  /* Forms — 16px inputs prevent iOS auto-zoom; bigger tap area */
  input[type="text"],
  input[type="password"],
  input[type="email"],
  input[type="number"],
  input[type="date"],
  input[type="datetime-local"],
  input[type="tel"],
  input[type="search"],
  input[type="url"],
  select,
  textarea {
    font-size: 16px;
    padding: 0.7rem 0.85rem;
    width: 100%;
    box-sizing: border-box;
  }

  .form,
  .admin-form {
    gap: 0.85rem;
  }

  .form-actions,
  .action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .form-actions .btn,
  .action-row > .btn {
    width: 100%;
  }

  /* Buttons — meet 44px touch target */
  .btn {
    min-height: 44px;
    padding: 0.65rem 1rem;
  }

  .btn-sm {
    min-height: 38px;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
  }

  /* Tables — horizontal scroll with a faint right-edge hint */
  .table-wrap,
  .admin-user-table-wrap {
    margin: 0 -1rem;   /* edge-to-edge on small screens */
    padding: 0 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background:
      linear-gradient(to right, var(--surface) 30%, rgba(255,255,255,0)) 0 0,
      linear-gradient(to right, rgba(255,255,255,0), var(--surface) 70%) 100% 0,
      radial-gradient(farthest-side at 100% 50%, rgba(11,29,22,0.18), rgba(11,29,22,0)) 100% 0;
    background-repeat: no-repeat;
    background-size: 28px 100%, 28px 100%, 14px 100%;
    background-attachment: local, local, scroll;
  }

  .data-table {
    font-size: 0.95rem;
    min-width: 540px; /* force scroll on phones */
  }

  .data-table th,
  .data-table td {
    padding: 0.75rem 0.65rem;
  }

  .actions-cell,
  .admin-actions-cell {
    white-space: normal;
    max-width: none;
  }

  .actions-cell .btn,
  .admin-actions-cell .btn {
    display: block;
    width: 100%;
    margin: 0.2rem 0;
  }

  .admin-actions-cell .inline-form {
    display: block;
    margin: 0.2rem 0;
  }

  /* Filters — full-width fields */
  .admin-user-filters,
  .admin-user-filters__actions,
  .list-filters-row,
  .filter-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-user-filters__field,
  .filter-field {
    flex: 1 1 auto;
    width: 100%;
  }

  .admin-user-filters__actions .btn,
  .filter-actions .btn {
    width: 100%;
  }

  /* Meta lists — stack key/value */
  .meta-list {
    grid-template-columns: 1fr;
    gap: 0.25rem 0;
  }

  .meta-list dt {
    margin-top: 0.5rem;
  }

  /* Documents upload — full-width controls already collapse at 600px */
  /* Reminder + Documents stack already collapses via .crm-edit-stack rule */

  /* Auth */
  .auth-card {
    margin: 1rem 0.75rem;
    padding: 1.25rem;
  }

  /* Charts */
  .chart-wrap-compact {
    height: 200px;
  }
}

/* Phones */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    padding: 0.55rem 0.75rem;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .page-header .btn,
  .report-actions .btn {
    width: 100%;
  }

  .report-actions {
    justify-content: stretch;
  }

  .panel {
    padding: 0.85rem;
  }

  /* Tighter table padding */
  .data-table {
    font-size: 0.92rem;
  }

  .data-table th,
  .data-table td {
    padding: 0.6rem 0.55rem;
  }

  /* Hide truly secondary muted columns on the smallest screens to reduce side-scroll */
  .data-table .hide-on-mobile,
  .data-table th.hide-on-mobile,
  .data-table td.hide-on-mobile {
    display: none;
  }
}

/* Larger screens — keep the sidebar always open (override the <details> behaviour) */
@media (min-width: 769px) {
  .sidebar-collapse > .sidebar-collapse-body {
    display: block !important;
  }
}

/* Terms and Conditions */
.terms-accept {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  margin: 0.5rem 0 0.25rem;
  font-size: 0.92rem;
  color: var(--text);
  font-weight: 500;
}

.terms-accept input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-top: 0.15rem;
  accent-color: var(--accent);
}

.terms-accept a {
  font-weight: 600;
}

.terms-page {
  margin: 2rem auto;
  max-width: 760px;
  padding: 2rem;
  line-height: 1.55;
}

.terms-page .terms-header {
  margin-bottom: 1.25rem;
  text-align: center;
}

.terms-page .terms-header h1 {
  margin: 0 0 0.25rem;
  color: var(--deep-green);
  font-size: 1.6rem;
}

.terms-page h2 {
  color: var(--deep-green);
  margin: 1.5rem 0 0.5rem;
  font-size: 1.15rem;
}

.terms-page h3 {
  color: var(--deep-green);
  margin: 1rem 0 0.4rem;
  font-size: 1rem;
}

.terms-page ul {
  padding-left: 1.25rem;
  margin: 0.25rem 0 0.85rem;
}

.terms-page li {
  margin: 0.15rem 0;
}

.terms-page hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.terms-footer-link {
  margin-top: 1.5rem;
  text-align: center;
}

@media (max-width: 600px) {
  .terms-page {
    margin: 1rem 0.5rem;
    padding: 1.25rem;
  }
}
