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

:root {
  --rakuten-red:    #BF0000;
  --rakuten-red-dk: #8C0000;
  --rakuten-red-lt: #f9e6e6;
  --gray-50:  #f8f8f8;
  --gray-100: #f0f0f0;
  --gray-200: #e0e0e0;
  --gray-400: #aaaaaa;
  --gray-600: #666666;
  --gray-800: #333333;
  --white:    #ffffff;
  --text:     #1a1a1a;
  --shadow-sm: 0 1px 4px rgba(0,0,0,.08);
  --shadow-md: 0 2px 12px rgba(0,0,0,.12);
}

body {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  background: var(--gray-50);
  color: var(--text);
  min-height: 100vh;
}

/* ── Survey/project navbar (survey.html + project.html) ──── */
.navbar {
  background: var(--rakuten-red);
  color: var(--white);
  padding: 0 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 60px;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.navbar-logo { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.navbar-logo svg { flex-shrink: 0; }
.nav-title { font-size: 1rem; font-weight: 700; color: var(--white); }
.nav-subtitle { font-size: .75rem; color: rgba(255,255,255,.75); font-weight: 400; }

/* ── Top bar ──────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--rakuten-red);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 200;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

.topbar-logo {
  display: flex;
  align-items: center;
  width: 200px;
  flex-shrink: 0;
}

.topbar-title {
  flex: 1;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: .01em;
}

.topbar-actions {
  width: 200px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.topbar-user {
  font-size: .82rem;
  color: rgba(255,255,255,.75);
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 56px;
  left: 0;
  bottom: 0;
  width: 200px;
  background: var(--gray-800);
  display: flex;
  flex-direction: column;
  padding: 24px 0 16px;
  z-index: 100;
  box-shadow: 2px 0 8px rgba(0,0,0,.12);
}

.sidebar-section {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(255,255,255,.3);
  padding: 0 20px;
  margin: 16px 0 6px;
}
.sidebar-section:first-child { margin-top: 0; }

.tab-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  color: rgba(255,255,255,.65);
  padding: 11px 20px;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 500;
  text-align: left;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}
.tab-btn:hover { background: rgba(255,255,255,.07); color: var(--white); }
.tab-btn.active {
  background: rgba(191,0,0,.25);
  color: var(--white);
  border-left-color: var(--rakuten-red);
  font-weight: 700;
}

.tab-btn .tab-icon { font-size: 1rem; width: 18px; text-align: center; flex-shrink: 0; }

/* ── Main content area ────────────────────────────────────── */
.admin-main {
  margin-top: 56px;
  margin-left: 200px;
  min-height: calc(100vh - 56px);
  background: var(--gray-50);
}

/* ── Page chrome ──────────────────────────────────────────── */
.page-header {
  background: var(--white);
  border-bottom: 3px solid var(--rakuten-red);
  padding: 28px 0 0;
}
.page-header .container { padding-bottom: 0; }
.page-header h1 { font-size: 1.6rem; font-weight: 700; color: var(--gray-800); }
.page-header .subtitle { color: var(--gray-600); margin-top: 6px; font-size: .95rem; }

.container { max-width: 960px; padding: 32px 32px; }
.tab-content--wide { padding: 32px 32px; max-width: 100%; box-sizing: border-box; }

@media (max-width: 1100px) {
  .tab-content--wide { padding: 24px 20px; }
  .container { padding: 24px 20px; }
}
@media (max-width: 700px) {
  .admin-main { margin-left: 0; }
  .sidebar { display: none; }
  .tab-content--wide { padding: 16px 12px; }
  .container { padding: 16px 12px; }
}

h1 { font-size: 1.7rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 16px; color: var(--gray-800); }
h3 { font-size: .95rem; font-weight: 700; margin-bottom: 12px; color: var(--gray-600); text-transform: uppercase; letter-spacing: .04em; }

.subtitle { color: var(--gray-600); margin-bottom: 28px; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: 6px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
}

.project-card {
  background: var(--white);
  border-radius: 6px;
  padding: 20px 24px;
  margin-bottom: 16px;
  border-top: 3px solid var(--rakuten-red);
  box-shadow: var(--shadow-sm);
  border-left: 1px solid var(--gray-200);
  border-right: 1px solid var(--gray-200);
  border-bottom: 1px solid var(--gray-200);
}

.project-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--gray-100);
}
.project-title { font-size: 1.05rem; font-weight: 700; color: var(--rakuten-red); }

/* ── Form fields ──────────────────────────────────────────── */
.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 24px;
}
@media (max-width: 600px) { .fields { grid-template-columns: 1fr; } }

.field-group { margin-bottom: 10px; }
.field-group--full { grid-column: 1 / -1; }
.fields-grid { grid-column: 1 / -1; }
.field-group label {
  display: block;
  font-size: .83rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--gray-800);
  text-transform: capitalize;
  letter-spacing: .01em;
}
.field-group--nested {
  margin-left: 20px;
  padding-left: 12px;
  border-left: 2px solid var(--gray-200);
}
.fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 20px;
}
@media (max-width: 560px) { .fields-grid { grid-template-columns: 1fr; } }

input[type=text],
input[type=number],
input[type=password],
textarea,
select {
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--gray-200);
  border-radius: 4px;
  font-size: .83rem;
  font-family: inherit;
  background: var(--white);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--rakuten-red);
  box-shadow: 0 0 0 3px rgba(191,0,0,.1);
  background: var(--white);
}
textarea { resize: vertical; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 4px;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  text-decoration: none;
}
.btn:hover { opacity: .88; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary   { background: var(--rakuten-red); color: var(--white); }
.btn-primary:hover { background: var(--rakuten-red-dk); opacity: 1; }

.btn-secondary { background: var(--gray-100); color: var(--gray-800); border: 1px solid var(--gray-200); }
.btn-secondary:hover { background: var(--gray-200); opacity: 1; }

.btn-danger    { background: var(--rakuten-red-lt); color: var(--rakuten-red); border: 1px solid #f5c0c0; }
.btn-sm        { padding: 5px 12px; font-size: .8rem; }

.actions { margin-top: 24px; display: flex; gap: 12px; align-items: center; }
#add-project-btn { margin: 4px 0 24px; }

/* ── Messages ─────────────────────────────────────────────── */
.message { padding: 12px 16px; border-radius: 4px; margin-top: 16px; font-size: .9rem; }
.message.error   { background: var(--rakuten-red-lt); color: var(--rakuten-red); border: 1px solid #f5c0c0; }
.message.success { background: #e6f4ea; color: #1a6630; border: 1px solid #b7dfc0; }
.hidden { display: none !important; }

/* ── Inline form ──────────────────────────────────────────── */
.tab-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 150px; }

/* ── Table ────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th {
  text-align: left;
  padding: 10px 14px;
  background: var(--gray-50);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-600);
  border-bottom: 2px solid var(--rakuten-red);
}
td { padding: 11px 14px; border-top: 1px solid var(--gray-100); vertical-align: top; }
tr:hover td { background: var(--gray-50); }

/* ── Filters ──────────────────────────────────────────────── */
.filters { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.filters input { flex: 1; min-width: 160px; }

/* ── Response cards ───────────────────────────────────────── */
.response-card { margin-bottom: 16px; }
.response-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.team-tag {
  background: var(--rakuten-red-lt);
  color: var(--rakuten-red);
  padding: 2px 10px;
  border-radius: 3px;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.date { margin-left: auto; color: var(--gray-400); font-size: .85rem; }
.response-table td.field-label { text-transform: capitalize; color: var(--gray-600); font-size: .85rem; width: 180px; }

/* ── Badges ───────────────────────────────────────────────── */
.badge { padding: 3px 10px; border-radius: 3px; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.badge-green  { background: #e6f4ea; color: #1a6630; }
.badge-yellow { background: #fff8e1; color: #856404; }

.link-small { font-size: .8rem; color: var(--rakuten-red); word-break: break-all; }

/* ── Login page ───────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-50);
}
.login-card {
  background: var(--white);
  border-radius: 6px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
  border-top: 4px solid var(--rakuten-red);
}
.login-card h1 { font-size: 1.4rem; margin-bottom: 6px; }
.login-card .subtitle { margin-bottom: 24px; font-size: .9rem; }

/* ── Dashboard ────────────────────────────────────────────── */
.dash-stat-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 800px) { .dash-stat-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 500px) { .dash-stat-row { grid-template-columns: repeat(2, 1fr); } }

.dash-stat-card {
  background: var(--white);
  border-radius: 6px;
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  border-top: 3px solid var(--gray-400);
}
.dash-stat-card--green  { border-top-color: #1a6630; }
.dash-stat-card--yellow { border-top-color: #856404; }
.dash-stat-card--blue   { border-top-color: #0d47a1; }
.dash-stat-card--purple { border-top-color: #6a1b9a; }

.dash-stat-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--gray-600); margin-bottom: 8px; }
.dash-stat-value { font-size: 2.2rem; font-weight: 700; color: var(--gray-800); line-height: 1; }

.dash-charts-row { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.dash-chart-card { flex: 1; min-width: 220px; }

.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut-bg { }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--gray-600); margin-bottom: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.bar-chart { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { font-size: .8rem; color: var(--gray-600); width: 140px; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 14px; background: var(--gray-100); border-radius: 7px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--rakuten-red); border-radius: 7px; transition: width .5s ease; }
.bar-fill--purple { background: #6a1b9a; }
.bar-count { font-size: .8rem; font-weight: 700; color: var(--gray-800); width: 24px; text-align: right; }

.progress-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.progress-team { font-size: .85rem; color: var(--gray-800); width: 160px; flex-shrink: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress-track { flex: 1; height: 10px; background: var(--gray-100); border-radius: 5px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 5px; transition: width .5s ease; }
.progress-label { font-size: .8rem; font-weight: 700; width: 40px; text-align: right; flex-shrink: 0; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: var(--white);
  border-radius: 6px;
  width: 90%; max-width: 640px;
  max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-md);
  border-top: 3px solid var(--rakuten-red);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--gray-200);
}
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--gray-200); display: flex; gap: 10px; }

/* ── Leadership tab ──────────────────────────────────────── */
#tab-leadership .stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
@media (max-width: 900px) { #tab-leadership .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px) { #tab-leadership .stat-grid { grid-template-columns: 1fr; } }

/* ── Respondents (Project PICs) table ─────────────────────── */
#respondents-table { font-size: .78rem; border-collapse: collapse; width: 100%; }
#respondents-table th { white-space: nowrap; padding: 5px 8px; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
#respondents-table tr { line-height: 1.3; border-bottom: 1px solid var(--gray-200); }
#respondents-table tr:hover { background: var(--gray-100); }

/* ── Mobile — admin.html ─────────────────────────────────── */

/* Mobile bottom tab bar (shown only on mobile) */
#mobile-tab-bar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--gray-800);
  z-index: 9999;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -2px 8px rgba(0,0,0,.25);
}
#mobile-tab-bar::-webkit-scrollbar { display: none; }
#mobile-tab-bar .mob-tab {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 14px 10px;
  color: rgba(255,255,255,.55);
  font-size: .6rem;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  border: none;
  background: transparent;
  white-space: nowrap;
  border-top: 2px solid transparent;
  min-width: 60px;
}
#mobile-tab-bar .mob-tab .mob-icon { font-size: 1.2rem; margin-bottom: 2px; }
#mobile-tab-bar .mob-tab.active { color: #fff; border-top-color: var(--rakuten-red); }

@media (max-width: 700px) {
  /* Show mobile nav, add bottom padding to content */
  #mobile-tab-bar { display: flex; }
  .admin-main { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important; }

  /* Topbar */
  .topbar { padding: 0 12px; }
  .topbar-title { font-size: .82rem; }
  .topbar-logo { width: auto; }
  .topbar-actions { width: auto; gap: 6px; }
  .topbar-user { display: none; }

  /* Tab content padding */
  .tab-content--wide { padding: 12px 10px !important; }

  /* All tables — horizontal scroll */
  .tab-content--wide table,
  #tab-responses table,
  #tab-respondents table,
  #tab-budget table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }

  /* Cards */
  .card { padding: 14px 12px !important; }

  /* ── Leadership tab ── */
  /* Track action 5-col grid → 2-col */
  #tab-leadership [style*="grid-template-columns:repeat(5"] {
    grid-template-columns: 1fr 1fr !important;
  }
  /* Budget alert stat boxes min-width fix */
  #tab-leadership [style*="min-width:110px"] { min-width: 0 !important; }
  /* Levers bar — label full width */
  #tab-leadership [style*="min-width:160px"] { min-width: 0 !important; width: 100% !important; }
  /* Subsidy slider — label and buttons wrap */
  #tab-leadership [style*="min-width:220px"] { min-width: 0 !important; }
  /* Snap buttons row — wrap */
  #tab-leadership [style*="display:flex"][style*="gap:6px"] { flex-wrap: wrap !important; }

  /* ── Dashboard tab ── */
  .dash-stat-row { grid-template-columns: repeat(2, 1fr) !important; }
  /* Chart cards full width on mobile */
  .dash-chart-card { min-width: 0 !important; flex: 1 1 100% !important; }

  /* ── Projects tab ── */
  /* Filters stack vertically */
  .filters { flex-direction: column !important; }
  .filters input, .filters select { width: 100% !important; max-width: 100% !important; }
  /* Multi-select panel full width */
  .ms-panel { min-width: 260px !important; max-width: calc(100vw - 20px) !important; left: 0 !important; }
  /* Bulk controls smaller */
  #bulk-controls { gap: 6px !important; font-size: .75rem !important; flex-wrap: wrap !important; }
  /* Project card header — stack on narrow */
  #tab-responses .card [style*="display:flex"][style*="align-items:center"] { flex-wrap: wrap !important; gap: 6px !important; }

  /* ── Project PICs tab ── */
  #respondents-search { max-width: 100% !important; width: 100% !important; }
  /* Add new respondent button row — stack */
  #tab-respondents [style*="display:flex"] { flex-wrap: wrap !important; }

  /* ── Budget Planning tab ── */
  /* Report card links — stack to full width */
  #tab-budget [style*="min-width:220px"] { min-width: 0 !important; flex: 1 1 100% !important; }
  /* Budget summary tables — already covered by global table rule */
  /* HW/HR pricing table action rows */
  #tab-budget [style*="display:flex"][style*="gap:8px"] { flex-wrap: wrap !important; }
}

@media (max-width: 420px) {
  /* Track action cards → 1-col on very small */
  #tab-leadership [style*="grid-template-columns:repeat(5"] {
    grid-template-columns: 1fr !important;
  }
  .dash-stat-row { grid-template-columns: repeat(2, 1fr) !important; }
  .topbar-title { display: none; }
  /* Projects — hide less important table columns */
  #responses-table th:nth-child(4),
  #responses-table td:nth-child(4),
  #responses-table th:nth-child(5),
  #responses-table td:nth-child(5) { display: none; }
}

/* ── Mobile — survey.html & project.html ─────────────────── */
@media (max-width: 640px) {
  /* Navbar: hide FAQ link text, shrink padding */
  .navbar { padding: 0 12px !important; }
  .navbar .nav-title { font-size: .85rem; }
  .navbar .nav-subtitle { font-size: .68rem; }

  /* Page header */
  .page-header { padding: 0; }
  .page-header h1 { font-size: 1.25rem; }
  .page-header .subtitle { font-size: .82rem; }

  /* Summary stats bar — wrap to 2 col instead of inline row */
  #summary-bar { padding: 8px 12px !important; }
  #summary-bar > div { gap: 8px !important; flex-direction: column; align-items: flex-start !important; }

  /* Main content padding */
  .page-header > div,
  #summary-bar > div { padding-left: 12px !important; padding-right: 12px !important; }

  /* Project cards */
  .project-card { padding: 10px 12px !important; }
  .project-title { font-size: .88rem !important; }

  /* Project card header row — allow wrapping, reduce gaps */
  .project-card [style*="display:flex"][style*="align-items:center"] { gap: 6px !important; }

  /* Field detail rows (min-width label) */
  .project-card [style*="min-width:140px"] { min-width: 100px !important; font-size: .75rem !important; }

  /* Buttons — full-width on small screens for primary actions */
  .actions .btn-primary { width: 100%; }

  /* PRISM modal */
  #prism-modal-overlay > div { width: 98% !important; max-height: 92vh !important; }

  /* Gamification panel */
  #gamification-panel { padding: 10px 12px 0 !important; }
  #gamification-panel [style*="font-size:2rem"],
  #gamification-panel [style*="font-size:1.8rem"] { font-size: 1.3rem !important; }

  /* Billing nudge banner */
  #summary-bar + div [style*="padding:12px 16px"] { padding: 8px 10px !important; }
}

@media (max-width: 420px) {
  .navbar { grid-template-columns: 1fr auto !important; }
  .navbar > div:last-child { display: none; } /* hide FAQ button on very small screens */
  .page-header h1 { font-size: 1.1rem; }
  .project-card [style*="min-width:140px"] { min-width: 80px !important; }
}

/* ── Responses table ──────────────────────────────────────── */
#responses-table { font-size: .78rem; }
#responses-table th { white-space: nowrap; padding: 6px 8px; font-size: .75rem; }
#responses-table th[data-sort]:hover { background: var(--gray-200); }
#responses-table td { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; font-size: .78rem; padding: 5px 8px; }
#responses-table td:first-child { color: var(--gray-400); font-weight: 700; width: 30px; }
#responses-table tr { line-height: 1.2; }
#tab-responses .filters { max-width: 100%; gap: 6px; margin-bottom: 10px; flex-wrap: nowrap; align-items: center; }
#tab-responses .filters input,
#tab-responses .filters select { font-size: .78rem; padding: 4px 8px; }
#tab-responses .filters input { min-width: 80px; max-width: 140px; flex: 1; }
#tab-responses .filters select { min-width: 90px; max-width: 160px; flex-shrink: 0; }
#tab-responses #filter-track { max-width: 185px; }
.ms-dropdown { position: relative; display: inline-block; }
.ms-btn {
  font-size: .78rem; padding: 4px 8px; border: 1px solid var(--gray-200);
  border-radius: 4px; background: #fff; cursor: pointer; white-space: nowrap;
  min-width: 110px; text-align: left; display: flex; align-items: center;
  justify-content: space-between; gap: 4px; height: 28px; box-sizing: border-box;
}
.ms-btn:hover { border-color: var(--gray-400); }
.ms-btn.active { border-color: var(--rakuten-red); color: var(--rakuten-red); }
.ms-panel {
  display: none; position: absolute; top: calc(100% + 2px); left: 0;
  z-index: 200; background: #fff; border: 1px solid var(--gray-200);
  border-radius: 4px; box-shadow: 0 4px 12px rgba(0,0,0,.12);
  min-width: 260px; max-height: 280px; overflow-y: auto; padding: 4px 0;
}
.ms-panel.open { display: block; }
.ms-panel label {
  display: flex; align-items: flex-start; gap: 7px; padding: 5px 12px;
  font-size: .78rem; cursor: pointer; color: var(--gray-800);
  white-space: nowrap; text-align: left; width: 100%; box-sizing: border-box;
}
.ms-panel label input[type=checkbox] { margin-top: 2px; flex-shrink: 0; }
.ms-panel label:hover { background: var(--gray-50); }
.ms-panel .ms-clear {
  padding: 5px 12px; font-size: .75rem; color: var(--rakuten-red);
  cursor: pointer; border-top: 1px solid var(--gray-100); margin-top: 2px;
  text-align: left;
}

/* ── M-Score table ────────────────────────────────────────── */
#scores-tbody tr td { padding: 5px 8px !important; font-size: .78rem; line-height: 1.2; }
#scores-tbody tr td:first-child { font-size: .75rem; }
#tab-strategy table thead th { padding: 6px 8px !important; font-size: .75rem; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Budget AI Chatbot ────────────────────────────────────── */
.chat-msg { display: flex; }
.chat-msg--user { justify-content: flex-end; }
.chat-msg--assistant { justify-content: flex-start; }
.chat-bubble {
  max-width: 78%; padding: 8px 12px; border-radius: 10px;
  font-size: .84rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word;
}
.chat-msg--user .chat-bubble {
  background: #0d47a1; color: #fff; border-bottom-right-radius: 3px;
}
.chat-msg--assistant .chat-bubble {
  background: #fff; color: #1a1a1a; border: 1px solid #e0e0e0;
  border-bottom-left-radius: 3px;
}
.chat-msg--typing .chat-bubble { color: #888; font-style: italic; }

/* ── Budget AI — floating widget ─────────────────────────── */
#chat-fab {
  position: fixed; bottom: 24px; right: 24px; z-index: 1000;
  width: 52px; height: 52px; border-radius: 50%;
  background: #0d47a1; color: #fff;
  display: none; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,.25);
  transition: transform .15s, box-shadow .15s;
}
#chat-fab.fab-visible { display: flex; }
#chat-fab:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(0,0,0,.3); }
#chat-fab.chat-open { background: #555; }

#chat-widget {
  position: fixed; bottom: 88px; right: 24px; z-index: 999;
  width: 380px; height: 520px;
  display: flex; flex-direction: column;
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,.22);
  font-family: 'Helvetica Neue', Arial, sans-serif;
}
#chat-widget-header {
  background: #0d47a1; color: #fff;
  padding: 11px 14px; display: flex;
  align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
#chat-widget-footer {
  padding: 10px 12px; background: #fff;
  border-top: 1px solid #e0e0e0;
  display: flex; gap: 8px; align-items: center; flex-shrink: 0;
}
#chat-widget-footer input {
  flex: 1; border: 1px solid #d0d0d0; border-radius: 20px;
  padding: 7px 14px; font-size: .84rem; font-family: inherit; outline: none;
}
#chat-widget-footer input:focus { border-color: #0d47a1; }
#chat-send-btn {
  width: 34px; height: 34px; border-radius: 50%;
  background: #0d47a1; color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background .15s;
}
#chat-send-btn:hover { background: #1565c0; }
#chat-send-btn:disabled { background: #aaa; cursor: default; }
.chat-widget-footer-note {
  font-size: .65rem; color: #aaa; text-align: center;
  padding: 0 12px 6px; background: #fff;
}

/* ── Subsidy rate buttons ─────────────────────────────────── */
.ap-rate-btn{padding:3px 10px;border:1px solid #ccc;border-radius:3px;background:#fff;cursor:pointer;font-size:.75rem;font-weight:400}
.ap-rate-btn.active{border-color:#0d47a1;background:#e8f4fd;font-weight:700;color:#0d47a1}
