:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --text: #1f2328;
  --muted: #6b6f76;
  --line: #e6e2da;
  --accent: #2c6e7f;
  --accent-ink: #ffffff;
  --danger: #b4443b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 20, 20, .05), 0 6px 18px rgba(20, 20, 20, .05);

  --c-planned: #8a8f98;
  --c-reachedout: #1f9d9a;
  --c-awaitingreply: #5fa85a;
  --c-applied: #3b7ddd;
  --c-screening: #8b5cf6;
  --c-interview: #e08a1e;
  --c-rejected: #c4473f;
  --c-ghosted: #7a86a8;
  --c-notinteresting: #a39a8c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1c2024;
    --surface-2: #181b1f;
    --text: #e8eaed;
    --muted: #9aa0a8;
    --line: #2b3036;
    --accent: #5aa9bc;
    --accent-ink: #0f1a1d;
    --danger: #e0766d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

html { color-scheme: light dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

h1, h2, h3, p { margin: 0; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 22px clamp(16px, 4vw, 40px);
}

.brand { display: flex; align-items: center; gap: 14px; }

.logo {
  display: block; flex: none;
  width: 44px; height: 44px;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(29, 82, 98, .35);
}

.top h1 { font-size: 22px; letter-spacing: -.01em; }
.sub { color: var(--muted); font-size: 13px; }

.top-actions { display: flex; gap: 10px; align-items: center; }

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform .06s ease, background .15s ease, border-color .15s ease;
  display: inline-flex; align-items: center;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.ghost:hover { background: var(--surface); }
.btn.signout { gap: 7px; background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: var(--danger); color: var(--danger); }
.btn.signout:hover { background: var(--danger); color: #fff; }
.btn.signout svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn:focus-visible, .filter-btn:focus-visible, .filter-item:focus-visible, .icon-btn:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

main { padding: 0 clamp(16px, 4vw, 40px) 60px; max-width: 1500px; margin: 0 auto; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat .n { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat.alert .n { color: var(--c-interview); }

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
#search {
  flex: 1 1 240px;
  max-width: 340px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.signin { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--bg); }
.signin[hidden] { display: none; }
.signin-card { width: min(380px, 100%); display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); text-align: center; }
.signin-card h2 { font-size: 22px; margin-top: 6px; }
.signin-card p { color: var(--muted); margin-bottom: 14px; }
.signin-options { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.signin-options .btn { width: 100%; justify-content: center; min-height: 46px; }

.filter { position: relative; flex: 0 0 auto; }
.filter-btn, .filter-item {
  display: flex; align-items: center; gap: 9px;
  font: inherit; font-size: 14px; color: var(--text); cursor: pointer; text-align: left;
}
.filter-btn {
  min-width: 190px; padding: 10px 12px 10px 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.filter-btn svg { width: 16px; height: 16px; margin-left: 2px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; opacity: .6; transition: transform .15s ease; }
.filter-btn[aria-expanded="true"] svg { transform: rotate(180deg); }
.filter .dot { width: 9px; height: 9px; flex: none; border-radius: 50%; background: var(--dot, var(--muted)); }
.filter-label { flex: 1 1 auto; }
.filter .count { opacity: .6; font-variant-numeric: tabular-nums; font-size: 13px; }
.filter-menu {
  position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; min-width: 100%; padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow), 0 12px 32px rgba(20, 20, 20, .12);
}
.filter-menu[hidden] { display: none; }
.filter-item { width: 100%; padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; }
.filter-item:hover { background: var(--surface-2); }
.filter-item.active { background: var(--surface-2); font-weight: 600; }

.tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.tag.warn { color: var(--c-interview); border-color: color-mix(in srgb, var(--c-interview) 45%, var(--line)); }
.tag.bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }

.status-sel {
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--dot);
  background: color-mix(in srgb, var(--dot) 14%, transparent);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
}
.status-sel option { color: var(--text); background: var(--surface); }
/* List */
.list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td .sub-line { color: var(--muted); font-size: 13px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  color: var(--dot);
  background: color-mix(in srgb, var(--dot) 14%, transparent);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--dot); }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Dialog */
dialog {
  border: 0;
  border-radius: 18px;
  padding: 0;
  width: min(720px, calc(100vw - 24px));
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(10, 12, 14, .5); backdrop-filter: blur(2px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 6px; }
.dlg-head h2 { font-size: 20px; }
.icon-btn { background: transparent; border: 0; color: var(--muted); font-size: 28px; line-height: 1; cursor: pointer; padding: 2px 8px; border-radius: 8px; }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; padding: 14px 24px 8px; }
.grid label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.grid .wide { grid-column: 1 / -1; }
.grid input, .grid select, .grid textarea {
  font: inherit; font-weight: 400;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  width: 100%;
}
.grid textarea { resize: vertical; }
.dlg-foot { display: flex; gap: 10px; align-items: center; padding: 14px 24px 22px; }
.spacer { flex: 1; }
.grid .check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-size: 14px; cursor: pointer; }
.grid .check input { width: 18px; height: 18px; min-height: 0; padding: 0; accent-color: var(--accent); }
.interview-tag { align-self: center; font-size: 11.5px; font-weight: 600; line-height: 1; color: var(--c-interview); }
.doc-badges { display: inline-flex; gap: 5px; margin-left: 8px; vertical-align: -2px; }
.doc-badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 3px; margin: -3px; border: 0; border-radius: 6px;
  background: transparent; color: var(--accent); cursor: pointer;
}
.doc-badge:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.doc-badge:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.doc-badge svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.docs-title { font-size: 12.5px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 8px; }
.doc-slot {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 9px 12px; margin-bottom: 8px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px;
}
.doc-label { font-weight: 600; min-width: 92px; }
.doc-info { flex: 1 1 160px; min-width: 0; overflow-wrap: anywhere; }
.doc-info a { color: var(--accent); }
.doc-meta, .doc-none { color: var(--muted); font-size: 12.5px; }
.btn.small { padding: 6px 12px; min-height: 0; font-size: 13px; }
.link-row { grid-column: 1 / -1; font-size: 13px; }
.link-row a { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px;
  font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}



.open-link { display: inline-block; margin-top: 4px; font-size: 13px; font-weight: 600; color: var(--accent); text-decoration: none; }
.open-link:hover { text-decoration: underline; }
.no-link { display: block; margin-top: 4px; font-style: italic; }

@media (max-width: 760px) {
  table { min-width: 0; }
  thead { display: none; }
  tbody tr { display: block; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  tbody tr:last-child { border-bottom: 0; }
  td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 5px 0; border: 0; text-align: right; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; text-align: left; }
  td.c-main { display: block; text-align: left; padding-bottom: 8px; }
  td.c-main::before { content: none; }
  .top { padding-top: 16px; }
  .top-actions { width: 100%; }
}

/* ==========================================================================
   Phone layout (max 640px). Everything mobile-specific lives in this block;
   nothing above this line changes for desktop or tablet.
   ========================================================================== */
@media (max-width: 640px) {
  main { padding-bottom: 104px; }

  /* header: compact brand, three equal tools, Add as a floating button */
  .top { padding: 14px 16px 4px; gap: 12px; }
  .brand { gap: 12px; }
  .logo { width: 40px; height: 40px; border-radius: 11px; box-shadow: none; }
  .top h1 { font-size: 20px; }
  .desk-only { display: none; }
  .top { position: relative; }
  .brand { padding-right: 56px; }
  .top-actions { width: 100%; }
  /* sign out: icon-only, pinned to the top-right corner */
  .btn.signout { position: absolute; top: 14px; right: 16px; width: 44px; height: 44px; min-height: 0; padding: 0; justify-content: center; border-radius: 12px; }
  .btn.signout svg { width: 20px; height: 20px; }
  .signout-label { display: none; }
  #addBtn {
    position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 20;
    min-height: 52px; padding: 14px 24px; border-radius: 999px; font-size: 16px; white-space: nowrap;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .4);
  }

  /* stats: one swipeable strip, follow-ups due first when there are any */
  .stats {
    display: flex; gap: 10px; margin: 0 -16px 14px; padding: 2px 16px 6px;
    overflow-x: auto; scroll-snap-type: x proximity; scroll-padding-inline: 16px; scrollbar-width: none;
  }
  .stats::-webkit-scrollbar { display: none; }
  .stat { flex: 0 0 auto; min-width: 112px; padding: 10px 14px; scroll-snap-align: start; box-shadow: none; }
  .stat .n { font-size: 22px; }
  .stat .l { font-size: 12px; white-space: nowrap; }
  .stat.alert { order: -1; }

  /* search + filters: full-width search, full-width filter dropdown */
  .toolbar { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 10px; margin-bottom: 14px; }
  #search { flex: none; max-width: none; width: 100%; min-height: 46px; font-size: 16px; }
  .filter, .filter-btn { width: 100%; }
  .filter-btn { min-height: 46px; font-size: 16px; }
  .filter-item { min-height: 44px; font-size: 16px; }

  /* jobs: folding cards. Collapsed = name, role and a status dot. Tap to open the rest. */
  .list { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  table, tbody { display: block; width: 100%; min-width: 0; }
  tbody tr {
    position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; align-items: start;
    padding: 14px 16px; margin-bottom: 10px;
    background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  }
  tbody tr:hover { background: var(--surface); }
  tbody tr:last-child { border-bottom: 1px solid var(--line); }
  td {
    display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start;
    gap: 3px; padding: 0; border: 0; text-align: left; min-width: 0; font-size: 15px; line-height: 1.4;
  }
  td::before { font-size: 11px; letter-spacing: .05em; }

  /* collapsed: only the title area is shown */
  tbody tr:not(.open) td:not(.c-main) { display: none; }
  tbody tr:not(.open) .loc-line,
  tbody tr:not(.open) .notes,
  tbody tr:not(.open) .edit-btn { display: none; }

  td.c-main { grid-column: 1 / -1; position: relative; gap: 2px; min-height: 44px; justify-content: center; padding: 0 34px 0 20px; }
  tbody tr.open td.c-main { padding-right: 100px; justify-content: flex-start; }
  td.c-main strong { font-size: 17px; line-height: 1.3; }
  td.c-main .sub-line { font-size: 14px; line-height: 1.35; }
  .status-dot { display: block; position: absolute; left: 0; top: 7px; width: 10px; height: 10px; border-radius: 50%; background: var(--dot); }
  .notes {
    display: block; margin: 10px -100px 0 -20px; padding-top: 10px; border-top: 1px solid var(--line);
    color: var(--muted); font-size: 14px; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere;
  }
  .fold-btn {
    display: flex; align-items: center; justify-content: center; position: absolute; top: -6px; right: -10px;
    width: 44px; height: 44px; padding: 0; border: 0; border-radius: 12px; background: transparent; color: var(--muted); cursor: pointer;
  }
  .fold-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; transition: transform .2s ease; }
  tbody tr.open .fold-btn svg { transform: rotate(180deg); }
  .edit-btn {
    display: inline-flex; align-items: center; position: absolute; top: 0; right: 38px; height: 32px; padding: 0 14px;
    border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--accent);
    font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  }

  /* opened: the details, in a roomy two-column grid */
  tbody tr.open td[data-label="Status"],
  tbody tr.open td[data-label="Link"],
  tbody tr.open td[data-label="Contact"] { grid-column: 1 / -1; }
  tbody tr.open td[data-label="Applied"] { grid-column: 1; }
  tbody tr.open td[data-label="Follow up"] { grid-column: 2; }
  tbody tr.open td[data-label="Deadline"] { grid-column: 1; }
  td[data-label="Contact"] span { display: block; }
  td[data-label="Contact"] br { display: none; }
  td.is-empty[data-label="Contact"] { display: none; }
  .status-sel { width: 100%; min-height: 46px; padding: 8px 32px 8px 14px; font-size: 15px; }
  .open-link { display: inline-flex; align-items: center; min-height: 32px; margin: 0; font-size: 15px; }
  .tag { font-size: 13px; padding: 3px 10px; }
  .empty { padding: 28px 0; }
  /* add / edit form: full-screen sheet with a pinned Save bar */
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  dialog[open] { display: flex; flex-direction: column; }
  #form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
  .dlg-head { padding: 16px 16px 4px; }
  .icon-btn { min-width: 44px; min-height: 44px; }
  .grid { flex: 1; overflow-y: auto; align-content: start; padding: 12px 16px 16px; gap: 14px; }
  .grid input, .grid select, .grid textarea { font-size: 16px; min-height: 46px; padding: 11px 14px; }
  .grid textarea { min-height: 120px; }
  .dlg-foot {
    position: sticky; bottom: 0; gap: 10px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .dlg-foot .btn { min-height: 48px; justify-content: center; }
  #deleteBtn[hidden] { display: none; }
  .dlg-foot .btn.primary { flex: 1; }

  .toast { bottom: calc(86px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); text-align: center; }
}

/* Bigger tap target for the document icons on a phone */
@media (max-width: 760px) {
  .doc-badge { padding: 8px; margin: -8px -3px; }
  .doc-badge svg { width: 18px; height: 18px; }
}
