:root {
  --bg: #f7fbff;
  --paper: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #dde8f3;
  --blue: #2f80ed;
  --cyan: #20c7b4;
  --green: #38b26d;
  --coral: #ff6b5f;
  --gold: #f4b740;
  --shadow: 0 16px 40px rgba(21, 52, 90, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(47, 128, 237, 0.08), transparent 300px),
    var(--bg);
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
}

body.auth-locked .app-shell {
  display: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.auth-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(47, 128, 237, 0.1), transparent 320px),
    var(--bg);
}

.auth-card {
  width: min(440px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
}

.auth-card .brand-mark {
  margin-bottom: 16px;
}

.auth-card h1 {
  margin: 0 0 12px;
  font-size: 24px;
}

.auth-card p {
  color: var(--muted);
  line-height: 1.7;
}

.google-login-button {
  width: 100%;
  margin-top: 12px;
  border: 0;
  border-radius: 8px;
  padding: 13px 16px;
  background: #172033;
  color: #ffffff;
  cursor: pointer;
  font-weight: 900;
}

.auth-note {
  margin: 12px 0 0;
  font-size: 12px;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #ffffff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: white;
  background: linear-gradient(135deg, #2f80ed, #20c7b4);
  border: 4px solid #172033;
  box-shadow: 4px 4px 0 #f4b740;
  font-weight: 900;
}

.brand h1,
.topbar h2,
.panel h3,
.hero-copy h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 18px;
}

.eyebrow,
.side-label {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  text-align: left;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.nav-tab.active {
  background: #eaf3ff;
  color: var(--blue);
}

.database-status {
  margin-top: auto;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.database-status.online {
  border-color: rgba(56, 178, 109, 0.35);
  background: #effbf4;
  color: #207848;
}

.database-status.cloud {
  border-color: rgba(47, 128, 237, 0.4);
  background: #eef6ff;
  color: var(--blue);
}

.side-panel {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.side-panel strong,
.side-panel span {
  display: block;
}

.side-panel span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.main {
  padding: 28px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 22px;
}

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
}

.auth-user {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.auth-user span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-user button {
  border: 0;
  border-radius: 6px;
  padding: 6px 8px;
  background: #eaf3ff;
  color: var(--blue);
  cursor: pointer;
  font-size: 12px;
  font-weight: 900;
}

.toolbar input[type="month"] {
  min-width: 150px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

label small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.45;
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: white;
  color: var(--ink);
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero-band,
.panel,
.metric-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.month-context {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.month-context article {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.month-context span,
.month-context small {
  display: block;
  color: var(--muted);
}

.month-context strong {
  display: block;
  margin: 5px 0 2px;
  font-size: 22px;
}

.dashboard-controls {
  display: grid;
  grid-template-columns: 1fr 170px auto;
  gap: 14px;
  align-items: end;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.dashboard-controls h3 {
  margin: 0;
}

.data-chip {
  align-self: center;
  justify-self: end;
  max-width: 260px;
  padding: 8px 10px;
  border-radius: 999px;
  background: #f4f9ff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hero-band {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) 1.2fr;
  gap: 24px;
  align-items: center;
  padding: 22px;
  margin-bottom: 18px;
  overflow: hidden;
}

.hero-progress {
  min-width: 0;
}

.hero-copy h3 {
  font-size: 28px;
}

.hero-copy p:last-child,
#dashboardLead {
  color: var(--muted);
}

.workday-progress-card {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid rgba(47, 128, 237, 0.22);
  border-radius: 8px;
  background: #f8fbff;
}

.workday-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.workday-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.workday-head strong {
  font-size: 24px;
}

.workday-meter {
  position: relative;
  height: 14px;
  overflow: hidden;
  border: 2px solid #172033;
  background: #eaf1f8;
}

.workday-fill,
.workday-sales-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
}

.workday-fill {
  background: rgba(244, 183, 64, 0.46);
}

.workday-sales-fill {
  height: 50%;
  top: auto;
  background: linear-gradient(90deg, var(--cyan), var(--green));
}

.workday-meta {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.workday-meta b {
  color: var(--ink);
}

.workday-meta b.good {
  color: #16794d;
}

.workday-meta b.behind {
  color: #d94251;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-card {
  padding: 16px;
}

.metric-card span,
.metric-card small {
  display: block;
  color: var(--muted);
}

.metric-card strong {
  display: block;
  margin: 8px 0 4px;
  font-size: 30px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(520px, 1.35fr) minmax(320px, 0.65fr);
  gap: 18px;
  align-items: start;
}

.opportunity-kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.opportunity-layout {
  display: grid;
  grid-template-columns: minmax(620px, 1.05fr) minmax(380px, 0.95fr);
  gap: 18px;
  align-items: start;
}

.opportunity-form {
  display: grid;
  gap: 16px;
}

.form-section {
  display: grid;
  gap: 12px;
}

.form-section h4,
.score-box h4 {
  margin: 0;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.score-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.score-box label {
  padding-top: 4px;
}

.opportunity-list {
  display: grid;
  gap: 12px;
}

.opportunity-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.opportunity-card-head,
.opportunity-follow-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.opportunity-card-head h3 {
  margin: 0;
  overflow-wrap: anywhere;
}

.opportunity-badges,
.opportunity-score-row,
.opportunity-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.opportunity-score-row span,
.opportunity-card-meta span {
  padding: 7px 9px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
}

.opportunity-score-row b {
  color: var(--ink);
}

.opportunity-follow-row {
  align-items: end;
}

.opportunity-follow-row label {
  min-width: 126px;
}

.opportunity-follow-row .muted {
  flex: 1;
  min-width: 180px;
  padding-bottom: 9px;
}

.opportunity-memo {
  margin: 0;
  padding: 10px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.opportunity-activity-list {
  display: grid;
  gap: 8px;
  padding-top: 2px;
}

.opportunity-activity {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.opportunity-activity strong {
  font-size: 13px;
}

.opportunity-activity span,
.opportunity-activity p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.recommendation-self {
  background: #eaf3ff;
  color: var(--blue);
}

.recommendation-toss {
  background: #fff3d8;
  color: #a36500;
}

.recommendation-hybrid {
  background: #edf8f5;
  color: #16794d;
}

.recommendation-nurture {
  background: #f4f9ff;
  color: var(--muted);
}

.recommendation-low {
  background: #ffeceb;
  color: #d94251;
}

.rank-s { background: #d8f8ff; }
.rank-a { background: #eaf3ff; }
.rank-b { background: #edf8f5; }
.rank-c { background: #fff3d8; }
.rank-d { background: #ffeceb; }

.trend-strip {
  margin-bottom: 18px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel.wide {
  grid-row: span 2;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.member-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.subsection-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 18px 0 10px;
}

.subsection-head.compact {
  margin-top: 14px;
}

.subsection-head h4 {
  margin: 0;
}

.member-kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.member-kpi-card {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
}

.member-kpi-card span {
  font-size: 22px;
  font-weight: 900;
}

.member-kpi-card small {
  color: var(--muted);
}

.member-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdff;
}

.member-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.progress-bar {
  height: 12px;
  border: 2px solid #172033;
  background: #eaf1f8;
  margin: 12px 0 8px;
  position: relative;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--green));
}

.rank-badge {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 900;
  color: #172033;
  background: #e6edf5;
}

.rank-bronze { background: #d69b6c; }
.rank-silver { background: #c9d5df; }
.rank-gold { background: #f4c24d; }
.rank-platinum { background: #d8f8ff; }

.hidden {
  display: none !important;
}

.ranking-list,
.report-kpis,
.timeline {
  display: grid;
  gap: 10px;
}

.report-kpis {
  align-content: start;
}

.ranking-item,
.timeline-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.ranking-item {
  grid-template-columns: 26px minmax(0, 1fr) auto;
}

.ranking-item div,
.timeline-item div {
  min-width: 0;
}

.ranking-item strong,
.ranking-item span,
.timeline-item strong,
.timeline-item span,
.timeline-item p {
  overflow-wrap: anywhere;
}

.ranking-item strong,
.timeline-item strong {
  display: block;
}

.ranking-item span,
.timeline-item span,
.muted {
  color: var(--muted);
  font-size: 12px;
}

.report-filter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.timeline-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.report-review {
  margin-top: 6px;
}

.report-review b {
  display: inline-block;
  margin-right: 6px;
  color: var(--ink);
}

.report-kpi {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 4px 12px;
  padding: 12px;
  border-radius: 8px;
  background: #f4f9ff;
}

.report-kpi small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
}

.report-kpi.member {
  background: #fffaf0;
}

.report-kpi.total {
  background: #edf8f5;
  border: 1px solid rgba(32, 199, 180, 0.35);
}

.kpi-summary-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(32, 199, 180, 0.35);
  border-radius: 8px;
  background: #edf8f5;
}

.kpi-summary-card.today {
  border-color: rgba(244, 183, 64, 0.45);
  background: #fff8e8;
}

.kpi-summary-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.kpi-summary-head span {
  color: var(--muted);
  font-weight: 800;
}

.kpi-summary-head strong {
  font-size: 28px;
}

.kpi-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.kpi-detail-grid span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 12px;
}

.kpi-detail-grid b {
  color: var(--ink);
}

.agency-actions {
  margin-bottom: 18px;
}

.inline-form {
  box-shadow: none;
}

.compact-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.list-layout {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) 390px;
  gap: 18px;
  align-items: start;
}

.sticky-head {
  position: sticky;
  top: 0;
  padding-bottom: 12px;
  background: white;
  z-index: 2;
}

.agency-table-wrap {
  max-height: calc(100vh - 180px);
  overflow: auto;
}

.agency-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.agency-table th,
.agency-table td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.agency-table th {
  position: sticky;
  top: 0;
  background: #f8fbff;
  z-index: 1;
  color: var(--muted);
  font-size: 12px;
}

.agency-row {
  cursor: pointer;
}

.agency-row:hover,
.agency-row.active {
  background: #eef7ff;
}

.agency-name {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}

.detail-panel {
  position: sticky;
  top: 28px;
}

.detail-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.detail-stat {
  padding: 12px;
  border-radius: 8px;
  background: #f4f9ff;
}

.detail-stat strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

.mini-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(44px, 1fr));
  gap: 8px;
  align-items: end;
  min-height: 168px;
  padding: 12px 0 0;
}

.mini-bar {
  width: 100%;
  min-height: 4px;
  background: linear-gradient(180deg, var(--blue), var(--cyan));
  border-radius: 4px 4px 0 0;
}

.mini-bar-item {
  display: grid;
  grid-template-rows: 92px auto auto;
  gap: 4px;
  align-items: end;
  min-width: 0;
  text-align: center;
}

.mini-bar-item span {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.mini-bar-item strong {
  font-size: 11px;
  white-space: nowrap;
}

.report-layout {
  display: grid;
  grid-template-columns: minmax(420px, 0.9fr) 1.1fr;
  gap: 18px;
  align-items: start;
}

.report-left,
.report-right {
  display: grid;
  gap: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.full-label {
  margin-top: 12px;
}

.primary-action {
  width: 100%;
  margin-top: 14px;
  border: 0;
  border-radius: 8px;
  padding: 13px 16px;
  background: #172033;
  color: #fff;
  font-weight: 900;
  cursor: pointer;
}

.secondary-action,
.tiny-action,
.icon-action {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.secondary-action {
  margin-top: 12px;
}

.tiny-action {
  padding: 7px 10px;
  font-size: 12px;
}

.icon-action {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
}

.target-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.target-inline {
  margin-top: 14px;
}

.entry-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 8px;
}

.entry-head h4 {
  margin: 0;
}

.report-entries {
  display: grid;
  gap: 10px;
}

.report-entry {
  display: grid;
  grid-template-columns: minmax(170px, 1.2fr) 90px 90px minmax(150px, 1fr) minmax(140px, 1fr) 34px;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.agency-target-planner {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.agency-target-head,
.agency-goal-title,
.forecast-history-item,
.forecast-editor-stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.agency-target-head h4 {
  margin: 0 0 4px;
}

.agency-target-controls,
.weekly-target-grid,
.agency-goal-grid {
  display: grid;
  gap: 10px;
}

.agency-target-controls {
  grid-template-columns: minmax(140px, 0.7fr) minmax(220px, 1.4fr) minmax(130px, 0.7fr);
  margin-top: 10px;
}

.weekly-target-grid {
  grid-template-columns: repeat(5, minmax(90px, 1fr));
  margin-top: 10px;
}

.weekly-target-grid small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
}

.agency-goal-grid {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.agency-goal-card,
.forecast-editor,
.forecast-history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.agency-goal-card {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.agency-goal-title {
  justify-content: flex-start;
}

.agency-goal-title .pixel-avatar {
  flex: 0 0 auto;
}

.agency-goal-title span,
.goal-meter-row span,
.forecast-chip span {
  color: var(--muted);
  font-size: 12px;
}

.goal-meter-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
}

.goal-meter-row .progress-bar {
  grid-column: 1 / -1;
}

.progress-bar.week .progress-fill {
  background: linear-gradient(90deg, #14b8a6, #2f80ed);
}

.forecast-chip {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #eef6ff;
  font-weight: 800;
}

.positive {
  color: #138a59;
}

.negative {
  color: #c44545;
}

.forecast-history-list {
  display: grid;
  gap: 8px;
}

.forecast-history-item {
  justify-content: flex-start;
  align-items: flex-start;
  padding: 10px;
}

.forecast-history-item > strong {
  min-width: 88px;
}

.forecast-history-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.forecast-editor {
  display: grid;
  gap: 10px;
  margin: 14px 0;
  padding: 12px;
}

.forecast-editor-stats {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.forecast-editor-stats span {
  padding: 6px 9px;
  border-radius: 999px;
  background: #eef6ff;
  font-size: 12px;
  font-weight: 800;
}

.forecast-form {
  display: grid;
  grid-template-columns: 110px 110px minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.forecast-form .secondary-action {
  margin-top: 0;
}

.forecast-calendar-chip {
  display: block;
  padding: 2px 5px;
  border-radius: 6px;
  background: #fff7da;
  color: #8a5a00;
  font-size: 11px;
  font-weight: 800;
}

.topic-form {
  display: grid;
  gap: 10px;
  margin: 16px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.topic-form h3 {
  margin: 0;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.calendar-day {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.calendar-day.sunday {
  color: #d94251;
}

.calendar-day.saturday {
  color: #2f80ed;
}

.calendar-cell {
  min-height: 86px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 6px;
}

button.calendar-cell {
  width: 100%;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

button.calendar-cell:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(23, 32, 51, 0.08);
}

.calendar-cell.selected-day {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px rgba(47, 128, 237, 0.22), 0 10px 22px rgba(47, 128, 237, 0.12);
}

.calendar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px;
}

.calendar-date-label {
  min-width: 0;
}

.calendar-cell strong {
  font-size: 13px;
}

.calendar-cell span {
  color: var(--muted);
  font-size: 12px;
}

.calendar-cell.has-report {
  border-color: rgba(32, 199, 180, 0.55);
  background: #ecfbf8;
}

.calendar-cell.saturday {
  border-color: rgba(47, 128, 237, 0.35);
  background: #f3f8ff;
}

.calendar-cell.sunday,
.calendar-cell.holiday {
  border-color: rgba(217, 66, 81, 0.35);
  background: #fff5f4;
}

.calendar-cell.has-report.saturday {
  background: #eef6ff;
}

.calendar-cell.has-report.sunday,
.calendar-cell.has-report.holiday {
  background: #fff1ef;
}

.calendar-cell.saturday strong {
  color: #2f80ed;
}

.calendar-cell.sunday strong,
.calendar-cell.holiday strong {
  color: #d94251;
}

.holiday-name {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: #d94251;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-bars {
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
}

.todo-bar {
  display: block;
  height: 16px;
  margin-left: -8px;
  margin-right: -8px;
  padding-left: 8px;
  overflow: hidden;
  color: #172033;
  font-size: 10px;
  font-weight: 900;
  line-height: 16px;
  white-space: nowrap;
}

.todo-bar.start {
  margin-left: 0;
  border-radius: 999px 0 0 999px;
}

.todo-bar.end {
  margin-right: 0;
  border-radius: 0 999px 999px 0;
}

.todo-bar.start.end {
  border-radius: 999px;
}

.muted-cell {
  background: transparent;
  border-color: transparent;
}

.todo-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.todo-form #todoTitle {
  grid-column: 1 / -1;
}

.todo-form .secondary-action {
  margin-top: 0;
  justify-self: start;
}

.todo-form .tiny-action {
  margin-top: 0;
  justify-self: start;
}

.weekly-todo-list {
  display: grid;
  gap: 12px;
}

.weekly-todo-week {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.weekly-todo-head {
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
}

.weekly-todo-head strong {
  color: var(--blue);
  font-size: 20px;
  line-height: 1;
}

.weekly-todo-head span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.weekly-todo-items {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.todo-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.weekly-todo-week .todo-item {
  background: #ffffff;
}

.todo-item.status-進行中 {
  border-color: rgba(244, 183, 64, 0.5);
  background: #fffaf0;
}

.todo-item.status-完了 {
  border-color: rgba(56, 178, 109, 0.35);
  background: #f0fbf5;
}

.todo-item.status-完了 strong {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}

.todo-type {
  border-radius: 999px;
  padding: 4px 9px;
  background: #eaf3ff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
}

.todo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.compact-empty {
  margin: 0;
  padding: 9px 10px;
}

.progress-map {
  display: grid;
  gap: 18px;
}

.quest-track {
  position: relative;
  min-height: 190px;
  padding: 18px 16px 36px;
  border: 2px solid #172033;
  background:
    linear-gradient(90deg, rgba(47,128,237,0.11) 0 25%, rgba(32,199,180,0.11) 25% 50%, rgba(244,183,64,0.14) 50% 75%, rgba(56,178,109,0.14) 75%),
    #fff;
  box-shadow: 5px 5px 0 #d7ecff;
}

.quest-track.compact {
  min-height: 180px;
}

.track-line {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 74px;
  height: 8px;
  background: #172033;
}

.track-flag {
  position: absolute;
  top: 20px;
  display: grid;
  justify-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 900;
  color: #172033;
}

.track-flag.start {
  left: 12px;
}

.track-flag.goal {
  right: 10px;
  color: var(--coral);
}

.track-flag span {
  width: 18px;
  height: 22px;
  background: var(--gold);
  border: 2px solid #172033;
  clip-path: polygon(0 0, 100% 20%, 100% 70%, 0 55%);
}

.track-flag.goal span {
  background: var(--coral);
}

.track-marks {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 66px;
  height: 36px;
}

.track-mark {
  position: absolute;
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 11px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.track-mark i {
  display: block;
  width: 2px;
  height: 24px;
  background: rgba(23, 32, 51, 0.35);
}

.track-runner {
  position: absolute;
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.track-runner em {
  color: var(--muted);
  font-size: 10px;
  font-style: normal;
}

.pixel-avatar {
  display: inline-block;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  image-rendering: pixelated;
  border: 3px solid #172033;
  background:
    linear-gradient(90deg, transparent 0 20%, rgba(255,255,255,0.5) 20% 35%, transparent 35%),
    var(--blue);
  box-shadow: 3px 3px 0 #172033;
  position: relative;
}

.pixel-avatar::before,
.pixel-avatar::after {
  content: "";
  position: absolute;
  top: 10px;
  width: 5px;
  height: 5px;
  background: #172033;
}

.pixel-avatar::before { left: 7px; }
.pixel-avatar::after { right: 7px; }

.avatar-bronze { background-color: #c68652; }
.avatar-silver { background-color: #b7c6d3; }
.avatar-gold { background-color: #f4b740; }
.avatar-platinum { background-color: #9fe9ff; }
.avatar-normal { background-color: #8ed1ff; }
.avatar-member { background-color: #20c7b4; }

.party-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfdff;
}

.activity-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.member-manager {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.member-manager-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.member-manager-row .check-pill {
  min-width: 0;
  flex: 1;
  border: 0;
  padding: 0;
  background: transparent;
}

.member-manager-row .check-pill span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-order-actions {
  display: flex;
  gap: 6px;
}

.member-order-button {
  width: 30px;
  height: 30px;
  font-size: 14px;
}

.member-order-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.member-add-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 10px;
  margin-top: 12px;
}

.member-add-form .secondary-action {
  margin-top: 0;
}

.check-pill {
  display: inline-flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
}

.check-pill input {
  width: 16px;
  height: 16px;
}

.stacked-progress {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 2px solid #172033;
  background:
    linear-gradient(90deg, rgba(47,128,237,0.08) 0 25%, rgba(32,199,180,0.08) 25% 50%, rgba(244,183,64,0.1) 50% 75%, rgba(56,178,109,0.1) 75%),
    #ffffff;
  box-shadow: 5px 5px 0 #d7ecff;
}

.stacked-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.stacked-head > div {
  min-width: 0;
}

.stacked-head strong {
  display: block;
  line-height: 1.35;
}

.stacked-head span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.stacked-head b {
  white-space: nowrap;
}

.stacked-scale {
  position: relative;
  height: 64px;
  margin: 6px 20px 0;
}

.stacked-scale::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 32px;
  height: 4px;
  background: #172033;
}

.scale-flag {
  position: absolute;
  top: 0;
  display: grid;
  justify-items: center;
  gap: 2px;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  z-index: 2;
}

.scale-flag.start {
  left: -4px;
}

.scale-flag.goal {
  right: -4px;
  color: var(--coral);
}

.scale-flag span {
  display: block;
}

.scale-flag i {
  width: 17px;
  height: 20px;
  background: var(--gold);
  border: 2px solid #172033;
  clip-path: polygon(0 0, 100% 20%, 100% 72%, 0 58%);
}

.scale-flag.goal i {
  background: var(--coral);
}

.scale-mark {
  position: absolute;
  top: 25px;
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.scale-mark i {
  width: 2px;
  height: 20px;
  background: rgba(23, 32, 51, 0.35);
}

.stacked-bar {
  display: flex;
  height: 28px;
  overflow: hidden;
  border: 2px solid #172033;
  background: #eef4fb;
}

.stacked-bar span {
  min-width: 0;
}

.stacked-legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(126px, max-content));
  gap: 8px 12px;
  max-height: 74px;
  overflow: auto;
  padding-right: 4px;
}

.stacked-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  max-width: 190px;
  color: var(--muted);
  font-size: 12px;
}

.stacked-legend i {
  width: 10px;
  height: 10px;
  border: 1px solid rgba(23, 32, 51, 0.35);
}

.stacked-legend b {
  color: var(--ink);
  white-space: nowrap;
}

.stacked-legend em {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stack-color-1 { background: #20c7b4; }
.stack-color-2 { background: #f4b740; }
.stack-color-3 { background: #2f80ed; }
.stack-color-4 { background: #ff6b5f; }
.stack-color-5 { background: #9bdb6f; }
.stack-color-6 { background: #b7c6d3; }
.stack-color-7 { background: #c68652; }
.stack-color-8 { background: #9fe9ff; }

.party-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.party-allies {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.ally {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: white;
}

.ally .pixel-avatar {
  flex-basis: 34px;
}

.ally > div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.ally strong {
  display: block;
  overflow: hidden;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ally-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 8px;
}

.ally-meta .muted {
  font-size: 11px;
  white-space: nowrap;
}

button.ally {
  width: 100%;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

button.ally:hover {
  border-color: var(--blue);
  background: #eef7ff;
}

.ally-toggle-row {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

.progress-toggle-agencies {
  min-width: 210px;
}

.text-link {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 900;
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.text-link:hover {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.detail-title-link {
  display: block;
  font-size: 20px;
  line-height: 1.35;
}

.period-trend {
  min-width: 0;
}

.period-table-wrap {
  overflow-x: auto;
}

.period-table {
  width: 100%;
  min-width: 760px;
  border-collapse: separate;
  border-spacing: 0 8px;
  font-size: 12px;
}

.period-table th {
  color: var(--muted);
  font-weight: 900;
  text-align: left;
  padding: 0 10px 2px;
  white-space: nowrap;
}

.period-table td {
  padding: 10px;
  background: #fbfdff;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.period-table td:first-child {
  border-left: 1px solid var(--line);
  border-radius: 8px 0 0 8px;
}

.period-table td:last-child {
  border-right: 1px solid var(--line);
  border-radius: 0 8px 8px 0;
}

.period-table b {
  color: var(--ink);
}

.agency-page-hero {
  display: grid;
  grid-template-columns: auto 1fr minmax(280px, 0.8fr);
  gap: 18px;
  align-items: center;
  padding: 20px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.agency-page-title {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.agency-page-title h3 {
  margin: 0;
  overflow-wrap: anywhere;
}

.agency-page-title span,
.agency-page-progress span {
  color: var(--muted);
  font-size: 12px;
}

.agency-page-progress {
  display: grid;
  gap: 6px;
}

.agency-page-progress strong {
  font-size: 30px;
}

.agency-page-grid {
  display: grid;
  grid-template-columns: minmax(340px, 0.8fr) minmax(520px, 1.2fr);
  gap: 18px;
  align-items: start;
}

.wide-stats {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.full-span {
  grid-column: 1 / -1;
}

.detail-avatar-button {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.detail-avatar-button:hover .pixel-avatar {
  box-shadow: 4px 4px 0 var(--blue);
}

.empty-state {
  color: var(--muted);
  margin: 0;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-tabs {
    grid-template-columns: repeat(4, 1fr);
  }

  .side-panel {
    display: none;
  }

  .hero-band,
  .dashboard-grid,
  .dashboard-controls,
  .opportunity-layout,
  .opportunity-kpi-grid,
  .score-grid,
  .list-layout,
  .report-layout,
  .agency-page-hero,
  .agency-page-grid,
  .month-context {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }

  .full-span {
    grid-column: auto;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 18px;
  }

  .topbar,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .kpi-grid,
  .opportunity-kpi-grid,
  .member-grid,
  .member-kpi-grid,
  .form-grid,
  .compact-grid,
  .target-list,
  .agency-target-controls,
  .weekly-target-grid,
  .agency-goal-grid,
  .forecast-form,
  .report-entry,
  .todo-form,
  .weekly-todo-week,
  .todo-item,
  .score-grid {
    grid-template-columns: 1fr;
  }

  .opportunity-card-head,
  .opportunity-follow-row {
    flex-direction: column;
  }

  .todo-form #todoTitle {
    grid-column: auto;
  }

  .nav-tabs {
    grid-template-columns: repeat(2, 1fr);
  }

  .agency-table {
    min-width: 720px;
  }
}
