/* Todo — self-contained styles. Dark-friendly, respects prefers-color-scheme. */

:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222c;
  --border: #2a2f3a;
  --text: #e8eaf0;
  --muted: #9aa1b1;
  --accent: #4f7cff;
  --accent-text: #ffffff;
  --danger: #ff6b6b;
  --ok: #3fb96f;
  --radius: 12px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --panel: #ffffff;
    --panel-2: #eef0f5;
    --border: #d8dce6;
    --text: #1c1f26;
    --muted: #5d6577;
    --accent: #2f5fe8;
  }
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over component display rules
   (e.g. .key-screen uses display:grid, which would otherwise override it). */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans",
    "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- app shell: full-viewport, no page scroll ---------- */
html, body { height: 100%; }
body { overflow: hidden; }
#app:not([hidden]) {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ---------- header ---------- */
.app-header {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.app-header h1 { font-size: 18px; margin: 0; }
.counts {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}
.counts .chip {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}
#key-reset { margin-left: 0; }

/* ---------- layout ---------- */
.layout {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 12px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}
@media (min-width: 1024px) {
  .layout {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(0, 1fr);
    overflow: hidden;
    align-items: stretch;
  }
  .panel { overflow-y: auto; min-height: 0; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px 12px;
}
.panel h2 {
  font-size: 17px;
  margin: 0 0 8px;
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--panel);
  padding: 12px 0 6px;
}

/* ---------- forms & buttons ---------- */
.add-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
#add-user {
  position: sticky;
  top: 43px;
  z-index: 5;
  background: var(--panel);
  padding: 4px 0 8px;
}
.add-form input[name="title"] { flex: 1 1 160px; }
.add-form input[name="notes"] { flex: 1 1 120px; }

.group-add {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.group-add input { flex: 1; }

input[type="text"], input[type="password"], textarea, select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 16px; /* >=16px prevents iOS focus zoom */
  min-height: 44px;
}
textarea { min-height: 44px; resize: vertical; width: 100%; }

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  min-height: 44px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.small { min-height: 36px; padding: 6px 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.delegate { border-color: var(--accent); color: var(--accent); background: transparent; font-weight: 600; }
.btn.now { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 700; }
.badge.now { color: #ff9f43; border-color: #ff9f43; }
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }

/* ---------- task list ---------- */
.task-list { list-style: none; margin: 0; padding: 0; }

.task {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
  padding: 8px 10px;
  margin-bottom: 6px;
}
.task .row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.task input[type="checkbox"] {
  width: 26px;
  height: 26px;
  margin-top: 4px;
  accent-color: var(--ok);
  flex: none;
  cursor: pointer;
}
.task .body { flex: 1; min-width: 0; }
.task .title { font-weight: 600; word-break: break-word; }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.task .notes {
  color: var(--muted);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 2px;
}
.badge {
  display: inline-block;
  font-size: 11px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0 7px;
  margin-left: 6px;
  vertical-align: middle;
}
.task .actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
  align-items: center;
}
.task .actions select { min-height: 36px; padding: 4px 8px; font-size: 13px; }

.task .edit-form { display: grid; gap: 8px; }

/* ---------- groups ---------- */
.group { margin-bottom: 12px; }
.group h3 {
  font-size: 14px;
  margin: 0 0 6px;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 8px;
  position: sticky;
  top: 43px;
  z-index: 4;
  background: var(--panel);
  padding: 6px 0 4px;
}
.group h3 .gcount { font-size: 12px; }
.group .empty { color: var(--muted); font-size: 13px; margin: 0 0 4px; }

/* ---------- done box ---------- */
.done-box { margin-top: 14px; }
.done-box summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  padding: 8px 0;
  min-height: 44px;
}
.done-box .task { opacity: 0.75; }

/* ---------- key screen ---------- */
.key-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.key-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
}
.key-card h1 { margin: 0; font-size: 22px; }
.key-card p { margin: 0; color: var(--muted); font-size: 14px; }
.key-card .error { color: var(--danger); }

.sync-note {
  flex: none;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  min-height: 18px;
  margin: 4px 12px 8px;
}
