:root {
  color-scheme: dark;
  --bg0: #070b17;
  --bg1: #0b1020;
  --surface: rgba(255, 255, 255, 0.06);
  --surface2: rgba(255, 255, 255, 0.09);
  --text: #eef2ff;
  --muted: rgba(238, 242, 255, 0.72);
  --border: rgba(255, 255, 255, 0.12);
  --accent: #7c5cff;
  --accent2: #2dd4bf;
  --danger: #ff4d6d;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --radiusSm: 12px;
  --tap: 44px;
  --pad: 14px;
  --gap: 12px;
  --font: "Tajawal", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px circle at 20% 0%, rgba(124, 92, 255, 0.18), transparent 55%),
    radial-gradient(900px circle at 80% 10%, rgba(45, 212, 191, 0.12), transparent 55%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  overflow-x: hidden;
}

::selection { background: rgba(124, 92, 255, 0.35); }

.muted { color: var(--muted); }
.small { font-size: 12px; }

.noscript {
  margin: 12px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

:focus-visible {
  outline: 2px solid rgba(124, 92, 255, 0.9);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(11, 16, 32, 0.86);
  backdrop-filter: blur(10px);
}

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: var(--pad);
  max-width: 980px;
  margin: 0 auto;
  flex-wrap: wrap;
}

.brand { min-width: 0; }
.brand__title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.1px;
}
.brand__meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__actions { display: inline-flex; gap: 10px; }

.btn,
.iconBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  border-radius: var(--radiusSm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn { padding: 0 14px; font-weight: 700; }
.iconBtn { width: var(--tap); height: var(--tap); padding: 0; }

.btn:hover,
.iconBtn:hover { background: rgba(255, 255, 255, 0.10); }

.btn:active,
.iconBtn:active { transform: translateY(1px); }

.btn.ghost,
.iconBtn.ghost { background: transparent; }

.btn.primary,
.iconBtn.primary {
  background: linear-gradient(180deg, rgba(124, 92, 255, 0.95), rgba(124, 92, 255, 0.78));
  border-color: rgba(124, 92, 255, 0.55);
}

.btn.primary:hover,
.iconBtn.primary:hover { filter: brightness(1.05); }

.iconBtn.danger,
.btn.danger { border-color: rgba(255, 77, 109, 0.55); color: #ffd6de; }
.iconBtn.danger:hover,
.btn.danger:hover { background: rgba(255, 77, 109, 0.12); }

.btn:disabled,
.iconBtn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.topbar__search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--gap);
  padding: 0 var(--pad) var(--pad);
  max-width: 980px;
  margin: 0 auto;
}

.searchBox {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding-inline: 12px;
  border-radius: var(--radiusSm);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
}

.searchBox:focus-within {
  border-color: rgba(124, 92, 255, 0.6);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.14);
}

.searchBox__icon { opacity: 0.85; flex: 0 0 auto; }

.searchBox input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  padding-block: 10px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 0 var(--pad) var(--pad);
  max-width: 560px;
  margin-inline: auto;
}

.tab {
  min-height: var(--tap);
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tab.is-active {
  background: rgba(124, 92, 255, 0.15);
  border-color: rgba(124, 92, 255, 0.5);
  color: var(--text);
}

.drawer { padding: 0 var(--pad) var(--pad); }
.drawer[hidden] { display: none !important; }

.addForm {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--gap);
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field__label { font-size: 12px; color: var(--muted); }

.field input,
.field select {
  width: 100%;
  min-height: var(--tap);
  padding-inline: 12px;
  padding-block: 10px;
  border-radius: var(--radiusSm);
  border: 1px solid var(--border);
  outline: none;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 15px;
}

.field input:focus,
.field select:focus {
  border-color: rgba(124, 92, 255, 0.6);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.14);
}

.field--inline { max-width: 420px; }

.hint { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }

.content {
  max-width: 920px;
  margin: 0 auto;
  padding: var(--pad);
  padding-bottom: calc(var(--pad) + 84px + env(safe-area-inset-bottom));
}

.panel[hidden] { display: none !important; }

.completedHeader { margin-bottom: 10px; }
.panelTitle { margin: 0 0 10px; font-size: 16px; font-weight: 800; }
.completedControls { margin-bottom: 8px; }

.list { display: flex; flex-direction: column; gap: 10px; }

.taskCard {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
}

.taskHeader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  align-items: start;
}

.taskMainBtn {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: start;
  cursor: pointer;
}

.taskChevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  font-size: 18px;
  line-height: 1;
  opacity: 0.85;
  margin-top: 2px;
  transition: transform 160ms ease;
}

.taskCard.is-expanded .taskChevron { transform: rotate(180deg); }

.taskText { flex: 1; min-width: 0; }

.taskTitleRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.taskTitle {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.pill {
  flex: 0 0 auto;
  padding: 2px 10px;
  font-size: 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  white-space: nowrap;
}

.pill.success {
  border-color: rgba(45, 212, 191, 0.5);
  background: rgba(45, 212, 191, 0.12);
  color: #c6fff6;
}

.metaLine {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.progressRow {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.progressBar {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.10);
}

.progressBar > span {
  display: block;
  height: 100%;
  width: var(--p, 0%);
  background: linear-gradient(90deg, rgba(124, 92, 255, 0.95), rgba(45, 212, 191, 0.92));
  border-radius: inherit;
}

.progressText { min-width: 64px; font-size: 12px; color: var(--muted); text-align: end; }

.taskActions { display: inline-flex; gap: 8px; justify-content: end; }

.taskBody {
  border-top: 1px dashed rgba(255, 255, 255, 0.14);
  padding: 12px;
  background: rgba(0, 0, 0, 0.12);
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 220ms ease, opacity 200ms ease;
  pointer-events: none;
}

.taskCard.is-expanded .taskBody {
  max-height: 3200px;
  opacity: 1;
  pointer-events: auto;
}

.subHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.subHeaderTitle { font-size: 13px; font-weight: 800; color: var(--muted); }

.subList { display: flex; flex-direction: column; gap: 8px; }

.subRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: var(--radiusSm);
  background: rgba(255, 255, 255, 0.03);
}

.subLeft { display: flex; gap: 10px; align-items: flex-start; min-width: 0; }
.subLeft input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent2);
}

.subContent { min-width: 0; }
.subTitle { font-weight: 700; overflow-wrap: anywhere; }
.subTitle.done { text-decoration: line-through; opacity: 0.75; }
.subMeta { margin-top: 4px; font-size: 12px; color: var(--muted); }

.subActions { display: inline-flex; gap: 8px; align-items: center; justify-content: end; }

.subAddForm { margin-top: 10px; display: grid; grid-template-columns: 1fr auto; gap: var(--gap); align-items: end; }
.subAddForm[hidden] { display: none !important; }

.emptyState {
  padding: 22px 14px;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.03);
  text-align: center;
}

.emptyState__title { margin: 0 0 6px; font-weight: 900; color: var(--text); }
.emptyState__text { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.emptyState__actions { margin-top: 12px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.skeletonCard {
  height: 104px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.04);
  position: relative;
  overflow: hidden;
}

.skeletonCard::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.12), transparent);
  transform: translateX(-40%);
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
  from { transform: translateX(-40%); }
  to { transform: translateX(140%); }
}

.toasts {
  position: fixed;
  inset-inline: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.55);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: toastIn 180ms ease-out;
}

.toast.success { border-color: rgba(45, 212, 191, 0.45); }
.toast.error { border-color: rgba(255, 77, 109, 0.55); }

.toast__msg { font-size: 14px; color: var(--text); line-height: 1.4; }
.toast__actions { display: inline-flex; gap: 8px; }

.toast__btn {
  min-height: 36px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}

.toast__btn:hover { background: rgba(255, 255, 255, 0.10); }

@keyframes toastIn {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  justify-content: center;
  align-items: end;
  padding: 12px;
  background: rgba(0, 0, 0, 0.55);
}

.overlay[hidden] { display: none !important; }

.modal {
  width: min(560px, 100%);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(20, 26, 45, 0.96);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal--sheet { width: min(620px, 100%); }

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.modal__title { margin: 0; font-size: 16px; font-weight: 900; }

.modal__body { padding: 12px; }
.modal__message { margin: 0; color: var(--muted); line-height: 1.65; }

.modal__footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.sheetGrid { display: grid; gap: 12px; }

.toggle {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  min-height: var(--tap);
  border-radius: var(--radiusSm);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
}

.toggle input {
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.sheetActions { display: flex; gap: 10px; flex-wrap: wrap; }

html.noScroll,
html.noScroll body { overflow: hidden; }

@media (min-width: 720px) {
  .overlay { align-items: center; }
  .tabs { width: min(560px, 100%); margin-inline: auto; }
  .topbar__search { grid-template-columns: 1fr auto; width: min(920px, 100%); margin-inline: auto; }
  .topbar__inner { width: min(920px, 100%); margin-inline: auto; }
  .drawer { width: min(920px, 100%); margin-inline: auto; }
}

@media (max-width: 640px) {
  :root { --pad: 12px; --gap: 10px; }
  .topbar__inner { row-gap: 6px; }
  .topbar__actions { width: 100%; justify-content: flex-end; }
  .topbar__search { grid-template-columns: 1fr; }
  .addForm { grid-template-columns: 1fr; }
  .taskHeader { grid-template-columns: 1fr; }
  .taskActions { justify-content: flex-start; }
  .progressRow { align-items: flex-start; }
  .subRow { grid-template-columns: 1fr; }
  .subActions { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .taskBody,
  .taskChevron,
  .toast,
  .skeletonCard::after { transition: none !important; animation: none !important; }
}
