:root {
  --bg: #f4f5f8; --card: #fff; --border: #e7e9ef;
  --ink: #14151a; --muted: #8b93a1; --faint: #aab0bb;
  --accent: #4f46e5; --accent-2: #4338ca; --accent-soft: #eef0ff;
  --green: #10b981; --amber: #d97706; --cyan: #0891b2;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; }

/* top bar (respects iOS safe area) */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 12px;
  background: #fff; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.refresh { width: 38px; height: 38px; border: 1px solid var(--border); background: #fff; border-radius: 10px;
  font-size: 18px; color: var(--muted); cursor: pointer; }
.refresh:active { background: var(--bg); }
.refresh.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* stats */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px 16px 4px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 13px 15px; }
.stat .sv { font-size: 26px; font-weight: 750; letter-spacing: -.02em; line-height: 1; }
.stat .sv .u { font-size: 13px; color: var(--faint); font-weight: 600; }
.stat .sk { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-top: 6px; }
.stat.applied .sv { color: var(--accent); }
.stat.rate .sv { color: var(--cyan); }
.stat.interviewing .sv { color: var(--amber); }
.stat.offers .sv { color: var(--green); }

/* search */
.searchbar { padding: 10px 16px 6px; }
.search { width: 100%; background: #fff; border: 1px solid var(--border); color: var(--ink);
  padding: 12px 14px; border-radius: 12px; outline: none; font-size: 15px; }
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.14); }

/* list */
.list { padding: 6px 16px calc(env(safe-area-inset-bottom, 0px) + 24px); display: flex; flex-direction: column; gap: 10px; }
.state { color: var(--muted); text-align: center; padding: 40px 16px; }

.card { display: block; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px 15px; }
.card:active { border-color: #d5d8e0; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-role { font-weight: 650; font-size: 15.5px; }
.card-company { color: var(--muted); font-size: 13.5px; margin-top: 3px; }
.card-meta { color: var(--faint); font-size: 12.5px; margin-top: 6px; }
.card-salary { color: var(--ink); font-size: 12.5px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.pill { flex: 0 0 auto; padding: 4px 11px; border-radius: 999px; font-size: 11px; font-weight: 650; white-space: nowrap;
  background: var(--accent-soft); color: var(--accent-2); }

/* wider screens: cap width, two-column cards */
@media (min-width: 720px) {
  .stats, .searchbar, .list { max-width: 900px; margin-left: auto; margin-right: auto; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .list { display: grid; grid-template-columns: 1fr 1fr; }
}

/* ---------- auth screen ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--border);
  border-radius: 18px; padding: 30px 24px; text-align: center; box-shadow: 0 20px 50px -20px rgba(20,21,26,.25); }
.auth-card h1 { font-size: 20px; margin: 14px 0 16px; letter-spacing: -.01em; }
.auth-input { width: 100%; box-sizing: border-box; margin-bottom: 10px; border: 1px solid var(--border);
  border-radius: 11px; padding: 13px 14px; font-size: 15px; background: #fbfbfc; color: var(--ink); outline: none; }
.auth-input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.btn { width: 100%; border: none; border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 650; cursor: pointer; font-family: inherit; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-2); }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--border); }
.auth-toggle { margin-top: 12px; font-size: 13px; color: var(--muted); }
.link { background: none; border: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 0; }
.auth-or { display: flex; align-items: center; gap: 8px; color: var(--faint); font-size: 12px; margin: 16px 0 12px; }
.auth-or::before, .auth-or::after { content: ''; height: 1px; background: var(--border); flex: 1; }
.auth-note { margin-top: 12px; font-size: 12.5px; min-height: 16px; color: var(--muted); }
.auth-note.err { color: #dc2626; }

.topbar-actions { display: flex; gap: 8px; }
.icon-btn { width: 38px; height: 38px; border: 1px solid var(--border); background: #fff; border-radius: 10px;
  font-size: 17px; color: var(--muted); cursor: pointer; }
.icon-btn:active { background: var(--bg); }
.card { display: block; width: 100%; text-align: left; font: inherit; cursor: pointer; }

/* ---------- detail / edit sheet ---------- */
.detail { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.detail-backdrop { position: absolute; inset: 0; background: rgba(15,17,22,.45); }
.detail-sheet { position: relative; width: 100%; max-width: 560px; background: var(--card);
  border-radius: 20px 20px 0 0; padding: 20px 20px calc(env(safe-area-inset-bottom, 0px) + 22px);
  box-shadow: 0 -10px 40px rgba(0,0,0,.2); animation: rise .2s ease; }
@keyframes rise { from { transform: translateY(20px); opacity: .6; } to { transform: none; opacity: 1; } }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.detail-role { font-size: 17px; font-weight: 700; }
.detail-company { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.detail-label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 12px 0 6px; }
.detail-select, .detail-notes { width: 100%; box-sizing: border-box; border: 1px solid var(--border);
  border-radius: 11px; padding: 12px 13px; font-size: 15px; font-family: inherit; background: #fbfbfc; color: var(--ink); outline: none; }
.detail-select:focus, .detail-notes:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.detail-notes { resize: vertical; }
.detail-link { display: inline-block; margin: 14px 0 4px; color: var(--accent); font-size: 13.5px; font-weight: 600; text-decoration: none; }
.detail .btn.primary { margin-top: 16px; }
.detail-note { margin-top: 10px; font-size: 12.5px; min-height: 16px; color: #0a6b3b; text-align: center; }
.detail-note.err { color: #dc2626; }

/* [hidden] must win over the display rules above */
.auth[hidden], .app[hidden], .detail[hidden] { display: none !important; }

/* expanded detail sheet */
.detail-sheet { display: flex; flex-direction: column; max-height: 88vh; }
.detail-head-titles { min-width: 0; }
.detail-scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; margin: 4px -2px 0; padding: 0 2px; }
.detail-input { width: 100%; box-sizing: border-box; border: 1px solid var(--border); border-radius: 11px;
  padding: 11px 13px; font-size: 15px; font-family: inherit; background: #fbfbfc; color: var(--ink); outline: none; }
.detail-input:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
.detail-meta { margin: 16px 0 4px; border-top: 1px solid var(--border); padding-top: 12px; }
.meta-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 4px 0; }
.meta-row span:first-child { color: var(--muted); }
.meta-row span:last-child { color: var(--ink); text-align: right; }
.jd-toggle { width: 100%; margin-top: 14px; background: #f2f3f6; border: 1px solid var(--border); color: var(--accent-2);
  border-radius: 10px; padding: 11px; font-size: 13.5px; font-weight: 600; cursor: pointer; font-family: inherit; }
.jd-body { margin-top: 10px; font-size: 13px; line-height: 1.5; color: #374151; white-space: pre-wrap;
  max-height: 320px; overflow-y: auto; background: #fbfbfc; border: 1px solid var(--border); border-radius: 10px; padding: 12px; }

/* ---------- drawer ---------- */
.drawer { position: fixed; inset: 0; z-index: 60; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(15,17,22,.45); }
.drawer-panel { position: absolute; top: 0; left: 0; bottom: 0; width: 78%; max-width: 300px;
  background: var(--card); box-shadow: 4px 0 24px rgba(0,0,0,.2); padding: calc(env(safe-area-inset-top,0px) + 18px) 14px 18px;
  display: flex; flex-direction: column; gap: 4px; animation: slideIn .18s ease; }
@keyframes slideIn { from { transform: translateX(-14px); opacity:.7; } to { transform:none; opacity:1; } }
.drawer-brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 18px; padding: 4px 8px 12px; }
.drawer-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: none; border: none;
  font: inherit; font-size: 15px; color: var(--ink); padding: 12px 10px; border-radius: 10px; cursor: pointer; }
.drawer-item span { width: 20px; text-align: center; }
.drawer-item:active { background: var(--bg); }
.drawer-item.danger { color: #dc2626; }
.drawer-sep { height: 1px; background: var(--border); margin: 8px 4px; }
.drawer-account { font-size: 12px; color: var(--muted); padding: 4px 10px 8px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- panels (filter + calendar) ---------- */
.panel { margin: 0 16px; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; }
.panel-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.panel-row label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.panel-row select { flex: 0 0 60%; border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; font: inherit; font-size: 14px; background: #fbfbfc; color: var(--ink); }
.panel-clear { width: 100%; margin-top: 4px; background: none; border: none; color: var(--accent); font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; padding: 6px; }

/* calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-weight: 700; font-size: 14px; }
.cal-nav { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; width: 30px; height: 30px; font-size: 16px; cursor: pointer; color: var(--muted); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-dow { text-align: center; font-size: 10px; font-weight: 700; color: var(--faint); padding: 2px 0; }
.cal-cell { position: relative; aspect-ratio: 1; border: none; background: transparent; border-radius: 8px; font: inherit; font-size: 13px; color: var(--ink); cursor: pointer; }
.cal-cell.empty { visibility: hidden; }
.cal-dow.wknd { color: #e05252; }
.cal-cell.wknd { color: #e05252; }
.cal-cell.lvl1 { background: #dcf7ea; color: #0a6b3b; }
.cal-cell.lvl2 { background: #a7ebc9; color: #0a6b3b; }
.cal-cell.lvl3 { background: #5fd6a0; color: #064e2b; font-weight: 700; }
.cal-cell.lvl4 { background: #16a06a; color: #fff; font-weight: 700; }
.cal-cell.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-cell.sel:not(.lvl1):not(.lvl2):not(.lvl3):not(.lvl4) { background: var(--accent); color: #fff; }
.cal-foot { text-align: center; font-size: 12px; color: var(--muted); margin-top: 10px; }

/* card heart + layout */
.card { position: relative; padding-right: 44px; }
.card-body { cursor: pointer; }
.fav-heart { position: absolute; top: 12px; right: 12px; background: none; border: none; font-size: 18px; line-height: 1; color: var(--faint); cursor: pointer; padding: 2px; }
.fav-heart.on { color: #e0245e; }
.day-filter { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.day-filter button { background: none; border: none; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }

/* detail fav + archive */
.fav-btn { background: none; border: none; font-size: 22px; line-height: 1; color: var(--faint); cursor: pointer; padding: 0 6px; }
.fav-btn.on { color: #e0245e; }
.detail-actions { margin-top: 14px; }
.btn.subtle { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

/* per-day application count badge */
.cal-count { position: absolute; top: 3px; right: 5px; font-size: 9px; font-weight: 700; font-style: normal;
  color: #0a6b3b; line-height: 1; }
.cal-cell.lvl4 .cal-count { color: #fff; }

/* today's date — dotted outline */
.cal-cell.today { outline: 2px dotted var(--accent); outline-offset: -2px; border-radius: 8px; }
.cal-cell.today.sel { outline-style: solid; }