:root {
  --portal-width: 1320px;
  --portal-sidebar: 240px;
  --portal-gap: 12px;
  --portal-card-gap: 10px;
  --portal-radius-lg: 26px;
  --portal-radius-md: 20px;
  --portal-radius-sm: 14px;
  --portal-shadow: 0 18px 50px rgba(92, 160, 210, .14);
}

/* 管理画面と顧客画面に共通する外枠 */
.admin-shell,
.app-shell {
  width: min(var(--portal-width), calc(100% - 28px));
  grid-template-columns: var(--portal-sidebar) minmax(0, 1fr);
  gap: var(--portal-gap);
  padding: 20px 0 48px;
}

.admin-sidebar,
.sidebar {
  top: 20px;
  height: calc(100vh - 40px);
  padding: 20px;
  border-radius: var(--portal-radius-lg);
  box-shadow: var(--portal-shadow);
}

.admin-brand,
.brand {
  padding-bottom: 18px;
}

.admin-brand img,
.sidebar > .brand-logo img {
  width: 144px;
  max-width: 100%;
}

.sidebar > .brand-logo {
  display: grid;
  width: 100%;
  height: 68px;
  place-items: center;
  margin: 0;
}

.admin-brand h1,
.brand h1 {
  margin: 6px 0 3px;
  font-size: 21px;
}

.admin-brand p,
.brand p,
.sidebar-foot {
  font-weight: 700;
}

.admin-sidebar nav,
.sidebar nav {
  gap: 8px;
  margin-top: 18px;
}

.admin-sidebar nav button,
.sidebar nav button {
  min-height: 42px;
  padding: 10px 14px;
  font-weight: 800;
}

.admin-topbar,
.topbar {
  position: static;
  top: auto;
  min-height: 64px;
  margin-bottom: var(--portal-gap);
  padding: 12px 16px;
  border-radius: var(--portal-radius-lg);
  box-shadow: 0 12px 32px rgba(92, 160, 210, .11);
}

#adminPageTitle,
#pageTitle {
  font-size: clamp(26px, 3vw, 32px);
}

.eyebrow {
  font-weight: 850;
}

/* タイトルと説明文の境界を全ポータルで統一する */
:is(.admin-main, .main) :is(h2, h3, strong) + p:not(.eyebrow),
.page > .page-lead:first-child {
  position: relative;
  margin-top: 0;
  padding-top: 9px;
}

:is(.admin-main, .main) :is(h2, h3, strong) + p:not(.eyebrow)::before,
.page > .page-lead:first-child::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: min(100%, 420px);
  height: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(55, 213, 237, .78), rgba(255, 94, 184, .58), transparent);
}

.setup-head h2 + p::before,
.step-card h3 + p::before {
  left: 50%;
  transform: translateX(-50%);
}

button,
.button {
  font-weight: 800;
}

button.primary,
.button.primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--pink2), var(--cyan2));
}

input,
select,
textarea {
  border-radius: var(--portal-radius-sm);
}

.admin-panel,
.dashboard,
.request-accordion,
.dm-card,
.setup-steps,
.plugin-card,
.backup-panel,
.account-panel {
  border-radius: var(--portal-radius-lg);
  box-shadow: var(--portal-shadow);
}

/* 管理画面 */
.summary-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--portal-card-gap);
  margin-bottom: var(--portal-gap);
}

.summary-grid article {
  min-height: 80px;
  padding: 14px;
  border-radius: var(--portal-radius-md);
}

.summary-grid strong {
  font-size: 32px;
  line-height: 1.1;
}

.summary-grid span {
  font-weight: 750;
}

.dashboard-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, .85fr);
  gap: var(--portal-gap);
  align-items: start;
  margin-bottom: var(--portal-gap);
}

.dashboard-workspace .admin-panel {
  height: 100%;
  margin-bottom: 0;
}

.dashboard-workspace .admin-panel:last-child {
  height: auto;
}

.admin-panel {
  margin-bottom: var(--portal-gap);
  padding: 16px;
}

.admin-panel h3,
.account-panel h3 {
  margin-bottom: 10px;
  font-size: 20px;
}

.panel-head {
  margin-bottom: 14px;
}

.split-page.active {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--portal-gap);
  align-items: start;
}

.split-page .admin-panel {
  margin-bottom: 0;
}

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

.customers-list {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: start;
}

.customer-card {
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding: 12px;
  border-radius: var(--portal-radius-md);
  box-shadow: 0 10px 30px rgba(92, 160, 210, .1);
}

.customer-card > div { min-width: 0; }
.customer-card-head { grid-column: 1 / -1; min-width: 0; }
.customer-identity { min-width: 0; }
.customer-list-switch { display: flex; flex-wrap: wrap; gap: 8px; }
.customer-list-switch button[aria-pressed="true"] { background: #e0f5fc; border-color: #359dbb; color: #205d75; }
.customer-visibility-note { margin: 6px 0; color: var(--muted); font-size: 12px; }
.customer-visibility-note:empty { display: none; }
.customer-visibility-button { margin-top: 6px; padding: 4px 10px; font-size: 12px; }
.customer-visibility-button[hidden] { display: none; }
.customer-title-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.customer-card h3 { margin: 0; font-size: 18px; line-height: 1.3; }
.customer-card p { margin: 2px 0 0; font-size: 13px; overflow-wrap: anywhere; }
.customer-assignment-count {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  color: #307693;
  background: rgba(126,238,255,.18);
  border: 1px solid rgba(126,238,255,.34);
  font-size: 11px;
  font-weight: 900;
}
.customer-card .customer-plugins { display: block; grid-column: 1; min-width: 0; border-top: 1px solid rgba(90,190,220,.18); padding-top: 7px; }
.customer-plugins > summary { cursor: pointer; color: var(--text); font-size: 12px; font-weight: 800; }
.customer-plugins[open] > summary { margin-bottom: 8px; }
.customer-section-label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 900; }
.customer-plugin-options { display: grid; gap: 5px; max-height: 220px; overflow-y: auto; }
.customer-card .customer-plugin-options label { display: flex; align-items: flex-start; gap: 7px; min-width: 0; width: 100%; padding: 6px 7px; border-radius: 10px; font-size: 12px; }
.customer-card .customer-plugin-options input { flex: 0 0 auto; margin: 2px 0 0; }
.customer-card .customer-plugin-options span { min-width: 0; overflow-wrap: anywhere; }
.customer-primary-action { margin-top: 8px; }
.customer-primary-action button { width: 100%; padding: 8px 10px; font-size: 12px; }
.customer-details { grid-column: 1 / -1; min-width: 0; border-top: 1px solid rgba(90,190,220,.18); padding-top: 7px; }
.customer-details > summary,
.customer-maintenance summary { cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 800; }
.customer-details[open] > summary { margin-bottom: 9px; }
.customer-detail-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.customer-detail-grid > div { min-width: 0; padding: 8px 10px; border-radius: 12px; background: rgba(255,255,255,.55); border: 1px solid rgba(90,190,220,.16); }
.customer-detail-grid span { display: block; margin-bottom: 3px; color: var(--muted); font-size: 10px; font-weight: 900; }
.customer-detail-grid strong,
.customer-detail-grid code { display: block; color: var(--text); font-size: 11px; overflow-wrap: anywhere; }
.customer-edit { margin-top: 8px; padding-top: 8px; border-top: 1px dashed rgba(90,190,220,.2); }
.customer-edit > summary { cursor: pointer; color: var(--muted); font-size: 12px; font-weight: 800; }
.customer-edit-form { display: grid; gap: 8px; margin-top: 9px; }
.customer-edit-form label { display: grid; gap: 4px; color: var(--text); font-size: 11px; font-weight: 800; }
.customer-edit-form input { min-width: 0; width: 100%; padding: 8px; }
.customer-edit-form small { color: var(--muted); font-size: 10px; line-height: 1.5; }
.customer-edit-form button { width: 100%; padding: 8px 10px; font-size: 12px; }
.customer-edit-form .result-message { margin: 0; font-size: 11px; }
.customer-details-actions { display: flex; gap: 8px; margin-top: 8px; }
.customer-details-actions button { padding: 8px 12px; font-size: 12px; }
.customer-maintenance { min-width: 0; margin-top: 8px; padding-top: 8px; border-top: 1px dashed rgba(90,190,220,.2); }
.customer-maintenance[open] summary { margin-bottom: 8px; }
.customer-maintenance .credential-note { margin-bottom: 8px; }
.customer-maintenance select { max-width: 100%; }
.customer-card .credential-box,
.customer-card .credential-list { margin-top: 8px; }
.create-form { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.create-form .plugin-selector { grid-column: 1 / -1; min-width: 0; }
.plugin-selector > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(100%, 360px);
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.74);
  cursor: pointer;
  font-weight: 850;
  list-style: none;
}
.plugin-selector > summary::-webkit-details-marker { display: none; }
.plugin-selector > summary small { margin-left: auto; color: var(--muted); font-size: 12px; }
.plugin-selector > summary::after { content: "⌄"; color: var(--cyan2); font-size: 20px; line-height: .7; }
.plugin-selector[open] > summary::after { transform: rotate(180deg); }
.plugin-selector .plugin-checks {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 620px);
  margin-top: 8px;
  padding: 10px;
}
.plugin-selector .plugin-check { min-width: 0; border-radius: 12px; padding: 8px 10px; }
.plugin-selector .plugin-check span { min-width: 0; overflow-wrap: anywhere; }
.create-form > button { grid-column: 1 / -1; justify-self: start; }
.customers-list, .requests-list, .stack-form, .simple-list, .admin-plugin-list { gap: 10px; }
.request-card, .simple-item, .info-card, .admin-plugin-item { padding: 14px; }

.customer-actions {
  grid-column: 1 / -1;
  align-items: center;
}

.customer-actions select {
  width: min(100%, 300px);
}

.credential-note {
  flex: 1 0 100%;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.request-card,
.admin-plugin-item,
.simple-item,
.info-card,
.loading-card,
.secure-result,
.global-message {
  border-radius: var(--portal-radius-sm);
  box-shadow: none;
}

/* 顧客画面 */
.dashboard {
  min-height: 0;
  margin-bottom: var(--portal-gap);
  padding: 16px 18px;
}

.dashboard h2 {
  font-size: clamp(26px, 3vw, 34px);
}

.dashboard p:not(.eyebrow),
.page-lead,
.setup-head p,
.step-card p,
.setup-note p {
  font-weight: 700;
}

.compact-request-layout {
  grid-template-columns: 1fr;
  gap: var(--portal-card-gap);
  align-items: start;
}

.request-accordion {
  min-width: 0;
}

.request-toggle {
  min-height: 52px;
  padding: 12px 16px;
}

.request-toggle span {
  font-size: 19px;
  font-weight: 850;
}

.request-toggle small {
  font-weight: 700;
}

.request-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: var(--muted);
  background:
    linear-gradient(90deg, rgba(55, 213, 237, .72), rgba(255, 94, 184, .52), transparent) top / 100% 2px no-repeat,
    rgba(255, 255, 255, .42);
}

.request-summary span {
  flex: 0 0 auto;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, .78);
  font-size: 12px;
  font-weight: 800;
}

.request-summary p {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.6;
}

.request-accordion .request-form {
  padding: 14px 16px;
}

.compact-dm-card {
  position: relative;
  top: auto;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  grid-template-areas:
    "icon title action"
    "icon body action"
    "id id id";
  gap: 10px 12px;
  align-items: center;
  align-content: start;
  padding: 18px;
}

.compact-dm-card .dm-icon {
  grid-area: icon;
  width: 48px;
  height: 48px;
  margin: 0;
  border-radius: 16px;
  font-size: 23px;
}

.compact-dm-card h2 {
  grid-area: title;
  align-self: center;
  margin: 0;
  font-size: 19px;
}

.compact-dm-card > p:not(.dm-id) {
  grid-area: body;
  margin: 2px 0;
  font-weight: 700;
}

.compact-dm-card > button {
  grid-area: action;
  width: auto;
}

.compact-dm-card .dm-id {
  grid-area: id;
  margin: 0;
  text-align: center;
}

.setup-steps {
  margin: var(--portal-gap) 0;
  padding: 16px;
}

.setup-head {
  margin-bottom: 12px;
}

.setup-head h2 {
  font-size: clamp(24px, 3vw, 32px);
}

.step-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--portal-card-gap);
}

.step-card {
  min-height: 0;
  min-width: 0;
  padding: 14px 12px;
  border-radius: var(--portal-radius-md);
  box-shadow: 0 10px 28px rgba(92, 160, 210, .1);
}

.step-number {
  width: 32px;
  height: 32px;
  margin-bottom: 8px;
  font-size: 16px;
}

.step-card h3 {
  margin-bottom: 8px;
  font-size: 16px;
}

.step-card p {
  margin-bottom: 8px;
  line-height: 1.5;
}

.setup-note {
  margin-top: 12px;
}

.step-card:not(:last-child)::after { display: none; }
.step-tag { padding: 4px 8px; }
.setup-badge { margin-bottom: 8px; }

.home-feed {
  gap: var(--portal-gap);
}

.plugin-header {
  margin-bottom: var(--portal-gap);
}

.plugin-list {
  gap: var(--portal-card-gap);
}

.plugin-row,
.plugin-card,
.backup-panel,
.account-panel {
  border-radius: var(--portal-radius-md);
  box-shadow: var(--portal-shadow);
}

.backup-panel,
.account-panel {
  padding: 16px;
}

.section-title {
  margin-top: 14px;
}

.page > .page-lead:first-child {
  margin-bottom: 16px;
}

@media (max-width: 1180px) {
  .dashboard-workspace,
  .split-page.active {
    grid-template-columns: 1fr;
  }

  .dashboard-workspace .admin-panel {
    height: auto;
  }

}

@media (max-width: 1100px) {
  .customers-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

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

  .admin-sidebar,
  .sidebar {
    position: static;
    height: auto;
  }

  .admin-sidebar nav,
  .sidebar nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .sidebar-foot {
    position: static;
    margin-top: 16px;
    text-align: center;
  }

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

@media (max-width: 700px) {
  .customers-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-shell,
  .app-shell {
    width: min(100% - 20px, var(--portal-width));
    padding-top: 10px;
  }

  .admin-sidebar,
  .sidebar,
  .admin-panel,
  .dashboard,
  .setup-steps,
  .account-panel,
  .backup-panel {
    padding: 14px;
  }

  .admin-sidebar nav,
  .sidebar nav,
  .summary-grid,
  .form-grid,
  .create-form,
  .customer-card {
    grid-template-columns: 1fr;
  }

  .customer-primary-action { align-items: stretch; }
  .customer-primary-action button { width: 100%; }
  .customer-detail-grid { grid-template-columns: 1fr; }

  .admin-topbar,
  .topbar {
    position: static;
    min-height: 0;
    align-items: flex-start;
  }

  .summary-grid article {
    min-height: 72px;
  }

  .compact-dm-card {
    grid-template-columns: 48px minmax(0, 1fr);
    grid-template-areas:
      "icon title"
      "body body"
      "action action"
      "id id";
  }

  .compact-dm-card > button {
    width: 100%;
  }

  .request-toggle {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .request-toggle small {
    order: 3;
    width: 100%;
  }

  .request-summary {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 540px) {
  .customers-list { grid-template-columns: minmax(0, 1fr); }
  .step-grid { grid-template-columns: 1fr; }
  .step-card { text-align: left; }
  .step-number { margin-left: 0; }
  .step-card h3 + p::before { left: 0; transform: none; }
  .customer-card .customer-plugins { grid-column: 1 / -1; }
}
