/* ---------------------------------------------------------------------------
   Task Manager — mobile-first stylesheet.
   Layout is driven by a single breakpoint at 860px: below it the app is a
   stack with a bottom tab bar (thumb reach), above it a sidebar + content.
--------------------------------------------------------------------------- */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #dce0e8;
  --text: #16181d;
  --text-dim: #61656f;
  --text-faint: #8b909c;
  --accent: #2f6fed;
  --accent-soft: #e6eeff;
  --danger: #d3382f;
  --danger-soft: #fdeceb;
  --warn: #b26a00;
  --warn-soft: #fdf1dc;
  --ok: #17794a;
  --ok-soft: #e3f5ec;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 24, 33, .06), 0 4px 14px rgba(20, 24, 33, .05);
  --tap: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --surface: #181b21;
    --surface-2: #1f232b;
    --border: #2c313b;
    --text: #e9ecf1;
    --text-dim: #a2a9b6;
    --text-faint: #767d8b;
    --accent: #6f9bff;
    --accent-soft: #1c2740;
    --danger: #ff6b60;
    --danger-soft: #35201f;
    --warn: #e0a145;
    --warn-soft: #33281a;
    --ok: #4bcb8f;
    --ok-soft: #162c23;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .6em; }
a { color: var(--accent); }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

.hidden { display: none !important; }

/* --- app shell ----------------------------------------------------------- */

#app { display: flex; flex-direction: column; min-height: 100%; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar h1 { flex: 1; font-size: 1.15rem; min-width: 0; }
.topbar .title-wrap { flex: 1; min-width: 0; }
.topbar .subtitle { font-size: .78rem; color: var(--text-dim); }

main {
  flex: 1;
  padding: 14px;
  padding-bottom: calc(78px + var(--safe-b));
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

/* --- bottom navigation (mobile) ------------------------------------------ */

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}

.tabbar button {
  flex: 1;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: 0;
  color: var(--text-faint);
  font-size: .68rem;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.tabbar button svg { width: 21px; height: 21px; }
.tabbar button[aria-current="page"] { color: var(--accent); }

.tabbar .badge {
  position: absolute;
  top: 6px;
  left: 50%;
  margin-left: 4px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: .62rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* --- cards and lists ----------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.card-head h2 { flex: 1; font-size: .95rem; }
.card-body { padding: 14px; }
.card-body.tight { padding: 0; }

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px 2px 8px;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-faint);
}
.section-title .count {
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: 20px;
  padding: 1px 8px;
  font-size: .72rem;
  letter-spacing: 0;
}

.row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 550; word-break: break-word; }
.row-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: .78rem;
  color: var(--text-dim);
}
.row.done .row-title { text-decoration: line-through; color: var(--text-faint); }

.empty {
  padding: 26px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: .88rem;
}
.empty strong { display: block; color: var(--text-dim); margin-bottom: 4px; font-size: .95rem; }

/* --- checkbox ------------------------------------------------------------ */

.check {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  margin-top: 1px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}
.check svg { width: 14px; height: 14px; opacity: 0; color: #fff; }
.check[aria-checked="true"] { background: var(--ok); border-color: var(--ok); }
.check[aria-checked="true"] svg { opacity: 1; }

/* --- pills / chips ------------------------------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 620;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--text-dim);
}
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.warn   { background: var(--warn-soft);   color: var(--warn); }
.pill.ok     { background: var(--ok-soft);     color: var(--ok); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }

/* Project colour keys. */
.c-slate  { background: #64748b; } .c-blue   { background: #3b82f6; }
.c-green  { background: #16a34a; } .c-amber  { background: #d97706; }
.c-red    { background: #dc2626; } .c-violet { background: #7c3aed; }
.c-pink   { background: #db2777; } .c-teal   { background: #0d9488; }

/* --- buttons ------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { min-height: 34px; padding: 0 11px; font-size: .8rem; }
.btn.icon { min-height: var(--tap); width: var(--tap); padding: 0; }
.btn.block { width: 100%; }
.btn svg { width: 17px; height: 17px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row.end { justify-content: flex-end; }

/* --- forms --------------------------------------------------------------- */

.field { margin-bottom: 13px; }
.field label {
  display: block;
  margin-bottom: 5px;
  font-size: .8rem;
  font-weight: 620;
  color: var(--text-dim);
}

.input, .select, .textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  /* 16px stops iOS Safari zooming the page when a field is focused. */
  font-size: 16px;
}
.textarea { min-height: 92px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; min-width: 0; }
.hint { font-size: .76rem; color: var(--text-faint); margin-top: 4px; }

/* --- voice input --------------------------------------------------------- */

.mic-wrap { position: relative; display: block; }

/* Room for the button so long dictated text never runs underneath it. */
.input.has-mic { padding-right: 46px; }
.textarea.has-mic { padding-right: 46px; }

.mic {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-faint);
  display: grid;
  place-items: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mic svg { width: 19px; height: 19px; }
.mic:hover { background: var(--surface-2); color: var(--text-dim); }
.mic:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* On a textarea the field is tall, so sit in the corner rather than centred. */
.mic-area { top: auto; bottom: 8px; transform: none; }

/* Listening: the button turns red and a ring pulses out of it. */
.mic.listening {
  background: var(--danger);
  color: #fff;
}
.mic.listening::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--danger);
  animation: mic-pulse 1.4s ease-out infinite;
}
@keyframes mic-pulse {
  0%   { transform: scale(1);   opacity: .7; }
  100% { transform: scale(2.1); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .mic.listening::after { animation: none; opacity: .5; }
}

/* --- modal / sheet ------------------------------------------------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(10, 12, 16, .5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(18px); opacity: .6; } }

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(20px + var(--safe-b));
  animation: rise .18s ease;
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.sheet-head h2 { flex: 1; }

/* --- toast --------------------------------------------------------------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 80;
  max-width: 92vw;
  padding: 11px 16px;
  border-radius: 22px;
  background: #22262e;
  color: #fff;
  font-size: .86rem;
  font-weight: 550;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .28);
  animation: rise .18s ease;
}
#toast.error { background: var(--danger); }

/* --- stats --------------------------------------------------------------- */

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; margin-bottom: 4px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
}
.stat .n { font-size: 1.45rem; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: .74rem; color: var(--text-dim); margin-top: 2px; }
.stat.alert .n { color: var(--danger); }

/* --- notes / log --------------------------------------------------------- */

.log-item {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.log-item:last-child { border-bottom: 0; }
.log-rail { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; padding-top: 5px; }
.log-rail .marker { width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.log-item.follow_up .marker { background: var(--warn); }
.log-item.resolved .marker { background: var(--ok); }
.log-main { flex: 1; min-width: 0; }
.log-body { white-space: pre-wrap; word-break: break-word; }
.log-item.resolved .log-body { color: var(--text-faint); }
.log-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 7px;
  margin-top: 5px; font-size: .74rem; color: var(--text-faint);
}
/* Actions stay together as one unit and hug the right edge, so they wrap as a
   group rather than the trash button dropping to a line of its own. */
.log-actions { display: flex; align-items: center; gap: 2px; margin-left: auto; flex: 0 0 auto; }
.log-actions .btn.sm { min-height: 30px; padding: 0 8px; }

/* --- tabs ---------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: 3px;
  margin-bottom: 14px;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 1;
  min-width: max-content;
  min-height: 38px;
  padding: 0 13px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: .84rem;
  font-weight: 620;
  cursor: pointer;
  white-space: nowrap;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* --- floating action button ---------------------------------------------- */

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(74px + var(--safe-b));
  z-index: 40;
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 5px 18px rgba(47, 111, 237, .4);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.fab svg { width: 25px; height: 25px; }

/* --- auth screen --------------------------------------------------------- */

.auth-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 26px 22px;
}
.auth-card h1 { margin-bottom: 6px; }
.auth-card .sub { color: var(--text-dim); font-size: .88rem; margin-bottom: 20px; }

/* --- search -------------------------------------------------------------- */

.searchbar { position: relative; margin-bottom: 12px; }
.searchbar .input { padding-left: 38px; }
.searchbar svg {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  width: 17px; height: 17px;
  color: var(--text-faint);
  pointer-events: none;
}
mark, .excerpt b {
  background: var(--warn-soft);
  color: inherit;
  font-weight: 700;
  border-radius: 3px;
  padding: 0 1px;
}
.excerpt { font-size: .8rem; color: var(--text-dim); margin-top: 3px; word-break: break-word; }

/* --- attachments --------------------------------------------------------- */

.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 9px; }
.file-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
  position: relative;
}
.file-tile a { display: block; text-decoration: none; color: inherit; }
.file-tile img { width: 100%; height: 78px; object-fit: cover; display: block; background: var(--surface-2); }
.file-tile .doc { height: 78px; display: grid; place-items: center; color: var(--text-faint); }
.file-tile .doc svg { width: 26px; height: 26px; }
.file-tile .name {
  padding: 6px 7px;
  font-size: .7rem;
  color: var(--text-dim);
  word-break: break-all;
  line-height: 1.35;
  max-height: 3.1em;
  overflow: hidden;
}
.file-tile .rm {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px;
  border: 0; border-radius: 50%;
  background: rgba(10, 12, 16, .62);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
}
.file-tile .rm svg { width: 13px; height: 13px; }

.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  text-align: center;
  color: var(--text-faint);
  font-size: .84rem;
  cursor: pointer;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* --- progress bar -------------------------------------------------------- */

.bar { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 7px; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 3px; transition: width .25s ease; }

/* --- desktop ------------------------------------------------------------- */

@media (min-width: 860px) {
  #app { flex-direction: row; }

  .tabbar {
    position: sticky;
    top: 0;
    left: auto; right: auto;
    height: 100dvh;
    width: 214px;
    flex: 0 0 214px;
    flex-direction: column;
    justify-content: flex-start;
    gap: 3px;
    padding: 16px 11px;
    border-top: 0;
    border-right: 1px solid var(--border);
  }
  .tabbar button {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 11px;
    min-height: 42px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    font-size: .89rem;
  }
  .tabbar button[aria-current="page"] { background: var(--accent-soft); }
  .tabbar .badge { position: static; margin-left: auto; }
  .tabbar .brand {
    display: flex; align-items: center; gap: 9px;
    padding: 4px 12px 16px;
    font-weight: 700; font-size: 1.02rem;
    color: var(--text);
  }
  .tabbar .brand svg { width: 21px; height: 21px; color: var(--accent); }

  .shell { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  main { padding: 20px 24px 40px; }
  .fab { display: none; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 16px; max-height: 86vh; }
  .row { padding: 13px 16px; }
  #toast { bottom: 28px; }
}

@media (max-width: 859px) {
  .tabbar .brand { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
