:root {
  --text: #1f2328;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --bg: #ffffff;
  --bg-soft: #f9fafb;
  --accent: #2563eb;
  --danger: #dc2626;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Segoe UI", sans-serif;
}

#app-root { height: 100%; }

button {
  font-family: inherit;
  cursor: pointer;
}

input, select, textarea, button {
  font-family: inherit;
  font-size: 14px;
}

/* --- ログイン画面 --- */
.login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  padding: 16px;
}
.login-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-card h1 { font-size: 18px; margin-bottom: 8px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.login-card input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* --- アプリシェル --- */
.app-shell {
  display: flex;
  height: 100%;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
}
.brand { font-weight: 700; margin-bottom: 20px; padding: 0 8px; line-height: 1.4; }
.sidebar ul { list-style: none; padding: 0; margin: 0; flex: 1; }
.sidebar a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  margin-bottom: 4px;
}
.sidebar a.active, .sidebar a:hover { background: var(--bg-soft); }
.nav-icon { font-size: 16px; }
.fab-desktop {
  margin-top: auto;
  padding: 10px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.bottom-nav { display: none; }
.fab-mobile { display: none; }

.view-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px 80px;
}

@media (max-width: 767px) {
  .sidebar { display: none; }
  .view-container { padding: 16px 16px 90px; }
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg);
    border-top: 1px solid var(--border);
    padding: 6px 0 max(6px, env(safe-area-inset-bottom));
    z-index: 20;
  }
  .bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    font-size: 11px;
    color: var(--text-muted);
    text-decoration: none;
  }
  .bottom-nav a.active { color: var(--accent); }
  .fab-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 16px;
    bottom: 70px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 26px;
    border: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    z-index: 21;
  }
}

.quick-add-menu {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  padding: 6px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  min-width: 160px;
}
.quick-add-menu button {
  background: none;
  border: none;
  text-align: left;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
}
.quick-add-menu button:hover { background: var(--bg-soft); }

/* --- 共通 --- */
.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 20px; margin: 0; flex: 1; }
.section-head { display: flex; align-items: center; justify-content: space-between; }
.home-section { margin-bottom: 28px; }
.home-section h2 { font-size: 15px; color: var(--text-muted); margin: 0 0 8px; }
.home-section-warn h2 { color: var(--danger); }
.hint { color: var(--text-muted); font-size: 13px; }
.muted { color: var(--text-muted); }
.error-text { color: var(--danger); font-size: 13px; }
.view-loading { color: var(--text-muted); padding: 40px 0; text-align: center; }

.btn-primary, .btn-secondary, .btn-danger {
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 8px 14px;
  font-weight: 600;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--bg); border-color: var(--border); color: var(--text); }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 13px; font-weight: 500; }
.icon-btn { background: none; border: none; font-size: 14px; color: var(--text-muted); padding: 4px 6px; }
.icon-btn:hover { color: var(--text); }

/* --- 一覧 --- */
.item-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.item-row:hover { background: var(--bg-soft); }
.item-time { color: var(--text-muted); font-size: 13px; min-width: 44px; }
.item-title { flex: 1; }
.item-sub { font-size: 12px; }
.event-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.task-checkbox { width: 18px; text-align: center; }
.done-text { text-decoration: line-through; color: var(--text-muted); }
.overdue-text { color: var(--danger); font-weight: 600; }

/* --- カレンダー --- */
.calendar-header { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.calendar-header h1 { flex: 1; text-align: center; font-size: 18px; margin: 0; }
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
}
.calendar-weekday {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 0;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
.calendar-cell {
  min-height: 84px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 4px;
  cursor: pointer;
}
.calendar-cell:hover { background: var(--bg-soft); }
.calendar-cell.is-muted { color: var(--text-muted); background: #fcfcfd; }
.calendar-cell.is-today .calendar-date {
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.calendar-date { font-size: 12px; margin-bottom: 4px; }
.calendar-items { display: flex; flex-direction: column; gap: 2px; }
.cal-item {
  font-size: 11px;
  padding: 1px 4px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-item-event { background: #dbeafe; color: #1e3a8a; }
.cal-item-task { background: #f3f4f6; color: #374151; }
.cal-item-more { font-size: 11px; color: var(--text-muted); }

@media (max-width: 767px) {
  .calendar-cell { min-height: 60px; }
  .cal-item { display: none; }
  .calendar-cell.has-items::after {
    content: '';
    display: block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: 2px;
  }
}

/* --- タブ --- */
.tab-bar { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: none;
  border: none;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.task-manage-list { list-style: none; margin: 0; padding: 0; }
.task-manage-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
}
.task-manage-row.priority-high { border-left-color: var(--danger); }
.task-manage-row.priority-normal { border-left-color: #d97706; }
.task-manage-row.priority-low { border-left-color: #9ca3af; }
.task-manage-main { flex: 1; cursor: pointer; }
.task-manage-title { font-weight: 500; }
.task-manage-meta { display: flex; gap: 10px; font-size: 12px; color: var(--text-muted); flex-wrap: wrap; }
.priority-select { border: 1px solid var(--border); border-radius: 6px; padding: 4px; }

/* --- フォーム --- */
.stack-form { display: flex; flex-direction: column; gap: 14px; }
.stack-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.stack-form input, .stack-form select, .stack-form textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
}
.form-row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.form-row .grow { flex: 1; min-width: 140px; }
.checkbox-inline { flex-direction: row !important; align-items: center; gap: 6px !important; }
.field-label { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }

.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--chip-color, var(--border));
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}
.chip input { display: none; }
.chip:has(input:checked) { background: var(--chip-color, var(--accent)); color: #fff; }
.chip-plain { border-color: var(--border); }
.chip-plain:has(input:checked) { background: var(--text); color: #fff; }

.modal-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }

.related-task-list, .subtask-list, .linked-event-list, .category-manage-list { list-style: none; margin: 0; padding: 0; }
.related-task-list li, .subtask-list li, .linked-event-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.related-task-list li > label, .subtask-list li > label { flex: 1; }
.category-manage-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.category-manage-list .cat-name { flex: 1; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; }

.search-results { border: 1px solid var(--border); border-radius: 6px; margin-top: 4px; max-height: 160px; overflow-y: auto; }
.search-result-item { padding: 8px 10px; cursor: pointer; font-size: 13px; }
.search-result-item:hover { background: var(--bg-soft); }

#summary-output { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
#summary-text { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; font-family: inherit; }

/* --- モーダル --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 22, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
}
.modal {
  background: var(--bg);
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
}
.modal-wide { max-width: 640px; }
.confirm-overlay { z-index: 50; }
.confirm-modal { max-width: 360px; }
.confirm-modal p { margin-top: 0; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-header h2 { font-size: 16px; margin: 0; }

/* --- トースト --- */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-error { background: var(--danger); }

@media (min-width: 768px) {
  .toast { bottom: 24px; }
}
