/* THE4KIND 経費管理 — 管理画面スタイル */
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7684;
  --line: #e2e6ea;
  --brand: #2f5b93;
  --brand-dark: #244a7a;
  --warn: #c0392b;
  --warn-bg: #fdecea;
  --ok: #2e7d5b;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  font-size: 14px;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== トップバー ===== */
.topbar { background: var(--brand); color: #fff; box-shadow: var(--shadow); }
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 24px; min-height: 56px; flex-wrap: wrap;
}
.brand { color: #fff; font-weight: 700; font-size: 16px; }
.brand:hover { text-decoration: none; opacity: .9; }
.mainnav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.mainnav a { color: #dbe5f1; padding: 8px 12px; border-radius: 6px; font-size: 14px; }
.mainnav a:hover { background: rgba(255,255,255,.12); text-decoration: none; }
.mainnav a.active { background: rgba(255,255,255,.2); color: #fff; font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.uemail { color: #cdd9e8; }
.logout { color: #fff; }

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

/* ===== 見出し ===== */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
.section-h { margin-top: 32px; }
.hint { color: var(--muted); font-size: 13px; margin: -8px 0 16px; }
.sub { color: var(--muted); font-weight: 400; font-size: 12px; }

/* ===== ボタン ===== */
button, .btn-primary {
  font-family: inherit; font-size: 14px; cursor: pointer;
  border: 1px solid var(--brand); background: var(--brand); color: #fff;
  padding: 8px 16px; border-radius: 6px;
}
button:hover { background: var(--brand-dark); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { display: inline-block; }
.btn-primary:hover { text-decoration: none; color: #fff; }
button.ghost { background: #fff; color: var(--brand); }
button.ghost:hover { background: #eef2f7; }
button.btn-warn { background: var(--warn); border-color: var(--warn); }
button.btn-warn:hover { background: #a5301f; }
button.sm { padding: 4px 10px; font-size: 12px; }

/* ===== カード ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; box-shadow: var(--shadow); }
.card-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.card-value { font-size: 22px; font-weight: 700; }
.card.up .card-value { color: var(--warn); }
.card.down .card-value { color: var(--ok); }
.card.warn .card-value { color: var(--warn); }

/* ===== パネル / グリッド ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; box-shadow: var(--shadow); }
.chart-wrap { position: relative; height: 300px; }
.chart-wrap-lg { position: relative; height: 440px; }
.cta-panel { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 10px; }
.cta-panel .btn-primary { margin-top: 4px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }

/* ===== ミニテーブル ===== */
.mini-table { width: 100%; border-collapse: collapse; }
.mini-table td { padding: 7px 4px; border-bottom: 1px solid var(--line); }
.mini-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ===== 期間切替 ===== */
.period-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.period-switch button { background: #fff; color: var(--ink); border: none; border-right: 1px solid var(--line); border-radius: 0; padding: 7px 14px; }
.period-switch button:last-child { border-right: none; }
.period-switch button.active { background: var(--brand); color: #fff; }

/* ===== フィルタ ===== */
.filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.filters label, .drawer-form label, .manual-form label, .rule-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47,91,147,.3); border-color: var(--brand); }
.list-summary { margin-bottom: 10px; color: var(--muted); }
.list-summary strong { color: var(--ink); font-size: 16px; }

/* ===== データテーブル ===== */
.table-scroll { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.data-table th { text-align: left; background: #eef2f7; color: var(--muted); font-weight: 600; font-size: 12px; padding: 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 10px; border-bottom: 1px solid var(--line); }
.data-table tbody tr[data-row] { cursor: pointer; }
.data-table tbody tr:hover { background: #f7f9fb; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .desc { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table tr.st-excluded { color: var(--muted); background: #fafafa; }
.data-table tr.st-warn { background: #fffdf3; }
.muted { color: var(--muted); }
.row-actions { white-space: nowrap; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: #eef2f7; color: var(--muted); }
.badge.st-warn { background: #fdf3d6; color: #8a6d1a; }
.badge.st-excluded { background: #e9ecef; color: #868e96; }
.badge.st-ok { background: #e3f3ea; color: var(--ok); }
.badge.st-auto { background: #e7eefa; color: var(--brand); }

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 16px; }
.pager span { color: var(--muted); }

/* ===== ドロワー(編集) ===== */
/* hidden属性を確実に効かせる(.drawerのdisplay:flexが[hidden]を上書きするのを防ぐ) */
.drawer[hidden], .drawer-backdrop[hidden] { display: none !important; }
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: 380px; max-width: 92vw;
  background: #fff; box-shadow: -2px 0 12px rgba(0,0,0,.15); z-index: 50;
  display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; }
.drawer-close { background: none; border: none; color: var(--muted); font-size: 24px; line-height: 1; padding: 0 6px; }
.drawer-close:hover { background: none; color: var(--ink); }
.drawer-form { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.drawer-form input, .drawer-form select, .drawer-form textarea { width: 100%; }
.drawer-actions { display: flex; gap: 10px; margin-top: 8px; }

/* ===== フォーム(手動登録・ルール) ===== */
.manual-form, .rule-form { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; max-width: 480px; }
.rule-form { max-width: 640px; }
.manual-form input, .manual-form select, .manual-form textarea,
.rule-form input, .rule-form select, .rule-form textarea { width: 100%; }
.form-msg { min-height: 20px; font-size: 13px; margin: 0; }
.form-msg.ok { color: var(--ok); }
.form-msg.err { color: var(--warn); }

/* ===== ログイン ===== */
.login-body { background: var(--brand); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: #fff; border-radius: 12px; padding: 32px; width: 360px; max-width: 100%; box-shadow: 0 8px 30px rgba(0,0,0,.2); }
.login-title { font-size: 18px; text-align: center; margin: 0 0 24px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-form input { width: 100%; }
.login-form button { padding: 11px; font-size: 15px; }
.login-error { background: var(--warn-bg); color: var(--warn); padding: 10px 12px; border-radius: 6px; font-size: 13px; margin: 0 0 16px; }

/* ===== レスポンシブ ===== */
@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
  .topbar-inner { gap: 12px; }
  .mainnav { order: 3; width: 100%; }
  .chart-wrap { height: 260px; }
}
