/* GYtodo — スマホ優先の画面スタイル */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --list-bg: #e9edf3;
  --text: #1d2330;
  --muted: #667085;
  --border: #d6dbe4;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --danger: #c62828;
  --overdue: #d93025;
  --overdue-bg: #fde7e5;
  --today: #c25e00;
  --today-bg: #ffead6;
  --soon: #8a6100;
  --soon-bg: #fff4c2;
  --done: #2e7d32;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08), 0 1px 3px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  --nav-h: 58px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1c2029;
    --surface-2: #252a35;
    --list-bg: #181c24;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --border: #343a46;
    --accent: #6b9cff;
    --accent-text: #0b1220;
    --danger: #ff6b6b;
    --overdue: #ff7a70;
    --overdue-bg: #3d1f1d;
    --today: #ffad5c;
    --today-bg: #3b2a18;
    --soon: #f5d061;
    --soon-bg: #363015;
    --done: #81c784;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------- レイアウト */
.app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  min-height: 52px;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.main { flex: 1; padding: 12px 12px calc(var(--nav-h) + var(--safe-bottom) + 16px); width: 100%; max-width: 900px; margin: 0 auto; }
.main.wide { max-width: none; padding-left: 0; padding-right: 0; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom); height: calc(var(--nav-h) + var(--safe-bottom));
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px;
}
.bottomnav a.active { color: var(--accent); font-weight: 600; }
.bottomnav svg { width: 24px; height: 24px; }

@media (min-width: 900px) {
  .bottomnav { top: 0; bottom: 0; right: auto; width: 84px; height: auto; flex-direction: column; justify-content: flex-start; padding-top: 12px; border-top: 0; border-right: 1px solid var(--border); }
  .bottomnav a { flex: 0 0 72px; }
  .app { padding-left: 84px; }
  .main { padding-bottom: 24px; }
  .fab { bottom: 24px !important; }
}

/* ---------------------------------------------------------------- 部品 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  text-decoration: none; color: var(--text); white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn svg { width: 18px; height: 18px; flex: 0 0 auto; }
.btn.small svg { width: 15px; height: 15px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 14px; }
.btn.block { width: 100%; }
.btn.big { min-height: 52px; font-size: 18px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.iconbtn { width: 40px; height: 40px; min-height: 40px; padding: 0; border: 0; background: transparent; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--text); }
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn:active { background: var(--surface-2); }

input[type=text], input[type=search], input[type=datetime-local], input[type=date], input[type=time], input[type=url], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); font-size: 16px; /* 16px 未満だと iPhone で拡大される */
}
textarea { resize: vertical; min-height: 88px; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: block; margin: 10px 0; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.hidden { display: none !important; }
.error { color: var(--danger); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 12px; }
.panel h2 { font-size: 16px; margin: 0 0 8px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 18px 4px 6px; letter-spacing: 0.02em; }
.empty { color: var(--muted); text-align: center; padding: 28px 8px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 8px 14px; min-height: 40px; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.switch { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.switch input { width: 22px; height: 22px; }
.badge { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge svg { width: 13px; height: 13px; }
.due-overdue { background: var(--overdue-bg); color: var(--overdue); font-weight: 700; }
.due-today { background: var(--today-bg); color: var(--today); font-weight: 700; }
.due-soon { background: var(--soon-bg); color: var(--soon); font-weight: 600; }
.chip-done { background: transparent; color: var(--done); }

/* ---------------------------------------------------------------- 一覧（期限順・検索・アーカイブ） */
.rowlist { list-style: none; margin: 0; padding: 0; }
.rowitem {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; box-shadow: var(--shadow);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.rowitem:active { background: var(--surface-2); }
.rowitem .body { flex: 1; min-width: 0; }
.rowitem .title { font-weight: 600; word-break: break-word; }
.rowitem .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; font-size: 13px; color: var(--muted); align-items: center; }
.rowitem.overdue { border-left: 5px solid var(--overdue); }
.rowitem.today { border-left: 5px solid var(--today); }
.rowitem.soon { border-left: 5px solid var(--soon); }
.check { width: 26px; height: 26px; flex: 0 0 26px; border-radius: 50%; border: 2px solid var(--border); background: transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; margin-top: 1px; }
.check.on { background: var(--done); border-color: var(--done); color: #fff; }
.check svg { width: 16px; height: 16px; }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px); z-index: 25;
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.fab svg { width: 28px; height: 28px; }

/* ---------------------------------------------------------------- ボード */
.boards .rowitem { align-items: center; }
.handle { cursor: grab; color: var(--muted); touch-action: none; display: inline-flex; padding: 6px; margin: -6px; }
.handle svg { width: 20px; height: 20px; }

.lists {
  display: flex; gap: 10px; align-items: flex-start; overflow-x: auto; overflow-y: hidden;
  padding: 12px; min-height: calc(100vh - 120px);
  scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
  scroll-padding: 12px;
}
body.dragging .lists { scroll-snap-type: none; }
.list {
  flex: 0 0 min(86vw, 320px); max-height: calc(100vh - var(--nav-h) - var(--safe-bottom) - 96px);
  display: flex; flex-direction: column; background: var(--list-bg); border-radius: var(--radius);
  scroll-snap-align: start; border: 1px solid var(--border);
}
@media (min-width: 900px) { .list { flex-basis: 290px; max-height: calc(100vh - 90px); } .lists { scroll-snap-type: none; } }
.list-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 4px 10px; }
.list-head .name { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-head .count { font-size: 12px; color: var(--muted); }
.cards { flex: 1; overflow-y: auto; padding: 4px 8px; min-height: 40px; }
.card {
  background: var(--surface); border-radius: 8px; padding: 10px 10px 8px; margin-bottom: 8px;
  box-shadow: var(--shadow); border: 1px solid var(--border); cursor: pointer;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.card .title { word-break: break-word; }
.card .meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.card.done .title { text-decoration: line-through; color: var(--muted); }
.card.overdue { border-left: 4px solid var(--overdue); }
.card.today { border-left: 4px solid var(--today); }
.card.soon { border-left: 4px solid var(--soon); }
.list-foot { padding: 4px 8px 8px; }
.add-card { width: 100%; text-align: left; background: transparent; border: 0; color: var(--muted); padding: 10px 6px; cursor: pointer; border-radius: 8px; }
.add-card:active { background: var(--surface-2); }
.add-list { flex: 0 0 min(86vw, 280px); scroll-snap-align: start; }

/* SortableJS のドラッグ中表示 */
.sortable-ghost { opacity: 0.35; }
.sortable-chosen { box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); }
.sortable-drag, .sortable-fallback { opacity: 0.95 !important; transform: rotate(2deg); }

/* ---------------------------------------------------------------- シート（カード詳細・ダイアログ） */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 22, 0.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 700px) { .overlay { align-items: center; padding: 24px; } }
.sheet {
  background: var(--bg); width: 100%; max-width: 720px; max-height: calc(100% - var(--safe-top) - 16px); overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 0 0 calc(var(--safe-bottom) + 16px);
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
@media (min-width: 700px) { .sheet { border-radius: 16px; max-height: 100%; } }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 14px; background: var(--surface); border-bottom: 1px solid var(--border); }
.sheet-head .where { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { padding: 12px 14px; }
.dialog { background: var(--surface); width: 100%; max-width: 480px; border-radius: 16px 16px 0 0; padding: 18px 16px calc(var(--safe-bottom) + 18px); max-height: 90%; overflow-y: auto; }
@media (min-width: 700px) { .dialog { border-radius: 16px; } }
.dialog h2 { margin: 0 0 10px; font-size: 18px; }
.dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.title-input { font-size: 20px; font-weight: 700; border: 0; background: transparent; padding: 4px 0; min-height: 0; resize: none; overflow: hidden; }
.title-input:focus { outline: none; border-bottom: 2px solid var(--accent); }
.tabs { display: flex; gap: 4px; margin-bottom: 6px; }
.tabs button { border: 0; background: transparent; padding: 6px 10px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.markdown { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; min-height: 60px; word-break: break-word; }
.markdown :first-child { margin-top: 0; }
.markdown :last-child { margin-bottom: 0; }
.markdown pre { background: var(--surface-2); padding: 8px; border-radius: 6px; overflow-x: auto; }
.markdown code { font-family: var(--mono); font-size: 0.92em; }
.markdown table { border-collapse: collapse; }
.markdown td, .markdown th { border: 1px solid var(--border); padding: 4px 8px; }

.mailref { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.mailref .when { font-size: 24px; font-weight: 800; letter-spacing: 0.01em; font-variant-numeric: tabular-nums; }
.mailref .who { font-size: 17px; font-weight: 600; word-break: break-all; }
.mailref .q { font-family: var(--mono); font-size: 13px; background: var(--surface-2); border-radius: 6px; padding: 6px 8px; margin-top: 6px; word-break: break-all; display: flex; align-items: center; gap: 8px; }
.mailref .q span { flex: 1; min-width: 0; }
.dir { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.dir.received { background: #e3f2fd; color: #0d47a1; }
.dir.sent { background: #ede7f6; color: #4527a0; }
@media (prefers-color-scheme: dark) { .dir.received { background: #12304d; color: #9ecbff; } .dir.sent { background: #2a2145; color: #c7b8ff; } }
.parse-box { border: 1px dashed var(--border); border-radius: 8px; padding: 10px; background: var(--surface-2); }
.missing input { border-color: var(--today); background: var(--today-bg); }

.reminder { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.reminder > svg { width: 18px; height: 18px; flex: 0 0 18px; color: var(--muted); }
.reminder > .small { white-space: nowrap; }
.section-title .badge { margin-left: 6px; }
svg { max-width: 100%; }
.reminder:last-child { border-bottom: 0; }
.reminder .t { flex: 1; font-variant-numeric: tabular-nums; }
.reminder.sent .t { color: var(--muted); text-decoration: line-through; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }

.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px; font-family: var(--mono); font-size: 17px; background: var(--surface-2); padding: 12px; border-radius: 8px; }
.bigcode { font-family: var(--mono); font-size: 34px; font-weight: 800; letter-spacing: 0.12em; text-align: center; padding: 12px; background: var(--surface-2); border-radius: 10px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-bottom) + 84px); z-index: 80; background: #222a38; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px); box-shadow: 0 4px 12px rgba(0,0,0,.3); font-size: 15px; }
.toast.error { background: var(--danger); }
.banner { background: var(--soon-bg); color: var(--text); padding: 10px 12px; display: flex; gap: 8px; align-items: center; font-size: 14px; }
.banner .grow { flex: 1; }

.login { max-width: 420px; margin: 0 auto; padding: calc(var(--safe-top) + 40px) 20px 40px; }
.login h1 { font-size: 28px; text-align: center; margin: 0 0 6px; }
.login .lead { text-align: center; color: var(--muted); margin-bottom: 28px; }
.login details { margin-top: 18px; }
.login summary { cursor: pointer; color: var(--accent); padding: 8px 0; }

.searchbox { position: sticky; top: calc(var(--safe-top) + 52px); z-index: 10; background: var(--bg); padding: 4px 0 8px; }
