:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1f2630;
  --border: #2b3340;
  --text: #e6edf3;
  --muted: #8b97a6;
  --brand: #1f6feb;
  --brand-dark: #1a5fd0;
  --open: #e3b341;
  --prog: #3b82f6;
  --done: #2ea043;
  --urgent: #f85149;
  --high: #f0883e;
  --med: #d29922;
  --low: #6e7681;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 16px;
}

body {
  padding-bottom: calc(72px + var(--safe-bottom));
  min-height: 100vh;
}

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.1rem; }
.logo { font-size: 1.3rem; }
.me { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); }
.me select {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
  max-width: 130px;
}

/* Stats */
.stats { display: flex; gap: 8px; padding: 12px 16px 0; }
.stat {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; text-align: center;
  color: var(--text); cursor: pointer;
}
.stat b { display: block; font-size: 1.5rem; }
.stat span { font-size: .72rem; color: var(--muted); }
.stat:nth-child(1) b { color: var(--open); }
.stat:nth-child(2) b { color: var(--prog); }
.stat:nth-child(3) b { color: var(--done); }

/* Views */
.view { display: none; padding: 12px 16px; }
.view.active { display: block; }

/* Filters */
.filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.search {
  width: 100%; padding: 11px 14px; border-radius: 10px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
}
.chips { display: flex; gap: 8px; overflow-x: auto; }
.chip {
  white-space: nowrap; padding: 7px 14px; border-radius: 999px;
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--border); cursor: pointer;
}
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.mine { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* Item cards */
.items { display: flex; flex-direction: column; gap: 10px; }
.card {
  display: flex; gap: 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px; cursor: pointer; align-items: stretch;
}
.card .thumb {
  width: 64px; height: 64px; border-radius: 10px; object-fit: cover;
  background: var(--surface-2); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.4rem; color: var(--muted);
}
.card .body { flex: 1; min-width: 0; }
.card .title { font-weight: 600; line-height: 1.25; }
.card .meta { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.card .tags { display: flex; gap: 6px; margin-top: 7px; flex-wrap: wrap; }

.badge {
  font-size: .68rem; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .3px;
}
.pri-Urgent { background: rgba(248,81,73,.18); color: var(--urgent); }
.pri-High   { background: rgba(240,136,62,.18); color: var(--high); }
.pri-Medium { background: rgba(210,153,34,.18); color: var(--med); }
.pri-Low    { background: rgba(110,118,129,.22); color: #adb6c2; }

.st { font-size: .68rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.st-Open { background: rgba(227,179,65,.18); color: var(--open); }
.st-Inprogress { background: rgba(59,130,246,.18); color: var(--prog); }
.st-Done { background: rgba(46,160,67,.18); color: var(--done); }

.assignee { display: inline-flex; align-items: center; gap: 5px; }
.avatar {
  width: 18px; height: 18px; border-radius: 50%; background: var(--brand);
  color: #fff; font-size: .6rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

.empty { text-align: center; color: var(--muted); margin-top: 40px; line-height: 1.6; }
.hidden { display: none; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.form.row { flex-direction: row; align-items: center; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); }
.form input, .form select, .form textarea {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  font-size: 1rem; font-family: inherit;
}
.form textarea { resize: vertical; }

.photo-field { cursor: pointer; }
.photo-preview {
  width: 100%; aspect-ratio: 4/3; border-radius: var(--radius);
  border: 2px dashed var(--border); background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: var(--muted); overflow: hidden;
}
.photo-preview .cam { font-size: 2.4rem; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }

button.primary {
  background: var(--brand); color: #fff; border: none;
  padding: 14px; border-radius: 10px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
button.primary:active { background: var(--brand-dark); }
button.primary:disabled { opacity: .6; }
.form.row .primary { width: auto; padding: 12px 18px; white-space: nowrap; }
.form.row input { flex: 1; }

/* People */
.hint { color: var(--muted); font-size: .82rem; margin: 10px 2px 0; }
#add-person-btn { width: 100%; }
.people { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.person {
  display: flex; align-items: center; gap: 10px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
  cursor: pointer;
}
.person .avatar { width: 30px; height: 30px; font-size: .8rem; }
.person .name { flex: 1; }
.person button {
  background: none; border: none; color: var(--urgent); font-size: 1.2rem; cursor: pointer;
}

/* Tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}
.tab {
  flex: 1; background: none; border: none; color: var(--muted);
  padding: 10px 0; font-size: 1.3rem; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: .68rem; }
.tab.active { color: var(--brand); }
.tab-new { color: var(--brand); }

/* Dialog */
dialog {
  border: none; border-radius: 16px; padding: 0; width: min(92vw, 460px);
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.6); }
#detail-body { padding: 18px; }
#detail-body img { width: 100%; border-radius: 12px; margin-bottom: 12px; }
#detail-body h2 { margin: 0 0 6px; font-size: 1.2rem; }
#detail-body .d-meta { color: var(--muted); font-size: .85rem; margin: 4px 0; }
#detail-body label { display: block; font-size: .8rem; color: var(--muted); margin-top: 12px; }
#detail-body select {
  width: 100%; margin-top: 6px; padding: 10px; border-radius: 8px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}
.dialog-actions { display: flex; gap: 8px; padding: 0 18px 18px; }
.dialog-actions button { flex: 1; padding: 12px; border-radius: 10px; border: none; cursor: pointer; font-weight: 600; }
.danger { background: rgba(248,81,73,.15); color: var(--urgent); }
.ghost { background: var(--surface-2); color: var(--text); }

/* Login overlay */
.login {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login.hidden { display: none; }  /* must beat .login's display:flex */
.login-card {
  width: 100%; max-width: 340px; text-align: center;
  display: flex; flex-direction: column; gap: 12px;
}
.login-logo { font-size: 3rem; }
.login-card h1 { margin: 0; font-size: 1.6rem; }
.login-card p { margin: 0; color: var(--muted); }
.login-card input {
  padding: 14px; border-radius: 10px; font-size: 1.1rem; text-align: center;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  letter-spacing: 2px;
}
.login-err { color: var(--urgent) !important; font-weight: 600; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #fff; color: #111; padding: 10px 18px; border-radius: 999px;
  font-size: .9rem; font-weight: 600; opacity: 0; pointer-events: none;
  transition: all .25s; z-index: 50; box-shadow: 0 6px 24px rgba(0,0,0,.3);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
