:root {
  --bg: #f4f7f9;
  --surface: #ffffff;
  --ink: #1a2634;
  --ink-2: #4b5a69;
  --ink-3: #8696a7;
  --line: #e3e9ef;
  --line-soft: #eef2f5;
  --orange: #e67e22;
  --orange-2: #d35400;
  --orange-soft: #fdf0e3;
  --red: #d93025;
  --red-soft: #fce8e6;
  --blue: #1a73e8;
  --blue-soft: #e8f0fe;
  --amber: #b06000;
  --amber-soft: #fef7e0;
  --green: #137333;
  --green-soft: #e6f4ea;
  --shadow: 0 1px 2px rgba(18, 28, 39, .06), 0 2px 8px rgba(18, 28, 39, .04);
  --radius: 14px;
  --tabbar: 64px;
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --surface: #17212c;
    --ink: #e8eef4;
    --ink-2: #aab7c4;
    --ink-3: #788898;
    --line: #26323f;
    --line-soft: #1e2934;
    --orange: #f0954a;
    --orange-2: #f5a25d;
    --orange-soft: #3a2614;
    --red: #f28b82;
    --red-soft: #3c1f1d;
    --blue: #8ab4f8;
    --blue-soft: #1c2b44;
    --amber: #fdd663;
    --amber-soft: #3a3017;
    --green: #81c995;
    --green-soft: #183323;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
/* Text is set in rem, so this one size scales the whole app (20px) */
html { font-size: 125%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 400 .9375rem/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1 { margin: 0; font-size: 1.6rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; }
button { font: inherit; color: inherit; }
a { color: inherit; }

/* Splash */
.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.splash img { border-radius: 16px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; transform: scale(.96); } }

/* Sign in */
.signin { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.signin-card {
  width: 100%; max-width: 380px; padding: 36px 28px; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
}
.signin-logo { margin: 0 auto 28px; display: block; height: 44px; width: auto; }
.signin-card h1 { font-size: 1.5rem; }
.signin-card p { margin: 10px 0 0; color: var(--ink-2); }
.btn-google {
  margin-top: 28px; width: 100%; min-height: 48px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn-google:hover { border-color: var(--ink-3); }
.btn-google:disabled { opacity: .6; cursor: progress; }
.signin-error { margin-top: 16px !important; padding: 10px 12px; border-radius: 10px; background: var(--red-soft); color: var(--red) !important; font-size: .9rem; text-align: left; }

/* App shell */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-logo { height: 30px; width: auto; display: block; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: none; color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--line-soft); }
.icon-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.account { position: relative; }
.account summary { list-style: none; cursor: pointer; padding: 4px; border-radius: 50%; }
.account summary::-webkit-details-marker { display: none; }
.account-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; padding: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(18, 28, 39, .18);
}
.account-name { font-weight: 600; }
.account-email { color: var(--ink-2); font-size: .85rem; word-break: break-all; }
.account-menu button {
  margin-top: 12px; width: 100%; min-height: 40px;
  border: 1px solid var(--line); border-radius: 8px; background: none; cursor: pointer; font-weight: 600; color: var(--red);
}

/* Tabs: a bottom bar on phones, under the header on wider screens */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab {
  min-height: var(--tabbar); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; color: var(--ink-3); font-size: .75rem; font-weight: 600; cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--orange-2); }
.tab:focus-visible { outline: 2px solid var(--orange); outline-offset: -4px; border-radius: 10px; }

.views { max-width: 860px; margin: 0 auto; padding: 18px 16px calc(var(--tabbar) + env(safe-area-inset-bottom) + 88px); }

@media (min-width: 768px) {
  .tabs {
    position: sticky; top: 61px; bottom: auto;
    display: flex; justify-content: center; gap: 4px; padding: 0 16px;
    border-top: 0; border-bottom: 1px solid var(--line);
  }
  .tab { flex-direction: row; gap: 8px; min-height: 48px; padding: 0 16px; font-size: .9rem; border-bottom: 2px solid transparent; }
  .tab svg { width: 18px; height: 18px; }
  .tab[aria-selected="true"] { border-bottom-color: var(--orange); }
  .views { padding-bottom: 104px; }
}

.ios-share { vertical-align: -3px; color: var(--blue); }
.btn-install {
  margin-top: 28px; width: 100%; min-height: 50px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 0; border-radius: 999px; background: var(--orange); color: #fff; font-weight: 650; cursor: pointer;
}
.btn-install:hover { background: var(--orange-2); }
.gate-how { margin-top: 20px !important; font-size: .95rem; }
.gate-how b { color: var(--ink); font-weight: 650; }
.gate-done { margin-top: 16px !important; padding: 10px 12px; border-radius: 10px; background: var(--green-soft); color: var(--green) !important; font-size: .9rem; }

.banner { margin: 0 0 14px; padding: 10px 14px; border-radius: 10px; background: var(--amber-soft); color: var(--amber); font-size: .9rem; }
.banner.error { background: var(--red-soft); color: var(--red); }

.view-head { display: grid; gap: 12px; margin-bottom: 14px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink-2);
  font-size: .875rem; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.chip b { font-weight: 700; }
.chip[aria-pressed="true"] { background: var(--blue-soft); border-color: transparent; color: var(--blue); }
.search {
  width: 100%; min-height: 42px; padding: 0 14px 0 38px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface) no-repeat 14px 50% / 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238696a7' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-4-4'/%3E%3C/svg%3E");
  font: inherit; color: var(--ink);
}
.search:focus { outline: 2px solid var(--orange); outline-offset: 1px; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list:empty { display: none; }
.row { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: start; padding: 14px 16px; border-top: 1px solid var(--line-soft); }
.row:first-child { border-top: 0; }
.row-main { min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--ink-2); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.row-side { text-align: right; font-size: .8rem; color: var(--ink-2); white-space: nowrap; }
.row-side strong { display: block; font-size: .85rem; color: var(--ink); font-weight: 600; }
.row-side .overdue { color: var(--red); }
.row-side .today { color: var(--blue); }
.action-line { display: flex; align-items: baseline; gap: 6px; margin-top: 6px; font-size: .9rem; }
.action-line .type { font-weight: 600; flex: none; }
.action-line .text { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.links { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; font-size: .85rem; }
.links a { color: var(--blue); text-decoration: none; }

.now { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--line-soft); }
.now:first-child { border-top: 0; }
.now span { flex: none; padding: 2px 8px; border-radius: 999px; background: var(--red); color: #fff; font-size: .7rem; font-weight: 700; letter-spacing: .06em; }
.now::after { content: ""; flex: 1; height: 2px; background: var(--red); border-radius: 2px; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  color: #fff; font-size: .85rem; font-weight: 700; background: var(--c, #6c86a1); background-size: cover; background-position: center;
}
.avatar-me { width: 32px; height: 32px; font-size: .75rem; }

.pill { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.pill.inbox { background: var(--line-soft); color: var(--ink-2); }
.pill.qualifying { background: var(--amber-soft); color: var(--amber); }
.pill.deal { background: var(--blue-soft); color: var(--blue); }
.pill.won { background: var(--green-soft); color: var(--green); }
.pill.lost, .pill.out { background: var(--red-soft); color: var(--red); }
.pill.rotting { background: var(--red-soft); color: var(--red); }
.pill.hold { background: var(--line-soft); color: var(--ink-3); }
.money { font-size: .8rem; font-weight: 600; color: var(--ink-2); }

.empty { padding: 40px 20px; text-align: center; color: var(--ink-2); }
.empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 4px; }

.skeleton .row-title, .skeleton .row-sub { height: 12px; border-radius: 6px; background: var(--line-soft); }
.skeleton .row-title { width: 55%; margin: 4px 0 10px; }
.skeleton .row-sub { width: 80%; }
.skeleton .avatar { background: var(--line-soft); }

/* New lead button */
.fab {
  position: fixed; z-index: 9; right: 16px; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 16px);
  display: inline-flex; align-items: center; gap: 8px; min-height: 52px; padding: 0 20px 0 16px;
  border: 0; border-radius: 999px; background: var(--orange); color: #fff;
  font-weight: 650; cursor: pointer; box-shadow: 0 6px 20px rgba(230, 126, 34, .4);
}
.fab:hover { background: var(--orange-2); }
.fab:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
@media (min-width: 768px) { .fab { bottom: 28px; right: 28px; } }

/* Sheet (a bottom sheet on phones, a dialog on wider screens) */
.sheet {
  width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; padding: 0;
  border: 0; border-radius: 20px 20px 0 0; background: var(--surface); color: var(--ink);
  box-shadow: 0 -10px 40px rgba(18, 28, 39, .2);
}
.sheet[open] { animation: sheet-up .25s ease-out; }
.sheet::backdrop { background: rgba(18, 28, 39, .45); }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 640px) {
  .sheet { max-width: 520px; margin: auto; border-radius: 20px; }
}
.sheet-form { display: flex; flex-direction: column; max-height: 92dvh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 20px; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; font-weight: 650; }
.sheet-body { overflow-y: auto; padding: 4px 20px 8px; }
.sheet-foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
}
.sheet fieldset { border: 0; margin: 0 0 16px; padding: 0; display: grid; gap: 12px; }
.sheet legend { padding: 0; margin-bottom: 8px; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.field { display: grid; gap: 5px; }
.field > span { font-size: .85rem; font-weight: 600; color: var(--ink-2); }
.field input, .field textarea, .field select {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  font: inherit; font-size: 1rem; color: var(--ink);
}
.field textarea { resize: vertical; min-height: 80px; }
.field select { appearance: none; -webkit-appearance: none; padding-right: 36px; background: var(--bg) no-repeat right 12px center / 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238696a7' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); }
.due-row { grid-template-columns: 1fr auto; }
.check { white-space: nowrap; display: flex; align-items: center; gap: 10px; align-self: end; min-height: 44px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--orange); }
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--orange); outline-offset: 0; border-color: transparent; background: var(--surface); }
.field input[aria-invalid="true"], .field select[aria-invalid="true"] { border-color: var(--red); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-hint { margin: -4px 0 0; font-size: .85rem; color: var(--green); }
.sheet-note { margin: 0 0 8px; font-size: .85rem; color: var(--ink-2); }
.form-error { margin: 8px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--red-soft); color: var(--red); font-size: .9rem; }
.btn-primary, .btn-secondary {
  min-height: 46px; padding: 0 22px; border-radius: 999px; font-weight: 650; cursor: pointer;
}
.btn-primary { border: 0; background: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-2); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-secondary { border: 1px solid var(--line); background: none; color: var(--ink); }
.row-action {
  margin-top: 8px; padding: 0; border: 0; background: none;
  color: var(--orange-2); font-size: .85rem; font-weight: 650; cursor: pointer;
}

/* Toast */
.toast {
  position: fixed; z-index: 20; left: 50%; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 84px);
  transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px);
  padding: 12px 18px; border-radius: 12px; background: var(--ink); color: var(--surface);
  font-weight: 600; box-shadow: 0 8px 24px rgba(18, 28, 39, .25);
}
@media (min-width: 768px) { .toast { bottom: 100px; } }

@media (prefers-reduced-motion: reduce) {
  .splash img, .icon-btn.spinning svg, .sheet[open] { animation: none; }
}
