:root {
  --teal: #029890;
  --teal-dark: #027a73;
  --teal-bg: #f0fdfa;
  --ink: #111827;
  --ink-soft: #374151;
  --muted: #6b7280;
  --faint: #9ca3af;
  --border: #e5e7eb;
  --border-soft: #f3f4f6;
  --bg: #f9fafb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --warn-bg: #fffbeb;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow-x: hidden; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button { font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ── Login ───────────────────────────────────────────── */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #029890 0%, #016b65 100%);
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
}
.login-card {
  background: #fff;
  border-radius: 18px;
  padding: 32px 26px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.login-logo {
  width: 52px; height: 52px;
  background: var(--teal);
  color: #fff;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; letter-spacing: 0.02em;
  margin-bottom: 14px;
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; font-weight: 800; }
.login-sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.lbl { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin: 14px 0 5px; }
.inp {
  width: 100%; min-width: 0; padding: 12px 13px; border: 1px solid #d1d5db; border-radius: 10px;
  font-size: 16px; outline: none; background: #fff; color: var(--ink);
}
.inp:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(2,152,144,0.12); }
.login-error {
  margin-top: 12px; font-size: 13px; color: var(--danger);
  background: var(--danger-bg); border: 1px solid var(--danger-border);
  padding: 9px 11px; border-radius: 8px;
}
.btn-primary {
  width: 100%; margin-top: 20px; padding: 13px; border: none; border-radius: 10px;
  background: var(--teal); color: #fff; font-size: 15px; font-weight: 700; cursor: pointer;
}
.btn-primary:active { background: var(--teal-dark); }
.btn-primary:disabled { opacity: 0.6; }

/* ── App shell ───────────────────────────────────────── */
.app { min-height: 100dvh; display: flex; flex-direction: column; }

.app-header { position: sticky; top: 0; z-index: 20; background: #fff; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-top)) 16px 2px;
  background: #fff;
}
.topbar-title { font-size: 17px; font-weight: 800; display: flex; align-items: center; gap: 26px; }
.topbar-logo { height: 22px; width: auto; display: block; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: none; background: transparent;
  color: var(--ink-soft); display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn:active { background: var(--border-soft); }

.search-bar { padding: 10px 16px 0; background: #fff; }

.view-tabs {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  padding: 12px 10px 14px 10px;
  background: #fff; border-bottom: 1px solid var(--border);
}
.tab-group { display: flex; justify-content: space-between; gap: 6px; flex: 1; min-width: 0; }
.sort-icon-btn { flex-shrink: 0; width: 28px; height: 28px; }

.sort-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 4px;
  padding: 10px 10px; background: #fff; border-bottom: 1px solid var(--border);
}
.sort-field-btn {
  padding: 4px 8px; border-radius: 999px; border: 1px solid var(--border);
  background: #fff; color: var(--ink-soft); font-size: 10.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.sort-field-btn.active { background: var(--teal); border-color: var(--teal); color: #fff; }
.sort-dir-btn {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; color: var(--teal); font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.tab {
  flex: 0 0 auto; padding: 6px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: #fff; color: var(--ink-soft); font-size: 11px; font-weight: 600; cursor: pointer;
  white-space: nowrap; text-align: center;
}
.tab.active { background: var(--teal); border-color: var(--teal); color: #fff; }

.task-list { flex: 1; padding: 10px 12px 90px; }
.loading { display: flex; justify-content: center; padding: 60px 0; }
.spinner {
  width: 26px; height: 26px; border: 3px solid var(--border);
  border-top-color: var(--teal); border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 60px 20px; color: var(--faint); font-size: 14px; }

/* ── Task cards ──────────────────────────────────────── */
.task-card {
  background: #fff; border: 1px solid var(--border); border-radius: 13px;
  padding: 12px 13px; margin-bottom: 8px; display: flex; gap: 11px;
  align-items: flex-start; cursor: pointer;
}
.task-card.overdue { background: var(--warn-bg); border-color: #fde68a; }
.task-card.completed { opacity: 0.55; }

.check-btn {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--teal);
  background: #fff; flex-shrink: 0; margin-top: 2px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: #fff; font-size: 11px;
}
.check-btn.checked { background: var(--teal); border-color: var(--teal); }

.task-main { flex: 1; min-width: 0; }
.task-title { font-size: 14px; font-weight: 400; color: var(--ink); line-height: 1.35; word-break: break-word; }
.task-title.completed { text-decoration: line-through; color: var(--muted); }
.task-notes { font-size: 12px; color: var(--faint); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.task-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.badge { font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid; white-space: nowrap; }
.chip { font-size: 10.5px; font-weight: 500; padding: 2px 8px; border-radius: 999px; border: 1px solid; white-space: nowrap; max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
.due-text { font-size: 11px; font-weight: 600; color: var(--muted); }
.due-text.overdue { color: var(--danger); }
.assignee-text { font-size: 11px; color: var(--muted); font-weight: 600; }
.assignee-label { color: var(--teal); }
.comment-count { font-size: 10.5px; color: var(--teal); font-weight: 600; }

/* ── Bottom sheet ────────────────────────────────────── */
.sheet-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 50;
  display: flex; align-items: flex-end;
}
.sheet {
  background: #fff; width: 100%; max-height: 92dvh; border-radius: 18px 18px 0 0;
  display: flex; flex-direction: column; animation: slideUp 0.22s ease-out;
  padding-bottom: var(--safe-bottom);
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 3px; margin: 10px auto 0; }
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px 12px; border-bottom: 1px solid var(--border);
}
.sheet-title { font-size: 16px; font-weight: 700; }
.sheet-body { padding: 14px 16px; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }

.field { margin-bottom: 14px; min-width: 0; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
.field-row { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 10px; min-width: 0; }
.field-row > .field { min-width: 0; }
.field-label-row { display: flex; justify-content: flex-start; align-items: center; gap: 8px; margin-bottom: 5px; }
.field-label-row label { margin-bottom: 0; }
.clear-link { font-size: 11px; font-weight: 600; color: var(--teal); cursor: pointer; }
.field-row-date { display: flex; gap: 10px; }
.field-row-date > .field { flex: 1; min-width: 0; }
.date-input-wrap {
  position: relative;
  overflow: hidden; border: 1px solid #d1d5db; border-radius: 10px; height: 47px;
  display: flex; align-items: center; background: #fff;
}
.date-input-wrap input[type="date"], .date-input-wrap input[type="time"] {
  border: none; outline: none; background: transparent; padding: 0 0 0 13px;
  font-size: 16px; color: transparent; font-family: inherit;
  transform: scale(0.8); transform-origin: left center; width: 128%; height: 100%;
}
.date-input-wrap input::-webkit-clear-button,
.date-input-wrap input::-webkit-inner-spin-button {
  display: none;
}
.date-display {
  position: absolute; left: 13px; top: 0; bottom: 0; display: flex; align-items: center;
  font-size: 13px; color: var(--ink); pointer-events: none; white-space: nowrap;
}
.date-display.placeholder { color: #9ca3af; }
textarea.inp { min-height: 70px; resize: vertical; }
.select-wrap { position: relative; }
.select-wrap select { color: transparent; width: 100%; display: block; }
.select-wrap select option { color: var(--ink); }
.select-wrap .select-display {
  position: absolute; left: 0; right: 0; top: 0; bottom: 0; display: flex;
  align-items: center; justify-content: flex-start;
  font-size: 13px; color: var(--ink); pointer-events: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 13px;
}
#f-title { font-size: 13px; text-align: left; }

.sheet-actions { display: flex; gap: 8px; margin-top: 4px; margin-bottom: 18px; }
.btn { flex: 1; padding: 11px; border-radius: 10px; border: 1px solid var(--border); background: #fff; font-size: 14px; font-weight: 700; cursor: pointer; }
.btn-teal { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.btn:disabled { opacity: 0.6; }

.section-label {
  font-size: 11px; font-weight: 700; color: var(--teal); text-transform: uppercase;
  letter-spacing: 0.05em; margin: 18px 0 8px;
}

.assoc-list { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.assoc-chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500;
  padding: 4px 9px; border-radius: 999px; border: 1px solid; max-width: 220px;
}
.assoc-chip button { background: none; border: none; color: inherit; opacity: 0.7; cursor: pointer; font-size: 12px; padding: 0; }
.assoc-add-btn {
  width: 26px; height: 26px; border-radius: 50%; border: 1px dashed #d1d5db; background: #fff;
  color: var(--faint); font-size: 15px; cursor: pointer;
}

.comments-box { border: 1px solid var(--border); border-radius: 10px; background: #fafafa; max-height: 220px; overflow-y: auto; }
.comment-item { padding: 9px 11px; border-bottom: 1px solid #eee; }
.comment-item:last-child { border-bottom: none; }
.comment-top { display: flex; justify-content: space-between; gap: 8px; }
.comment-author { font-size: 12px; font-weight: 700; }
.comment-time { font-size: 10.5px; color: var(--faint); }
.comment-body { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.comment-del { background: none; border: none; color: var(--danger); opacity: 0.7; cursor: pointer; font-size: 12px; }
.comment-empty { padding: 12px; font-size: 12px; color: var(--faint); }
.comment-add-row { display: flex; gap: 8px; margin-top: 8px; }
.comment-add-row .inp { flex: 1; padding: 9px 11px; font-size: 13.5px; }
.comment-send { background: var(--teal); color: #fff; border: none; border-radius: 8px; padding: 0 14px; font-size: 13px; font-weight: 700; cursor: pointer; }

.form-error { font-size: 12.5px; color: var(--danger); margin-top: 4px; }

.toast {
  position: fixed; bottom: calc(24px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px;
  z-index: 100; max-width: 88vw; text-align: center;
}

.fab-new {
  position: fixed; right: 18px; bottom: calc(20px + var(--safe-bottom));
  width: 54px; height: 54px; border-radius: 50%; background: var(--teal); color: #fff;
  border: none; box-shadow: 0 6px 18px rgba(2,152,144,0.4); font-size: 26px; cursor: pointer;
  display: none; align-items: center; justify-content: center; z-index: 15;
}
