:root {
  --ink: #1c1c21;
  --muted: #6b6b76;
  --faint: #9a9aa6;
  --line: #e4e4ea;
  --page: #f6f6f8;
  --card: #ffffff;
  --user-bubble: #edebfd;
  --user-ink: #2c2166;
  --app-bubble: #f1f1f4;
  --accent: #4f46b8;
  --accent-ink: #ffffff;
  --success-bg: #e2f4ec;
  --success-ink: #0d6b4f;
  --warn-bg: #fdf0d9;
  --warn-ink: #7c4d08;
  --info-bg: #e7f0fb;
  --info-ink: #1a5c9e;
  --danger: #dc2626;
}

* { box-sizing: border-box; }
html {
  font-size: 15px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body { max-width: 100%; overflow-x: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--page);
  color: var(--ink);
  line-height: 1.5;
  margin: 0;
  padding: clamp(12px, 4vw, 24px);
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}
main {
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}
img { max-width: 100%; }

/* ---- App header / branding ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.app-header .brand { display: flex; align-items: center; gap: 10px; }
.app-header .brand img.logo { height: 26px; width: auto; display: block; }
.app-header .brand .app-name { font-size: 1.05rem; font-weight: 600; letter-spacing: -0.2px; }
.app-header .brand .app-name small { display: block; font-size: 0.7rem; font-weight: 500; color: var(--muted); }
.profile-btn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--user-bubble); color: var(--user-ink);
  border: none; font-weight: 600; font-size: 0.95rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

h1 { margin: 0 0 2px; font-size: 1.4em; }
.sub { color: var(--muted); margin: 0 0 16px; font-size: 0.9em; }

/* ---- Status row (date + location pill) — lifted straight from the mockups ---- */
.statusrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; position: relative; }
.statusrow[hidden] { display: none; }
.statusrow .time { font-size: 12.5px; color: var(--muted); margin-right: auto; }
.pill { font-size: 11.5px; padding: 3px 10px; border-radius: 999px; font-weight: 500; }
.pill.ok { background: var(--success-bg); color: var(--success-ink); }
.pill.info { background: var(--info-bg); color: var(--info-ink); }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill[hidden] { display: none; }

/* A plain muted button standing in for the raw date input — tapping it opens the
   real (visually hidden but functional) native picker via showPicker(). */
.date-display {
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  padding: 4px 0;
  margin: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.date-display::after { content: '▾'; font-size: 8px; opacity: 0.7; }
.date-input-native {
  position: absolute;
  left: 0; top: 0;
  width: 1px; height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  pointer-events: none;
}

/* ---- Day / Week summary tabs ---- */
.view-tabs {
  display: flex;
  gap: 4px;
  background: var(--app-bubble);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 18px;
}
.view-tab {
  flex: 1;
  font: inherit;
  font-size: 0.88em;
  font-weight: 600;
  padding: 8px 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.view-tab.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(28,28,33,0.08); }

/* ---- Week summary: datacard/ledger, matching the mockup's payroll ledger card ---- */
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.week-nav button {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 1.1em;
  cursor: pointer;
  color: var(--ink);
}
#week-range-label { font-weight: 600; font-size: 0.95em; }

.datacard { background: #fafafc; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; margin-bottom: 10px; }
.datacard .dh { font-size: 11px; color: var(--faint); margin-bottom: 6px; }
.kv { display: flex; justify-content: space-between; font-size: 13px; padding: 3px 0; }
.kv .k { color: var(--muted); }
.kv .v { text-align: right; }
.kv .v.strong { font-weight: 600; }
.kv.total { border-top: 1px solid var(--line); margin-top: 5px; padding-top: 7px; }

.ledger .row { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.ledger .row:last-child { border-bottom: none; }
.ledger .row:hover { background: var(--app-bubble); }
.ledger .l1 { font-size: 13.5px; }
.ledger .l2 { font-size: 11.5px; color: var(--muted); }
.ledger .row.empty .l2 { color: var(--faint); }
.ledger .hrs { font-size: 13.5px; white-space: nowrap; }
.ledger .hrs .tick { color: var(--success-ink); }
.ledger .row.total { border-top: 1.5px solid var(--ink); cursor: default; }
.ledger .row.total:hover { background: none; }
#week-hint { text-align: left; }

form { margin-top: 20px; }
label { display: block; margin-bottom: 16px; font-weight: 600; font-size: 0.92em; }
input, select, textarea {
  font: inherit;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; line-height: 1.35; }
input, select, textarea { width: 100%; }

/* ---- Day ledger: entries render as flat rows in one card, exactly like the Week
   summary ledger — project/task + title on the left, hours + a ✓ (once it's actually
   saved in Zoho) on the right. Edit/delete/remove stay out of the way until hovered
   (or, with no hover on touch, tapped) so the list reads clean, like a receipt. ---- */
#day-ledger #add-entry { margin-top: 10px; }

.entry-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.entry-row:last-child { border-bottom: none; }
.entry-row:hover { background: var(--app-bubble); }
.entry-row .entry-index { display: none; }

.entry-view {
  display: flex;
  align-items: center;
  gap: 10px;
}
.entry-view-text { min-width: 0; flex: 1; cursor: pointer; }
.entry-view-main {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ev-sep { color: var(--faint); margin: 0 2px; }
.entry-view-sub {
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entry-view-sub:empty { display: none; }

.entry-view-end { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.entry-view-hours {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--ink);
  white-space: nowrap;
}
.ev-tick { color: var(--success-ink); }
.ev-tick[hidden] { display: none; }

/* Reveal on hover (desktop); on touch, tapping the row's text toggles .show-actions. */
.row-hover-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.entry-row:hover .row-hover-actions,
.entry-row:focus-within .row-hover-actions,
.entry-row.show-actions .row-hover-actions {
  opacity: 1;
  pointer-events: auto;
}
.row-hover-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1em;
  padding: 4px;
  line-height: 1;
  color: var(--muted);
  font-family: inherit;
}
.row-hover-actions .remove-entry { color: var(--danger); }
.row-actions { display: flex; align-items: center; gap: 2px; }
.row-actions[hidden] { display: none; }

.entry-edit-fields { display: flex; flex-direction: column; gap: 8px; }
.entry-edit-fields .field-label {
  display: block;
  margin: 0;
  font-weight: 600;
  font-size: 0.82em;
  color: var(--muted);
}
.entry-edit-fields .field-label > select,
.entry-edit-fields .field-label > input,
.entry-edit-fields .field-label > textarea {
  margin-top: 4px;
}
.done-entry-btn {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 0.88em;
}

.entry-row:not(.editing) .entry-edit-fields { display: none; }
.entry-row.editing .entry-view { display: none; }
.entry-row.editing {
  background: var(--app-bubble);
  border-radius: 10px;
  border-bottom-color: transparent;
  padding: 10px;
  margin: 2px 0;
}

/* Lock state rides entirely on the ✓ tick (same convention as the Week summary) —
   no border/background tint, so rows read as one plain ledger, not a status list.
   needs-review is the exception: it's an actionable warning, not a status. */
.entry-row.needs-review { border-left: 3px solid #f0b73f; padding-left: 8px; }

.row-delete-confirm {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.85em;
  color: var(--warn-ink);
  background: var(--warn-bg);
  padding: 8px 10px;
  border-radius: 8px;
  margin-top: 6px;
}
.row-delete-confirm[hidden] { display: none; }
.row-delete-confirm button {
  font: inherit;
  padding: 5px 10px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
}
.row-delete-confirm .row-delete-yes { background: var(--danger); color: #fff; }
.row-delete-confirm .row-delete-no { background: #fff; border: 1px solid var(--line); }
.row-delete-confirm button:disabled { opacity: 0.6; cursor: not-allowed; }

.entry-status { font-size: 0.85em; }
.entry-hint { font-size: 0.85em; color: var(--warn-ink); }
.entry-row.needs-review select,
.entry-row.needs-review .hours,
.entry-row.needs-review .title,
.entry-row.needs-review .description {
  border-color: #f0b73f;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); }
  70% { box-shadow: 0 0 0 14px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

/* ---- Hands-free panel ---- */
#handsfree-panel {
  margin-top: 4px;
  margin-bottom: 20px;
  padding: 22px 16px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
}
#handsfree-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#handsfree-btn svg { width: 24px; height: 24px; fill: #fff; }
#handsfree-btn.active { background: var(--danger); }
#handsfree-btn.listening { animation: pulse 1.2s infinite; }
.wave { display: flex; gap: 3px; justify-content: center; align-items: center; height: 14px; margin-top: 12px; visibility: hidden; }
#handsfree-btn.listening + .wave { visibility: visible; }
.wave i { width: 3px; border-radius: 2px; background: var(--accent); opacity: 0.55; animation: wave-bounce 0.9s ease-in-out infinite; }
.wave i:nth-child(1){height:5px; animation-delay: 0s}
.wave i:nth-child(2){height:11px; animation-delay: .1s}
.wave i:nth-child(3){height:7px; animation-delay: .2s}
.wave i:nth-child(4){height:13px; animation-delay: .3s}
.wave i:nth-child(5){height:6px; animation-delay: .4s}
.wave i:nth-child(6){height:10px; animation-delay: .5s}
.wave i:nth-child(7){height:4px; animation-delay: .6s}
@keyframes wave-bounce {
  0%, 100% { transform: scaleY(0.6); opacity: 0.55; }
  50% { transform: scaleY(1.4); opacity: 0.9; }
}
#handsfree-label { margin-top: 10px; font-size: 0.95em; font-weight: 600; }
#handsfree-status {
  margin-top: 4px;
  font-size: 0.9em;
  color: var(--muted);
  min-height: 1.2em;
}
#handsfree-hint {
  margin-top: 10px;
  font-size: 0.8em;
  color: var(--faint);
  line-height: 1.4;
}
#hf-transcript-toggle {
  margin-top: 14px;
  font: inherit;
  font-size: 0.82em;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--app-bubble);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
#hf-unread-badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.75em;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
#hf-transcript-toggle[hidden], #hf-unread-badge[hidden] { display: none; }

/* ---- Hands-free conversation drawer: transcript stays out of the way during a
   voice session (audio carries it); opens on demand instead of forcing a read. ---- */
.drawer-overlay {
  position: fixed; inset: 0;
  background: rgba(28, 28, 33, 0.35);
  z-index: 55;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.drawer-overlay.open { opacity: 1; }
.hf-drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100%;
  width: min(340px, 88vw);
  background: var(--card);
  box-shadow: -4px 0 24px rgba(28, 28, 33, 0.12);
  z-index: 60;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
.hf-drawer.open { transform: translateX(0); }
.hf-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.hf-drawer-header button {
  border: none;
  background: none;
  font-size: 1.1em;
  cursor: pointer;
  color: var(--muted);
}
.hf-drawer-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* ---- Chat panel (bubble language lifted from the mockups) ---- */
#chat-panel {
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  overflow: hidden;
}
#chat-log {
  max-height: 300px;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
#chat-log:empty { display: none; padding: 0; }
.chat-msg {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 15px;
  font-size: 0.9em;
  line-height: 1.5;
  white-space: pre-wrap;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-ink);
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
  align-self: flex-start;
  background: var(--app-bubble);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.chat-msg.chat-confirm {
  background: var(--warn-bg);
  color: var(--warn-ink);
  align-self: stretch;
  max-width: 100%;
}
.chat-confirm-btns { margin-top: 8px; display: flex; gap: 8px; }
.confirm-delete-btn {
  background: var(--danger);
  color: white;
  border: none;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.cancel-delete-btn {
  background: #fff;
  border: 1px solid var(--line);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.confirm-delete-btn:disabled, .cancel-delete-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Typed input is collapsed behind this by default — the mockups never show a
   persistent text box, just the mic. Tapping it reveals input + mic buttons + Send. */
#chat-input-toggle {
  display: block;
  width: 100%;
  text-align: center;
  font: inherit;
  font-size: 0.85em;
  font-weight: 500;
  padding: 10px 12px;
  border: none;
  border-top: 1px solid var(--line);
  background: none;
  color: var(--muted);
  cursor: pointer;
}
#chat-input-toggle:hover { color: var(--ink); background: var(--app-bubble); }
#chat-input-toggle[hidden] { display: none; }
#chat-input-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--card);
}
#chat-input-row[hidden] { display: none; }
#chat-input { width: 100%; }
#mic-edit-btn, #mic-direct-btn {
  border: none;
  background: var(--app-bubble);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#mic-edit-btn svg, #mic-direct-btn svg { width: 17px; height: 17px; fill: var(--ink); }
#mic-direct-btn { background: var(--ink); }
#mic-direct-btn svg { fill: #fff; }
#mic-edit-btn.recording, #mic-direct-btn.recording {
  background: var(--danger);
  animation: pulse 1.2s infinite;
}
#mic-edit-btn.recording svg, #mic-direct-btn.recording svg { fill: #fff; }
#chat-send-btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
}
#chat-send-btn:disabled, #mic-edit-btn:disabled, #mic-direct-btn:disabled { opacity: 0.6; cursor: not-allowed; }
#chat-status { padding: 0 12px 10px; font-size: 0.85em; color: var(--muted); }

button[type="button"]#add-entry {
  background: none;
  border: 1px dashed var(--faint);
  padding: 9px 14px;
  border-radius: 8px;
  cursor: pointer;
  margin-right: 8px;
  color: var(--ink);
}

#submit-btn {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 11px 22px;
  border-radius: 8px;
  cursor: pointer;
}
#submit-btn:disabled { opacity: 0.6; cursor: not-allowed; }

#results { margin-top: 24px; }
#results ul { list-style: none; padding: 0; }
#results li { padding: 4px 0; }
#results li.ok { color: var(--success-ink); }
#results li.fail { color: var(--danger); }

/* ---- Profile modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(28, 28, 33, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-overlay[hidden] { display: none; }
.modal-card {
  background: var(--card);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 360px;
}
.modal-card h2 { margin: 0 0 4px; font-size: 1.1em; }
.modal-card .modal-sub { color: var(--muted); font-size: 0.85em; margin: 0 0 16px; }
.modal-card label { margin-bottom: 14px; }
.voice-gender-options {
  display: flex; gap: 8px;
}
.voice-gender-options label {
  flex: 1; margin: 0;
  display: flex; align-items: center; justify-content: center;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9em;
}
.voice-gender-options input { width: auto; }
.voice-gender-options label:has(input:checked) {
  border-color: var(--accent);
  background: var(--user-bubble);
  color: var(--user-ink);
}
.modal-actions { display: flex; gap: 8px; margin-top: 18px; }
.modal-actions button {
  flex: 1;
  font: inherit;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  border: none;
}
.modal-actions .save-btn { background: var(--accent); color: var(--accent-ink); }
.modal-actions .logout-btn { background: #fff; border: 1px solid var(--line); color: var(--danger); }
