:root {
  --brand: #1c5d3f;
  --brand-dark: #133f2b;
  --available: #1c7a3e;
  --reserved: #b7791f;
  --sold: #2b6cb0;
  --unavailable: #a02020;
  --bg: #eef2ee;
  --border: #dcdfdb;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* A real branded canvas, not a barely-there tint — main content floats on
     top of this as its own white surface (see the `main` rule below). */
  background:
    radial-gradient(circle at 12% 8%, rgba(255,255,255,0.10), transparent 42%),
    radial-gradient(circle at 88% 92%, rgba(255,206,122,0.12), transparent 45%),
    linear-gradient(160deg, #0d3021 0%, #1c5d3f 38%, #2f7a54 68%, #1c5d3f 100%);
  background-attachment: fixed;
  color: #1a1a1a;
}


.center-screen, .login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-screen {
  padding: 20px;
  /* Layers paint top-to-bottom: a dark brand-tinted wash (keeps the white
     card legible), then an optional real photo, then a gradient fallback
     that's used automatically if no photo is present. Drop an estate photo
     at assets/img/login-bg.jpg and it takes over with no code changes. */
  background:
    linear-gradient(160deg, rgba(19,63,43,0.80), rgba(9,28,19,0.90)),
    url('../img/login-bg.jpg') center/cover no-repeat,
    radial-gradient(circle at 15% 15%, #2f8a5c, transparent 55%),
    linear-gradient(135deg, var(--brand-dark), #0a2417);
  background-size: cover;
}

.login-card {
  background: #fff;
  padding: 40px;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
  width: 340px;
  max-width: 100%;
}
.login-card h1 { margin: 0 0 4px; color: var(--brand-dark); }
.login-card .subtitle { margin: 0 0 24px; color: #666; font-size: 14px; }
.login-card label { display: block; font-size: 13px; margin: 12px 0 4px; color: #444; }
.login-card input {
  width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
}
.login-card button {
  margin-top: 20px; width: 100%; padding: 11px; background: var(--brand); color: #fff;
  border: none; border-radius: 6px; font-size: 15px; cursor: pointer;
}
.login-card button:hover { background: var(--brand-dark); }
.error { color: var(--unavailable); font-size: 13px; }

.topbar {
  background: linear-gradient(115deg, var(--brand-dark), #1a4a33);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 56px;
  gap: 24px;
}
.brand { font-weight: 700; cursor: pointer; letter-spacing: 0.5px; }
.mobile-nav-toggle { display: none; }
.mobile-nav-toggle, .mobile-nav-panel { display: none; }
.topbar nav { display: flex; gap: 8px; flex: 1; }
.topbar nav button {
  background: transparent; border: none; color: #cfe0d6; padding: 8px 14px;
  border-radius: 6px; cursor: pointer; font-size: 14px;
}
.topbar nav button.active, .topbar nav button:hover { background: rgba(255,255,255,0.12); color: #fff; }

.nav-dropdown { position: relative; }
.nav-dropdown-toggle {
  background: transparent; border: none; color: #cfe0d6; padding: 8px 14px;
  border-radius: 6px; cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 4px;
}
.nav-dropdown-toggle.active, .nav-dropdown-toggle:hover { background: rgba(255,255,255,0.12); color: #fff; }
.nav-caret { font-size: 10px; opacity: 0.8; }
.nav-dropdown-menu {
  position: absolute; top: calc(100% + 4px); left: 0; background: #fff; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25); padding: 6px; display: flex; flex-direction: column;
  min-width: 180px; z-index: 50;
}
.topbar .nav-dropdown-menu button {
  background: none; border: none; text-align: left; padding: 9px 12px; border-radius: 6px;
  cursor: pointer; font-size: 14px; font-weight: 500; color: #12271b; white-space: nowrap;
}
.topbar .nav-dropdown-menu button.active, .topbar .nav-dropdown-menu button:hover { background: #dcece1; color: #0c1c13; }

.user-badge { font-size: 13px; display: flex; align-items: center; gap: 12px; color: #cfe0d6; }

.global-search { position: relative; }
.global-search input {
  width: 260px; padding: 8px 30px 8px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.12); color: #fff; font-size: 13px;
}
.global-search input::placeholder { color: #cfe0d6; }
.global-search input:focus { outline: none; background: rgba(255,255,255,0.2); }
.search-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: #cfe0d6; font-size: 18px; cursor: pointer; line-height: 1;
}
.global-search-results {
  position: absolute; top: calc(100% + 6px); left: 0; width: 320px; max-height: min(420px, 60vh); overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.3); padding: 6px; z-index: 90;
}
.search-group-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: #888; padding: 8px 10px 4px; }
.search-result { padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13.5px; color: #14291d; }
.search-result:hover { background: #eef5f0; }
.search-result.no-click { cursor: default; }
.search-result.no-click:hover { background: none; }
.search-result span { display: block; font-size: 12px; margin-top: 1px; }
.link-btn { background: none; border: none; color: #fff; text-decoration: underline; cursor: pointer; font-size: 13px; }

main {
  padding: 28px; max-width: 1100px; margin: 24px auto;
  background: #fdfdfc; border-radius: 16px;
  box-shadow: 0 16px 50px rgba(0,0,0,0.22);
}

.section-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin: 24px 0 12px; }
.section-header button {
  background: var(--brand); color: #fff; border: none; padding: 8px 14px; border-radius: 6px; cursor: pointer;
}
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.bulk-form { display: flex; flex-direction: column; gap: 8px; }
.bulk-row { display: flex; flex-wrap: wrap; gap: 8px; }
.bulk-row input, .bulk-row select { flex: 1; min-width: 120px; }
.bulk-result { background: #eef7ee; border: 1px solid var(--available); border-radius: 6px; padding: 10px 14px; margin: 10px 0; font-size: 13px; }

.bulk-status-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  background: #f3f6f3; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; margin: 12px 0;
}
.bulk-status-count { font-weight: 600; font-size: 13px; color: var(--brand); }

.status-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 16px 0 32px; }
.stat-card { background: #fff; border-radius: 8px; padding: 18px; text-align: center; border-top: 4px solid #ccc; }
.stat-card .num { font-size: 28px; font-weight: 700; }
.stat-card.available { border-color: var(--available); }
.stat-card.reserved { border-color: var(--reserved); }
.stat-card.sold { border-color: var(--sold); }
.stat-card.unavailable { border-color: var(--unavailable); }

.my-work-panel {
  background: linear-gradient(135deg, var(--brand-dark), #143a28);
  border-radius: 10px; padding: 18px 20px; margin: 16px 0 28px;
}
.my-work-panel h3 { color: #fff; margin: 0 0 12px; font-size: 15px; letter-spacing: 0.3px; }
.my-work-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.work-card {
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15); border-radius: 8px;
  padding: 14px 16px; cursor: pointer; transition: background 0.15s;
}
.work-card:hover { background: rgba(255,255,255,0.16); }
.work-card .num { font-size: 24px; font-weight: 700; color: #fff; }
.work-card div:last-child { font-size: 12.5px; color: #cfe0d6; margin-top: 2px; }
.work-card.attention { border-color: var(--reserved); }
.work-card.attention .num { color: #ffce7a; }

.crm-board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.crm-column { background: #eef1ee; border-radius: 8px; padding: 10px; min-width: 220px; flex: 1; }
.crm-column-header { font-weight: 600; font-size: 13px; margin-bottom: 8px; padding: 0 2px; }
.crm-card {
  background: #fff; border-radius: 6px; padding: 10px 12px; margin-bottom: 8px;
  cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,0.08); border-left: 3px solid var(--brand);
}
.crm-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.crm-card.overdue { border-left-color: var(--unavailable); }
.crm-card-name { font-weight: 600; font-size: 14px; }
.crm-card-meta { font-size: 12px; color: #666; margin-top: 2px; }
.crm-card-followup { font-size: 12px; margin-top: 4px; color: var(--reserved); }
.crm-card.overdue .crm-card-followup { color: var(--unavailable); font-weight: 600; }
.overdue-text { color: var(--unavailable); font-weight: 600; }

.data-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
.data-table th { background: #eef1ee; font-weight: 600; }
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: #f0f4f1; }

.badge { padding: 3px 9px; border-radius: 12px; font-size: 12px; color: #fff; text-transform: capitalize; }
.badge-available { background: var(--available); }
.badge-reserved { background: var(--reserved); }
.badge-sold { background: var(--sold); }
.badge-unavailable { background: var(--unavailable); }
.badge-active { background: #4a5568; }
.badge-fully_sold { background: var(--sold); }
.badge-archived { background: #999; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.estate-card {
  background: #fff; border-radius: 10px; padding: 18px; cursor: pointer;
  border: 1px solid #dde3de; box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  border-top: 4px solid var(--brand); transition: transform 0.12s, box-shadow 0.12s;
}
.estate-card:hover { box-shadow: 0 8px 20px rgba(0,0,0,0.14); transform: translateY(-2px); border-color: var(--brand); }
.estate-card h3 { margin: 0 0 6px; }
.mini-counts { margin-top: 10px; font-size: 12px; color: #555; }

.inline-form {
  background: #fff; padding: 16px; border-radius: 8px; margin-bottom: 20px;
  display: flex; flex-wrap: wrap; gap: 8px;
}
.inline-form input, .inline-form select, .inline-form textarea {
  padding: 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}
.inline-form textarea { width: 100%; min-height: 50px; }
.inline-form button {
  background: var(--brand); color: #fff; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer;
}

.back-link { background: none; border: none; color: var(--brand); cursor: pointer; padding: 0; margin-bottom: 12px; font-size: 14px; }

.estate-stats {
  display: flex; flex-wrap: wrap; gap: 14px; background: #fff; padding: 12px 16px;
  border-radius: 8px; margin: 12px 0; font-size: 14px;
}
.estate-stats .c-available { color: var(--available); }
.estate-stats .c-reserved { color: var(--reserved); }
.estate-stats .c-sold { color: var(--sold); }
.estate-stats .c-unavailable { color: var(--unavailable); }

.map-section { background: #fff; padding: 16px; border-radius: 8px; margin: 16px 0; }
.map-canvas-wrap { position: relative; display: inline-block; max-width: 100%; margin-bottom: 10px; }
.estate-map-img { max-width: 100%; border-radius: 6px; display: block; }
.estate-map-img.placing { cursor: crosshair; }

.plot-pin {
  position: absolute; transform: translate(-50%, -50%);
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: #fff;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.45);
  cursor: pointer; line-height: 1;
}
.plot-pin.pin-available { background: var(--available); }
.plot-pin.pin-reserved { background: var(--reserved); }
.plot-pin.pin-sold { background: var(--sold); }
.plot-pin.pin-unavailable { background: var(--unavailable); }

.plot-popover {
  position: absolute; transform: translate(-50%, -110%);
  background: #fff; border: 1px solid #ddd; border-radius: 8px;
  padding: 10px 12px; min-width: 170px; box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  z-index: 20; font-size: 13px; display: flex; flex-direction: column; gap: 6px;
}
.plot-popover select { width: 100%; }
.popover-actions { display: flex; justify-content: space-between; margin-top: 2px; }

.danger-btn { background: var(--unavailable) !important; color: #fff; }
.danger-link { color: var(--unavailable) !important; }

.comment-list { list-style: none; padding: 0; margin: 8px 0; max-height: 220px; overflow-y: auto; }
.comment-list li { border-bottom: 1px solid #eee; padding: 6px 0; }
.comment-list li:last-child { border-bottom: none; }
.comment-meta { font-size: 11px; color: #888; }
.comment-form { margin-bottom: 16px; }
.comment-form textarea { width: 100%; min-height: 50px; }

.plot-placement-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 8px; font-size: 13px; }
.plot-placement-tools select { margin-left: 6px; }
.plot-position-line { font-size: 13px; margin-bottom: 10px; }

.muted { color: #888; font-size: 13px; }

.action-cell { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.small-btn {
  background: var(--brand); color: #fff; border: none; padding: 5px 10px; border-radius: 5px;
  font-size: 12px; cursor: pointer;
}
.small-btn.danger { background: var(--unavailable); }
.link-btn-inline { background: none; border: none; color: var(--brand); text-decoration: underline; cursor: pointer; font-size: 12px; }

.expand-panel { background: #f8faf8; padding: 14px; border-left: 3px solid var(--brand); }
.doc-list { list-style: none; padding: 0; margin: 10px 0 0; font-size: 13px; }
.doc-list li { padding: 6px 0; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.doc-list a { margin-left: auto; color: var(--brand); }

.badge-doc-full { background: #2b6cb0; color: #fff; padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.badge-doc-division { background: #6b46c1; color: #fff; padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.badge-doc-view_only { background: #b7791f; color: #fff; padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.badge-doc-restricted { background: #718096; color: #fff; padding: 2px 8px; border-radius: 10px; font-size: 11px; }

.badge-res-pending { background: #b7791f; color: #fff; padding: 3px 9px; border-radius: 12px; font-size: 12px; }
.badge-res-approved { background: #1c7a3e; color: #fff; padding: 3px 9px; border-radius: 12px; font-size: 12px; }
.badge-res-rejected { background: #a02020; color: #fff; padding: 3px 9px; border-radius: 12px; font-size: 12px; }
.badge-res-expired { background: #718096; color: #fff; padding: 3px 9px; border-radius: 12px; font-size: 12px; }
.badge-res-converted { background: #2b6cb0; color: #fff; padding: 3px 9px; border-radius: 12px; font-size: 12px; }
.badge-res-released { background: #999; color: #fff; padding: 3px 9px; border-radius: 12px; font-size: 12px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: #fff; padding: 24px; border-radius: 10px; width: 380px; max-width: 90vw;
  max-height: 85vh; overflow-y: auto;
}
.modal h3 { margin-top: 0; }
.modal label { display: block; font-size: 13px; margin: 10px 0 4px; color: #444; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.secondary-btn { background: #e2e8f0; color: #333; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; }
.secondary-btn.active { background: var(--brand); color: #fff; }

.title-transfer-block { background: #fff; border-radius: 6px; padding: 12px; margin-bottom: 16px; border: 1px solid var(--border); }
.stage-actions { margin: 8px 0; }

.settings-form { background: #fff; padding: 20px; border-radius: 8px; max-width: 480px; }
.settings-form h3 { margin: 20px 0 8px; font-size: 15px; color: var(--brand-dark); }
.settings-form h3:first-child { margin-top: 0; }
.settings-form label { display: block; font-size: 13px; margin: 10px 0 4px; color: #444; }
.settings-form input[type="checkbox"] { width: auto; display: inline-block; margin-right: 6px; }
.settings-form input {
  width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}
.settings-form button {
  margin-top: 20px; background: var(--brand); color: #fff; border: none; padding: 10px 18px;
  border-radius: 6px; cursor: pointer;
}

/* ==========================================================================
   Mobile responsiveness
   ========================================================================== */

@media (max-width: 768px) {
  main { padding: 16px; margin: 10px; border-radius: 12px; }

  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 14px;
    gap: 10px;
    position: relative;
  }
  /* Desktop dropdown nav is replaced entirely by the hamburger drawer on
     mobile — dropdown panels clipped by this bar's own horizontal scroll
     depending on scroll position, which is what made mobile nav feel broken. */
  .topbar > nav { display: none; }
  .mobile-nav-toggle {
    display: block; background: none; border: none; color: #fff; font-size: 22px;
    cursor: pointer; padding: 4px 10px; line-height: 1;
  }
  .mobile-nav-panel {
    position: absolute; top: 100%; left: 0; right: 0; background: var(--brand-dark);
    display: flex; flex-direction: column; padding: 8px; box-shadow: 0 10px 30px rgba(0,0,0,0.35);
    z-index: 70; max-height: 75vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  }
  .mobile-nav-panel button {
    background: none; border: none; color: #fff; text-align: left; padding: 13px 14px;
    font-size: 15px; border-radius: 6px; min-height: 44px;
  }
  .mobile-nav-panel button.active, .mobile-nav-panel button:hover { background: rgba(255,255,255,0.15); }
  .mobile-nav-section-label {
    color: #9fc2ac; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px;
    padding: 12px 14px 2px; border-top: 1px solid rgba(255,255,255,0.1); margin-top: 4px;
  }
  .mobile-nav-section-label:first-child { border-top: none; margin-top: 0; }

  .user-badge { flex: 1 1 100%; justify-content: space-between; }
  .global-search { flex: 1 1 100%; }
  .global-search input { width: 100%; }
  .global-search-results { width: 100%; }

  .status-cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

  /* Tables scroll horizontally instead of squeezing columns unreadably */
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .data-table th, .data-table td { white-space: nowrap; }

  .modal { width: 100%; }
  .modal-actions { flex-wrap: wrap; }

  /* Larger touch targets */
  button, select { min-height: 40px; }
  .link-btn-inline, .small-btn { min-height: 34px; }

  /* Prevent iOS Safari auto-zoom-on-focus (triggered by inputs under 16px) */
  input, select, textarea { font-size: 16px !important; }

  /* Plot markers are easier to tap with a bit more size on touchscreens */
  .plot-pin { width: 28px; height: 28px; font-size: 11px; }
  .plot-popover { max-width: calc(100vw - 40px); }

  .crm-column { min-width: 200px; }
  .my-work-cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

  .search-result { min-height: 40px; display: flex; flex-direction: column; justify-content: center; }
  .search-group-label { padding-top: 10px; }

  .bulk-status-bar { flex-direction: column; align-items: stretch; }
  .bulk-status-bar select, .bulk-status-bar input { width: 100%; }

  .crm-board { gap: 10px; }
  .crm-card { padding: 12px; }

  /* Estate detail action rows and status/title-prep controls are cramped
     side-by-side on phones — stack them for legibility */
  td .link-btn-inline { display: inline-block; margin: 2px 6px 2px 0; }

  .login-card { padding: 28px 24px; }
}

@media (max-width: 480px) {
  .status-cards { grid-template-columns: 1fr 1fr; }
  .estate-stats { flex-direction: column; gap: 6px; }
  .bulk-row { flex-direction: column; }
  .bulk-row input, .bulk-row select { width: 100%; }
  .action-cell { flex-direction: column; align-items: stretch; }
  .action-cell > * { width: 100%; }
}
