/* Tasks — single page, RTL, automatic dark mode. */

:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --line: #e4e2dc;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #d8efec;
  --high: #d4342c;
  --overdue: #b4231b;
  --danger: #b4231b;
  --today: #0f766e;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 8px 24px rgb(0 0 0 / 0.06);
  --radius: 14px;
  --font: system-ui, -apple-system, "SF Arabic", "Segoe UI", "Noto Sans Arabic", Tahoma, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1b1b1a;
    --surface-2: #262523;
    --text: #ecebe6;
    --muted: #9c9a94;
    --line: #2e2d2a;
    --accent: #2cc4b0;
    --accent-text: #08201d;
    --accent-soft: #163a36;
    --high: #f26b63;
    --overdue: #f58b84;
    --danger: #f58b84;
    --today: #2cc4b0;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.35);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; font-weight: 750; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; font-weight: 700; }

.muted { color: var(--muted); }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  border-radius: 10px;
  min-height: 44px;
  padding: 0 16px;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.primary { background: var(--accent); color: var(--accent-text); font-weight: 650; }
.ghost { color: var(--muted); }
.ghost:hover { background: var(--surface-2); color: var(--text); }
.danger { color: var(--danger); }
.danger.armed { background: var(--danger); color: #fff; }
.small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; }
.icon { min-width: 44px; padding: 0; font-size: 1.1rem; }
.wide { width: 100%; margin-top: 8px; }

input[type="text"], input[type="password"], input[type="date"], select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 16px; /* prevents iOS zoom on focus */
}

textarea { resize: vertical; line-height: 1.6; }

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: left 12px center;
  background-size: 16px;
  background-repeat: no-repeat;
  padding-left: 36px;
}

.error { color: var(--danger); margin: 0; font-size: 0.92rem; }
.error:empty { display: none; }

/* --- Login ----------------------------------------------------------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  display: grid;
  gap: 12px;
}

.login-card h1 { margin-bottom: 8px; }
.login-card label { color: var(--muted); font-size: 0.92rem; }

/* --- App shell -------------------------------------------------------- */

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.top p { margin: 4px 0 0; font-size: 0.95rem; }

.quick-add input {
  min-height: 54px;
  font-size: 17px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-color: transparent;
  padding-inline: 18px;
}

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 14px 0 10px;
}

@media (min-width: 620px) {
  .filters { grid-template-columns: minmax(150px, 1fr) auto auto; align-items: center; }
}

.filters select { min-height: 40px; padding-block: 6px; font-size: 15px; }

/* Segmented control */
.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 3px;
  gap: 2px;
}

.seg button {
  flex: 1;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 9px;
  font-size: 0.92rem;
  color: var(--muted);
  white-space: nowrap;
}

.seg button.on {
  background: var(--surface);
  color: var(--text);
  font-weight: 650;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
}

/* --- List ------------------------------------------------------------- */

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.task {
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  border-inline-start: 4px solid transparent;
}

.task.prio-high { border-inline-start-color: var(--high); }

.task .check {
  flex: none;
  width: 52px;
  min-height: 56px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 0;
}

.task .check::before {
  content: "";
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--muted);
  transition: background 0.15s, border-color 0.15s;
}

.task .check:hover::before { border-color: var(--accent); }

.task.done .check::before,
.task .check.ticking::before {
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 14px no-repeat;
  border-color: var(--accent);
}

.task .open {
  flex: 1;
  min-width: 0;
  text-align: start;
  padding: 10px 4px 10px 14px;
  border-radius: 0;
  display: grid;
  gap: 3px;
}

.task .title {
  font-weight: 550;
  overflow-wrap: anywhere;
}

.task.prio-low .title { color: var(--muted); font-weight: 450; }
.task.done .title { color: var(--muted); text-decoration: line-through; font-weight: 450; }

.task .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 0.84rem;
  color: var(--muted);
}

.task .meta:empty { display: none; }

.due.today { color: var(--today); font-weight: 650; }
.due.overdue { color: var(--overdue); font-weight: 650; }
.badge {
  background: var(--accent-soft);
  color: var(--text);
  padding: 0 8px;
  border-radius: 6px;
}
.has-notes::before { content: "✎ "; }
.proj { unicode-bidi: isolate; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 0 24px;
}

/* --- Editor dialog ---------------------------------------------------- */

.editor {
  width: min(600px, 100%);
  max-height: min(92dvh, 900px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow);
}

.editor::backdrop { background: rgb(0 0 0 / 0.45); }

@media (max-width: 619px) {
  .editor {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    border: 0;
  }
}

.editor form {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: inherit;
}

.editor-head, .editor-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg);
}

.editor-head {
  border-bottom: 1px solid var(--line);
  padding-top: max(12px, env(safe-area-inset-top));
}

.editor-foot {
  border-top: 1px solid var(--line);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.editor-foot .primary { flex: 1; max-width: 220px; }

.editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.field { display: grid; gap: 6px; }
.field > span, .field > label, .details-head > span { font-size: 0.88rem; color: var(--muted); }

.grid { display: grid; gap: 14px; }
@media (min-width: 520px) { .grid { grid-template-columns: 1fr 1fr; } }

.date-row { display: flex; gap: 6px; }
.date-row input { flex: 1; }

#e-title { font-size: 17px; font-weight: 600; min-height: 0; resize: none; }

.details-head { display: flex; align-items: center; justify-content: space-between; }

.meta-line { font-size: 0.8rem; margin: 0; }

/* --- Rendered Markdown ------------------------------------------------ */

.md {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  overflow-wrap: anywhere;
}

.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { font-size: 1.05rem; margin: 1em 0 0.4em; }
.md h1 { font-size: 1.2rem; }
.md p { margin: 0.5em 0; }
.md ul, .md ol { margin: 0.5em 0; padding-inline-start: 1.4em; }
.md li { margin: 0.15em 0; }
.md a { color: var(--accent); }
.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
}
.md pre {
  background: var(--surface-2);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
}
.md pre code { background: none; padding: 0; }
.md blockquote {
  margin: 0.5em 0;
  padding-inline-start: 12px;
  border-inline-start: 3px solid var(--line);
  color: var(--muted);
}
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.md .md-empty { color: var(--muted); }

/* --- Toast ------------------------------------------------------------ */

.toast {
  position: fixed;
  inset-inline: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  margin: 0 auto;
  max-width: 420px;
  background: var(--text);
  color: var(--bg);
  border-radius: 12px;
  padding: 12px 16px;
  text-align: center;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: none; }
