/* ===== リセット & 基本 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg:        #c8cdd6;
  --surface:   #f0f4f8;
  --border:    #9aa5b4;
  --primary:   #1e40af;
  --primary-d: #1a35a0;
  --text:      #0d1a2a;
  --muted:     #4a5568;
  --danger:    #b91c1c;
  --warning:   #c2410c;
  --success:   #15803d;
  --radius:    12px;
  --shadow:    0 1px 4px rgba(0,0,0,.14), 0 4px 16px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.28);
  --header-h:  56px;
  --cell-h:    160px;
  --grid-cols: 5;
  --grid-gap:  12px;
}
[data-theme="dark"] {
  --bg:        #0d1117;
  --surface:   #161b22;
  --border:    #2d3748;
  --primary:   #4d78f0;
  --primary-d: #3d62d8;
  --text:      #e2e8f0;
  --muted:     #8899aa;
  --danger:    #f87171;
  --warning:   #fb923c;
  --success:   #4ade80;
  --shadow:    0 1px 4px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
}
html, body { font-family:'Hiragino Sans','Hiragino Kaku Gothic ProN',Meiryo,sans-serif; background:var(--bg); color:var(--text); font-size:15px; transition: background .3s, color .3s; }

/* ===== 認証ページ ===== */
.auth-page { display:flex; align-items:center; justify-content:center; min-height:100vh; background:linear-gradient(135deg,#667eea 0%,#764ba2 100%); }
.auth-card { background:var(--surface); border-radius:16px; padding:40px; width:100%; max-width:400px; box-shadow:var(--shadow-lg); }
.auth-logo { text-align:center; margin-bottom:16px; }
.auth-card h1 { text-align:center; font-size:22px; margin-bottom:6px; }
.auth-subtitle { text-align:center; color:var(--muted); font-size:14px; margin-bottom:24px; }

/* ===== フォーム ===== */
.form-group { margin-bottom:16px; }
.form-group label { display:block; font-size:13px; font-weight:600; color:var(--muted); margin-bottom:6px; }
.form-group input,.form-group select,.form-group textarea {
  width:100%; padding:10px 14px; border:1.5px solid var(--border);
  border-radius:8px; font-size:15px; background:#fafafa; color:var(--text); transition:border-color .15s;
}
.form-group input:focus,.form-group select:focus,.form-group textarea:focus {
  outline:none; border-color:var(--primary); background:#fff;
}

/* ===== ボタン ===== */
.btn { display:inline-flex; align-items:center; gap:6px; padding:8px 16px; border-radius:8px; font-size:14px; font-weight:600; cursor:pointer; border:none; transition:all .15s; text-decoration:none; white-space:nowrap; }
.btn-primary { background:var(--primary); color:#fff; }
.btn-primary:hover { background:var(--primary-d); }
.btn-ghost { background:transparent; color:var(--text); border:1.5px solid var(--border); }
.btn-ghost:hover { background:var(--bg); }
.btn-full { width:100%; justify-content:center; padding:12px; font-size:16px; }
.btn-sm { padding:5px 12px; font-size:13px; }
.btn-danger { background:var(--danger); color:#fff; }

/* ===== アラート ===== */
.alert { padding:10px 14px; border-radius:8px; font-size:14px; margin-bottom:16px; }
.alert-error   { background:#fff5f5; color:var(--danger);  border:1px solid #ffc9c9; }
.alert-success { background:#ebfbee; color:var(--success); border:1px solid #b2f2bb; }
.global-alert  { margin:8px 16px 0; }

/* ===== ヘッダー ===== */
.top-bar { position:fixed; top:0; left:0; right:0; height:var(--header-h); background:var(--surface); border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; padding:0 20px; z-index:200; box-shadow:0 1px 4px rgba(0,0,0,.06); }
.top-bar-left  { display:flex; align-items:center; gap:16px; }
.top-bar-right { display:flex; align-items:center; gap:8px; }
.app-name {
  font-size:17px; font-weight:700; color:var(--primary);
  /* ヘッダーは高さ固定なので、折り返すと下にはみ出して他の要素と重なる */
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
  max-width:40vw;
}
.top-bar-left  { min-width:0; }   /* flexアイテムを縮められるようにする */

/* ===== ヘッダーの「⋮」ドロップダウンメニュー =====
   開閉は <details> に任せている（JSが動かなくても開くようにするため）。
   .menu-wrap は <details>、その中の <summary> が「⋮」ボタン。            */
.menu-wrap { position: relative; }

.menu-wrap > summary {
  /* summary の既定の三角マーカーを消して、普通のボタンに見せる */
  display: inline-flex; align-items: center; justify-content: center;
  list-style: none;
  cursor: pointer;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.menu-wrap > summary::-webkit-details-marker { display: none; }
.menu-wrap > summary::marker { content: ''; }

#btnTopMenu { font-size: 18px; line-height: 1; padding: 5px 12px; }

.dropdown-menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 300;
  /* 既定は非表示。<details open> のときだけ表示する */
  display: none;
}
.menu-wrap[open] > .dropdown-menu,
.dropdown-menu.open {
  display: block;
  animation: ddIn .14s ease;
}

/* メニューを開いている間の背景。外側タップで閉じるために使う */
.menu-backdrop { position: fixed; inset: 0; z-index: 190; background: transparent; }
.menu-backdrop[hidden] { display: none; }

/* ── スマホ：右上の小さな吹き出しだと押しにくい／隠れることがあるので、
      画面下部のシートとして出す（指が届きやすく、重なりの影響も受けない）── */
@media (max-width: 720px) {
  .menu-wrap[open] > .dropdown-menu {
    position: fixed;
    top: auto; right: 10px; left: 10px; bottom: 10px;
    min-width: 0;
    border-radius: 18px;
    padding: 8px;
    box-shadow: 0 10px 36px rgba(0,0,0,.34);
    z-index: 400;
  }
  .menu-wrap[open] > .dropdown-menu .dropdown-item {
    padding: 15px 14px;     /* 指で押しやすい高さにする */
    font-size: 15px;
  }
  .menu-backdrop { background: rgba(0,0,0,.35); }
}
@keyframes ddIn { from { opacity:0; transform: translateY(-4px); } to { opacity:1; transform:none; } }
.dropdown-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none; background: none;
  border-radius: 9px;
  font-size: 14px; font-weight: 600;
  color: var(--text); text-decoration: none;
  text-align: left; cursor: pointer;
  white-space: nowrap;
}
.dropdown-item:hover { background: var(--bg); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item .dd-ico { width: 20px; text-align: center; flex-shrink: 0; }
.dropdown-sep { height: 1px; background: var(--border); margin: 6px 4px; }
.top-bar-right { flex-shrink:0; }

/* ===================================================
   ダッシュボードグリッド — フルスクリーン
   grid-template-columns/rows は JS の rebuildLayout() が動的に設定
   使用されている行・列のみ 1fr で表示、空行列はゼロ
   =================================================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr); /* JS で上書き */
  grid-template-rows: repeat(6, 1fr);   /* JS で上書き */
  grid-auto-rows: 0;
  gap: var(--grid-gap);
  padding: calc(var(--header-h) + var(--grid-gap)) var(--grid-gap) var(--grid-gap);
  height: 100vh;
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
}

/* 編集モード時のグリッド線オーバーレイ */
body.edit-mode .dashboard-grid::before {
  content: '';
  position: fixed;
  top: calc(var(--header-h) + 44px);
  left: 0; right: 0; bottom: 0;
  background-image:
    linear-gradient(rgba(59,91,219,.10) 1px, transparent 1px),
    linear-gradient(90deg, rgba(59,91,219,.10) 1px, transparent 1px);
  background-size:
    calc((100vw - var(--grid-gap) * 4) / 5 + var(--grid-gap)) calc(var(--cell-h) + var(--grid-gap));
  background-position: calc(var(--grid-gap) / 2) calc(var(--grid-gap) / 2);
  pointer-events: none;
  z-index: 1;
}

/* ===== ウィジェット ===== */
.widget {
  /* グリッドセルを完全に埋める */
  min-height: 0;          /* flexの高さ収縮を許可 */
  height: 100%;           /* 行高(rowSpan × cell-h + gap)を受け取る */
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1.5px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;       /* 内容が溢れてもグリッドを崩さない */
  transition: box-shadow .2s, transform .15s;
  position: relative;
  z-index: 2;
}
.widget.widget-hidden { display: none !important; }
.widget.dragging {
  opacity: .75;
  transform: scale(1.04);
  box-shadow: var(--shadow-lg);
  z-index: 100 !important;
  cursor: grabbing;
}

/* 編集モード */
body.edit-mode .widget { border-color: rgba(59,91,219,.35); }
body.edit-mode .widget:hover { box-shadow: 0 4px 20px rgba(59,91,219,.2); border-color: var(--primary); }

/* ドロップ先ゴースト */
.drop-ghost {
  border: 2.5px dashed var(--primary);
  border-radius: var(--radius);
  background: rgba(59,91,219,.06);
  pointer-events: none;
  z-index: 1;
  position: relative;
}

/* ===== ウィジェットヘッダー ===== */
.widget-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px 6px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.widget-title { font-size: 13px; font-weight: 700; color: var(--text); }

/* 編集コントロール（編集モード時のみ表示） */
.widget-controls { display: none; align-items: center; gap: 3px; }
body.edit-mode .widget-controls { display: flex; }

.wc-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; padding: 0;
  border: 1px solid var(--border); border-radius: 5px;
  background: #fff; color: var(--muted); font-size: 12px;
  cursor: pointer; transition: all .1s;
}
.wc-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.wc-hide:hover { background: var(--danger); border-color: var(--danger); }

.drag-handle {
  font-size: 18px; color: #b0bec5; cursor: grab; padding: 0 3px;
  margin-left: 4px; user-select: none;
}
.drag-handle:active { cursor: grabbing; }

/* ===== ウィジェットボディ =====
   flex:1 + min-height:0 で親の高さ制約を継承し内部スクロール */
.widget-body {
  flex: 1;
  min-height: 0;       /* 重要: flexアイテムの縮小を許可 */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 12px;
  scroll-behavior: smooth;
}
.widget-footer {
  padding: 6px 12px; border-top: 1px solid var(--border); flex-shrink: 0;
  display: none;
}
body.edit-mode .widget-footer { display: block; }

/* ===== 編集パネル ===== */
.edit-panel {
  position: sticky; top: var(--header-h); z-index: 150;
  background: #1e293b; border-bottom: 2px solid var(--primary);
}
.edit-panel-inner {
  display: flex; align-items: center; padding: 7px 14px; gap: 8px; flex-wrap: wrap;
}

/* ===== 非表示ウィジェット復元バー ===== */
.hidden-widget-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 180;
  background: #1e293b; border-top: 2px solid #f59e0b;
  padding: 6px 14px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.hidden-widget-bar .bar-label { color: #94a3b8; font-size: 12px; }
.ep-hidden-label { color: #f59e0b; font-size: 12px; font-weight: 600; white-space: nowrap; }
.restore-btn {
  background: #f59e0b; color: #000; border: none; border-radius: 6px;
  padding: 3px 10px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.restore-btn:hover { background: #fbbf24; }

/* ===== 共通コンテンツ ===== */
.loading   { color: var(--muted); font-size: 13px; text-align: center; padding: 20px; }
.error-msg { color: var(--danger); font-size: 13px; padding: 4px; }
.no-data   { color: var(--muted); font-size: 13px; text-align: center; padding: 16px; line-height: 1.6; }

/* ===== 設定バナー ===== */
.sheet-config-banner { background: #fffbeb; border-bottom: 1px solid #fcd34d; padding: 10px 20px; margin-top: var(--header-h); font-size: 13px; }

/* ===== モーダル ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 300; }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); z-index: 301; width: 100%; max-width: 460px; padding: 0 16px; }
.modal-content { background: var(--surface); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow-lg); }
.modal-content h3 { margin-bottom: 20px; font-size: 17px; }

/* ===== デジタル時計 ===== */
.clock-widget {
  display: flex; flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px;
  height: 100%;
}
.clock-time  { font-size: var(--clock-size, 52px); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1; color: var(--text); }
.clock-secs  { font-size: calc(var(--clock-size, 52px) * .45); font-weight: 400; color: var(--muted); }
.clock-date  { font-size: 14px; color: var(--muted); margin-top: 4px; }
.clock-size-btns { display: none; gap: 6px; margin-top: 8px; }
body.edit-mode .clock-size-btns { display: flex; }
.clock-size-btn  { background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer; color: var(--muted); }
.clock-size-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== 天気ウィジェット ===== */
.wx-now { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.wx-now-icon { font-size: 48px; line-height: 1; flex-shrink: 0; }
.wx-now-info { flex: 1; min-width: 0; }
.wx-now-temp { font-size: 32px; font-weight: 700; line-height: 1; color: var(--text); }
.wx-now-desc { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wx-now-sub  { font-size: 12px; color: var(--muted); margin-top: 3px; }
.wx-now-office { font-size: 10px; color: var(--muted); margin-top: 4px; opacity: 0.7; }

.wx-hourly-wrap { overflow: visible; margin-bottom: 8px; }
.wx-hourly { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 2px 6px; }
.wx-h-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 46px; background: var(--bg); border-radius: 8px;
  padding: 5px 4px; font-size: 11px; flex: 1 0 46px; max-width: 68px;
}
.wx-h-item.wx-h-now { background: rgba(30,64,175,.15); border: 1px solid var(--primary); }
.wx-h-label { font-size: 10px; color: var(--muted); font-weight: 600; }
.wx-h-icon  { font-size: 18px; line-height: 1; }
.wx-h-moon  { font-size: 13px; line-height: 1; min-height: 14px; }
.wx-h-temp  { font-size: 12px; font-weight: 700; color: var(--text); }
.wx-h-pop   { font-size: 10px; min-height: 13px; }

.wx-weekly  { display: flex; gap: 4px; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
.wx-w-item  { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 44px; flex: 1; background: var(--bg); border-radius: 8px; padding: 6px 3px; font-size: 11px; }
.wx-w-date  { font-size: 10px; color: var(--muted); font-weight: 600; }
.wx-w-day   { font-size: 11px; font-weight: 700; color: var(--text); }
.wx-w-icon  { font-size: 18px; line-height: 1; }
.wx-w-pop   { font-size: 10px; }
.wx-w-temp  { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.wx-t-hi    { font-size: 12px; font-weight: 700; color: #c2410c; }
.wx-t-lo    { font-size: 11px; color: #1d4ed8; }
.wx-sat     { color: #1d4ed8; }
.wx-sun     { color: #b91c1c; }

/* ===== カレンダーウィジェット ===== */
.cal-allday-bar { background: var(--primary); color: #fff; border-radius: 6px; padding: 4px 8px; font-size: 12px; margin-bottom: 6px; }
.cal-grid { display: flex; flex-direction: column; }
.cal-hour-row { display: flex; align-items: flex-start; min-height: 22px; gap: 4px; padding: 1px 0; }
.cal-hour-row.hour-even { background: rgba(0,0,0,.02); }
.cal-hour-label { width: 32px; font-size: 10px; color: var(--muted); flex-shrink: 0; padding-top: 3px; }
.cal-event-block { font-size: 11px; border-radius: 4px; padding: 2px 6px; flex: 1; }
.color-1 { background: rgba(30,64,175,.15); border-left: 3px solid #1e40af; }
.color-2 { background: rgba(21,128,61,.15); border-left: 3px solid #15803d; }
.color-3 { background: rgba(194,65,12,.15); border-left: 3px solid #c2410c; }
.color-4 { background: rgba(126,34,206,.15); border-left: 3px solid #7e22ce; }
.cal-no-event { color: var(--muted); text-align: center; padding: 24px; font-size: 13px; }

/* ===== 電車遅延ウィジェット ===== */
.train-list { display: flex; flex-direction: column; gap: 6px; }
.train-item { background: var(--bg); border-radius: 8px; padding: 8px 10px; border-left: 4px solid var(--success); }
.train-item.delayed   { border-left-color: var(--warning); }
.train-item.suspended { border-left-color: var(--danger); }
.train-name   { font-size: 13px; font-weight: 700; color: var(--text); }
.train-status { font-size: 12px; color: var(--muted); }
.train-detail { font-size: 11px; color: var(--muted); margin-top: 3px; }
.train-updated { font-size: 10px; color: var(--muted); text-align: right; margin-top: 4px; }

/* ===== ニュースウィジェット ===== */
.news-list  { display: flex; flex-direction: column; gap: 0; }
.news-item  { padding: 6px 0; border-bottom: 1px solid var(--border); }
.news-item:last-child { border-bottom: none; }
.news-item a { font-size: 13px; color: var(--text); text-decoration: none; line-height: 1.4; display: block; }
.news-item a:hover { color: var(--primary); text-decoration: underline; }
.news-meta  { font-size: 10px; color: var(--muted); margin-top: 2px; }

/* ===== 献立ウィジェット ===== */
.menu-today         { display: flex; flex-direction: column; gap: 8px; }
.menu-date-label    { font-size: 13px; font-weight: 700; color: var(--primary); }
.menu-card          { display: flex; flex-direction: column; gap: 4px; background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.menu-item          { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.menu-item-icon     { font-size: 18px; flex-shrink: 0; width: 26px; text-align: center; }
.menu-item-body     { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.menu-item-cat      { font-size: 10px; color: var(--muted); line-height: 1; }
.menu-item-name     { font-size: 15px; font-weight: 600; color: var(--text); line-height: 1.3; }
.menu-calories      { display: flex; align-items: center; justify-content: space-between; background: var(--bg); border-radius: 8px; padding: 6px 10px; }
.menu-cal-label     { font-size: 12px; color: var(--muted); }
.menu-cal-val       { font-size: 18px; font-weight: 700; }
.menu-upcoming-title{ font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 4px; }
.menu-upcoming-list { display: flex; flex-direction: column; gap: 3px; }
.menu-upcoming-row  { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 0; border-bottom: 1px solid var(--border); }
.menu-upcoming-date { font-weight: 700; color: var(--primary); white-space: nowrap; min-width: 56px; }
.menu-upcoming-dishes{ flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-upcoming-cal  { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ===== 食費ウィジェット ===== */
.budget-gauge { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.budget-stats { display: flex; flex-direction: column; gap: 6px; }
.budget-stat-val { font-size: 14px; font-weight: 700; color: var(--text); }
.budget-stat-val.budget-over { color: var(--danger); }
.budget-set-btn { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--muted); margin-top: 4px; }
.budget-set-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.budget-location-list { display: flex; flex-direction: column; gap: 2px; }
.budget-loc-row { display: flex; align-items: center; gap: 4px; font-size: 11px; }
.budget-loc-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.budget-loc-bar-wrap { flex: 1; background: var(--border); border-radius: 3px; height: 6px; }
.budget-loc-bar { height: 100%; border-radius: 3px; min-width: 2px; }
.budget-loc-amount { text-align: right; color: var(--muted); white-space: nowrap; }

/* ===== 配達追跡ウィジェット ===== */
.delivery-list  { display: flex; flex-direction: column; gap: 8px; }
.delivery-item  { background: var(--bg); border-radius: 8px; padding: 8px 10px; }
.delivery-title { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 12px; font-weight: 600; color: var(--text); flex-wrap: wrap; }
.delivery-carrier-badge { background: var(--primary); color: #fff; border-radius: 4px; padding: 1px 6px; font-size: 10px; font-weight: 700; }
.track-link { font-size: 11px; color: var(--primary); text-decoration: none; margin-left: auto; }
.track-link:hover { text-decoration: underline; }
.delivery-actions { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.delivery-actions select { font-size: 12px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); -webkit-appearance: auto; appearance: auto; }
.delivery-progress { margin-top: 4px; }
.delivery-bar-track { height: 4px; background: var(--border); border-radius: 2px; margin-bottom: 4px; }
.delivery-bar-fill  { height: 100%; border-radius: 2px; transition: width .4s; }
.delivery-steps     { display: flex; justify-content: space-between; }
.dstep       { display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 9px; color: var(--muted); }
.dstep-active { color: var(--primary); }
.dstep-label  { font-size: 9px; }
.delivery-add { display: flex; gap: 6px; margin-top: 8px; }
.delivery-add input { flex: 1; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: var(--surface); color: var(--text); }
.delivery-add input:focus { outline: none; border-color: var(--primary); }

/* ===== 配達追跡 — 入力行・予定日 ===== */
.delivery-input-row { display: flex; gap: 6px; margin-bottom: 8px; align-items: center; flex-wrap: wrap; }
.delivery-track-input { flex: 1; min-width: 120px; padding: 6px 10px; border: 1.5px solid var(--border); border-radius: 6px; font-size: 13px; background: var(--surface); color: var(--text); }
.delivery-track-input:focus { outline: none; border-color: var(--primary); }
.delivery-date-inp { width: 130px; padding: 5px 8px; border: 1.5px solid var(--border); border-radius: 6px; font-size: 12px; background: var(--surface); color: var(--text); }
.delivery-date-inp:focus { outline: none; border-color: var(--primary); }
.delivery-date-input { width: 130px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 11px; background: var(--surface); color: var(--text); }
.delivery-date-input:focus { outline: none; border-color: var(--primary); }
.delivery-expected-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.delivery-meta-label { font-size: 10px; color: var(--muted); white-space: nowrap; }
.delivery-expected-val { font-size: 11px; font-weight: 700; color: var(--primary); }
.delivery-num { font-size: 11px; word-break: break-all; }
.delivery-track-detail { font-size: 10px; color: var(--muted); margin-top: 3px; text-align: center; }
.delivery-fetch-status { font-size: 10px; color: var(--muted); margin-top: 3px; text-align: center; animation: pulse 1.2s ease-in-out infinite; }
.delivery-fetch-fail   { color: var(--warning) !important; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
[data-theme="dark"] .delivery-date-inp,
[data-theme="dark"] .delivery-date-input { background: rgba(255,255,255,.08); }
[data-theme="dark"] .delivery-track-input { background: rgba(255,255,255,.08); }

/* ===== 地震ウィジェット ===== */
.quake-list { display: flex; flex-direction: column; gap: 6px; }
.quake-item { display: flex; align-items: center; gap: 10px; background: var(--bg); border-radius: 8px; padding: 8px 10px; border-left: 4px solid #94a3b8; }
.quake-intensity { font-size: 18px; font-weight: 900; min-width: 28px; text-align: center; }
.quake-info { flex: 1; min-width: 0; }
.quake-location { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quake-meta     { font-size: 11px; color: var(--muted); }

/* ===== 献立 — フォントサイズ拡大 ===== */
.menu-row     { font-size: 15px; }
.menu-row-val { font-size: 15px; font-weight: 600; }

/* ===== 天気 — 時間別（8コマ、通常1段・狭い時2×4） ===== */
.wx-hourly {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  padding: 4px 2px 6px;
}
.wx-h-item { min-width: 0; max-width: unset; flex: unset; }

/* ===== 地震ウィジェット — リンク対応 ===== */
.quake-item {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: opacity .15s, background .15s;
}
.quake-item:hover { opacity: .82; background: rgba(0,0,0,.04); }
.quake-intensity {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 6px;
  font-size: 14px; font-weight: 900;
  color: #fff; flex-shrink: 0;
}

/* ===== 配達追跡 — アコーディオン & ドラッグ ===== */
.delivery-drag-handle {
  font-size: 16px; color: var(--muted); cursor: grab;
  padding: 0 4px; user-select: none; margin-right: 2px;
}
.delivery-drag-handle:active { cursor: grabbing; }
.delivery-header {
  display: flex; align-items: center; gap: 6px;
  cursor: pointer; user-select: none;
  padding: 2px 0;
}
.delivery-chevron {
  font-size: 12px; color: var(--muted);
  transition: transform .2s; margin-left: auto; flex-shrink: 0;
}
.delivery-detail-panel {
  max-height: 0; overflow: hidden;
  transition: max-height .25s ease, padding .2s;
  padding: 0 2px;
}
.delivery-detail-panel.open {
  max-height: 300px;
  padding: 6px 2px 2px;
}
.delivery-item.dragging-item {
  opacity: .5; border: 2px dashed var(--primary);
}

/* ===== 食費ウィジェット — 新レイアウト ===== */
.budget-main-layout {
  display: flex; gap: 12px; align-items: flex-start;
}
.budget-left  { flex-shrink: 0; }
.budget-right { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.budget-loc-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; flex-shrink: 0;
  vertical-align: middle;
}
.budget-loc-pct {
  color: var(--muted); font-size: 11px; white-space: nowrap;
}
.budget-loc-row { align-items: center; }

/* ===== ゴミ収集ウィジェット ===== */
.trash-area   { font-size: 10px; color: var(--muted); margin-bottom: 6px; }
.trash-list   { display: flex; flex-direction: column; gap: 6px; }
.trash-item   { display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 8px; padding: 7px 10px; }
.trash-icon   { font-size: 20px; flex-shrink: 0; line-height: 1; }
.trash-info   { flex: 1; min-width: 0; }
.trash-type   { font-size: 13px; font-weight: 600; color: var(--text); }
.trash-date   { font-size: 11px; color: var(--muted); margin-top: 1px; }
.trash-badge  {
  font-size: 10px; font-weight: 700; border-radius: 4px;
  padding: 2px 7px; flex-shrink: 0;
  background: var(--border); color: var(--muted);
}
.trash-badge.today    { background: var(--danger);  color: #fff; }
.trash-badge.tomorrow { background: var(--warning); color: #fff; }

/* ===== NAS監視ウィジェット ===== */
.nas-info         { font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.nas-sys-row      { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2px; }
.nas-model        { font-size: 12px; font-weight: 700; color: var(--text); }
.nas-uptime       { font-size: 11px; color: var(--muted); }
.nas-gauge-row    { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.nas-gauge        { display: flex; align-items: center; gap: 6px; }
.nas-gauge-label  { font-size: 10px; font-weight: 700; color: var(--muted); width: 28px; flex-shrink: 0; }
.nas-gauge-val    { font-size: 11px; font-weight: 700; width: 34px; text-align: right; flex-shrink: 0; }
.nas-gauge-sub    { font-size: 9px; color: var(--muted); white-space: nowrap; }
.nas-section-title{ font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 8px 0 4px; }
.nas-volume       { background: var(--bg); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; }
.nas-vol-header   { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.nas-vol-id       { font-size: 12px; font-weight: 700; color: var(--text); }
.nas-vol-status   { font-size: 10px; font-weight: 600; color: var(--success); }
.nas-vol-status.warn { color: var(--danger); }
.nas-bar-wrap     { height: 6px; background: var(--border); border-radius: 3px; margin-bottom: 4px; }
.nas-bar          { height: 100%; border-radius: 3px; background: var(--primary); transition: width .4s; }
.nas-bar.nas-bar-warn { background: var(--warning); }
.nas-bar.nas-bar-danger { background: var(--danger); }
.nas-vol-stats    { display: flex; gap: 8px; font-size: 10px; color: var(--muted); }
.nas-disk-grid    { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 6px; }
.nas-disk         { background: var(--bg); border-radius: 8px; padding: 7px 8px; border: 1.5px solid var(--border); }
.nas-disk-warn    { border-color: var(--danger); }
.nas-disk-slot    { font-size: 10px; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.nas-disk-name    { font-size: 11px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nas-disk-model   { font-size: 9px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.nas-disk-size    { font-size: 10px; color: var(--muted); margin-top: 2px; }
.nas-disk-status  { font-size: 10px; font-weight: 700; margin-top: 2px; }
.nas-disk-status.ok   { color: var(--success); }
.nas-disk-status.warn { color: var(--danger); }
.nas-disk-temp    { font-size: 10px; color: var(--muted); margin-top: 1px; }

/* ===== 雨雲レーダー ===== */
.radar-widget-body { padding: 0 !important; position: relative; overflow: hidden; }

/* ── 雨雲レーダー ロックオーバーレイ（PCではJSで非表示） ── */
.radar-lock-overlay {
  position: absolute; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  pointer-events: auto;
}
.radar-lock-overlay.unlocked { pointer-events: none; }
.radar-lock-btn {
  background: rgba(0,0,0,.60); color: #fff;
  border: none; border-radius: 10px;
  padding: 10px 20px; font-size: 14px;
  cursor: pointer; white-space: nowrap;
}
.radar-lock-overlay.unlocked .radar-lock-btn { display: none; }
.radar-iframe {
  width: 100%; height: 100%; border: none; display: block;
}

/* ===== ダークモード追加オーバーライド ===== */
[data-theme="dark"] .wc-btn { background: var(--surface); color: var(--muted); }
[data-theme="dark"] .wx-h-item { background: rgba(255,255,255,.06); }
[data-theme="dark"] .wx-w-item { background: rgba(255,255,255,.06); }
[data-theme="dark"] .wx-h-item.wx-h-now { background: rgba(77,120,240,.2); }
[data-theme="dark"] .train-item { background: rgba(255,255,255,.06); }
[data-theme="dark"] .delivery-item { background: rgba(255,255,255,.06); }
[data-theme="dark"] .quake-item { background: rgba(255,255,255,.06); }
[data-theme="dark"] .cal-hour-row.hour-even { background: rgba(255,255,255,.03); }
[data-theme="dark"] .delivery-add input { background: rgba(255,255,255,.08); }
[data-theme="dark"] .delivery-actions select,
[data-theme="dark"] .delivery-actions select option {
  background: #2d3748 !important;
  color: #e2e8f0 !important;
  border-color: #4a5568 !important;
}
[data-theme="dark"] .budget-set-btn { background: rgba(255,255,255,.08); }
[data-theme="dark"] .trash-item { background: rgba(255,255,255,.06); }
[data-theme="dark"] .nas-volume { background: rgba(255,255,255,.06); }
[data-theme="dark"] .nas-disk   { background: rgba(255,255,255,.06); }
[data-theme="dark"] .quake-item:hover { background: rgba(255,255,255,.04); }
[data-theme="dark"] .sheet-config-banner { background: rgba(251,191,36,.1); border-color: rgba(251,191,36,.3); color: var(--text); }
[data-theme="dark"] .wx-t-hi { color: #fb923c; }
[data-theme="dark"] .wx-t-lo { color: #60a5fa; }

/* ===== スマホ対応レスポンシブ (≤768px) ===== */
@media (max-width: 768px) {
  :root { --header-h: 48px; --grid-gap: 8px; }

  /* ヘッダー — ボタン縮小 */
  .top-bar { padding: 0 10px; }
  /* スマホではアプリ名を隠す。
     幅が足りずに折り返して潰れるうえ、無くても困らないため。 */
  .app-name { display: none; }
  .top-bar-left { gap: 8px; }
  .top-bar-right { gap: 4px; }
  .top-bar-right .btn { padding: 5px 8px; font-size: 12px; }
  /* ボタンが多いので、はみ出す場合は横スクロールさせる */
  .top-bar-right { overflow-x: auto; scrollbar-width: none; }
  .top-bar-right::-webkit-scrollbar { display: none; }

  /* グリッドを縦1列スタックに切り替え */
  .dashboard-grid {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    overflow: visible !important;
    padding: calc(var(--header-h) + 8px) 8px 80px !important;
  }

  /* 各ウィジェットのグリッド位置を無効化 */
  .widget {
    grid-column: unset !important;
    grid-row: unset !important;
    height: auto !important;
    min-height: 160px;
    margin-bottom: 8px;
  }

  /* 時計は高さを自動に */
  .clock-widget { padding: 16px 10px; }
  .clock-time { font-size: min(var(--clock-size, 52px), 13vw); }

  /* 天気 — 時間別（狭い画面では2×4） */
  .wx-hourly { grid-template-columns: repeat(4, 1fr); }
  .wx-h-item { min-width: 0; }

  /* 週間予報 — 横スクロール */
  .wx-weekly { overflow-x: auto; flex-wrap: nowrap; }

  /* 電車遅延 — 路線名とステータスを縦に */
  .train-item > div:first-child { flex-wrap: wrap; gap: 4px; }

  /* 配達 — 入力行を縦並びに */
  .delivery-input-row { flex-direction: column; align-items: stretch; }
  .delivery-date-inp  { width: 100%; }

  /* 編集パネルをコンパクトに */
  .edit-panel-inner { padding: 5px 10px; gap: 4px; }
  .edit-panel-inner span:nth-child(2) { display: none; } /* ヒント非表示 */

  /* 非表示バーを上に表示 */
  .hidden-widget-bar { bottom: 56px; }
}

/* ===== 接続履歴ウィジェット ===== */
.connlog-list { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; max-height: 100%; }
.connlog-row  { background: var(--bg); border-radius: 6px; padding: 5px 8px; font-size: 11px; border-left: 3px solid var(--border); }
.connlog-row-fail { border-left-color: var(--danger); background: rgba(201,42,42,.06); }
.connlog-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; }
.connlog-ts   { color: var(--muted); white-space: nowrap; }
.connlog-detail { display: flex; flex-wrap: wrap; gap: 6px; color: var(--muted); }
.connlog-ip   { color: var(--text); font-weight: 600; }
.connlog-user { color: var(--primary); }
.connlog-ep   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.connlog-details { color: var(--danger); font-style: italic; }
.connlog-badge      { display: inline-flex; align-items: center; padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.connlog-badge.ok   { background: #d3f9d8; color: #2f9e44; }
.connlog-badge.fail { background: #ffe3e3; color: #c92a2a; }
.connlog-badge.page { background: var(--border); color: var(--muted); }
[data-theme="dark"] .connlog-row { background: rgba(255,255,255,.04); }
[data-theme="dark"] .connlog-row-fail { background: rgba(201,42,42,.12); }
[data-theme="dark"] .connlog-badge.ok   { background: rgba(47,158,68,.25); color: #69db7c; }
[data-theme="dark"] .connlog-badge.fail { background: rgba(201,42,42,.25); color: #ff8787; }

/* ===== さらに小さい画面 (≤480px) ===== */
@media (max-width: 480px) {
  .wx-now-icon { font-size: 36px; }
  .wx-now-temp { font-size: 26px; }
  .news-item a { font-size: 12px; }
  .budget-gauge { flex-direction: column; align-items: flex-start; }
  .delivery-actions { flex-wrap: wrap; }
  .delivery-actions select { font-size: 11px; }
}
