/* ============ Tasks PWA — iOS-native styling ============ */
:root {
  --bg: #0d0f14;
  --bg-raise: #151923;
  --card: #171c27;
  --card-2: #1e2432;
  --border: rgba(255, 255, 255, 0.07);
  --text: #f2f3f7;
  --text-2: #9aa3b2;
  --text-3: #5d6675;
  --accent: #ffd60a;
  --accent-ink: #1a1500;
  --green: #30d158;
  --red: #ff453a;
  --orange: #ff9f0a;
  --sheet: #161a24;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  --row-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

html[data-theme="light"] {
  --bg: #f2f3f7;
  --bg-raise: #ffffff;
  --card: #ffffff;
  --card-2: #eef0f5;
  --border: rgba(0, 0, 0, 0.08);
  --text: #17181c;
  --text-2: #5c6472;
  --text-3: #9aa3b2;
  --accent: #e6b800;
  --accent-ink: #1a1500;
  --green: #248a3d;
  --red: #d70015;
  --orange: #b25000;
  --sheet: #ffffff;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  --row-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

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

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

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

/* ---------- Top bar ---------- */
#topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: calc(var(--safe-t) + 14px) 18px 12px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
}
#top-title { font-size: 30px; font-weight: 800; letter-spacing: -0.5px; }
#top-sub { font-size: 14px; color: var(--text-2); margin-top: 2px; }
#top-actions { display: flex; gap: 10px; padding-bottom: 4px; }

.icon-btn {
  width: 40px; height: 40px;
  border: none; border-radius: 50%;
  background: var(--card);
  color: var(--text);
  font-size: 20px;
  display: grid; place-items: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.icon-btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.icon-btn:active { transform: scale(0.92); }

/* ---------- Main view ---------- */
#view {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0 calc(96px + var(--safe-b));
  -webkit-overflow-scrolling: touch;
}
.section {
  padding: 0 18px;
  margin-bottom: 6px;
}
.section-head {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-3);
  padding: 14px 0 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.section-head.overdue { color: var(--red); }
.section-count { color: var(--text-3); font-weight: 600; }

/* ---------- Task rows (swipeable) ---------- */
.row-wrap {
  position: relative;
  margin: 2px 10px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg);
}
.row-bg {
  position: absolute; inset: 0;
  display: flex; justify-content: flex-end; align-items: stretch;
  background: transparent;
  border-radius: 14px;
}
.row-del {
  width: 88px;
  border: none;
  background: var(--red);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  touch-action: none;
  border-radius: 0 14px 14px 0;
}
.row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border-radius: 14px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
  transform: translateX(0);
  will-change: transform;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: var(--row-shadow);
}
.row.swiping { transition: none; }
.row.done { opacity: 0.55; }

.check {
  flex: 0 0 auto;
  width: 24px; height: 24px;
  margin-top: 1px;
  border-radius: 50%;
  border: 2px solid var(--text-3);
  background: transparent;
  display: grid; place-items: center;
  font-size: 13px; color: transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.check.done {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}
.task-body { flex: 1; min-width: 0; }
.task-title {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.task.done .task-title { text-decoration: line-through; color: var(--text-2); }
.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-2);
}
.chip-mini {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--card-2);
  font-weight: 500;
}
.chip-mini.overdue { background: rgba(255, 69, 58, 0.16); color: var(--red); font-weight: 600; }
.chip-mini.today { background: rgba(255, 214, 10, 0.14); color: var(--accent); font-weight: 600; }
.chip-mini.pri { color: var(--orange); font-weight: 700; background: transparent; padding: 2px 2px; }
.chip-mini.tag { color: var(--text-2); }
.chip-mini.list { background: var(--card-2); }

.empty {
  text-align: center;
  color: var(--text-3);
  padding: 60px 30px;
}
.empty .big { font-size: 42px; margin-bottom: 14px; }
.empty p { font-size: 15px; line-height: 1.5; }

/* ---------- Lists view ---------- */
.list-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 2px 10px;
  cursor: pointer;
}
.list-emoji { font-size: 24px; }
.list-name { font-size: 16.5px; font-weight: 600; flex: 1; }
.list-count { color: var(--text-3); font-size: 14px; }
.btn-new-list { margin: 14px 10px; width: calc(100% - 20px); }

/* ---------- Done view ---------- */
.done-date { font-size: 12.5px; color: var(--text-3); margin-top: 6px; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: var(--card-2);
  color: var(--text);
  transition: transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn.accent { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); }

/* ---------- Sheet ---------- */
#overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
  animation: fade 0.2s ease;
}
#sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  background: var(--sheet);
  border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(var(--safe-b) + 20px);
  max-height: 92dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow);
  animation: slideUp 0.26s cubic-bezier(0.32, 0.72, 0.3, 1);
}
#sheet-handle {
  width: 38px; height: 4.5px;
  border-radius: 3px;
  background: var(--text-3);
  margin: 4px auto 14px;
  opacity: 0.6;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

#f-title {
  width: 100%;
  font-size: 19px;
  font-weight: 600;
  background: transparent;
  border: none;
  color: var(--text);
  outline: none;
  padding: 8px 0;
}
#f-notes {
  width: 100%;
  font-size: 15px;
  background: transparent;
  border: none;
  color: var(--text);
  outline: none;
  resize: none;
  padding: 6px 0 14px;
  border-bottom: 1px solid var(--border);
  font-family: inherit;
}
#f-title::placeholder, #f-notes::placeholder { color: var(--text-3); }

.field { margin-top: 16px; }
.field > label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-3);
  margin-bottom: 8px;
}
.field select, .field input[type="date"], #f-tags {
  width: 100%;
  background: var(--card-2);
  color: var(--text);
  border: none;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15.5px;
  font-family: inherit;
  outline: none;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip input[type="date"] {
  background: transparent;
  border: none;
  color: inherit;
  font-size: inherit;
  font-family: inherit;
  width: 130px;
  outline: none;
  color-scheme: dark;
}
html[data-theme="light"] .chip input[type="date"] { color-scheme: light; }

.seg { display: flex; background: var(--card-2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-2);
  border-radius: 8px;
  padding: 9px 0;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn.on { background: var(--accent); color: var(--accent-ink); }

.sheet-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 22px;
}
.sheet-actions .btn { flex: 1; }
.sheet-actions .btn:first-child:last-child { flex: 1; }

/* ---------- Confirm modal ---------- */
.confirm {
  position: fixed; inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.5);
  display: grid; place-items: center;
  animation: fade 0.15s ease;
}
.confirm-box {
  background: var(--sheet);
  border-radius: 16px;
  padding: 22px;
  max-width: 330px;
  width: calc(100% - 48px);
  box-shadow: var(--shadow);
}
.confirm-box p { font-size: 15.5px; line-height: 1.45; margin-bottom: 18px; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }

.sheet-title { font-size: 18px; font-weight: 700; padding: 6px 0 2px; }

/* ---------- Search ---------- */
#search-overlay {
  position: fixed; inset: 0;
  z-index: 45;
  background: var(--bg);
  padding: calc(var(--safe-t) + 12px) 14px 0;
  display: flex;
  flex-direction: column;
  animation: fade 0.15s ease;
}
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 10px;
}
.search-ico { color: var(--text-3); font-size: 17px; }
#search-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 16.5px;
  outline: none;
  padding: 9px 0;
  font-family: inherit;
}
#search-close { padding: 8px 10px; }
#search-results { flex: 1; overflow-y: auto; padding-top: 10px; }
.search-hint { color: var(--text-3); text-align: center; padding: 40px 20px; font-size: 14.5px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card-2);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 8px 10px 18px;
  box-shadow: var(--shadow);
  font-size: 14.5px;
  max-width: 88vw;
  animation: slideUp 0.22s ease;
}
#toast-undo { padding: 7px 14px; border-radius: 999px; font-size: 14px; }

/* ---------- Tab bar ---------- */
#tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + var(--safe-b));
}
.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  cursor: pointer;
  font-family: inherit;
}
.tab-ico { font-size: 21px; filter: grayscale(1); opacity: 0.75; }
.tab-lbl { font-size: 10.5px; font-weight: 600; letter-spacing: 0.2px; }
.tab.active { color: var(--accent); }
.tab.active .tab-ico { filter: none; opacity: 1; }

/* Scrollbar polish (non-iOS) */
::-webkit-scrollbar { width: 0; height: 0; }
