:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #2d3f55;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --red: #ef4444;
  --orange: #f97316;
  --yellow: #eab308;
  --green: #22c55e;
  --gray: #64748b;
  --radius: 12px;
  --radius-sm: 8px;
  --nav-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100%;
  padding-top: var(--safe-t);
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}
textarea { resize: vertical; min-height: 80px; }
select option { background: var(--surface); }

a { color: var(--primary); text-decoration: none; }

/* ── Header ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.app-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}
.status-dot {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.status-dot .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}
.status-dot.offline .dot { background: var(--yellow); }
.status-dot.unreachable .dot { background: var(--red); }

/* ── Bottom Nav ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-b);
  height: calc(var(--nav-h) + var(--safe-b));
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px;
  color: var(--text-dim);
  font-size: 11px;
  min-height: 44px;
  transition: color .15s;
  position: relative;
}
.nav-btn.active { color: var(--primary); }
.nav-btn .icon { font-size: 20px; line-height: 1; }
.badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 5px;
  min-width: 16px;
  text-align: center;
}

/* ── Main Content ── */
.main {
  padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 80px);
  max-width: 700px;
  margin: 0 auto;
}
.view { display: none; }
.view.active { display: block; }

/* ── Section heading ── */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}
.section-title {
  font-size: 18px;
  font-weight: 700;
}
.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filter-btn {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface);
  white-space: nowrap;
}
.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  right: 16px;
  z-index: 90;
  background: var(--primary);
  color: #fff;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  box-shadow: 0 4px 16px rgba(99,102,241,.4);
  line-height: 1;
}

/* ── Task Card ── */
.task-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  border-left: 4px solid var(--gray);
  position: relative;
}
.task-card.urgent { border-left-color: var(--red); }
.task-card.today { border-left-color: var(--orange); }
.task-card.soon { border-left-color: var(--yellow); }
.task-card.normal { border-left-color: var(--green); }
.task-card.done { border-left-color: var(--gray); opacity: .6; }

.card-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}
.card-title {
  flex: 1;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.35;
}
.task-card.done .card-title { text-decoration: line-through; }
.urgency-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.tag-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface-2);
}
.priority-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}
.priority-pill.LOW { background: #1e293b; color: var(--text-muted); border: 1px solid var(--border); }
.priority-pill.NORMAL { background: #1e3a5f; color: #60a5fa; }
.priority-pill.HIGH { background: #451a03; color: var(--orange); }
.priority-pill.CRITICAL { background: #450a0a; color: var(--red); }

.card-date {
  font-size: 12px;
  color: var(--text-muted);
}
.card-date.overdue { color: var(--red); font-weight: 600; }
.card-source {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 3px;
}

.card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.action-btn {
  font-size: 13px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.action-btn:hover, .action-btn:active { background: var(--border); }
.action-btn.primary { background: var(--primary); color: #fff; }
.action-btn.danger { background: #450a0a; color: var(--red); }

/* ── Inbox Card ── */
.inbox-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  border-left: 4px solid var(--primary);
}

/* ── Empty State ── */
.empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}
.empty .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty p { font-size: 15px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  -webkit-overflow-scrolling: touch;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(24px + var(--safe-b));
  width: 100%;
  max-width: 700px;
  max-height: 90dvh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-title { font-size: 18px; font-weight: 700; }
.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-full {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  min-height: 48px;
  margin-top: 6px;
}
.snooze-options { display: flex; flex-direction: column; gap: 8px; }
.snooze-opt {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 15px;
  text-align: left;
  min-height: 48px;
}
.snooze-opt:hover, .snooze-opt:active { background: var(--border); }

/* ── Offline banner ── */
.offline-banner {
  background: var(--surface-2);
  border: 1px solid var(--yellow);
  color: var(--yellow);
  text-align: center;
  padding: 8px 16px;
  font-size: 13px;
  display: none;
}
.offline-banner.visible { display: block; }

/* ── Desktop 2-col ── */
@media (min-width: 640px) {
  .main { padding-top: 20px; }
  .card-actions { gap: 8px; }
  .modal-overlay { align-items: center; padding: 16px; }
  .modal { border-radius: 20px; max-height: 80vh; }
}
