:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1a1d21;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #b31b1b; /* Cornell carnelian */
  --brand-ink: #7a1212;
  --accent: #12507a;
  --ok: #15803d;
  --warn: #b45309;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #191c22;
    --ink: #e8eaed;
    --muted: #9aa1ac;
    --line: #2a2e37;
    --brand: #e0564f;
    --brand-ink: #f0847e;
    --accent: #5aa9e6;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 14px;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:hover { border-color: var(--muted); }
button:active { transform: translateY(1px); }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover { background: var(--brand-ink); }
button.ghost { background: transparent; }
button.danger { color: #fff; background: #b91c1c; border-color: #b91c1c; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; }
.brand span { letter-spacing: -0.01em; }
.views { display: flex; gap: 4px; margin-left: 8px; }
.views button { border: none; background: transparent; color: var(--muted); border-radius: 999px; padding: 8px 16px; }
.views button.active { background: var(--brand); color: #fff; }
.topbar #addBtn { margin-left: auto; }

main { padding: 20px; max-width: 1200px; margin: 0 auto; }

/* Listing grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(0,0,0,.12); }
.card .thumb {
  height: 170px;
  background: linear-gradient(135deg, #e7e9ee, #d5d9e0);
  background-size: cover;
  background-position: center;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 40px;
}
.card .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; }
.card .name { font-weight: 650; font-size: 17px; }
.card .addr { color: var(--muted); font-size: 13px; }
.card .rentline { font-size: 20px; font-weight: 700; margin-top: 2px; }
.card .rentline small { font-size: 13px; font-weight: 500; color: var(--muted); }
.card .meta { display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); font-size: 13px; margin-top: 2px; }
.card .foot { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }

.badge {
  display: inline-block; font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px; text-transform: capitalize;
}
.badge.interested { background: #dbeafe; color: #1e40af; }
.badge.toured { background: #fef3c7; color: #92400e; }
.badge.applied { background: #ede9fe; color: #5b21b6; }
.badge.decided { background: #dcfce7; color: #166534; }
.badge.passed { background: #f3f4f6; color: #6b7280; }
@media (prefers-color-scheme: dark) {
  .badge.interested { background: #1e3a5f; color: #bfdbfe; }
  .badge.toured { background: #4a3410; color: #fde68a; }
  .badge.applied { background: #3a2a5c; color: #ddd6fe; }
  .badge.decided { background: #14432a; color: #bbf7d0; }
  .badge.passed { background: #2a2e37; color: #cbd5e1; }
}
.stars { color: #f59e0b; letter-spacing: 1px; font-size: 15px; }
.stars .off { color: var(--line); }

.empty { text-align: center; color: var(--muted); padding: 80px 20px; }
.empty h2 { color: var(--ink); font-weight: 650; }

/* Map */
#map { height: calc(100vh - 130px); border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); }
.leaflet-popup-content { font: inherit; }
.mappin { font-weight: 700; }

/* Budget table */
.budget-controls { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.tablewrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; min-width: 720px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; }
tbody tr:hover { background: color-mix(in srgb, var(--brand) 5%, transparent); }
tr.cheapest td { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.cellinput { width: 90px; text-align: right; border: 1px solid transparent; background: transparent; color: var(--ink); border-radius: 8px; padding: 6px 8px; }
.cellinput:hover { border-color: var(--line); }
.cellinput:focus { border-color: var(--accent); outline: none; background: var(--bg); }
.perperson { font-weight: 700; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center; background: rgba(0,0,0,.5); padding: 30px 16px; overflow-y: auto; }
.modal.hidden { display: none; }
.modal-card { position: relative; width: 100%; max-width: 720px; background: var(--card); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,.4); padding: 26px; }
.modal-close { position: absolute; top: 12px; right: 12px; border: none; background: transparent; font-size: 26px; line-height: 1; color: var(--muted); padding: 4px 10px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 70px; }

.modal h2 { margin: 0 0 4px; }
.modal .subhead { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.modal-actions .spacer { margin-right: auto; }

.tabs { display: flex; gap: 4px; margin: 4px 0 18px; border-bottom: 1px solid var(--line); }
.tabs button { border: none; background: transparent; color: var(--muted); border-radius: 0; border-bottom: 2px solid transparent; padding: 8px 14px; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }

.rating-input { display: flex; gap: 4px; font-size: 24px; color: var(--line); }
.rating-input span { cursor: pointer; }
.rating-input span.on { color: #f59e0b; }

/* Media manager */
.media-section h3 { margin: 18px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.uploaders { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.uploaders label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; }
.uploaders label:hover { border-color: var(--accent); }
.uploaders input[type=file] { display: none; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.tile { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--bg); aspect-ratio: 1; display: flex; align-items: center; justify-content: center; }
.tile img { width: 100%; height: 100%; object-fit: cover; }
.tile .doc { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; padding: 8px; text-align: center; }
.tile .doc .ic { font-size: 30px; }
.tile a.open { position: absolute; inset: 0; }
.tile .del { position: absolute; top: 4px; right: 4px; z-index: 2; background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 6px; padding: 2px 7px; font-size: 13px; }
.tile .tag { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 10px; padding: 2px 5px; text-transform: capitalize; }
.tile .assignbtn { position: absolute; top: 4px; left: 4px; z-index: 2; background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 6px; padding: 2px 7px; font-size: 12px; cursor: pointer; }
.tile .assignbtn:hover { background: var(--brand); }
.assign-list { display: flex; flex-direction: column; gap: 6px; max-height: 52vh; overflow: auto; margin-top: 6px; }
.assign-row { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.assign-row span:nth-of-type(1) { flex: 1; }
.assign-row:hover { border-color: var(--accent); }

.linkrow { display: flex; gap: 8px; margin-bottom: 8px; }
.linkrow input { flex: 1; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow); z-index: 100; font-size: 14px; }
.toast.hidden { display: none; }

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

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip { font-size: 12px; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); border-radius: 999px; padding: 3px 10px; }
.chip.building-note { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }

/* Filter bar */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.filters .search { flex: 1 1 240px; min-width: 200px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
.filters select, .filters .num { padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }
.filters .num { width: 100px; }
.filters .availfilter { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.filters .availfilter input { padding: 7px 9px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); }

/* Breadcrumbs + detail header */
.crumbs { margin-bottom: 12px; display: flex; align-items: center; gap: 4px; }
.crumbs .ghost { padding: 4px 8px; }
.detail-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 16px; }
.detail-head h1 { margin: 0 0 4px; font-size: 26px; }
.detail-head .subhead { margin: 0; color: var(--muted); }
.head-actions { display: flex; gap: 8px; }

/* Info boxes */
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-bottom: 8px; }
.info-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.info-box.full { grid-column: 1 / -1; }
.info-box h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 20px; }
.fact { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed var(--line); padding: 5px 0; }
.fact .k { color: var(--muted); }
.fact .v { font-weight: 600; text-align: right; }

/* Section headings */
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 26px 0 12px; }
.section-head h3 { margin: 0; font-size: 18px; }

/* Bedroom cards */
.bedroom-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.bedroom-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.bedroom-card h4 { margin: 0 0 8px; }
.bedroom-card ul { margin: 0; padding-left: 2px; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }

/* Dropzone */
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); font-size: 14px; margin: 8px 0 12px; transition: background .15s, border-color .15s; }
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); color: var(--accent); }

/* FAQ / questions */
.qa-list { display: flex; flex-direction: column; gap: 10px; }
.qa-item { display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.qa-item.done { opacity: .68; }
.qa-done { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.qa-body { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.qa-a { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); resize: vertical; min-height: 42px; }

/* Notes log */
.log-list { display: flex; flex-direction: column; gap: 8px; }
.log-item { display: grid; grid-template-columns: 130px 1fr auto; gap: 12px; align-items: start; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.log-item.inherited { background: color-mix(in srgb, var(--brand) 4%, var(--card)); }
.log-meta { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.log-text { white-space: pre-wrap; }

/* Checkbox grid (services / amenities) */
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.cb { display: flex; align-items: center; gap: 6px; font-size: 14px; }

/* Repeater (bedrooms in editor) */
.repeater { display: flex; flex-direction: column; gap: 12px; }
.repeater-row { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; background: var(--bg); }
.rr-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.rr-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
button.small { padding: 4px 10px; font-size: 13px; }

/* Attribution */
.log-author { font-weight: 600; color: var(--ink); }
.edited { font-size: 12px; color: var(--muted); margin: 2px 0 4px; }

/* User area in top bar */
.user-area { display: flex; align-items: center; gap: 8px; }
.group-btn { padding: 6px 12px; }
.college-select { padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font: inherit; }
.user-chip { font-size: 13px; color: var(--muted); white-space: nowrap; }
body.unauth .views, body.unauth #addBtn, body.unauth .user-area { display: none; }

/* Auth screens */
.auth-wrap { display: flex; justify-content: center; padding: 40px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; }
.auth-brand { font-weight: 700; font-size: 18px; margin-bottom: 18px; }
.auth-card h2 { margin: 0 0 4px; }
.auth-card .subhead { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.auth-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.auth-field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.auth-input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); }
.auth-input:focus { outline: none; border-color: var(--accent); }
button.block { width: 100%; padding: 11px; margin-top: 6px; }
.auth-err { background: color-mix(in srgb, #b91c1c 14%, transparent); color: #b91c1c; border-radius: 10px; padding: 9px 12px; font-size: 14px; margin-bottom: 12px; }
.auth-foot { text-align: center; margin: 16px 0 0; font-size: 14px; color: var(--muted); }

/* Group panel */
.panel-h { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.grouplist { display: flex; flex-direction: column; gap: 6px; }
.grouprow { text-align: left; }
.grouprow.active { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.memberlist { display: flex; flex-direction: column; gap: 6px; }
.memberrow { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.memberrow code, code { background: var(--bg); padding: 2px 8px; border-radius: 6px; font-size: 13px; }

/* Favorites + ranking */
.card { position: relative; }
.viewbar { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.fav-toggle.on { color: var(--brand); border-color: var(--brand); }
.heart { border: none; background: transparent; color: var(--muted); font-size: 20px; line-height: 1; padding: 2px 6px; cursor: pointer; }
.heart:hover { color: #e0245e; }
.heart.on { color: #e0245e; }
.heart.card-heart { position: absolute; top: 8px; right: 8px; z-index: 3; display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; background: rgba(255,255,255,.85); border-radius: 999px; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
@media (prefers-color-scheme: dark) { .heart.card-heart { background: rgba(0,0,0,.5); } }
.heart.big { font-size: 24px; }
.foot-right { display: inline-flex; align-items: center; gap: 8px; }
.rank-badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 2px 8px; font-size: 12px; font-weight: 700; }
.rank-ctl { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.rank-input { width: 56px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }

@media (max-width: 560px) {
  .form-grid, .rr-fields { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .topbar #addBtn { margin-left: 0; }
  .log-item { grid-template-columns: 1fr; }
  .memberrow { grid-template-columns: 1fr auto; }
}
