:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e5e7eb;
  --ink: #1f2430;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --ok-bg: #dcfce7; --ok-ink: #15803d;
  --warn-bg: #fef9c3; --warn-ink: #a16207;
  --hi-bg: #fee2e2; --hi-ink: #b91c1c;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header.topnav {
  background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 18px;
  padding: 10px 20px; position: sticky; top: 0; z-index: 20;
}
header.topnav .brand { font-weight: 700; font-size: 16px; }
header.topnav .v { color: var(--muted); font-size: 12px; font-weight: 400; }
header.topnav nav { display: flex; gap: 6px; margin-left: auto; }
header.topnav nav .logout-form { display: inline-flex; margin: 0; }
header.topnav nav a {
  padding: 6px 12px; border-radius: 8px; color: var(--ink); font-weight: 500;
}
header.topnav nav a:hover { background: var(--bg); text-decoration: none; }
header.topnav nav a.active { background: var(--accent); color: var(--accent-ink); }
.nav-logout {
  border: 0; padding: 6px 12px; color: var(--muted); background: transparent;
  font-weight: 500;
}
.nav-logout:hover { background: var(--bg); color: var(--ink); }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
body[data-page="table"] main { max-width: none; }
h1 { font-size: 22px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 18px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
select, input[type=text], input[type=number] {
  font: inherit; padding: 5px 8px; border: 1px solid var(--border);
  border-radius: 7px; background: #fff; color: var(--ink);
}
button {
  font: inherit; cursor: pointer; border: 1px solid var(--border);
  background: #fff; border-radius: 8px; padding: 6px 12px;
}
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--hi-ink); border-color: var(--hi-bg); }
button:hover { filter: brightness(0.97); }

/* Hosted app login */
.login-page { min-height: 100vh; display: grid; place-items: center; }
.login-wrap { width: min(420px, 100%); padding: 24px; }
.login-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.10); padding: 28px;
}
.login-brand { color: var(--muted); font-size: 13px; font-weight: 600; margin-bottom: 18px; }
.login-form { display: grid; gap: 14px; }
.login-form label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; }
.login-form input {
  width: 100%; font: inherit; padding: 9px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; color: var(--ink);
}
.login-form button { margin-top: 4px; padding: 9px 12px; }
.login-error {
  margin: 0 0 14px; padding: 9px 11px; border-radius: 8px;
  background: var(--hi-bg); color: var(--hi-ink); font-size: 13px;
}
.login-version { margin-top: 18px; color: var(--muted); font-size: 11px; text-align: center; }

.rollups { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.rollup {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 16px; box-shadow: var(--shadow); min-width: 150px;
}
.rollup .n { font-size: 22px; font-weight: 700; }
.rollup .l { color: var(--muted); font-size: 12px; }

/* Cards / gallery */
.room-group { margin-bottom: 26px; }
.room-group h2 { font-size: 16px; margin: 0 0 10px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
  cursor: pointer; transition: box-shadow .12s, transform .12s;
}
.card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.12); transform: translateY(-1px); }
.card:focus { outline: 2px solid var(--accent); }
.card .cid { color: var(--muted); font-weight: 400; font-size: 12px; }
.card .no-photo { color: var(--muted); font-size: 12px; padding: 10px; }
.room-group .cnt { color: var(--muted); font-weight: 400; }
.diy-group { margin: 8px 0 14px; }
.diy-title { font-size: 13px; margin: 0 0 8px; color: var(--ink); font-weight: 600; }
.diy-title .cnt { color: var(--muted); font-weight: 400; }
.card .thumbs { display: flex; gap: 2px; overflow-x: auto; background: #eef0f3; min-height: 8px; }
.card .thumbs img { height: 120px; width: auto; object-fit: cover; cursor: pointer; }
.card .body { padding: 10px 12px; }
.card .item { font-weight: 600; }
.card .repair { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.pill { display: inline-block; border-radius: 20px; padding: 1px 9px; font-size: 11px; font-weight: 600; background: var(--bg); color: var(--muted); }
.pill.status-done { background: var(--ok-bg); color: var(--ok-ink); }
.pill.status-inprogress { background: var(--warn-bg); color: var(--warn-ink); }
.pill.prio-high { background: var(--hi-bg); color: var(--hi-ink); }
.pill.diy { background: #e0e7ff; color: #3730a3; }
.pill.pro { background: #fae8ff; color: #86198f; }

/* Table (Tabulator) */
#grid { background: var(--card); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
.tabulator { font-size: 13px; }
.tabulator .tabulator-header .tabulator-col { background: #f9fafb; }
.rowthumb { height: 42px; border-radius: 4px; cursor: pointer; vertical-align: middle; }
.thumb-more { font-size: 11px; color: var(--muted); margin-left: 3px; }
.add-photo-btn { display: inline-block; color: var(--accent); font-size: 12px; font-weight: 600; border: 1px dashed var(--accent); border-radius: 6px; padding: 3px 7px; cursor: pointer; }
.photocell { cursor: pointer; }
.photocell:hover { background: #eff6ff; }
.tabulator-cell.cell-saved { background: #ecfdf5 !important; transition: background .2s; }
.tabulator-cell.cell-err { background: #fef2f2 !important; transition: background .2s; }
.t-open, .t-dup, .t-del { border: none; background: transparent; cursor: pointer; font-size: 14px; padding: 0 4px; line-height: 1; }
.t-open { color: var(--ink); }
.t-dup { color: var(--accent); }
.t-del { color: var(--hi-ink); }
.t-open:hover, .t-dup:hover, .t-del:hover { filter: brightness(0.8); }
.itemcell { cursor: pointer; }
.itemcell:hover { background: #eff6ff; }
.item-link { color: var(--accent); }
.itemcell:hover .item-link { text-decoration: underline; }
.item-open { color: var(--accent); font-weight: 600; }
/* Column chooser */
.cols-wrap { position: relative; display: inline-block; }
.cols-panel { position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; background: var(--card); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.15); padding: 8px; min-width: 170px; max-height: 320px; overflow-y: auto; }
.cols-item { display: flex; align-items: center; gap: 6px; padding: 3px 4px; font-size: 13px; border-radius: 6px; cursor: pointer; }
.cols-item:hover { background: var(--bg); }

/* Recycle bin */
.bin-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.bin-list { display: flex; flex-direction: column; gap: 8px; max-height: 56vh; overflow-y: auto; }
.bin-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px; }
.bin-info { flex: 1; min-width: 0; }
.bin-title { font-weight: 600; font-size: 14px; }
.bin-sub { color: var(--muted); font-size: 12px; }
.tabulator .sel-col { cursor: pointer; }

/* Manage-lists modal */
.mg-tabs { display: flex; gap: 6px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.mg-tab { border: none; background: transparent; padding: 6px 12px; border-bottom: 2px solid transparent; cursor: pointer; color: var(--muted); font-weight: 600; }
.mg-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.mg-addbar { display: flex; gap: 8px; margin-bottom: 12px; }
.mg-addbar input { flex: 1; }
.mg-list { display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow-y: auto; }
.mg-row { display: flex; align-items: center; gap: 8px; }
.mg-row .mg-name { flex: 1; padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; font: inherit; }
.mg-row .mg-use { font-size: 11px; color: var(--muted); white-space: nowrap; min-width: 54px; text-align: right; }
.mg-row .mg-save, .mg-row .mg-del { font-size: 12px; padding: 4px 8px; }
.mg-row .mg-del[disabled] { opacity: .4; cursor: not-allowed; }
/* Combobox cells: hint they're pick-or-type with a caret + hover. */
.combo-cell { position: relative; cursor: pointer; }
.combo-cell:hover { background: #eff6ff; }
.combo-cell::after { content: "▾"; position: absolute; right: 5px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 10px; opacity: .55; pointer-events: none; }
.combo-empty { color: var(--muted); font-style: italic; }

/* Photo grid */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.photo-grid.size-sm { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.photo-grid.size-md { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.photo-grid.size-lg { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.photo-tile { position: relative; border: 2px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--card); cursor: pointer; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.photo-tile .img-wrap { position: relative; }
.photo-tile img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.photo-tile.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.photo-tile .check { position: absolute; top: 6px; left: 6px; background: rgba(255,255,255,.9); color: transparent; border-radius: 50%; width: 22px; height: 22px; text-align: center; line-height: 20px; font-size: 13px; font-weight: 700; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.18); z-index: 2; }
.photo-tile.selected .check { background: var(--accent); color: #fff; }
.photo-tile .zoom { position: absolute; top: 6px; right: 6px; background: rgba(17,24,39,.6); color: #fff; border: none; border-radius: 6px; width: 26px; height: 26px; font-size: 14px; cursor: pointer; display: none; z-index: 2; }
.photo-tile:hover .zoom { display: block; }

/* Gallery area sections + size control */
.gallery-section { margin-bottom: 22px; }
.gallery-area { font-size: 16px; margin: 0 0 10px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.gallery-area .cnt { color: var(--muted); font-weight: 400; }
.area-toggle {
  display: flex; align-items: center; gap: 6px; width: 100%;
  background: none; border: none; padding: 0; margin: 0;
  font: inherit; font-size: 16px; color: inherit; text-align: left; cursor: pointer;
}
.area-toggle .chev { display: inline-block; font-size: 11px; color: var(--muted); transition: transform 0.15s ease; }
.gallery-section.collapsed .area-toggle .chev { transform: rotate(-90deg); }
.gallery-section.collapsed .photo-grid { display: none; }
.gallery-section.collapsed .gallery-area { border-bottom-color: transparent; margin-bottom: 4px; }
.size-control { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.size-btn { border: none; background: #fff; padding: 5px 10px; cursor: pointer; font-size: 13px; border-left: 1px solid var(--border); }
.size-btn:first-child { border-left: none; }
.size-btn.active { background: var(--accent); color: #fff; }

.ptags { display: flex; flex-wrap: wrap; gap: 3px; padding: 6px; background: var(--card); border-top: 1px solid var(--border); min-height: 8px; }
.ptag { display: inline-flex; align-items: center; gap: 4px; background: var(--bg); color: #1f2430; font-size: 11px; font-weight: 600; border-radius: 10px; padding: 2px 4px 2px 8px; max-width: 100%; }
.ptag-label { cursor: pointer; }
.ptag-label:hover { text-decoration: underline; }
.ptag.unassigned { background: var(--warn-bg); color: var(--warn-ink); padding: 1px 8px; }
.ptag.area { background: #dbeafe; color: #1e40af; padding: 2px 4px 2px 7px; }
.ptag.more { background: var(--bg); color: var(--muted); }
.ptag-x, .parea-x { border: none; background: transparent; color: var(--hi-ink); font-size: 15px; line-height: 1; cursor: pointer; padding: 0 3px; }
.ptag-x:hover, .parea-x:hover { color: #7f1d1d; }

/* Touch devices: no hover, so always show the photo preview button. */
@media (hover: none) {
  .photo-tile .zoom { display: block; }
}

.empty { color: var(--muted); padding: 30px; text-align: center; grid-column: 1 / -1; }

/* Changelog / About */
.changelog { max-width: 760px; }
.cl-entry { background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 14px 18px; margin-bottom: 12px; }
.cl-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.cl-title { font-size: 15px; }
.cl-date { color: var(--muted); font-size: 12px; }
.cl-list { margin: 0; padding-left: 20px; }
.cl-list li { margin: 3px 0; color: var(--ink); }

#g-selbar { position: sticky; top: 52px; z-index: 15; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.selbar { flex-wrap: wrap; }
.selbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.act-btn { font-size: 13px; }
.act-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.linkish { border: none; background: transparent; color: var(--accent); cursor: pointer; }
.selbar-panel { display: none; flex-basis: 100%; align-items: center; gap: 10px; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); }
.selbar-panel label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: none; align-items: center; justify-content: center; z-index: 50; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 6px; }
.lightbox .close { position: absolute; top: 16px; right: 22px; color: #fff; font-size: 30px; cursor: pointer; }

.notice { position: fixed; bottom: 18px; right: 18px; background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .3s; z-index: 60; }
.notice.show { opacity: .95; }

.nav-muted { color: var(--muted) !important; font-weight: 400 !important; }

/* Repair detail drawer */
.drawer-overlay { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: none; z-index: 45; }
.drawer-overlay.open { display: block; }
.drawer { position: absolute; top: 0; right: 0; height: 100%; width: min(460px, 96vw); background: var(--card); box-shadow: -8px 0 30px rgba(0,0,0,.2); display: flex; flex-direction: column; animation: slidein .18s ease; }
@keyframes slidein { from { transform: translateX(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.drawer-head strong { font-size: 16px; }
.drawer-head button { border: none; background: transparent; font-size: 24px; color: var(--muted); cursor: pointer; line-height: 1; }
.drawer-body { padding: 16px 18px; overflow-y: auto; }
.rd-group { margin-bottom: 16px; }
.rd-group-title { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.rd-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.rd-field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.rd-field.full { grid-column: 1 / -1; }
.rd-label { color: var(--muted); font-weight: 600; }
.rd-field input, .rd-field select, .rd-field textarea { font: inherit; font-size: 13px; padding: 5px 7px; border: 1px solid var(--border); border-radius: 7px; background: #fff; width: 100%; }
.rd-field textarea { resize: vertical; }
.rd-h { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.rd-photos-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 8px; }
button.sm { padding: 4px 10px; font-size: 13px; }
.rd-saved { margin-left: auto; margin-right: 12px; font-size: 12px; font-weight: 600; }
.rd-saved.saving { color: var(--muted); }
.rd-saved.ok { color: var(--ok-ink); }
.rd-saved.err { color: var(--hi-ink); }

/* Photo picker modal (opens from the drawer, so it must sit above it) */
#photo-picker { z-index: 48; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.pp-spacer { flex: 1; }
.pp-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.pp-toolbar label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
#pp-grid { max-height: 52vh; overflow-y: auto; }
.photo-tile.here { outline: 2px solid var(--ok-ink); outline-offset: -2px; }
.ptag.on-here { background: var(--ok-bg); color: var(--ok-ink); }

/* Photo manager modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(17,24,39,.55); display: none; align-items: flex-start; justify-content: center; z-index: 40; padding: 40px 16px; overflow-y: auto; }
.modal-overlay.open { display: flex; }
.modal { background: var(--card); border-radius: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.25); width: min(1000px, 96vw); max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head strong { font-size: 16px; }
.modal-head button { border: none; background: transparent; font-size: 22px; line-height: 1; color: var(--muted); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.pm-section { margin-bottom: 20px; }
.pm-section h4 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.pm-addbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 6px; }
.pm-addbar h4 { margin: 0; }
.pm-addbar #pm-search { min-width: 200px; flex: 1; }
.pm-move { font-size: 13px; color: var(--ink); display: flex; align-items: center; gap: 5px; }
.pm-uploadbtn { font-size: 13px; cursor: pointer; border: 1px solid var(--accent); color: var(--accent); border-radius: 8px; padding: 5px 10px; }
.pm-hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.pm-attached-empty { color: var(--muted); font-size: 13px; }
.pm-tile { position: relative; border: 2px solid transparent; border-radius: 10px; overflow: hidden; background: #eef0f3; cursor: pointer; }
.pm-tile img { width: 100%; height: 120px; object-fit: cover; display: block; }
.pm-tile.on { border-color: var(--accent); }
.pm-tile .tags { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(17,24,39,.72); color: #fff; font-size: 10px; padding: 2px 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pm-tile .rm { position: absolute; top: 4px; right: 4px; background: var(--hi-ink); color: #fff; border: none; border-radius: 50%; width: 20px; height: 20px; font-size: 12px; line-height: 20px; cursor: pointer; padding: 0; }
.pm-tile .badge { position: absolute; top: 4px; left: 4px; background: var(--accent); color: #fff; border-radius: 50%; width: 20px; height: 20px; text-align: center; line-height: 20px; font-size: 12px; }
