/* ============================================================
   予実管理アプリ - Loglass風スタイル
   - 紺/深青ベース、白背景、大型見出し、余白ゆったり
   - 角丸、薄シャドウ、シャープなサンセリフ
   - スマホファースト
   ============================================================ */

:root {
  /* カラー: 深い紺をプライマリ、明るい青をアクセント */
  --c-primary:        #0B2545;   /* 深紺 (見出し・主要テキスト) */
  --c-primary-2:      #13315C;   /* 紺2 */
  --c-accent:         #1F6FEB;   /* 青アクセント (CTA・リンク) */
  --c-accent-2:       #2E7DF6;
  --c-accent-soft:    #E8F0FE;   /* 青ホバー背景 */
  --c-positive:       #16A34A;   /* 緑 (+差分) */
  --c-negative:       #DC2626;   /* 赤 (-差分) */
  --c-bg:             #F7F9FC;   /* ページ背景 */
  --c-card:           #FFFFFF;
  --c-text:           #1A1F36;
  --c-text-muted:     #5B6478;
  --c-text-faint:     #8A93A6;
  --c-border:         #E5E9F0;
  --c-border-strong:  #CBD3E0;
  --c-hover:          #F1F4F9;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(11, 37, 69, 0.04);
  --shadow-md: 0 2px 8px rgba(11, 37, 69, 0.06);
  --shadow-lg: 0 8px 24px rgba(11, 37, 69, 0.08);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Hiragino Sans',
               'Hiragino Kaku Gothic ProN', 'Yu Gothic Medium', 'Meiryo', sans-serif;
  --font-num:  'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: var(--font-sans);
  background: var(--c-bg);
  color: var(--c-text);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "palt" 1;
  line-height: 1.55;
}

body {
  padding-bottom: 76px; /* 下部タブ分 */
  min-height: 100vh;
}

a { color: var(--c-accent); text-decoration: none; }
a:hover { color: var(--c-accent-2); text-decoration: underline; }

/* ============================================================
   ヘッダー (アプリバー)
   ============================================================ */
.app-header {
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border);
  padding: 14px 16px 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-header h1 {
  font-size: 19px;
  font-weight: 700;
  color: var(--c-primary);
  letter-spacing: -0.01em;
}
.app-header .sub {
  font-size: 12px;
  color: var(--c-text-muted);
  margin-top: 3px;
}
.app-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.app-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.app-brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--c-primary) 0%, var(--c-accent) 100%);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

/* ============================================================
   メインコンテンツ
   ============================================================ */
main {
  padding: var(--space-4);
  max-width: 1200px;
  margin: 0 auto;
}

.card {
  background: var(--c-card);
  padding: var(--space-5);
  border-radius: var(--r-lg);
  margin-bottom: var(--space-4);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
}
.card h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--c-primary);
  margin-bottom: var(--space-3);
  letter-spacing: -0.01em;
}
.card h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}
.card-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: flex-end;
}

/* ステータス表示 */
.status {
  padding: var(--space-4);
  border-radius: var(--r-md);
  background: var(--c-accent-soft);
  color: var(--c-primary);
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid #DCE6FB;
}
.status.error {
  background: #FEF2F2;
  color: #991B1B;
  border-color: #FECACA;
}
.status.success {
  background: #ECFDF5;
  color: #065F46;
  border-color: #A7F3D0;
}

/* ============================================================
   下部タブナビ
   ============================================================ */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--c-card);
  border-top: 1px solid var(--c-border);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 8px rgba(11, 37, 69, 0.04);
}
.tabbar-item {
  flex: 1;
  text-align: center;
  padding: 10px 4px 12px;
  color: var(--c-text-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  border-top: 2px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.tabbar-item:hover {
  color: var(--c-primary);
  text-decoration: none;
}
.tabbar-item.active {
  color: var(--c-accent);
  border-top-color: var(--c-accent);
  font-weight: 700;
}
.tabbar-icon {
  width: 20px;
  height: 20px;
  display: inline-block;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tabbar-label { display: block; }

/* ============================================================
   ボタン
   ============================================================ */
button, .btn {
  font: inherit;
  font-weight: 600;
  padding: 10px 18px;
  background: var(--c-accent);
  color: #fff;
  border: 0;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button:hover, .btn:hover { background: var(--c-accent-2); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn:disabled {
  background: var(--c-border-strong);
  color: var(--c-text-faint);
  cursor: not-allowed;
  transform: none;
}

.btn-secondary, button.secondary {
  background: var(--c-card);
  color: var(--c-primary);
  border: 1px solid var(--c-border-strong);
}
.btn-secondary:hover, button.secondary:hover {
  background: var(--c-hover);
  border-color: var(--c-primary-2);
}

.btn-ghost {
  background: transparent;
  color: var(--c-accent);
  padding: 6px 10px;
}
.btn-ghost:hover { background: var(--c-accent-soft); }

.btn-danger {
  background: var(--c-negative);
}
.btn-danger:hover { background: #B91C1C; }

.btn-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
}

/* ============================================================
   フォーム
   ============================================================ */
label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-muted);
  margin-bottom: 6px;
}
select, input[type="month"], input[type="date"], input[type="text"], input[type="file"], input[type="number"] {
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-md);
  background: #fff;
  color: var(--c-text);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select:focus, input:focus {
  outline: none;
  border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.15);
}

.form-row {
  display: grid;
  gap: var(--space-3);
}
@media (min-width: 600px) {
  .form-row.cols-2 { grid-template-columns: 1fr 1fr; }
  .form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
}

/* ファイルドロップ */
.drop-area {
  border: 2px dashed var(--c-border-strong);
  border-radius: var(--r-lg);
  padding: var(--space-6) var(--space-4);
  text-align: center;
  background: var(--c-bg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.drop-area:hover, .drop-area.dragover {
  border-color: var(--c-accent);
  background: var(--c-accent-soft);
}
.drop-area .icon {
  font-size: 32px;
  color: var(--c-accent);
  margin-bottom: var(--space-2);
}
.drop-area .hint {
  font-size: 13px;
  color: var(--c-text-muted);
  margin-top: var(--space-1);
}
.drop-area-file {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-3);
  font-size: 13px;
}
.drop-area-file .filename { color: var(--c-primary); font-weight: 600; }
.drop-area-file .removelink { color: var(--c-negative); cursor: pointer; }

/* ============================================================
   タブ・チップ
   ============================================================ */
.tabs {
  display: inline-flex;
  background: var(--c-hover);
  padding: 3px;
  border-radius: var(--r-md);
  gap: 2px;
}
.tabs button {
  background: transparent;
  color: var(--c-text-muted);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 7px;
}
.tabs button.active {
  background: var(--c-card);
  color: var(--c-primary);
  box-shadow: var(--shadow-sm);
}
.tabs button:hover { color: var(--c-primary); }

.chip {
  display: inline-flex;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--r-pill);
  background: var(--c-accent-soft);
  color: var(--c-accent);
  vertical-align: middle;
}
.chip-positive { background: #DCFCE7; color: #166534; }
.chip-negative { background: #FEE2E2; color: #991B1B; }
.chip-muted    { background: var(--c-hover); color: var(--c-text-muted); }

/* ============================================================
   推移表テーブル
   ============================================================ */
.scroll-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--c-card);
  border-radius: var(--r-lg);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
}
.transition-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.transition-table th,
.transition-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--c-border);
  text-align: right;
  white-space: nowrap;
}
.transition-table th:first-child,
.transition-table td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--c-card);
  z-index: 1;
  min-width: 160px;
  border-right: 1px solid var(--c-border);
  font-weight: 500;
}
.transition-table thead th {
  background: var(--c-bg);
  font-weight: 700;
  color: var(--c-text-muted);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  z-index: 2;
  padding-top: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--c-border-strong);
}
.transition-table thead th:first-child { z-index: 3; }
.transition-table tbody tr:hover { background: var(--c-hover); }
.transition-table tbody tr:hover td:first-child { background: var(--c-hover); }
.transition-table .total-row {
  background: #F0F4FB;
  font-weight: 700;
  color: var(--c-primary);
}
.transition-table .total-row td:first-child { background: #F0F4FB; }
.transition-table .group-row td {
  background: var(--c-bg);
  font-weight: 700;
  color: var(--c-primary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.transition-table .group-row td:first-child { background: var(--c-bg); }
.transition-table .sub-row td:first-child {
  padding-left: 32px;
  color: var(--c-text-muted);
  font-weight: 400;
}
.transition-table .delta {
  font-size: 10px;
  display: block;
  margin-top: 1px;
}
.transition-table .delta.plus  { color: var(--c-positive); }
.transition-table .delta.minus { color: var(--c-negative); }
.transition-table .future-cell { color: var(--c-text-faint); }
.transition-table .future-cell::after {
  content: "計画";
  display: none;
}

/* ドリルダウンの▶ */
.expander {
  display: inline-block;
  width: 14px;
  font-size: 10px;
  color: var(--c-text-muted);
  margin-right: 4px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s;
}
.expander.open { transform: rotate(90deg); }

/* ============================================================
   比較カード
   ============================================================ */
.compare-card {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  margin-bottom: var(--space-2);
  align-items: center;
  font-size: 13px;
}
.compare-card .label {
  font-size: 11px;
  color: var(--c-text-muted);
  display: block;
  margin-bottom: 1px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.compare-card .value {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--c-primary);
}
.compare-card .account-name {
  font-weight: 600;
  color: var(--c-primary);
}
.compare-card .sub-name {
  font-size: 11px;
  color: var(--c-text-muted);
  margin-top: 1px;
}
.compare-card .delta.plus  { color: var(--c-positive); }
.compare-card .delta.minus { color: var(--c-negative); }

.compare-section-header {
  font-size: 11px;
  font-weight: 700;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-4) 0 var(--space-2);
}

@media (max-width: 600px) {
  .compare-card {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
  }
  .compare-card .account-name-col { grid-column: 1 / -1; }
}

/* ============================================================
   サマリーカード (KPI)
   ============================================================ */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.kpi-card {
  background: var(--c-card);
  padding: var(--space-4);
  border-radius: var(--r-lg);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
  cursor: grab;
  touch-action: none;
  user-select: none;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}
/* 掴んだ瞬間：押し込み＋アクセント枠でフィードバック */
.kpi-card.kpi-card-grabbed {
  cursor: grabbing;
  transform: scale(0.96);
  border-color: var(--c-accent);
  box-shadow: 0 0 0 2px var(--c-accent-soft, rgba(59,130,246,0.3));
}
/* ドラッグ中：持ち上げて少し傾ける */
.kpi-card.kpi-card-dragging {
  cursor: grabbing;
  opacity: 0.95;
  border-color: var(--c-accent);
  box-shadow: 0 14px 30px rgba(0,0,0,0.25);
  transform: scale(1.06) rotate(-1.5deg);
  z-index: 5;
}
.kpi-card .label {
  font-size: 11px;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: var(--space-2);
}
.kpi-card .value {
  font-size: 22px;
  font-weight: 700;
  color: var(--c-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.kpi-card .delta {
  font-size: 12px;
  margin-top: 4px;
  font-weight: 600;
}
.kpi-card .delta.plus  { color: var(--c-positive); }
.kpi-card .delta.minus { color: var(--c-negative); }
/* カード未選択時のプレースホルダ */
.kpi-card-empty {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  border-style: dashed;
  border-color: var(--c-border-strong);
  background: transparent;
  box-shadow: none;
  text-align: center;
  color: var(--c-text-muted);
}
.kpi-card-empty:hover { background: var(--c-accent-soft); text-decoration: none; }
.kpi-card-empty .label { color: var(--c-accent); text-transform: none; letter-spacing: 0; }

/* ============================================================
   科目設定 (リスト)
   ============================================================ */
.account-list {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.account-list-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--c-border);
  align-items: center;
  font-size: 13px;
}
.account-list-item:last-child { border-bottom: 0; }
.account-list-item:hover { background: var(--c-hover); }
.account-list-item.is-hidden { opacity: 0.4; }
.account-list-item .name { font-weight: 600; color: var(--c-primary); }
.account-list-item .meta { font-size: 11px; color: var(--c-text-muted); }

.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--c-border-strong);
  border-radius: 22px;
  cursor: pointer;
  transition: background 0.15s;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.switch input:checked + .switch-slider { background: var(--c-accent); }
.switch input:checked + .switch-slider::before { transform: translateX(16px); }
/* 科目設定: カード/表示トグル並び */
.acc-toggles { display: flex; gap: 14px; align-items: center; }
.acc-toggle { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.acc-toggle-label { font-size: 10px; color: var(--c-text-muted); font-weight: 600; }

/* ============================================================
   トースト
   ============================================================ */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--c-primary);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast-error   { background: var(--c-negative); }
.toast-success { background: var(--c-positive); }

/* ============================================================
   ローディング
   ============================================================ */
.loading {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 37, 69, 0.25);
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(2px);
}
.loading::after {
  content: '';
  width: 36px;
  height: 36px;
  border: 3px solid var(--c-accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   ユーティリティ
   ============================================================ */
.muted { color: var(--c-text-muted); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-right { text-align: right; }
.numeric { font-variant-numeric: tabular-nums; }

/* ============================================================
   PC幅最適化
   ============================================================ */
@media (min-width: 768px) {
  main { padding: var(--space-5); }
  .card { padding: var(--space-6); }
  .app-header { padding: 18px 24px; }
  .app-header h1 { font-size: 22px; }
  .tabbar-item { font-size: 13px; }
  .transition-table th,
  .transition-table td { padding: 9px 16px; font-size: 13px; }
}
