/* =========================================================
   マイカレンダー — style.css
   色はすべて :root のトークンで定義し、ダークモードで差し替える
   ========================================================= */
:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e0db;
  --text: #1a1a19;
  --text-2: #52514e;
  --text-3: #7d7c77;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e3eefb;
  --danger: #c93a39;
  --warning: #9a5b00;
  --warning-soft: #fdf3e1;
  --sun: #c93a39;
  --sat: #256abf;
  --today: #2a78d6;
  --income: #2a78d6;   /* グラフ: 収入（カテゴリ1） */
  --expense: #eb6834;  /* グラフ: 支出（カテゴリ2） */
  --positive: #0f7a52;
  --negative: #c93a39;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 1px 1px rgba(0, 0, 0, .03);
  --radius: 12px;
  --font: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #33332f;
    --text: #f2f1ec;
    --text-2: #c3c2b7;
    --text-3: #93928a;
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --accent-soft: #1d2d42;
    --danger: #e66767;
    --warning: #e8b04b;
    --warning-soft: #33280f;
    --sun: #e66767;
    --sat: #6da7ec;
    --today: #3987e5;
    --income: #3987e5;
    --expense: #d95926;
    --positive: #3cc28f;
    --negative: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #33332f;
  --text: #f2f1ec; --text-2: #c3c2b7; --text-3: #93928a;
  --accent: #3987e5; --accent-ink: #ffffff; --accent-soft: #1d2d42;
  --danger: #e66767; --warning: #e8b04b; --warning-soft: #33280f; --sun: #e66767; --sat: #6da7ec; --today: #3987e5;
  --income: #3987e5; --expense: #d95926; --positive: #3cc28f; --negative: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
h1, h2 { margin: 0; line-height: 1.3; }
h2 { font-size: 16px; font-weight: 700; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- ヘッダー ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.brand-icon { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tab {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 999px;
  color: var(--text-2); cursor: pointer; white-space: nowrap; font-weight: 600;
}
.tab:hover { background: var(--surface-2); }
.tab.is-active { background: var(--accent-soft); color: var(--accent); }

.container { max-width: 1200px; margin: 0 auto; padding: 16px 24px 48px; }

/* ---------- 月切り替え ---------- */
.month-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.month-title { font-size: 22px; font-weight: 700; min-width: 9.5em; text-align: center; font-variant-numeric: tabular-nums; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-size: 20px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- 共通パーツ ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.link-btn { border: 0; background: none; padding: 2px 4px; color: var(--text-3); cursor: pointer; font-size: 13px; border-radius: 4px; }
.link-btn:hover { color: var(--text); background: var(--surface-2); }
.link-btn.danger:hover { color: var(--danger); }
.hint { color: var(--text-3); font-size: 13px; margin: 6px 0 12px; }
.empty { color: var(--text-3); text-align: center; padding: 24px 0; margin: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 13px; cursor: pointer; color: var(--text-2);
}
.chip.is-active { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.chip .x { border: 0; background: none; cursor: pointer; color: var(--text-3); padding: 0 0 0 2px; font-size: 14px; line-height: 1; }
.chip .x:hover { color: var(--danger); }

/* ---------- サマリー ---------- */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { padding: 14px 18px; }
.stat-label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.stat-value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat-value.positive { color: var(--positive); }
.stat-value.negative { color: var(--negative); }
.stat-sub { font-size: 12.5px; color: var(--text-3); min-height: 1.5em; }

/* ---------- ビュー切り替え ---------- */
.view { display: none; }
.view.is-active { display: block; }

/* ---------- カレンダー ---------- */
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.calendar { padding: 10px; }
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-weekdays div { text-align: center; font-size: 12px; font-weight: 600; color: var(--text-3); padding: 4px 0 8px; }
.cal-weekdays .sun { color: var(--sun); }
.cal-weekdays .sat { color: var(--sat); }
.cal-grid { gap: 2px; }
.day {
  position: relative; min-height: 104px; padding: 5px 5px 6px;
  border-radius: 8px; border: 1px solid transparent; background: transparent;
  text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 3px;
  overflow: hidden;
}
.day:hover { background: var(--surface-2); }
.day.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.day.is-other { opacity: .38; }
.day-num { font-size: 13px; font-weight: 600; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; font-variant-numeric: tabular-nums; }
.day.sun .day-num { color: var(--sun); }
.day.sat .day-num { color: var(--sat); }
.day.is-today .day-num { background: var(--today); color: #fff; }
.shift-chip {
  display: block; font-size: 11px; line-height: 1.35; padding: 2px 5px; border-radius: 4px;
  color: var(--text); background: color-mix(in srgb, var(--job) 16%, transparent);
  border-left: 3px solid var(--job);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums;
}
/* 予定のチップ（シフトと見分けられるよう、左の線ではなく全体を淡く塗る） */
.shift-chip.is-event { border-left: 0; padding-left: 6px; background: color-mix(in srgb, var(--job) 24%, transparent); }
.day-expense { font-size: 11px; color: var(--text-2); margin-top: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.day-dots { display: none; gap: 3px; flex-wrap: wrap; }
.day-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--job); }

/* ---------- 日別パネル ---------- */
.day-panel { position: sticky; top: 72px; }
.dp-date { font-size: 18px; font-weight: 700; }
.dp-total { font-size: 13px; color: var(--text-2); margin: 2px 0 12px; font-variant-numeric: tabular-nums; }
.dp-section { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.dp-section h3 { font-size: 13px; color: var(--text-2); margin: 0 0 8px; display: flex; justify-content: space-between; align-items: center; }
.tpl-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tpl-btn {
  display: inline-flex; flex-direction: column; align-items: flex-start;
  padding: 6px 10px; border-radius: 8px; cursor: pointer;
  border: 1px dashed color-mix(in srgb, var(--job) 70%, var(--border));
  background: color-mix(in srgb, var(--job) 8%, var(--surface));
  font-size: 12px; line-height: 1.3; text-align: left;
}
.tpl-btn:not(:disabled):hover { background: color-mix(in srgb, var(--job) 18%, var(--surface)); }
/* その日に追加済みのテンプレート */
.tpl-btn:disabled { cursor: default; opacity: .55; border-style: solid; }
.tpl-btn b { font-size: 13px; }
.tpl-btn span { color: var(--text-2); font-variant-numeric: tabular-nums; }

.entry { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.entry:last-child { border-bottom: 0; }
.entry-bar { width: 4px; align-self: stretch; border-radius: 2px; background: var(--job, var(--text-3)); }
.entry-main { flex: 1; min-width: 0; }
.entry-title { font-weight: 600; font-size: 14px; }
.entry-sub { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.entry-kind { display: inline-block; padding: 0 6px; margin-right: 4px; border-radius: 999px; font-size: 11px; font-weight: 600; color: var(--text); background: color-mix(in srgb, var(--job) 22%, transparent); }
.entry-amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.entry-actions { display: flex; gap: 2px; }

.quick-expense { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.quick-expense input, .quick-expense select { min-width: 0; }
.quick-expense .full { grid-column: 1 / -1; }

input[type="text"], input[type="number"], input[type="date"], input[type="time"], select {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

/* ---------- 支出一覧 ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; color: var(--text-3); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border); }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--border); }
.table tfoot td { font-weight: 700; border-bottom: 0; }
.table .cat { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); font-size: 12px; }
.table .memo { color: var(--text-2); }
.table td:last-child { text-align: right; white-space: nowrap; }

/* ---------- グラフ ---------- */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-wide { grid-column: 1 / -1; }
.chart-desc { color: var(--text-3); font-size: 13px; margin: 2px 0 10px; }
.chart svg text { pointer-events: none; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis-label { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .baseline { stroke: var(--text-3); stroke-width: 1; }
.chart .value-label { fill: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .cat-label { fill: var(--text); font-size: 12.5px; }
.chart .hover-band { fill: var(--text); opacity: 0; }
.chart .hover-band.is-on { opacity: .05; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart details { margin-top: 10px; font-size: 13px; color: var(--text-2); }
.chart details summary { cursor: pointer; color: var(--text-3); }
.chart details table { margin-top: 6px; }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 4px 16px rgba(0,0,0,.12);
  font-variant-numeric: tabular-nums; min-width: 140px;
}
.tooltip .tt-title { font-weight: 700; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; align-items: center; }
.tooltip .tt-row span { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }
.tooltip .tt-row i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* ---------- 設定 ---------- */
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .swatch { width: 12px; height: 12px; border-radius: 50%; background: var(--job); flex: none; }
.list .li-main { flex: 1; min-width: 0; }
.list .li-title { font-weight: 600; }
.list .li-sub { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.inline-form { display: flex; gap: 6px; }
.inline-form input { flex: 1; }

/* ---------- ダイアログ ---------- */
.dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0;
  background: var(--surface); color: var(--text); width: min(460px, calc(100vw - 32px));
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
}
.dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-2); font-weight: 600; flex: 1; min-width: 0; }
.dialog .row { display: flex; gap: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.preview { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.preview b { color: var(--text); }
/* 入力内容に問題があるときの説明（保存ボタンは押せなくなる） */
.form-error { margin: 0; font-size: 13px; font-weight: 600; color: var(--danger); }
/* 注意だけ（保存はできる）。例: 予定とシフトの時間が重なっている */
.form-warning { margin: 0; padding: 8px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--warning); background: var(--warning-soft); }
.dialog label.check { flex-direction: row; align-items: center; gap: 8px; flex: none; cursor: pointer; }
.dialog label.check input { width: 18px; height: 18px; margin: 0; }
.color-pick { border: 0; padding: 0; margin: 0; }
.color-pick legend { font-size: 13px; color: var(--text-2); font-weight: 600; margin-bottom: 6px; }
.color-pick #job-colors { display: flex; gap: 8px; flex-wrap: wrap; }
.color-dot { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--surface); outline: 2px solid transparent; cursor: pointer; background: var(--c); }
.color-dot.is-active { outline-color: var(--text); }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px;
  font-size: 14px; width: max-content; max-width: calc(100vw - 32px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60;
  display: flex; gap: 12px; align-items: center;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 0; }

/* ---------- レスポンシブ ---------- */
@media (max-width: 900px) {
  .cal-layout { grid-template-columns: 1fr; }
  .day-panel { position: static; }
  .charts, .settings { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { padding: 8px 16px; flex-direction: column; align-items: stretch; gap: 6px; }
  .tabs { justify-content: space-between; }
  .tab { padding: 6px 10px; flex: 1; }
  .container { padding: 12px 16px 40px; }
  .month-title { font-size: 19px; min-width: 0; flex: 1; }
  .summary { grid-template-columns: 1fr 1fr; gap: 8px; }
  .summary .stat:first-child { grid-column: 1 / -1; }
  .stat { padding: 10px 14px; }
  .stat-value { font-size: 22px; }
  .calendar { padding: 6px; }
  .day { min-height: 58px; padding: 3px; align-items: center; }
  .day-num { font-size: 12px; width: 22px; height: 22px; }
  .shift-chip { display: none; }
  .day-dots { display: flex; justify-content: center; }
  .day-expense { font-size: 10px; margin-top: auto; }
  .dialog .row { flex-wrap: wrap; }
  .dialog .row label { min-width: 120px; }
}
