/* ==========================================================================
   Design tokens
   ========================================================================== */
:root{
  --bg: #FAFAF8;
  --surface: #FFFFFF;
  --surface-2: #F2F0EA;
  --text: #1C1B1A;
  --text-muted: #706C64;
  --border: #E6E2D9;
  --accent: #2D5A4A;
  --accent-strong: #1F4536;
  --accent-tint: #E4EEE9;
  --danger: #B3402A;
  --danger-tint: #F6E6E1;
  --shadow: 0 1px 2px rgba(28,27,26,.04), 0 8px 24px -12px rgba(28,27,26,.16);
  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 20px;
  color-scheme: light;
}

html[data-theme="dark"]{
  --bg: #14161A;
  --surface: #1C1F24;
  --surface-2: #20242A;
  --text: #EDEBE6;
  --text-muted: #9A978F;
  --border: #2B2F36;
  --accent: #7FCBA4;
  --accent-strong: #9BDAB8;
  --accent-tint: #1E2E27;
  --danger: #E38268;
  --danger-tint: #2E211D;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 28px -14px rgba(0,0,0,.6);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark){
  html:not([data-theme="light"]){
    --bg: #14161A;
    --surface: #1C1F24;
    --surface-2: #20242A;
    --text: #EDEBE6;
    --text-muted: #9A978F;
    --border: #2B2F36;
    --accent: #7FCBA4;
    --accent-strong: #9BDAB8;
    --accent-tint: #1E2E27;
    --danger: #E38268;
    --danger-tint: #2E211D;
    color-scheme: dark;
  }
}

/* ==========================================================================
   Reset & base
   ========================================================================== */
*, *::before, *::after{ box-sizing: border-box; }
html,body{ height: 100%; }
body{
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", -apple-system, "Segoe UI", Tahoma, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s ease, color .25s ease;
}
button{ font-family: inherit; }
button{ background: none; border: none; cursor: pointer; color: inherit; }
input{ font-family: inherit; color: inherit; }
h1{ margin: 0; font-weight: 800; }
p{ margin: 0; }
ul{ list-style: none; margin: 0; padding: 0; }
:focus-visible{ outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce){
  *{ animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

.wrap{
  min-height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(20px, 6vw, 64px) 16px 40px;
}

.card{
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow);
  padding: clamp(20px, 4vw, 32px);
}

.muted{ color: var(--text-muted); font-size: 14px; }

/* ==========================================================================
   Theme toggle
   ========================================================================== */
.theme-toggle{
  position: fixed;
  top: 16px;
  left: 16px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  z-index: 20;
  box-shadow: var(--shadow);
}
.theme-toggle svg{ width: 19px; height: 19px; }
.theme-toggle .icon-moon{ display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun{ display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon{ display: block; }

/* ==========================================================================
   Auth screen
   ========================================================================== */
.auth-head{ text-align: center; margin-bottom: 22px; }
.auth-head h1{ font-size: 26px; margin-bottom: 6px; }

.tabs{
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-m);
  padding: 4px;
  margin-bottom: 20px;
}
.tab{
  flex: 1;
  padding: 9px 0;
  border-radius: calc(var(--radius-m) - 4px);
  font-weight: 600;
  font-size: 14px;
  color: var(--text-muted);
  transition: background-color .18s ease, color .18s ease;
}
.tab.is-active{ background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.auth-form{ display: flex; flex-direction: column; gap: 14px; }
.field{ display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.field input{
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-s);
  padding: 11px 13px;
  font-size: 15px;
  transition: border-color .15s ease;
}
.field input:focus-visible{ border-color: var(--accent); }

.form-error{
  font-size: 13px;
  color: var(--danger);
  background: var(--danger-tint);
  border-radius: var(--radius-s);
  padding: 9px 12px;
}

.btn-primary{
  margin-top: 4px;
  background: var(--accent);
  color: var(--surface);
  font-weight: 700;
  font-size: 15px;
  padding: 12px;
  border-radius: var(--radius-s);
  transition: background-color .15s ease, transform .1s ease;
}
.btn-primary:hover{ background: var(--accent-strong); }
.btn-primary:active{ transform: scale(.98); }

.btn-ghost{
  font-size: 13px;
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
}
.btn-ghost:hover{ color: var(--text); border-color: var(--text-muted); }

/* ==========================================================================
   App screen
   ========================================================================== */
.app-head{
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}
.app-head h1{ font-size: 22px; }
#user-email{ margin-top: 2px; }

.add-row{
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: 6px 6px 6px 14px;
  margin-bottom: 18px;
}
.add-row input[type="text"]{
  flex: 1;
  border: none;
  background: transparent;
  font-size: 15px;
  padding: 8px 0;
  min-width: 0;
}
.add-row input[type="text"]::placeholder{ color: var(--text-muted); }
.add-row input[type="date"]{
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  width: 128px;
  padding: 8px 2px;
}
.btn-add{
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--surface);
  display: grid;
  place-items: center;
  transition: background-color .15s ease, transform .1s ease;
}
.btn-add svg{ width: 18px; height: 18px; }
.btn-add:hover{ background: var(--accent-strong); }
.btn-add:active{ transform: scale(.92); }

.toolbar{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 12px;
}
.filters{ display: flex; gap: 4px; }
.filter{
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 6px 11px;
  border-radius: 999px;
  transition: background-color .15s ease, color .15s ease;
}
.filter.is-active{ background: var(--accent-tint); color: var(--accent-strong); font-weight: 700; }
.count{ font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }

.todo-list{ display: flex; flex-direction: column; }

.todo-item{
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--border);
  animation: item-in .22s ease both;
}
.todo-item:last-child{ border-bottom: none; }
.todo-item.dragging{ opacity: .4; }
.todo-item.removing{ animation: item-out .18s ease forwards; }

@keyframes item-in{
  from{ opacity: 0; transform: translateY(-4px); }
  to{ opacity: 1; transform: translateY(0); }
}
@keyframes item-out{
  to{ opacity: 0; transform: scale(.97); }
}

.drag-handle{
  flex-shrink: 0;
  width: 20px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--border);
  cursor: grab;
  opacity: 0;
  transition: opacity .15s ease;
}
.todo-item:hover .drag-handle{ opacity: 1; }
.drag-handle svg{ width: 14px; height: 14px; }

.check{
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin-top: 4px;
  color: var(--border);
}
.check svg{ width: 24px; height: 24px; overflow: visible; }
.check-ring{ fill: none; stroke: currentColor; stroke-width: 1.6; transition: stroke .15s ease; }
.check-mark{
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 16;
  stroke-dashoffset: 16;
  transition: stroke-dashoffset .28s ease;
}
.check:hover{ color: var(--accent); }
.todo-item.is-completed .check{ color: var(--accent); }
.todo-item.is-completed .check-mark{ stroke-dashoffset: 0; }

.todo-body{ flex: 1; min-width: 0; padding-top: 3px; }
.todo-text{
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  border-radius: 4px;
  transition: color .15s ease;
}
.todo-text:focus-visible{ outline: 2px solid var(--accent); outline-offset: 3px; }
.todo-item.is-completed .todo-text{
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-color: var(--border);
}
.todo-due{
  display: none;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.todo-due.is-visible{ display: inline-block; }
.todo-due.is-overdue{ color: var(--danger); font-weight: 600; }

.star{ flex-shrink: 0; width: 22px; height: 22px; margin-top: 5px; color: var(--border); }
.star svg{ width: 18px; height: 18px; }
.star:hover{ color: #D9A441; }
.todo-item.is-important .star{ color: #D9A441; }
.todo-item.is-important .star svg{ fill: #D9A441; }

.delete{
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  margin-top: 5px;
  color: var(--border);
  opacity: 0;
  transition: opacity .15s ease, color .15s ease;
}
.todo-item:hover .delete,
.todo-item:focus-within .delete{ opacity: 1; }
.delete svg{ width: 16px; height: 16px; }
.delete:hover{ color: var(--danger); }

.empty-state{
  text-align: center;
  padding: 34px 10px 16px;
  color: var(--text-muted);
}
.empty-state svg{ width: 46px; height: 46px; margin-bottom: 10px; opacity: .55; }
.empty-state p{ font-size: 14px; }

.app-foot{ display: flex; justify-content: center; margin-top: 6px; min-height: 20px; }
.btn-text{
  font-size: 13px;
  color: var(--text-muted);
  padding: 8px 10px;
}
.btn-text:hover{ color: var(--danger); }

/* ==========================================================================
   Toast
   ========================================================================== */
.toast{
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translate(-50%, 12px);
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 30;
}
.toast.is-visible{ opacity: 1; transform: translate(-50%, 0); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 480px){
  .wrap{ padding: 14px 10px 28px; }
  .card{ border-radius: var(--radius-m); padding: 18px; }
  .theme-toggle{ top: 12px; left: 12px; width: 36px; height: 36px; }
  .add-row{ flex-wrap: wrap; padding: 8px; }
  .add-row input[type="date"]{ width: auto; margin-inline-start: auto; }
  .drag-handle{ display: none; }
}

@media (min-width: 768px){
  .card{ padding: 36px; }
}
