:root {
  --bg:            #0c0c12;
  --surface:       #16161f;
  --surface2:      #1e1e2a;
  --surface3:      #27273a;
  --border:        #2a2a3d;
  --border2:       #363650;

  --text:          #eeeef5;
  --text2:         #8888a8;
  --text3:         #4a4a68;

  --critical:      #f24848;
  --critical-bg:   rgba(242, 72, 72, 0.10);
  --critical-bdr:  rgba(242, 72, 72, 0.30);

  --overdue-bg:    rgba(242, 72, 72, 0.08);

  --escalated:     #f59e0b;
  --escalated-bg:  rgba(245, 158, 11, 0.10);
  --escalated-bdr: rgba(245, 158, 11, 0.30);

  --accent:        #6366f1;
  --accent-dim:    rgba(99, 102, 241, 0.15);

  --success:       #22c55e;

  --r:  12px;
  --rs: 8px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Login screen ─────────────────────────────────────────────────────────── */

#loginScreen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
}

.login-box {
  width: 100%;
  max-width: 380px;
}

.login-header {
  text-align: center;
  margin-bottom: 44px;
}

.login-header h1 {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 7px;
  margin-bottom: 10px;
}

.login-header p {
  font-size: 14px;
  color: var(--text3);
  letter-spacing: 0.5px;
}

.auth-message {
  padding: 12px 14px;
  border-radius: var(--rs);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 16px;
}

.auth-message.error {
  background: var(--critical-bg);
  border: 1px solid var(--critical-bdr);
  color: var(--critical);
}

.auth-message.success {
  background: rgba(34, 197, 94, 0.10);
  border: 1px solid rgba(34, 197, 94, 0.30);
  color: var(--success);
}

.auth-toggle {
  text-align: center;
  margin-top: 22px;
  font-size: 13px;
  color: var(--text3);
}

.btn-text {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 0 4px;
}

/* ── Main app shell ───────────────────────────────────────────────────────── */

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px 120px;
}

/* ── Header ───────────────────────────────────────────────────────────────── */

header {
  padding: 26px 0 16px;
  margin-bottom: 4px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.header-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

h1 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 5px;
}

.header-sub {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text3);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 50%;
  transition: color 0.15s;
}
.icon-btn:active { color: var(--text); }

/* ── Stats chips ──────────────────────────────────────────────────────────── */

.stats-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  color: var(--text2);
  background: var(--surface);
}

.chip.red   { color: var(--critical);  border-color: var(--critical-bdr); background: var(--critical-bg); }
.chip.amber { color: var(--escalated); border-color: var(--escalated-bdr); background: var(--escalated-bg); }

/* ── Section labels ───────────────────────────────────────────────────────── */

.section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text3);
  padding: 18px 0 8px;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */

.empty {
  text-align: center;
  padding: 72px 24px 24px;
}

.empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--border2);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.empty h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 8px;
}

.empty p {
  font-size: 14px;
  color: var(--text3);
  line-height: 1.6;
}

/* ── Task card ────────────────────────────────────────────────────────────── */

.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 12px 12px;
  margin-bottom: 8px;
  position: relative;
  overflow: hidden;
  transition: opacity 0.25s, transform 0.25s;
}

.task-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
}

.task-card.is-critical {
  border-color: var(--critical-bdr);
  background: linear-gradient(135deg, var(--critical-bg) 0%, var(--surface) 60%);
}
.task-card.is-critical::before { background: var(--critical); }

.task-card.is-overdue:not(.is-critical) {
  border-color: rgba(242,72,72,0.25);
  background: var(--overdue-bg);
}
.task-card.is-overdue:not(.is-critical)::before { background: var(--critical); }

.task-card.is-escalated:not(.is-critical):not(.is-overdue) {
  border-color: var(--escalated-bdr);
  background: var(--escalated-bg);
}
.task-card.is-escalated:not(.is-critical):not(.is-overdue)::before { background: var(--escalated); }

.task-card.completing {
  opacity: 0;
  transform: scale(0.96);
}

/* ── Task body layout ─────────────────────────────────────────────────────── */

.task-body {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.check-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border2);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
  margin-top: 1px;
}
.check-btn:active {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.15);
}
.check-icon { opacity: 0.25; color: var(--text2); }
.check-btn:active .check-icon { opacity: 1; color: var(--success); }

.task-content {
  flex: 1;
  min-width: 0;
}

/* ── Task title row ───────────────────────────────────────────────────────── */

.task-title-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 8px;
}

.task-title {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.45;
  color: var(--text);
  word-break: break-word;
}

.source-icon {
  font-size: 12px;
  color: var(--text3);
  flex-shrink: 0;
  margin-top: 2px;
}

.notes-toggle {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 2px;
  margin-top: -1px;
  transition: transform 0.2s, color 0.15s;
  transform: rotate(0deg);
}
.notes-toggle.open { transform: rotate(90deg); color: var(--text2); }

/* ── Notes body ───────────────────────────────────────────────────────────── */

.notes-body {
  font-size: 13px;
  color: var(--text2);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface3);
  border-radius: var(--rs);
  padding: 10px 12px;
  margin-bottom: 8px;
}

/* ── Task badges row ──────────────────────────────────────────────────────── */

.task-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-critical  { background: var(--critical); color: #fff; }
.badge-overdue   { background: var(--critical-bg); color: var(--critical); border: 1px solid var(--critical-bdr); }
.badge-deadline  { background: var(--surface3); color: var(--text2); font-weight: 500; }
.badge-today     { background: rgba(245,158,11,0.15); color: var(--escalated); border: 1px solid var(--escalated-bdr); }
.badge-soon      { background: var(--accent-dim); color: #a5b4fc; border: 1px solid rgba(99,102,241,0.3); }
.badge-escalated { background: var(--escalated-bg); color: var(--escalated); border: 1px solid var(--escalated-bdr); }

.task-age {
  font-size: 11px;
  color: var(--text3);
  margin-left: auto;
  white-space: nowrap;
}

/* ── Priority toggle ──────────────────────────────────────────────────────── */

.priority-btn {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border2);
  background: transparent;
  color: var(--text3);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  margin-top: 1px;
  line-height: 1;
}
.priority-btn.critical {
  border-color: var(--critical);
  color: var(--critical);
  background: var(--critical-bg);
}

/* ── FAB ──────────────────────────────────────────────────────────────────── */

#fab {
  position: fixed;
  bottom: 28px;
  right: 22px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 24px rgba(99,102,241,0.45);
  transition: transform 0.2s, box-shadow 0.2s;
  z-index: 100;
}
#fab:active {
  transform: scale(0.93);
  box-shadow: 0 2px 12px rgba(99,102,241,0.35);
}

/* ── Overlays ─────────────────────────────────────────────────────────────── */

.overlay, .menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
}

/* ── Bottom sheets ────────────────────────────────────────────────────────── */

.sheet, .confirm-dialog {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 640px;
  margin: 0 auto;
  background: var(--surface2);
  border-radius: 20px 20px 0 0;
  z-index: 300;
  transform: translateY(0);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.sheet         { padding: 12px 20px 40px; }
.confirm-dialog { padding: 28px 20px 40px; }

.sheet.hidden, .confirm-dialog.hidden {
  transform: translateY(110%);
  pointer-events: none;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border2);
  margin: 0 auto 20px;
}

.sheet-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 18px;
}

/* ── Form fields ──────────────────────────────────────────────────────────── */

.field { margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 7px;
}

.field-row { display: flex; gap: 12px; margin-bottom: 14px; }
.field-half { flex: 1; }

textarea, input[type="date"], input[type="email"], input[type="password"] {
  width: 100%;
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: var(--rs);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  padding: 12px 14px;
  outline: none;
  resize: none;
  -webkit-appearance: none;
  appearance: none;
  line-height: 1.5;
}
textarea:focus,
input[type="date"]:focus,
input[type="email"]:focus,
input[type="password"]:focus { border-color: var(--accent); }
textarea::placeholder,
input::placeholder { color: var(--text3); }

/* ── Priority group ───────────────────────────────────────────────────────── */

.prio-group {
  display: flex;
  border: 1px solid var(--border2);
  border-radius: var(--rs);
  overflow: hidden;
}
.prio-btn {
  flex: 1;
  padding: 11px 6px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  background: var(--surface3);
  color: var(--text3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.prio-btn.active             { background: var(--accent);   color: #fff; }
.prio-btn#prioCritical.active { background: var(--critical); color: #fff; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */

.btn-primary {
  width: 100%;
  padding: 15px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--rs);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.85; }

.confirm-msg {
  font-size: 15px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 24px;
  line-height: 1.5;
}
.confirm-actions { display: flex; gap: 12px; }

.btn-ghost {
  flex: 1;
  padding: 14px;
  background: var(--surface3);
  color: var(--text2);
  border: 1px solid var(--border2);
  border-radius: var(--rs);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn-done {
  flex: 2;
  padding: 14px;
  background: var(--success);
  color: white;
  border: none;
  border-radius: var(--rs);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn-done:active  { opacity: 0.85; }
.btn-ghost:active { opacity: 0.75; }

/* ── User menu ────────────────────────────────────────────────────────────── */

.menu-overlay { background: rgba(0,0,0,0.4); z-index: 400; }

.user-menu {
  position: fixed;
  top: 64px;
  right: 16px;
  width: 290px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  padding: 16px;
  z-index: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.menu-email {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  word-break: break-all;
}

.menu-section { margin-bottom: 16px; }

.menu-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 8px;
}

.forward-addr {
  font-family: monospace;
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(99,102,241,0.25);
  border-radius: var(--rs);
  padding: 8px 10px;
  word-break: break-all;
  margin-bottom: 8px;
}

.btn-copy {
  font-size: 12px;
  color: var(--text2);
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  margin-bottom: 8px;
}
.btn-copy:active { opacity: 0.75; }

.menu-hint {
  font-size: 12px;
  color: var(--text3);
  line-height: 1.5;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 0;
}

.btn-signout {
  width: 100%;
  margin-top: 16px;
  padding: 11px;
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: var(--rs);
  color: var(--text2);
  font-size: 14px;
  cursor: pointer;
}
.btn-signout:active { background: var(--surface3); }
