:root {
  --navy: #0f1c2e;
  --navy-2: #16283f;
  --teal: #0d9488;
  --teal-light: #14b8a6;
  --emerald: #059669;
  --grad: linear-gradient(135deg, #0d9488, #2563eb);
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --red: #dc2626;
  --amber: #d97706;
  --green: #16a34a;
  --blue: #2563eb;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

#loading {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  color: var(--muted); background: var(--bg);
}

/* ============ レイアウト ============ */
#app { display: flex; min-height: 100vh; }
#sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--navy); color: #cbd5e1;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sb-logo { display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px; }
.logo-mark {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--grad); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; letter-spacing: .5px;
  flex-shrink: 0;
}
.logo-mark.sm { width: 34px; height: 34px; font-size: 13px; border-radius: 9px; }
.sb-logo-text { font-size: 11px; line-height: 1.35; letter-spacing: .5px; color: #e2e8f0; }
.sb-logo-text b { color: var(--teal-light); }
.sb-section-label {
  font-size: 10px; letter-spacing: 1.5px; color: #64748b;
  padding: 14px 16px 6px; text-transform: uppercase;
}
#brand-list { padding: 0 10px; }
.brand-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px; margin-bottom: 3px;
  border: none; background: transparent; color: #cbd5e1;
  border-radius: 8px; font-size: 13px; text-align: left;
}
.brand-item:hover { background: var(--navy-2); }
.brand-item.active { background: var(--grad); color: #fff; font-weight: 700; }
.brand-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.brand-count { margin-left: auto; font-size: 11px; opacity: .75; }
#nav-menu { padding: 0 10px; }
.nav-item {
  display: block; width: 100%; padding: 9px 10px; margin-bottom: 2px;
  border: none; background: transparent; color: #cbd5e1;
  border-radius: 8px; font-size: 13px; text-align: left;
}
.nav-item:hover { background: var(--navy-2); }
.nav-item.active { background: var(--navy-2); color: #fff; font-weight: 700; border-left: 3px solid var(--teal-light); }
.sb-user { margin-top: auto; padding: 14px 16px; border-top: 1px solid var(--navy-2); font-size: 12px; }
#sb-user-name { color: #fff; font-weight: 700; word-break: break-all; }
#sb-user-role { color: #94a3b8; font-size: 11px; margin: 3px 0 8px; }
.sb-logout {
  background: transparent; border: 1px solid #334155; color: #94a3b8;
  padding: 4px 10px; border-radius: 6px; font-size: 11px;
}

#main { flex: 1; min-width: 0; }
#topbar {
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 12px 24px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 5; gap: 12px;
}
#page-title { font-size: 17px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
#role-badge { font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 20px; white-space: nowrap; }
.badge-staff { background: #ecfdf5; color: var(--emerald); border: 1px solid #a7f3d0; }
.badge-client { background: #eff6ff; color: var(--blue); border: 1px solid #bfdbfe; }
#content { padding: 20px 24px 60px; }

/* ============ 共通パーツ ============ */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 26px; font-weight: 800; margin-top: 4px; }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }
.section-title { font-size: 14px; font-weight: 700; margin: 22px 0 10px; }
.section-title:first-child { margin-top: 0; }

.btn {
  border-radius: 8px; font-size: 12.5px; font-weight: 700; padding: 8px 14px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
}
.btn:hover { border-color: var(--teal); }
.btn-primary { background: var(--grad); color: #fff; border: none; }
.btn-sm { padding: 4px 10px; font-size: 11.5px; }
.btn-danger { color: var(--red); }

.pill {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 9px; border-radius: 20px; white-space: nowrap;
}
table.tbl { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 12px; overflow: hidden; border: 1px solid var(--border); }
.tbl th {
  text-align: left; font-size: 11px; color: var(--muted); font-weight: 600;
  padding: 10px 12px; background: #f8fafc; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl td { padding: 11px 12px; border-bottom: 1px solid #f1f5f9; font-size: 13px; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.clickable { cursor: pointer; }
.tbl tr.clickable:hover { background: #f8fafc; }

/* ============ カンバン ============ */
#kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 16px; align-items: flex-start; }
.kb-col { width: 232px; flex-shrink: 0; background: #eef2f7; border-radius: 12px; padding: 10px; }
.kb-col.drag-over { outline: 2px dashed var(--teal); }
.kb-head { display: flex; align-items: center; gap: 6px; padding: 2px 4px 10px; }
.kb-head .name { font-size: 12.5px; font-weight: 700; }
.kb-head .cnt { font-size: 11px; color: var(--muted); margin-left: auto; }
.kb-dot { width: 8px; height: 8px; border-radius: 50%; }
.kb-card {
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px; cursor: grab;
  box-shadow: 0 1px 2px rgba(15,28,46,.05);
}
.kb-card:hover { border-color: var(--teal); }
.kb-card .nm { font-weight: 700; font-size: 13px; }
.kb-card .meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.kb-card .next { font-size: 11px; margin-top: 6px; color: var(--amber); }
.kb-card .next.overdue { color: var(--red); font-weight: 700; }
.src-badge { font-size: 10px; padding: 1px 6px; border-radius: 4px; background: #f1f5f9; color: var(--muted); border: 1px solid var(--border); }
.auto-badge { font-size: 10px; padding: 1px 6px; border-radius: 4px; background: #ecfdf5; color: var(--emerald); }

/* ============ ドロワー・モーダル ============ */
#drawer-overlay, #modal-overlay { position: fixed; inset: 0; background: rgba(15,28,46,.45); z-index: 40; }
#drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 460px; max-width: 94vw;
  background: #fff; z-index: 50; overflow-y: auto;
  box-shadow: -12px 0 40px rgba(0,0,0,.18);
  padding: 22px;
}
#modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 480px; max-width: 94vw; max-height: 90vh; overflow-y: auto;
  background: #fff; z-index: 50; border-radius: 14px; padding: 24px;
  box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.dr-close {
  position: absolute; top: 14px; right: 14px;
  border: none; background: #f1f5f9; border-radius: 8px;
  width: 30px; height: 30px; font-size: 14px;
}
.dr-name { font-size: 19px; font-weight: 800; margin-top: 4px; }
.dr-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.dr-row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.dr-field { flex: 1; min-width: 120px; background: #f8fafc; border-radius: 8px; padding: 8px 10px; }
.dr-field .lb { font-size: 10.5px; color: var(--muted); }
.dr-field .vl { font-size: 13px; font-weight: 700; margin-top: 2px; }
.dr-section { font-size: 12.5px; font-weight: 700; margin: 20px 0 8px; color: var(--navy); }
.tl-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed #f1f5f9; }
.tl-date { font-size: 11px; color: var(--muted); white-space: nowrap; padding-top: 2px; width: 74px; flex-shrink: 0; }
.tl-body { font-size: 12.5px; line-height: 1.55; }
.tl-internal { font-size: 10px; color: var(--amber); font-weight: 700; }
.memo-box { background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 10px 12px; font-size: 12.5px; line-height: 1.6; }
.memo-label { font-size: 10.5px; color: var(--amber); font-weight: 700; margin-bottom: 4px; }

/* フォーム */
.fm-label { display: block; font-size: 11.5px; color: var(--muted); margin: 12px 0 4px; }
.fm-input, .fm-select, .fm-textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; background: #fff;
}
.fm-textarea { min-height: 72px; resize: vertical; }
.fm-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.fm-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; }
.fm-check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.fm-check input { width: auto; }
.modal-title { font-size: 16px; font-weight: 800; }

/* ============ 請求 ============ */
.bill-sum { display: flex; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.bill-sum .card { flex: 1; min-width: 160px; }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; }
.status-cycle { border: 1px solid var(--border); background: #fff; border-radius: 20px; padding: 2px 9px; font-size: 11px; font-weight: 700; }

/* ダッシュボードのブランドカード */
.bcard { cursor: pointer; transition: box-shadow .15s, border-color .15s; }
.bcard:hover { border-color: var(--teal); box-shadow: 0 4px 16px rgba(13,148,136,.12); }
.bcard-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.bcard-name { font-weight: 800; font-size: 15px; }
.bcard-cat { font-size: 11px; color: var(--muted); }
.bcard-stats { display: flex; gap: 14px; margin-top: 8px; }
.bcard-stat .n { font-size: 20px; font-weight: 800; }
.bcard-stat .l { font-size: 10.5px; color: var(--muted); }
.phase-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin-top: 12px; background: #f1f5f9; }

.alert-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed #f1f5f9; font-size: 13px; flex-wrap: wrap; }
.alert-row:last-child { border-bottom: none; }

.note-info {
  background: #eff6ff; border: 1px solid #bfdbfe; color: #1d4ed8;
  border-radius: 10px; padding: 10px 14px; font-size: 12.5px; margin-bottom: 16px; line-height: 1.7;
}
.empty { color: var(--muted); font-size: 13px; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; font-size: 13px; font-weight: 700;
  padding: 10px 20px; border-radius: 30px; z-index: 60;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
#toast.err { background: var(--red); }

@media (max-width: 760px) {
  #sidebar { width: 64px; }
  .sb-logo-text, .sb-section-label, .brand-item span:not(.brand-dot), .brand-count, .nav-item, .sb-user { display: none; }
  #content { padding: 14px 12px 60px; }
  .fm-2col { grid-template-columns: 1fr; }
}

/* FC売上シート */
.tbl.sheet .sub { font-size: 11px; color: var(--muted); font-weight: 400; }
.tbl.sheet .warn { font-size: 11px; color: var(--red); font-weight: 700; }
.tbl.sheet tr.sheet-detail td { background: #f8fafc; font-size: 12.5px; }
.tbl.sheet tr.sheet-total td { font-weight: 800; border-top: 2px solid #e2e8f0; }
body.busy, body.busy * { cursor: progress !important; }
