* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b0f19;
  --panel: #0f172a;
  --line: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --faint: #64748b;
  --accent: #0C6B70;
  --accent-2: #14b8a6;
  --danger: #f87171;
  --warn: #fbbf24;
  --p1: #f97316;
  --ok: #34d399;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --touch: 44px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(16px + var(--safe-top)) 16px calc(20px + var(--safe-bottom));
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
}

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

.top-title { min-width: 0; flex: 1; }

h1 {
  font-size: 1.25rem;
  color: var(--accent-2);
  letter-spacing: 0.02em;
  line-height: 1.2;
}

h2 { font-size: 1rem; font-weight: 700; }

.sub, .muted { color: var(--muted); }
.small { font-size: 12px; }
.top-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.login-panel { max-width: 420px; margin-left: auto; margin-right: auto; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.count {
  display: inline-flex;
  min-width: 1.5em;
  padding: 0 7px;
  margin-left: 6px;
  border-radius: 999px;
  background: #132033;
  color: var(--accent-2);
  font-size: 12px;
  vertical-align: middle;
  justify-content: center;
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 10px 0 6px;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 14px 0 4px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  line-height: 1.35;
  -webkit-user-select: none;
  user-select: none;
}

.check-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-top: 1px;
  flex-shrink: 0;
  accent-color: var(--accent-2);
}

/* 16px+ avoids iOS zoom-on-focus */
input[type="text"],
input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  background: #0b1220;
  border: 1px solid #334155;
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  min-height: var(--touch);
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-2);
}

.btn {
  border: 1px solid #334155;
  background: #1e293b;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: var(--touch);
  min-width: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.btn:hover { border-color: var(--accent-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active { transform: scale(0.98); }

.btn.primary {
  background: linear-gradient(135deg, #0C6B70, #0f766e);
  border-color: #0f766e;
  color: #fff;
}

.btn.ghost { background: transparent; }
.btn.danger { border-color: #7f1d1d; color: #fecaca; }
.btn.sm {
  padding: 8px 12px;
  font-size: 13px;
  min-height: 40px;
}

.login-panel .btn.primary { margin-top: 14px; width: 100%; }

.add-heading { margin-bottom: 10px; }

.add-form {
  display: grid;
  grid-template-columns: 2fr 1fr 70px 1.4fr auto;
  gap: 8px;
  align-items: stretch;
}

.add-row-secondary {
  display: contents;
}

.mobile-tabs {
  display: none;
  gap: 8px;
  margin-bottom: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 4px 0 8px;
  background: linear-gradient(to bottom, var(--bg) 70%, transparent);
}

.mobile-tabs .tab {
  flex: 1;
  min-height: var(--touch);
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.mobile-tabs .tab.active {
  color: #ecfdf5;
  border-color: #0f766e;
  background: linear-gradient(135deg, #0C6B70, #0f766e);
}

.mobile-tabs .tab.active .count {
  background: rgba(0, 0, 0, 0.25);
  color: #ecfdf5;
}

.cols {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 16px;
  align-items: start;
}

.list { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: #0b1220;
  border: 1px solid #1e293b;
  border-radius: 12px;
  padding: 12px 14px;
  transition: border-color .15s;
}

.card:hover { border-color: #334155; }
.card.p1 { border-color: rgba(249, 115, 22, 0.45); }

.card-top {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.pri {
  flex: 0 0 auto;
  min-width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  background: #132033;
  color: var(--accent-2);
  border: 1px solid #1e3a4a;
}

.card.p1 .pri {
  background: #3b1c0c;
  color: #fdba74;
  border-color: #9a3412;
}

.pri.done {
  background: #022c22;
  color: var(--ok);
  border-color: #14532d;
}

.card-main { flex: 1; min-width: 0; }
.card-title {
  font-size: 15px;
  font-weight: 650;
  color: #f8fafc;
  word-break: break-word;
}
.card-meta { font-size: 12px; color: var(--faint); margin-top: 3px; }

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.card-actions .btn-done-main {
  flex: 1 1 auto;
  min-width: 88px;
}

.notes {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #1e293b;
}

.notes h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  margin-bottom: 6px;
}

.notes ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.notes li {
  font-size: 13px;
  color: #cbd5e1;
  padding: 8px 10px;
  background: #0f172a;
  border-radius: 8px;
  border: 1px solid #1e293b;
  word-break: break-word;
}

.note-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 8px;
}

.error { color: var(--danger); font-size: 13px; margin-top: 10px; }
.warn { color: var(--warn); font-size: 13px; margin-top: 10px; }

.toast {
  position: fixed;
  bottom: calc(16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  right: auto;
  background: #134e4a;
  border: 1px solid #0f766e;
  color: #ecfdf5;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 50;
  max-width: min(420px, calc(100vw - 32px));
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.toast.bad {
  background: #3f1d1d;
  border-color: #7f1d1d;
  color: #fee2e2;
}

footer {
  margin-top: 8px;
  text-align: center;
  font-size: 11px;
  color: #475569;
}

footer code { color: #64748b; }

.empty {
  color: var(--faint);
  font-size: 13px;
  padding: 12px 4px;
}

/* ---- Mobile-first refinements ---- */
@media (max-width: 900px) {
  body { padding: calc(12px + var(--safe-top)) 12px calc(16px + var(--safe-bottom)); }

  h1 { font-size: 1.1rem; }

  .hide-mobile { display: none !important; }

  .top {
    align-items: center;
    margin-bottom: 12px;
  }

  .top-actions .btn {
    padding: 8px 10px;
    font-size: 13px;
  }

  .add-form {
    grid-template-columns: 1fr;
  }

  .add-row-secondary {
    display: grid;
    grid-template-columns: 1fr 72px;
    gap: 8px;
  }

  .btn-add {
    width: 100%;
    min-height: 48px;
    font-size: 16px;
  }

  .mobile-tabs { display: flex; }

  .cols {
    grid-template-columns: 1fr;
    gap: 0;
  }

  /* tab panes: only active column visible */
  body.tab-open .col-done { display: none; }
  body.tab-done .col-open { display: none; }

  .col-open.panel,
  .col-done.panel {
    margin-bottom: 0;
    border: none;
    background: transparent;
    padding: 0;
  }

  .card { padding: 14px; }

  .card-title { font-size: 16px; }

  .card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .card-actions .btn {
    width: 100%;
  }

  .card-actions .btn-done-main {
    grid-column: 1 / -1;
    min-height: 48px;
    font-size: 15px;
  }

  .card-actions .btn-reopen-main {
    grid-column: 1 / -1;
    min-height: 48px;
  }

  .note-form {
    grid-template-columns: 1fr;
  }

  .note-form .btn {
    width: 100%;
  }

  footer {
    margin-top: 20px;
    font-size: 10px;
    padding: 0 8px;
  }
}

@media (min-width: 901px) {
  body { padding: 24px; }
  .mobile-tabs { display: none !important; }
  body.tab-open .col-done,
  body.tab-done .col-open {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn:active { transform: none; }
  .card { transition: none; }
}
