/**
 * task-manager 共通スタイル。
 * 対応: docs/SRS.md 8章(画面一覧), CONSTRAINTS.md C-SEC-003(XSS: innerHTML禁止と対で運用)
 * カラーはdataviz skillの検証済みデフォルトパレット(参照: ~/.claude/skills配下 dataviz/references/palette.md)を採用。
 */

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #f9f9f7;
  --surface-card: #ffffff;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.1);
  --baseline: #c3c2b7;

  /* ステータス(固定順: todo=blue, doing=orange, done=aqua) */
  --status-todo: #2a78d6;
  --status-doing: #eb6834;
  --status-done: #1baf7a;

  /* 優先度(SRS FR-DATA-006指定: high=赤/medium=黄/low=緑。status paletteを採用) */
  --priority-high: #d03b3b;
  --priority-medium: #fab219;
  --priority-low: #0ca30c;

  /* Googleカレンダー予定(外部連携の識別色。カテゴリカルパレットslot7 violet) */
  --gcal: #4a3aa7;

  --accent: #2a78d6;
  --danger: #d03b3b;
  --danger-bg: #fbeceb;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #0d0d0d;
    --surface-card: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.1);
    --baseline: #383835;

    --status-todo: #3987e5;
    --status-doing: #d95926;
    --status-done: #199e70;

    --priority-high: #e66767;
    --priority-medium: #fab219;
    --priority-low: #0ca30c;
    --gcal: #9085e9;

    --accent: #3987e5;
    --danger: #e66767;
    --danger-bg: #3a1f1f;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #0d0d0d;
  --surface-card: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.1);
  --baseline: #383835;

  --status-todo: #3987e5;
  --status-doing: #d95926;
  --status-done: #199e70;

  --priority-high: #e66767;
  --priority-medium: #fab219;
  --priority-low: #0ca30c;
  --gcal: #9085e9;

  --accent: #3987e5;
  --danger: #e66767;
  --danger-bg: #3a1f1f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--surface-2);
  color: var(--text-primary);
  min-height: 100vh;
}

h1, h2, h3 {
  margin: 0 0 0.5em;
}

button {
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-card);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 0.5em 1em;
}

.btn:hover {
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-danger {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input, select, textarea {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.5em 0.6em;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-card);
  color: var(--text-primary);
  width: 100%;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.3em;
}

.field {
  margin-bottom: 1em;
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.4em;
  min-height: 1.2em;
}

/* ===== 共通ナビ (nav.js) ===== */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5em;
  padding: 0.75em 1.25em;
  background: var(--surface-card);
  border-bottom: 1px solid var(--gridline);
  flex-wrap: wrap;
}

.topbar .brand {
  font-weight: 700;
  font-size: 1.05rem;
  margin-right: auto;
}

.topbar nav {
  display: flex;
  gap: 0.25em;
}

.topbar nav a {
  padding: 0.4em 0.8em;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.topbar nav a.active {
  background: var(--surface-2);
  color: var(--text-primary);
  font-weight: 600;
}

.main {
  flex: 1;
  padding: 1.25em;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  margin-bottom: 1em;
  flex-wrap: wrap;
}

/* ===== フィルタバー (FR-SYS-003, FR-SYS-004) ===== */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 1.25em;
  flex-wrap: wrap;
  padding: 0.6em 0.9em;
  background: var(--surface-card);
  border: 1px solid var(--gridline);
  border-radius: var(--radius);
  margin-bottom: 1em;
  font-size: 0.85rem;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5em;
  flex-wrap: wrap;
}

.filter-group .group-label {
  color: var(--text-muted);
  font-weight: 600;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.3em 0.7em;
  border-radius: 999px;
  border: 1px solid var(--gridline);
  background: var(--surface-2);
  cursor: pointer;
  user-select: none;
  color: var(--text-secondary);
}

.chip input {
  width: auto;
  margin: 0;
}

.chip.active {
  border-color: var(--accent);
  color: var(--text-primary);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface-2));
}

/* ===== カンバン (SCR-02) ===== */
.kanban {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1em;
}

@media (max-width: 800px) {
  .kanban {
    grid-template-columns: 1fr;
  }
}

.kanban-col {
  background: var(--surface-card);
  border: 1px solid var(--gridline);
  border-radius: var(--radius);
  min-height: 200px;
  display: flex;
  flex-direction: column;
}

.kanban-col.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

.kanban-col-head {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.8em 1em;
  border-bottom: 1px solid var(--gridline);
  font-weight: 600;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.todo { background: var(--status-todo); }
.status-dot.doing { background: var(--status-doing); }
.status-dot.done { background: var(--status-done); }

.count-badge {
  margin-left: auto;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
  font-size: 0.85rem;
}

.kanban-col-body {
  padding: 0.75em;
  display: flex;
  flex-direction: column;
  gap: 0.6em;
  flex: 1;
}

.empty-state {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 1.5em 0.5em;
}

.task-card {
  background: var(--surface-2);
  border: 1px solid var(--gridline);
  border-radius: 8px;
  padding: 0.7em 0.8em;
  cursor: grab;
}

.task-card:active {
  cursor: grabbing;
}

.task-card.dragging {
  opacity: 0.4;
}

.task-card-title {
  font-weight: 600;
  margin-bottom: 0.4em;
  word-break: break-word;
}

.task-card-meta {
  display: flex;
  align-items: center;
  gap: 0.5em;
  flex-wrap: wrap;
  font-size: 0.78rem;
}

.priority-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.15em 0.5em;
  border-radius: 999px;
  font-weight: 600;
  border: 1px solid var(--border);
}

.priority-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.priority-high .dot { background: var(--priority-high); }
.priority-medium .dot { background: var(--priority-medium); }
.priority-low .dot { background: var(--priority-low); }

.tag-pill {
  padding: 0.15em 0.5em;
  border-radius: 999px;
  background: var(--surface-card);
  border: 1px solid var(--gridline);
  color: var(--text-secondary);
}

.due-badge {
  color: var(--text-muted);
  margin-left: auto;
}

.due-badge.overdue {
  color: var(--danger);
  font-weight: 600;
}

/* ===== Googleカレンダー連携 (FR-CAL-001〜003) ===== */
.gcal-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1em;
  font-size: 0.85rem;
}

.gcal-connect-btn {
  color: var(--gcal);
  border-color: var(--gcal);
}

.gcal-status {
  color: var(--gcal);
  font-weight: 600;
}

.gcal-error {
  color: var(--danger);
}

/* ===== カレンダー (SCR-03) ===== */
.calendar-nav {
  display: flex;
  align-items: center;
  gap: 0.75em;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--gridline);
  border: 1px solid var(--gridline);
  border-radius: var(--radius);
  overflow: hidden;
}

.calendar-weekday {
  background: var(--surface-2);
  color: var(--text-muted);
  text-align: center;
  font-size: 0.78rem;
  padding: 0.5em 0;
}

.calendar-cell {
  background: var(--surface-card);
  min-height: 100px;
  padding: 0.4em;
  display: flex;
  flex-direction: column;
  gap: 0.25em;
}

.calendar-cell.outside {
  background: var(--surface-2);
  color: var(--text-muted);
}

.calendar-cell.today .cell-date {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
}

.cell-date {
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cell-task {
  font-size: 0.72rem;
  padding: 0.15em 0.4em;
  border-radius: 4px;
  background: var(--surface-2);
  border-left: 3px solid var(--status-todo);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.cell-task.priority-high { border-left-color: var(--priority-high); }
.cell-task.priority-medium { border-left-color: var(--priority-medium); }
.cell-task.priority-low { border-left-color: var(--priority-low); }
.cell-task-gcal { border-left-color: var(--gcal); color: var(--gcal); }

.cell-more {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ===== ダッシュボード (SCR-04) ===== */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1em;
}

.card {
  background: var(--surface-card);
  border: 1px solid var(--gridline);
  border-radius: var(--radius);
  padding: 1em 1.2em;
}

.card h3 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.stat-tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75em;
}

.stat-tile {
  background: var(--surface-card);
  border: 1px solid var(--gridline);
  border-radius: var(--radius);
  padding: 0.9em 1em;
  text-align: center;
}

.stat-tile .value {
  font-size: 1.8rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-tile .label {
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-top: 0.2em;
}

.donut-wrap {
  display: flex;
  align-items: center;
  gap: 1.2em;
}

.donut {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.donut-center {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--surface-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.donut-center .pct {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.donut-center .pct-label {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.legend {
  display: flex;
  gap: 1em;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.6em;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.tag-bar-row {
  display: grid;
  grid-template-columns: 90px 1fr 3.5em;
  align-items: center;
  gap: 0.6em;
  margin-bottom: 0.55em;
  font-size: 0.82rem;
}

.tag-bar-row .tag-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-secondary);
}

.tag-bar-track {
  display: flex;
  height: 14px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface-2);
  gap: 2px;
}

.tag-bar-seg {
  height: 100%;
}

.tag-bar-seg.todo { background: var(--status-todo); }
.tag-bar-seg.doing { background: var(--status-doing); }
.tag-bar-seg.done { background: var(--status-done); }

.tag-bar-row .total {
  text-align: right;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.trend-chart {
  width: 100%;
  height: auto;
}

.trend-chart .grid-line {
  stroke: var(--gridline);
  stroke-width: 1;
}

.trend-chart .axis-label {
  fill: var(--text-muted);
  font-size: 9px;
}

.trend-line-created {
  fill: none;
  stroke: var(--status-todo);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trend-line-completed {
  fill: none;
  stroke: var(--status-done);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trend-dot {
  cursor: pointer;
}

/* ===== モーダル (SCR-05) ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1em;
  z-index: 50;
}

.modal {
  background: var(--surface-card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5em;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1em;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-muted);
  padding: 0.2em 0.5em;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.6em;
  margin-top: 1.4em;
}

.modal-actions .right {
  display: flex;
  gap: 0.6em;
}

.tag-input-row {
  display: flex;
  gap: 0.5em;
}

.tag-select-list {
  display: flex;
  gap: 0.4em;
  flex-wrap: wrap;
  margin-top: 0.5em;
}

/* ===== ログイン (SCR-01) ===== */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1em;
}

.login-card {
  background: var(--surface-card);
  border: 1px solid var(--gridline);
  border-radius: var(--radius);
  padding: 2em;
  width: 100%;
  max-width: 340px;
}

.login-card h1 {
  font-size: 1.2rem;
  text-align: center;
}

.hint {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
