:root {
  --brand: #1b4d3e;
  --brand-dark: #133a2e;
  --brand-soft: #e4efe9;
  --accent: #c8963e;
  --bg: #f4f5f3;
  --line: #e6e8e5;
  --muted: #6b716d;
  --danger: #b3261e;
}
* { box-sizing: border-box; }
/* Author styles that set display would otherwise override the [hidden] attribute */
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: #1a1a1a;
}
label { display: block; font-size: 13px; color: #555; margin: 10px 0 4px; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=datetime-local],
input[type=number], input[type=tel], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d0d2d6;
  border-radius: 6px;
  background: #fff;
}
input:disabled, select:disabled, textarea:disabled { background: #f6f7f6; color: #333; }
textarea { resize: vertical; }
button {
  cursor: pointer;
  border-radius: 6px;
  padding: 9px 16px;
  border: 1px solid #d0d2d6;
  background: #fff;
  white-space: nowrap;
}
button:hover { background: #f0f1f3; }
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.primary:hover { background: var(--brand-dark); }
button.danger { color: var(--danger); border-color: #e7b9b5; }
button.danger:hover { background: #fbe9e7; }
button.ghost { background: transparent; }
button.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: 0.55; cursor: default; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-size: 13px; }
.spacer { flex: 1; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: #fff; border-radius: 10px; padding: 2rem; width: 340px; box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
.login-brand { color: var(--brand); font-weight: 700; letter-spacing: 0.5px; font-size: 20px; margin-bottom: 4px; }
.login-card h1 { font-size: 16px; margin: 0 0 1rem; color: #444; font-weight: 500; }
.login-card button { width: 100%; margin-top: 14px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px;
  background: var(--brand); color: #fff;
  position: sticky; top: 0; z-index: 5;
}
.topbar .brand { font-weight: 600; }
.tabs { display: flex; gap: 4px; margin-left: 20px; flex-wrap: wrap; }
.tab-btn { background: transparent; border: none; color: #cfe3d9; padding: 8px 14px; border-radius: 6px; }
.tab-btn:hover { background: rgba(255,255,255,0.1); }
.tab-btn.active { background: rgba(255,255,255,0.18); color: #fff; font-weight: 500; }
.topbar .muted { color: #d4e6dc; }
.topbar button.ghost { color: #fff; border-color: rgba(255,255,255,0.4); padding: 6px 12px; }
.topbar button.ghost:hover { background: rgba(255,255,255,0.1); }

.content { max-width: 1240px; margin: 0 auto; padding: 20px; }

/* Stats + dashboard */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat-card { background: #fff; border-radius: 8px; padding: 14px 16px; }
.stat-label { font-size: 13px; color: #666; margin: 0 0 4px; }
.stat-value { font-size: 24px; font-weight: 600; margin: 0; }
.stat-value.money { color: var(--brand); }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.panel { background: #fff; border-radius: 8px; padding: 14px 16px; margin-bottom: 12px; }
.panel h3 { margin: 0 0 10px; font-size: 15px; }
.mini-row { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid #f0f0f0; font-size: 13px; cursor: pointer; }
.mini-row:last-child { border-bottom: none; }
.mini-row:hover { background: #f8faf9; }
.mini-when { width: 120px; flex-shrink: 0; color: var(--brand); font-weight: 500; }
.bar-row { display: grid; grid-template-columns: 100px 1fr 90px; gap: 8px; align-items: center; font-size: 13px; padding: 4px 0; }
.bar-track { background: #eef1ef; border-radius: 4px; height: 14px; overflow: hidden; }
.bar-fill { background: var(--brand); height: 100%; border-radius: 4px; }
.bar-num { text-align: right; color: #555; }

/* Toolbars */
.toolbar { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input[type=text] { flex: 1; min-width: 220px; }
.toolbar select { width: auto; min-width: 140px; }
.seg { display: inline-flex; border: 1px solid #d0d2d6; border-radius: 6px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 7px 12px; background: #fff; }
.seg button + button { border-left: 1px solid #d0d2d6; }
.seg button.active { background: var(--brand); color: #fff; }

/* Tables */
.table-card { background: #fff; border-radius: 8px; overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 10px 12px; color: #666; font-weight: 500; border-bottom: 1px solid #eaeaea; background: #fafafa; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { background: #f0f1f3; }
th.sort-asc::after { content: " \25B2"; font-size: 10px; }
th.sort-desc::after { content: " \25BC"; font-size: 10px; }
td { padding: 9px 12px; border-bottom: 1px solid #f0f0f0; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.num, th.num { text-align: right; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f7faf8; }
.empty { padding: 30px; text-align: center; color: var(--muted); font-size: 14px; }

.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 4px; background: #eef0f3; color: #444; }
.b-Available, .b-Completed, .b-Received, .b-Done { background: #e2f3e5; color: #1e6b30; }
.b-Reserved, .b-Booking, .b-Signed, .b-Invoiced { background: #fdf1d8; color: #8a5b0c; }
.b-Sold, .b-Rented { background: #e3edfb; color: #2a5b9c; }
.b-Withdrawn, .b-Lost, .b-Cancelled, .b-No-show { background: #fbe4e4; color: #9c2b2b; }
.b-Offer, .b-Negotiation { background: #eee6fb; color: #5a3c9c; }
.b-Scheduled, .b-Viewing, .b-Enquiry { background: #e6f0ec; color: var(--brand); }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); margin-right: 3px; }
.lock { color: var(--accent); font-size: 12px; }
.overdue { color: var(--danger); font-weight: 600; }

/* Listing cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.pcard { background: #fff; border-radius: 10px; overflow: hidden; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,0.05); display: flex; flex-direction: column; }
.pcard:hover { box-shadow: 0 3px 10px rgba(0,0,0,0.1); }
.pcard-img { height: 160px; background: #e8ebe9 center/cover no-repeat; position: relative; display: flex; align-items: center; justify-content: center; color: #9aa39e; font-size: 13px; }
.pcard-img .badge { position: absolute; top: 8px; left: 8px; }
.pcard-img .pc-count { position: absolute; bottom: 8px; right: 8px; background: rgba(0,0,0,0.55); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 10px; }
.pcard-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; }
.pc-ref { font-size: 11px; color: var(--muted); }
.pc-title { font-weight: 600; font-size: 14px; line-height: 1.3; }
.pc-price { color: var(--brand); font-weight: 600; font-size: 15px; }
.pc-meta { font-size: 12px; color: #555; }
.pc-agent { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Modals */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 10;
}
.sub-overlay { z-index: 20; }
.modal { background: #fff; border-radius: 10px; padding: 1.5rem; width: 460px; max-width: 96vw; max-height: 92vh; display: flex; gap: 16px; }
.wide-modal { width: 900px; }
.modal-body { flex: 1; min-width: 0; overflow-y: auto; max-height: calc(92vh - 3rem); padding-right: 6px; }
.modal-side { width: 140px; flex-shrink: 0; display: flex; flex-direction: column; gap: 8px; border-left: 1px solid #eee; padding-left: 16px; padding-top: 4px; }
.modal-side button { width: 100%; }
.modal h2 { margin: 0 0 2px; font-size: 17px; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: 1 / -1; }
.form-section { grid-column: 1 / -1; font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--brand); font-weight: 600; margin: 16px 0 0; padding-bottom: 4px; border-bottom: 1px solid var(--brand-soft); }
.check-row { display: flex; gap: 14px; flex-wrap: wrap; padding: 6px 0; }
.check-row label, label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; color: #333; font-size: 14px; }
.with-btn { display: flex; gap: 6px; }
.with-btn select, .with-btn input { flex: 1; min-width: 0; }
.with-btn button, .with-btn a { padding: 7px 10px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.warn-box { background: #fdf1d8; border: 1px solid #f0c96b; border-radius: 6px; padding: 8px 10px; font-size: 13px; color: #7a5a0c; margin-top: 6px; }
.info-box { background: var(--brand-soft); border-radius: 6px; padding: 8px 10px; font-size: 13px; color: var(--brand-dark); margin: 8px 0; }
.call-btn, .wa-btn { display: inline-flex; align-items: center; color: #fff; padding: 7px 10px; border-radius: 6px; text-decoration: none; font-size: 13px; white-space: nowrap; }
.call-btn { background: #1f8a4c; }
.wa-btn { background: #25d366; }
.divider { border: none; border-top: 1px solid #eee; margin: 18px 0 10px; }
.sub-h { font-size: 14px; margin: 0 0 8px; }
.history-item { font-size: 13px; padding: 6px 0; border-bottom: 1px solid #f0f0f0; }
.history-item:last-child { border-bottom: none; }
.related-list .mini-row { cursor: pointer; }
.temp-password { font-family: "Courier New", monospace; font-size: 20px; font-weight: 600; background: #f4f5f7; border: 1px dashed #c8cbd1; border-radius: 6px; padding: 10px 14px; text-align: center; margin: 10px 0; }

/* Photos */
.photo-rule { background: #fff7e8; border: 1px solid #f0d49b; border-radius: 6px; padding: 8px 10px; font-size: 13px; color: #6d4c0c; margin-bottom: 8px; }
.photo-upload { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.photo-tile { position: relative; border-radius: 6px; overflow: hidden; background: #eee; aspect-ratio: 4 / 3; cursor: zoom-in; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile .pt-actions { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; padding: 4px; background: linear-gradient(transparent, rgba(0,0,0,0.55)); }
.photo-tile .pt-actions button { padding: 2px 7px; font-size: 11px; background: rgba(255,255,255,0.9); border: none; }
.photo-tile .cover-tag { position: absolute; top: 4px; left: 4px; background: var(--brand); color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 8px; }

.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 40; display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 92vw; max-height: 90vh; object-fit: contain; }
.lb-close, .lb-nav { position: absolute; background: rgba(255,255,255,0.15); color: #fff; border: none; font-size: 28px; line-height: 1; padding: 8px 14px; }
.lb-close { top: 14px; right: 14px; }
.lb-prev { left: 14px; top: 50%; }
.lb-next { right: 14px; top: 50%; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 50; }
.toast.err { background: var(--danger); }

/* Responsive: tablet and mobile */
.view-toggle { display: inline-flex; }
.view-toggle button { border-radius: 0; margin: 0; }
.view-toggle button:first-child { border-radius: 6px 0 0 6px; }
.view-toggle button:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
.view-toggle button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.kanban { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.kanban[hidden] { display: none; }
.kcol { flex: 0 0 230px; background: #f1f3f5; border-radius: 8px; padding: 8px; min-height: 120px; }
.kcol.over { background: #dfece6; outline: 2px dashed var(--brand); }
.kcol-head { display: flex; justify-content: space-between; align-items: center; padding: 2px 2px 8px; font-size: 12px; }
.kcol-body { display: flex; flex-direction: column; gap: 8px; }
.kcard { background: #fff; border: 1px solid #e1e4e8; border-radius: 6px; padding: 8px 10px; cursor: grab; font-size: 13px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.kcard:hover { border-color: var(--brand); }
.kcard.dragging { opacity: .45; }
.kcard-sub { color: #666; margin: 2px 0 6px; }
.kcard-row { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; margin-top: 2px; }
.kcard-move { margin-top: 8px; width: 100%; font-size: 12px; padding: 3px; }
.kempty { color: #aaa; font-size: 12px; text-align: center; padding: 18px 0; border: 1px dashed #ccd; border-radius: 6px; }
@media (max-width: 720px) {
  .content { padding: 12px; }
  .topbar { flex-wrap: wrap; padding: 10px 14px; row-gap: 8px; position: static; }
  .topbar .tabs { order: 3; width: 100%; margin-left: 0; }
  .topbar .spacer { display: none; }
  .tab-btn { padding: 7px 10px; }
  .stats-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-value { font-size: 20px; }
  .dash-grid { grid-template-columns: 1fr; }
  .toolbar input[type=text], .toolbar select { width: 100%; min-width: 0; flex: 1 1 100%; }
  .toolbar-actions button { flex: 1; }
  .table-card table { min-width: 760px; }
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal, .wide-modal { width: 100%; max-width: 100%; max-height: 94vh; border-radius: 14px 14px 0 0; flex-direction: column; padding: 1.1rem 1rem; }
  .modal-body { max-height: calc(94vh - 8rem); }
  .modal-side { width: 100%; flex-direction: row; flex-wrap: wrap; border-left: none; border-top: 1px solid #eee; padding-left: 0; padding-top: 10px; }
  .modal-side button { flex: 1; width: auto; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .span-2, .form-grid .span-3 { grid-column: 1 / -1; }
  .bar-row { grid-template-columns: 80px 1fr 70px; }
}
