:root {
  --bg: #101418;
  --panel: #1a2027;
  --panel2: #232b34;
  --text: #e8edf2;
  --muted: #8a97a5;
  --accent: #ffb454;
  --accent2: #4fc3f7;
  --ok: #66bb6a;
  --warn: #ef5350;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif; font-size: 16px; }
body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
#app { max-width: 560px; margin: 0 auto; padding: 12px 14px 140px; }

h1 { font-size: 1.35rem; margin: 8px 0 14px; }
h2 { font-size: 1.05rem; margin: 18px 0 8px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; }
a { color: var(--accent2); text-decoration: none; }

.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.topbar .back { font-size: 1.6rem; line-height: 1; padding: 4px 10px 6px; background: var(--panel);
  border-radius: 10px; }
.topbar h1 { flex: 1; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card { background: var(--panel); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; }

button, .btn {
  appearance: none; border: 0; border-radius: 12px; padding: 13px 16px;
  background: var(--panel2); color: var(--text); font-size: 1rem; font-weight: 600;
  cursor: pointer; touch-action: manipulation;
}
button:active { opacity: .7; }
.btn-primary { background: var(--accent); color: #1a1205; }
.btn-blue { background: var(--accent2); color: #06222e; }
.btn-danger { background: var(--warn); color: #fff; }
.btn-big { width: 100%; padding: 16px; font-size: 1.05rem; margin-top: 8px; }
.btn-sm { padding: 8px 12px; font-size: .9rem; font-weight: 500; }

input[type=text], input[type=password], textarea {
  width: 100%; border: 1px solid #2e3944; border-radius: 12px; background: var(--panel2);
  color: var(--text); padding: 12px; font-size: 1rem; font-family: inherit;
}
textarea { min-height: 110px; resize: vertical; }
label { display: block; margin: 10px 0 4px; color: var(--muted); font-size: .9rem; }

.sync { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: #0b0e11ee; backdrop-filter: blur(8px); display: flex; align-items: center; gap: 10px;
  font-size: .85rem; color: var(--muted); border-top: 1px solid #202830; }

/* Recording bar - persistent, above the sync bar */
.recbar { position: fixed; left: 0; right: 0; bottom: calc(38px + env(safe-area-inset-bottom));
  padding: 10px 16px; display: flex; align-items: center; gap: 10px; font-size: .95rem;
  background: #1c1114f2; backdrop-filter: blur(8px); border-top: 1px solid #3a2126; z-index: 5; }
.recbar.resume { background: #10201af2; border-top-color: #1f3a2e; }
.reddot { width: 12px; height: 12px; border-radius: 50%; background: var(--warn);
  animation: pulse 1.2s infinite; flex: none; }
.sync .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex: none; }
.sync.pending .dot { background: var(--accent); animation: pulse 1.2s infinite; }
.sync.offline .dot { background: var(--warn); }
@keyframes pulse { 50% { opacity: .3; } }

.visit-item { display: block; background: var(--panel); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px; color: var(--text); }
.visit-item .meta { color: var(--muted); font-size: .85rem; margin-top: 4px; }
.visit-item.closed { opacity: .55; }

.timer-row { display: flex; align-items: center; gap: 10px; background: var(--panel2);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.timer-row .name { flex: 1; font-weight: 600; }
.timer-row .elapsed { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; }

.feed { margin-top: 6px; }
.feed-item { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid #222a33;
  font-size: .93rem; align-items: flex-start; }
.feed-item .ts { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; font-size: .82rem; padding-top: 2px; }
.feed-item .body { flex: 1; white-space: pre-wrap; word-break: break-word; }
.feed-item img { max-width: 120px; border-radius: 8px; display: block; }
.feed-item .tag { font-size: .75rem; color: var(--accent2); }
.feed-item .pending { color: var(--accent); font-size: .75rem; }

.quickbtns { display: grid; grid-template-columns: 1fr; gap: 8px; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { flex: 1; background: var(--panel); }
.tabs button.active { background: var(--accent); color: #1a1205; }

.ai-out { white-space: pre-wrap; font-size: .95rem; line-height: 1.5; }
.error { color: var(--warn); margin: 8px 0; }
.hint { color: var(--muted); font-size: .85rem; margin-top: 6px; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid #ffffff33;
  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Review view */
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; padding: 4px 8px 6px 0; border-bottom: 1px solid #2e3944; }
.tbl td { padding: 6px 8px 6px 0; border-bottom: 1px solid #222a33; }
.tbl tr.total td { border-bottom: 0; color: var(--accent); }
.ts-inline { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .82rem; margin-right: 8px; }
.photo-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.photo-card { background: var(--panel); border-radius: var(--radius); overflow: hidden; }
.photo-card img { width: 100%; max-height: 340px; object-fit: cover; display: block; }
.photo-meta { padding: 10px 12px 12px; }
.transcript { white-space: pre-wrap; font-size: .88rem; background: var(--panel2); border-radius: 8px;
  padding: 10px; margin-top: 6px; font-family: ui-monospace, "SF Mono", Consolas, monospace; }

/* Visits list */
.list-sel { background: var(--panel); color: var(--text); border: 1px solid #2e3944;
  border-radius: 10px; padding: 8px 10px; font-size: .85rem; flex: 1; min-width: 105px; }
.client-badge { background: var(--panel2); color: var(--accent2); font-size: .75rem;
  padding: 2px 8px; border-radius: 10px; margin-left: 6px; font-weight: 600; }

/* Ad-hoc top row - unassigned record/timer/photo/note */
.adhoc-row { display: flex; gap: 8px; margin-bottom: 12px; }
.adhoc-btn, label.adhoc-btn { flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; padding: 12px 4px; font-size: .8rem; line-height: 1.2;
  font-family: inherit; color: var(--text); border-radius: 12px; box-sizing: border-box;
  background: var(--panel2); border: 1px solid #2e3944; font-weight: 600; cursor: pointer;
  margin: 0; text-align: center; }

/* Quick actions - one per row, big icon left */
.qa-btn { display: flex; flex-direction: row; align-items: center; justify-content: flex-start;
  gap: 14px; padding: 13px 16px; font-size: .95rem; line-height: 1.25; text-align: left; }
.qa-ico { font-size: 1.7rem; line-height: 1; flex: none; }

/* Running timer chips under the ad-hoc row - full-width rows on mobile */
.run-chips { display: flex; flex-direction: column; gap: 8px; margin: -4px 0 12px; }
.run-chip { display: flex; align-items: center; gap: 10px; width: 100%; padding: 14px 16px;
  border-radius: 12px; background: #2a2113; border: 1px solid #4a3a1a; color: var(--accent);
  font-size: 1rem; font-weight: 600; text-align: left; }
.run-chip .elapsed { font-variant-numeric: tabular-nums; margin-left: auto; font-size: 1.1rem; }

@media (min-width: 760px) {
  .run-chips { flex-direction: row; flex-wrap: wrap; }
  .run-chip { width: auto; padding: 10px 14px; font-size: .9rem; border-radius: 20px; }
  .run-chip .elapsed { margin-left: 0; font-size: .95rem; }
}

/* Modal input */
.modal-wrap { position: fixed; inset: 0; background: #000a; z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 15vh 16px 0; }
.modal { background: var(--panel); border-radius: var(--radius); padding: 16px; width: 100%;
  max-width: 420px; box-shadow: 0 10px 40px #000c; }
.modal h3 { margin: 0 0 10px; font-size: 1.05rem; }
.modal-input { width: 100%; border: 1px solid #2e3944; border-radius: 12px; background: var(--panel2);
  color: var(--text); padding: 12px; font-size: 1rem; }

/* Topbar menu (mobile navigation) */
.menu-btn { background: var(--panel); border-radius: 10px; padding: 9px 12px; font-size: .9rem; flex: none; }
.menu-drop { position: absolute; right: 14px; top: 60px; z-index: 40; background: var(--panel);
  border: 1px solid #2e3944; border-radius: 12px; overflow: hidden; box-shadow: 0 8px 30px #000b;
  display: flex; flex-direction: column; min-width: 150px; }
.menu-drop button { border-radius: 0; text-align: left; background: var(--panel); padding: 13px 18px; }
.menu-drop button.active { background: var(--accent); color: #1a1205; }
.topbar { position: relative; }

/* Swipe to archive */
.visit-item { touch-action: pan-y; transition: transform .15s; position: relative; }
.visit-item.swipe-armed { background: #3a1d20; }
.visit-item.dragging { transition: none; z-index: 20; opacity: .9; box-shadow: 0 8px 24px #000a; }
.visit-drag { position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 1.3rem; padding: 10px; touch-action: none; cursor: grab; }
.folder-head.drop-target { color: var(--accent); background: #2a2113; border-radius: 8px; padding: 4px 8px; }

/* In-page camera */
.cam-wrap { position: fixed; inset: 0; background: #000; z-index: 100;
  display: flex; flex-direction: column; }
.cam-wrap video { flex: 1; width: 100%; object-fit: cover; min-height: 0; }
.cam-wrap.flash video { opacity: .3; }
.cam-caption { position: absolute; top: calc(14px + env(safe-area-inset-top)); left: 0; right: 0;
  text-align: center; color: #fff; font-weight: 700; text-shadow: 0 1px 6px #000; }
.cam-count { position: absolute; top: calc(44px + env(safe-area-inset-top)); left: 0; right: 0;
  text-align: center; color: #7dff9b; font-weight: 600; text-shadow: 0 1px 6px #000; font-size: .9rem; }
.cam-bar { flex: none; display: flex; align-items: center; justify-content: space-around;
  padding: 18px 20px calc(24px + env(safe-area-inset-bottom)); background: #000; }
.cam-shutter { width: 74px; height: 74px; border-radius: 50%; background: #fff;
  border: 5px solid #888; padding: 0; }
.cam-shutter:active { background: #ccc; transform: scale(.94); }
.cam-side { background: none; border: 0; color: #fff; font-size: 1.5rem; line-height: 1.2;
  text-align: center; padding: 8px 14px; }
.cam-side small { font-size: .65rem; color: #aaa; }

/* Editor drag & drop */
.sort-row { touch-action: none; user-select: none; transition: transform .12s; }
.sort-row.dragging { transition: none; z-index: 10; position: relative; opacity: .9;
  box-shadow: 0 6px 18px #0008; }
.drag-handle { font-size: 1.2rem; color: var(--muted); padding: 6px 10px 6px 2px;
  cursor: grab; touch-action: none; }
.sink-sel { background: var(--panel); color: var(--text); border: 1px solid #2e3944;
  border-radius: 8px; padding: 6px; font-size: .82rem; max-width: 110px; }

/* Chat */
.chat-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg .bubble { max-width: 85%; padding: 10px 13px; border-radius: 14px; white-space: pre-wrap;
  font-size: .95rem; line-height: 1.45; background: var(--panel); }
.chat-msg.user .bubble { background: #1d3a52; }

/* Mobile: tabs hidden, navigation via topbar menu */
@media (max-width: 759px) {
  .tabs { display: none; }
}

/* Desktop layout */
@media (min-width: 760px) {
  #app { max-width: 1040px; }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
  .quickbtns { grid-template-columns: repeat(2, 1fr); }
  .menu-btn { display: none; }
  body { font-size: 15px; }
}
