/* Mobile-first styles. Palette: navy header, neutral background, status colours. */
:root {
  --navy: #1d3557;
  --navy-dark: #14263f;
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #1a1d21;
  --muted: #667085;
  --border: #d9dee5;
  --green: #2e9e5b;
  --green-bg: #d9f2e3;
  --amber: #b97c10;
  --amber-bg: #fdeeca;
  --red: #d33f49;
  --red-bg: #fadadd;
  --blue: #3466aa;
  --blue-bg: #dde9f8;
  --grey-bg: #e6e9ee;
  --hatch-a: #e6e9ee;
  --hatch-b: #d0d5dd;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(4.5rem + env(safe-area-inset-bottom)); /* room for bottom nav */
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0.8rem 0 0.6rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.5rem; }
h3 { font-size: 0.95rem; margin: 0.8rem 0 0.4rem; }
code { background: var(--grey-bg); padding: 0.1em 0.3em; border-radius: 4px; }

.container { max-width: 60rem; margin: 0 auto; padding: 0 0.8rem 1.5rem; }

/* Top bar */
.topbar {
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.5rem 0.8rem;
  padding-top: calc(0.5rem + env(safe-area-inset-top));
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { color: #fff; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.topnav { display: none; gap: 0.15rem; flex: 1; flex-wrap: wrap; }
.topnav a {
  color: #cdd8e8; padding: 0.4rem 0.6rem; border-radius: 6px; white-space: nowrap;
}
.topnav a:hover { color: #fff; text-decoration: none; background: var(--navy-dark); }
.topnav a.active { color: #fff; background: var(--navy-dark); }
.logout-form { margin-left: auto; }
.linklike { background: none; border: none; color: #cdd8e8; cursor: pointer; font: inherit; padding: 0.3rem; }
.linklike:hover { color: #fff; }

/* Bottom nav (mobile) */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; text-align: center; padding: 0.45rem 0 0.4rem;
  color: var(--muted); font-size: 0.68rem; line-height: 1.3;
}
.bottomnav a:hover { text-decoration: none; }
.bottomnav a.active { color: var(--navy); font-weight: 600; }
.bottomnav .icon { display: block; font-size: 1.25rem; position: relative; }
.bottomnav .icon .badge { position: absolute; top: -0.2rem; margin-left: 0.1rem; }

@media (min-width: 800px) {
  body { padding-bottom: 1.5rem; }
  .bottomnav { display: none; }
  .topnav { display: flex; }
  h1 { font-size: 1.7rem; }
}

/* Cards, stats */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem;
  margin: 0.8rem 0;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.6rem;
  margin: 0.8rem 0;
}
@media (min-width: 800px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem;
  color: var(--text);
  display: block;
}
.stat:hover { text-decoration: none; border-color: var(--blue); }
.stat .num { font-size: 1.6rem; font-weight: 700; }
.stat .num .sub { font-size: 1rem; color: var(--muted); font-weight: 400; }
.stat .label { color: var(--muted); font-size: 0.85rem; }
.stat.alert-stat { border-color: var(--red); background: var(--red-bg); }

/* Buttons */
.btn {
  display: inline-block;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  text-align: center;
  min-height: 44px; /* touch target */
  line-height: 1.6;
}
.btn:hover { text-decoration: none; border-color: var(--blue); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-dark); }
.btn.danger-outline { border-color: var(--red); color: var(--red); }
.btn.small { padding: 0.3rem 0.6rem; min-height: 36px; font-size: 0.85rem; line-height: 1.4; }
.btn.block { display: block; width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.6rem 0 0.2rem; align-items: center; }
.btn-row form { margin: 0; }
.quick-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.8rem 0; }

/* Badges & pills */
.badge {
  display: inline-block; min-width: 1.2rem; padding: 0 0.3rem;
  border-radius: 999px; font-size: 0.7rem; font-weight: 700;
  text-align: center; color: #fff; margin-left: 0.3rem; line-height: 1.5;
}
.badge.red { background: var(--red); }
.badge.amber { background: var(--amber); }
.pill {
  display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600; white-space: nowrap;
}
.pill.red, .pill.overdue { background: var(--red-bg); color: var(--red); }
.pill.amber, .pill.due_soon { background: var(--amber-bg); color: var(--amber); }
.pill.green, .pill.paid { background: var(--green-bg); color: var(--green); }
.pill.vacant { background: var(--grey-bg); color: var(--muted); }
.pill.reserved { background: var(--blue-bg); color: var(--blue); }
.pill.out_of_service { background: repeating-linear-gradient(45deg, var(--hatch-a), var(--hatch-a) 4px, var(--hatch-b) 4px, var(--hatch-b) 8px); color: var(--muted); }

/* Forms */
.form label { display: block; margin: 0 0 0.8rem; font-size: 0.88rem; color: var(--muted); font-weight: 600; }
.form input, .form select, .form textarea,
.inline-form input, .inline-form select, .search-row input, .filter-form input, .filter-form select {
  display: block; width: 100%;
  margin-top: 0.25rem;
  padding: 0.6rem;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  min-height: 44px;
}
.form textarea { min-height: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.check-row { display: flex; gap: 1.2rem; margin-bottom: 0.8rem; }
label.check { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; color: var(--text); margin-bottom: 0.8rem; }
label.check input { width: 1.3rem; height: 1.3rem; min-height: auto; margin: 0; }
.inline-form { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; margin: 0.4rem 0; }
.inline-form input, .inline-form select { display: inline-block; width: auto; flex: 1; min-width: 8rem; margin-top: 0; }
.inline-form .btn { flex-shrink: 0; }
.search-row { display: flex; gap: 0.5rem; margin: 0.8rem 0 0.4rem; }
.search-row input { margin: 0; flex: 1; }
.filter-form { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: end; }
.filter-form label { font-size: 0.85rem; color: var(--muted); flex: 1; min-width: 8rem; }
.hidden { display: none; }

/* Filter chips */
.filter-row { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.6rem 0; }
.chip {
  padding: 0.35rem 0.8rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-size: 0.85rem;
}
.chip:hover { text-decoration: none; border-color: var(--blue); }
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }

/* Tables */
.table-card { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.6rem 0.7rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:last-child td { border-bottom: none; }
.num-col { text-align: right; }

/* Lists */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li {
  display: flex; justify-content: space-between; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.rows li:last-child { border-bottom: none; }
.rows .right { margin-left: auto; text-align: right; }

/* Key-value blocks */
.kv div { display: flex; gap: 0.8rem; padding: 0.3rem 0; }
.kv .k { color: var(--muted); min-width: 6.5rem; font-size: 0.85rem; padding-top: 0.1rem; }
.kv .total { border-top: 1px solid var(--border); margin-top: 0.4rem; padding-top: 0.6rem; }

/* Yard map */
.legend { display: flex; flex-wrap: wrap; gap: 0.8rem; font-size: 0.8rem; color: var(--muted); margin: 0.6rem 0; }
.legend .sq { display: inline-block; width: 0.9rem; height: 0.9rem; border-radius: 3px; vertical-align: -2px; margin-right: 0.25rem; border: 1px solid rgba(0,0,0,0.15); }
.zone h2 { margin: 1rem 0 0.5rem; }
.space-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.6rem, 1fr));
  gap: 0.45rem;
}
.space-tile {
  border-radius: 8px;
  padding: 0.5rem 0.3rem;
  text-align: center;
  color: var(--text);
  border: 1px solid rgba(0,0,0,0.12);
  min-height: 3.6rem;
  display: flex; flex-direction: column; justify-content: center;
}
.space-tile:hover { text-decoration: none; outline: 2px solid var(--navy); }
.space-tile .tile-label { font-weight: 700; }
.space-tile .tile-sub { font-size: 0.68rem; opacity: 0.8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.space-tile.paid, .sq.paid { background: var(--green-bg); }
.space-tile.due_soon, .sq.due_soon { background: var(--amber-bg); }
.space-tile.overdue, .sq.overdue { background: var(--red-bg); }
.space-tile.vacant, .sq.vacant { background: var(--grey-bg); color: var(--muted); }
.space-tile.reserved, .sq.reserved { background: var(--blue-bg); border-style: dashed; border-color: var(--blue); }
.space-tile.out_of_service, .sq.out_of_service {
  background: repeating-linear-gradient(45deg, var(--hatch-a), var(--hatch-a) 5px, var(--hatch-b) 5px, var(--hatch-b) 10px);
  color: var(--muted);
}

/* Page furniture */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }
.page-head > div { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.section-head { display: flex; justify-content: space-between; align-items: center; }
.muted { color: var(--muted); font-size: 0.87rem; }
.text-red { color: var(--red); font-weight: 600; }
.alert { border-radius: 8px; padding: 0.7rem 0.9rem; margin: 0.8rem 0; }
.alert.error { background: var(--red-bg); color: var(--red); }
.alert.ok { background: var(--green-bg); color: var(--green); }
.flash { background: var(--green-bg); color: var(--green); border-radius: 8px; padding: 0.7rem 0.9rem; margin: 0.8rem 0; }

/* Overdue cards */
.overdue-card .overdue-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.overdue-card .name { font-size: 1.05rem; font-weight: 700; }
.overdue-meta { margin: 0.4rem 0; font-size: 0.92rem; }

/* Customer detail bits */
.contract-row { display: flex; justify-content: space-between; gap: 0.6rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.contract-row:last-child { border-bottom: none; }
.contract-row.ended { opacity: 0.55; }
.thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; vertical-align: middle; margin-right: 0.4rem; }
.preview { max-width: 100%; max-height: 240px; border-radius: 8px; }
.photo-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.photo-row .thumb { width: 72px; height: 72px; }
.vehicle-row > span:first-child { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }

/* Login */
.login-wrap { max-width: 22rem; margin: 12vh auto 0; text-align: center; }
.login-wrap .card { text-align: left; }

/* Link box */
.linkbox { word-break: break-all; background: var(--grey-bg); padding: 0.6rem; border-radius: 8px; }

/* Receipt printing */
@media print {
  .topbar, .bottomnav, .no-print, .flash { display: none !important; }
  body { background: #fff; padding: 0; }
  .card { border: none; }
}
