:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1c2024;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #4f46e5;
  --brand-ink: #ffffff;
  --danger: #dc2626;
  --negative: #dc2626;
  --radius: 12px;
}

* { 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);
  line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.brand { font-weight: 700; font-size: 1.05rem; color: var(--ink); }
.brand:hover { text-decoration: none; }
.topnav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topnav .user { color: var(--muted); font-size: 0.9rem; }
.topnav .logout { color: var(--muted); }

.container { max-width: 1000px; margin: 1.5rem auto; padding: 0 1.25rem; }
.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 2rem 1rem; }

h1 { font-size: 1.5rem; margin: 0.2rem 0; }
h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.page-head .actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card.empty { text-align: center; color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

.budget-card { text-align: center; }
.budget-big { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.02em; margin: 0.25rem 0; }
.negative { color: var(--negative); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
td.num, th.num { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #fafafe; }
table.kv th { width: 40%; color: var(--muted); font-weight: 500; }
.nowrap { white-space: nowrap; }
.mono, .mono * { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78rem; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

.btn {
  display: inline-block; cursor: pointer;
  background: var(--brand); color: var(--brand-ink);
  border: 1px solid var(--brand); border-radius: 8px;
  padding: 0.5rem 0.9rem; font-size: 0.9rem; font-weight: 600;
  text-decoration: none;
}
.btn:hover { filter: brightness(0.95); text-decoration: none; }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-danger { background: #fff; color: var(--danger); border-color: #f0c4c4; }
.btn-small { padding: 0.3rem 0.55rem; font-size: 0.8rem; }
.row-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

.badge { display: inline-block; background: var(--brand); color: #fff; font-size: 0.68rem; padding: 0.08rem 0.4rem; border-radius: 999px; vertical-align: middle; margin-left: 0.3rem; }
.badge-muted { background: #e5e7eb; color: #374151; }

label { display: block; margin-bottom: 0.9rem; font-size: 0.9rem; font-weight: 600; }
label.radio, label.check { font-weight: 400; display: flex; gap: 0.5rem; align-items: flex-start; }
input[type="text"], input[type="email"], input[type="date"], input[type="number"] {
  width: 100%; padding: 0.5rem 0.6rem; margin-top: 0.25rem;
  border: 1px solid var(--line); border-radius: 8px; font-size: 0.95rem; font-weight: 400;
}
input[type="radio"], input[type="checkbox"] { margin-top: 0.3rem; width: auto; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 0.9rem; padding: 0.75rem; }
legend { font-size: 0.85rem; color: var(--muted); padding: 0 0.4rem; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: 0.78rem; margin-top: 0.25rem; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.inline-form { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { margin-bottom: 0; }
.callout { background: #f1f5ff; border: 1px solid #dbe4ff; border-radius: 8px; padding: 0.6rem 0.8rem; font-size: 0.9rem; margin: 0.5rem 0 1rem; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: none; }

/* Button alignment in headers */
.page-head .actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.page-head .actions form { display: inline-flex; margin: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; line-height: 1.2; vertical-align: middle; }

/* Avatars */
.avatar { position: relative; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: #fff; font-weight: 700; overflow: hidden; flex: 0 0 auto; }
.avatar-fallback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.avatar-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.name-cell { display: flex; align-items: center; gap: 0.6rem; }
.detail-id { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.25rem; }
.detail-id h1 { margin: 0; }

/* Phone thumbnails */
.device-cell { display: flex; align-items: center; gap: 0.55rem; }
.phone-thumb { display: block; flex: 0 0 auto; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.12)); }
.thumb-box { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; }
.device-head { display: flex; gap: 1rem; align-items: flex-start; }
.device-head .thumb-box { padding-top: 1.6rem; }
.device-head-fields { flex: 1; }
.return-box { border-color: #f0d2b8; background: #fdf6ef; }

/* Date picker */
.datefield { display: block; }
.dp-input { cursor: pointer; background: #fff; }
.dp-input.dp-error { border-color: var(--danger); }
.dp-popup { position: absolute; z-index: 1000; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,0.16); padding: 0.6rem; width: 264px; }
.dp-head { display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.5rem; }
.dp-head select { flex: 1; padding: 0.3rem; border: 1px solid var(--line); border-radius: 6px; font-size: 0.85rem; background: #fff; }
.dp-nav { background: #f3f4f6; border: 1px solid var(--line); border-radius: 6px; width: 30px; height: 30px; cursor: pointer; font-size: 0.7rem; color: var(--ink); }
.dp-nav:hover { background: #e5e7eb; }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-dow { text-align: center; font-size: 0.7rem; color: var(--muted); padding: 0.2rem 0; }
.dp-day { background: none; border: none; border-radius: 6px; padding: 0.35rem 0; cursor: pointer; font-size: 0.85rem; color: var(--ink); }
.dp-day:hover { background: #eef2ff; }
.dp-day.sel { background: var(--brand); color: #fff; }
.dp-foot { margin-top: 0.4rem; text-align: center; }
.dp-today { background: none; border: none; color: var(--brand); cursor: pointer; font-size: 0.8rem; }

.signin { max-width: 420px; margin: 3rem auto; text-align: center; }
.btn-google { display: inline-flex; align-items: center; gap: 0.5rem; }
.dev-login { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px dashed var(--line); }
.dev-login input { max-width: 260px; margin: 0.25rem auto; }
