/* ── RESET & BASE ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d0d0d;
  --bg1:       #161616;
  --bg2:       #1e1e1e;
  --bg3:       #272727;
  --border:    rgba(255,255,255,0.08);
  --border2:   rgba(255,255,255,0.14);
  --text:      #f0f0f0;
  --text2:     #a0a0a0;
  --text3:     #606060;
  --accent:    #3b8ef3;
  --accent2:   #1a5dbf;
  --danger:    #e24b4a;
  --warn:      #ef9f27;
  --ok:        #2db87a;
  --info:      #3b8ef3;
  --pri-pol:   #e24b4a;
  --pri-kiire: #ef9f27;
  --pri-mood:  #3b8ef3;
  --pri-aega:  #2db87a;
  --radius:    12px;
  --radius-sm: 8px;
  --font:      'DM Sans', system-ui, sans-serif;
  --font-mono: 'DM Mono', monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ── SCREENS ───────────────────────────────────────────────────── */
.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* ── LOGIN ─────────────────────────────────────────────────────── */
#login-screen, #register-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
  min-height: 100vh;
}
.login-box {
  width: 100%;
  max-width: 380px;
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2rem;
}
.logo-mark {
  font-size: 1.4rem;
  color: var(--accent);
  font-weight: 600;
}
.login-logo h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.form-error {
  background: rgba(226,75,74,0.12);
  border: 1px solid rgba(226,75,74,0.3);
  border-radius: var(--radius-sm);
  color: #f09595;
  font-size: 0.85rem;
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
}

/* ── FORMS ─────────────────────────────────────────────────────── */
.field {
  margin-bottom: 0.9rem;
  flex: 1;
}
.field label {
  display: block;
  font-size: 0.75rem;
  color: var(--text2);
  margin-bottom: 0.3rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  padding: 0.6rem 0.8rem;
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%23606060' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.field textarea {
  min-height: 80px;
  resize: vertical;
}
.field-row {
  display: flex;
  gap: 0.75rem;
}

/* ── BUTTONS ───────────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.65rem 1.25rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn-primary:hover  { background: var(--accent2); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary.full   { width: 100%; margin-top: 0.5rem; padding: 0.8rem; }

.btn-ghost {
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 0.65rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-ghost:hover { background: var(--bg3); }
.btn-ghost.full  { width: 100%; margin-top: 0.5rem; padding: 0.75rem; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg3); color: var(--text); }

/* ── TOP BAR ───────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(13,13,13,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  max-width: 960px;
  margin: 0 auto;
}
.topbar-logo {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.topbar-actions { display: flex; gap: 4px; }

/* ── SUMMARY STRIP ─────────────────────────────────────────────── */
.summary-strip {
  display: flex;
  gap: 8px;
  padding: 10px 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.summary-strip::-webkit-scrollbar { display: none; }
.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 20px;
  white-space: nowrap;
  font-size: 0.8rem;
  border: 1px solid transparent;
}
.stat-pill.danger { background: rgba(226,75,74,0.12); border-color: rgba(226,75,74,0.25); color: #f09595; }
.stat-pill.warn   { background: rgba(239,159,39,0.12); border-color: rgba(239,159,39,0.25); color: #FAC775; }
.stat-pill.info   { background: rgba(59,142,243,0.12); border-color: rgba(59,142,243,0.25); color: #85B7EB; }
.stat-pill.ok     { background: rgba(45,184,122,0.12); border-color: rgba(45,184,122,0.25); color: #2db87a; }
.stat-num { font-weight: 600; font-size: 0.9rem; }
.stat-lbl { color: inherit; opacity: 0.8; }

/* ── FILTER BAR ────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 8px;
  padding: 8px 1rem;
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.filter-select {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 5px 24px 5px 10px;
  white-space: nowrap;
  flex-shrink: 0;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2 3.5l3 3 3-3' stroke='%23606060' stroke-width='1.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
  transition: border-color 0.15s;
}
.filter-select:focus { outline: none; border-color: var(--accent); }
.filter-select.active { border-color: var(--accent); color: var(--accent); }
.filter-clear {
  background: rgba(226,75,74,0.12);
  border: 1px solid rgba(226,75,74,0.25);
  border-radius: 20px;
  color: #f09595;
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s;
}
.filter-clear:hover { background: rgba(226,75,74,0.2); }

/* ── BOARD ─────────────────────────────────────────────────────── */
.board {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding-bottom: calc(80px + var(--safe-bottom));
  max-width: 960px;
  margin: 0 auto;
}
.board-col {
  border-bottom: 1px solid var(--border);
}
.col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 1rem 8px;
  position: sticky;
  top: 116px;
  z-index: 10;
  background: rgba(13,13,13,0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.col-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text2);
}
.col-badge {
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--bg3);
  color: var(--text2);
  border-radius: 10px;
  padding: 1px 7px;
}
.col-cards {
  padding: 4px 1rem 12px;
}
.col-empty {
  text-align: center;
  color: var(--text3);
  font-size: 0.8rem;
  padding: 12px 0;
}

/* ── TASK CARD ─────────────────────────────────────────────────── */
.task-card {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  border-left-width: 3px;
}
.task-card:hover  { background: var(--bg2); border-color: var(--border2); }
.task-card:active { transform: scale(0.99); }

.task-card[data-pri="Põleb"]    { border-left-color: var(--pri-pol); }
.task-card[data-pri="Kiire"]    { border-left-color: var(--pri-kiire); }
.task-card[data-pri="Mõõdukas"] { border-left-color: var(--pri-mood); }
.task-card[data-pri="Aega on"]  { border-left-color: var(--pri-aega); }

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.card-title {
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.4;
  flex: 1;
}
.card-title.done { text-decoration: line-through; color: var(--text3); }

.pri-badge {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  font-family: var(--font-mono);
}
.pri-badge[data-pri="Põleb"]    { background: rgba(226,75,74,0.15); color: #f09595; }
.pri-badge[data-pri="Kiire"]    { background: rgba(239,159,39,0.15); color: #FAC775; }
.pri-badge[data-pri="Mõõdukas"] { background: rgba(59,142,243,0.15); color: #85B7EB; }
.pri-badge[data-pri="Aega on"]  { background: rgba(45,184,122,0.15); color: #5DCAA5; }

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.meta-tag {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 8px;
  background: var(--bg3);
  color: var(--text2);
  white-space: nowrap;
}
.meta-tag.inbox { background: rgba(226,75,74,0.12); color: #f09595; }
.meta-date {
  font-size: 0.72rem;
  color: var(--text3);
  font-family: var(--font-mono);
}
.meta-date.overdue { color: var(--danger); font-weight: 500; }
.meta-date.today   { color: var(--warn); font-weight: 500; }

.subtask-bar {
  margin-top: 8px;
}
.subtask-track {
  height: 2px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}
.subtask-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}
.subtask-label {
  font-size: 0.68rem;
  color: var(--text3);
  margin-top: 3px;
  font-family: var(--font-mono);
}

/* ── MODALS ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: fadein 0.15s ease;
}
@keyframes fadein { from { opacity: 0; } }

.modal-sheet {
  background: var(--bg1);
  border-radius: var(--radius);
  border: 1px solid var(--border2);
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: popIn 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes popIn { from { transform: scale(0.95); opacity: 0; } }

.detail-sheet { max-height: 88vh; }

.modal-handle { display: none; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 1rem 8px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 1rem;
  font-weight: 600;
}
.modal-body { padding: 1rem; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* ── DETAIL CONTENT ────────────────────────────────────────────── */
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 1rem;
}
.detail-notes {
  font-size: 0.88rem;
  color: var(--text2);
  line-height: 1.7;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin-bottom: 1rem;
  white-space: pre-wrap;
}
.detail-section {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text3);
  margin: 1rem 0 0.5rem;
}
.detail-status-row {
  display: flex;
  gap: 8px;
  margin-bottom: 1rem;
}
.detail-status-row select {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 0.55rem 0.8rem;
  -webkit-appearance: none;
}
.detail-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 1rem;
}
.detail-action-btn {
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 0.75rem;
  color: var(--text3);
  cursor: pointer;
  padding: 2px 0;
  transition: color 0.15s;
}
.detail-action-btn:hover { color: var(--text2); }
.detail-action-btn.danger:hover { color: var(--danger); }

/* ── SUBTASKS IN DETAIL ────────────────────────────────────────── */
.subtask-list { margin-bottom: 0.5rem; }
.subtask-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.subtask-row:last-child { border-bottom: none; }
.subtask-check {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
  accent-color: var(--accent);
  cursor: pointer;
}
.subtask-text {
  flex: 1;
  font-size: 0.9rem;
  line-height: 1.4;
}
.subtask-text.done { text-decoration: line-through; color: var(--text3); }
.subtask-del {
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 2px;
  line-height: 1;
  transition: color 0.15s;
}
.subtask-del:hover { color: var(--danger); }
.sub-subtask-list { margin-left: 28px; }
.sub-subtask-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}
.sub-subtask-row:last-child { border-bottom: none; }

.add-subtask-form {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.add-subtask-form input {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 6px 10px;
}
.add-subtask-form input:focus { outline: none; border-color: var(--accent); }
.add-subtask-form button {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-family: var(--font);
  font-size: 0.82rem;
  padding: 6px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.add-subtask-form button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── TAG PICKER ────────────────────────────────────────────────── */
.tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 32px;
}
.tag-chip {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--border2);
  background: var(--bg2);
  color: var(--text2);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  white-space: nowrap;
  user-select: none;
}
.tag-chip:hover { border-color: var(--accent); color: var(--text); }
.tag-chip.selected { background: rgba(59,142,243,0.18); border-color: var(--accent); color: var(--accent); }
.tag-group-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text3);
  width: 100%;
  margin-top: 4px;
}
.toast {
  position: fixed;
  bottom: calc(1.5rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: 20px;
  padding: 0.55rem 1.1rem;
  font-size: 0.85rem;
  z-index: 999;
  white-space: nowrap;
  animation: fadein 0.2s ease;
}

/* ── DESKTOP ADJUSTMENTS ───────────────────────────────────────── */
@media (min-width: 640px) {
  .board {
    flex-direction: row;
    align-items: flex-start;
    padding: 1rem;
    gap: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .board-col {
    flex: 1 1 240px;
    min-width: 220px;
    max-width: 340px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg1);
    min-height: 200px;
  }
  .col-head {
    position: static;
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    backdrop-filter: none;
  }
  .col-cards { padding: 8px 10px 12px; }
}
