:root {
  --ink: #172127;
  --muted: #66757d;
  --line: #dce4e7;
  --paper: #fff;
  --background: #f2f6f5;
  --primary: #087b69;
  --primary-dark: #055e51;
  --danger: #b83b45;
  --warning: #9a6211;
  font-family: Inter, "Noto Sans JP", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--background); }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; }
button { border: 0; border-radius: 8px; padding: 10px 15px; color: #fff; background: var(--primary); cursor: pointer; font-weight: 800; }
button:hover { background: var(--primary-dark); }
button:disabled { cursor: not-allowed; opacity: .45; }
button.danger { color: var(--danger); background: #fae9eb; }
label { display: grid; gap: 6px; color: #4e5c63; font-size: 12px; font-weight: 750; }
input, select, textarea { width: 100%; border: 1px solid #c8d3d7; border-radius: 7px; padding: 9px 10px; color: var(--ink); background: #fff; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(8, 123, 105, .14); border-color: var(--primary); }

.site-header { display: flex; align-items: center; justify-content: space-between; gap: 25px; min-height: 74px; padding: 13px clamp(18px, 5vw, 72px); color: #fff; background: linear-gradient(120deg, #093d3a, #087b69); }
.brand { display: grid; color: #fff; text-decoration: none; }
.brand span { font-size: 26px; font-weight: 950; letter-spacing: .08em; }
.brand small { opacity: .7; font-size: 9px; letter-spacing: .15em; }
.account-nav { display: flex; align-items: center; gap: 15px; }
.account-nav > span { display: grid; padding-right: 8px; text-align: right; }
.account-nav small { opacity: .7; }
.account-nav a, .link-button { padding: 4px 0; color: #fff; background: none; font-size: 13px; font-weight: 750; text-decoration: none; }
.account-nav a:hover, .link-button:hover { color: #fff; background: none; text-decoration: underline; }
.account-nav form { margin: 0; }

.flash-stack { position: relative; z-index: 10; display: grid; gap: 6px; width: min(1100px, calc(100% - 32px)); margin: 14px auto -2px; }
.flash { margin: 0; border-left: 4px solid var(--primary); border-radius: 8px; padding: 11px 14px; background: #e4f3ef; font-size: 13px; }
.flash.error { border-color: var(--danger); background: #fae9eb; }
.flash.warning { border-color: var(--warning); background: #fff3d7; }
.flash.token { border-color: var(--warning); background: #fffaf0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.8; word-break: break-all; user-select: all; }

.auth-shell { display: grid; min-height: calc(100vh - 74px); place-items: center; padding: 30px 16px; }
.auth-card { width: min(460px, 100%); border: 1px solid var(--line); border-radius: 16px; padding: clamp(24px, 5vw, 42px); background: var(--paper); box-shadow: 0 16px 50px rgba(17, 49, 48, .1); }
.eyebrow { margin: 0 0 7px; color: var(--primary); font-size: 11px; font-weight: 900; letter-spacing: .18em; }
h1, h2, h3, p { margin-top: 0; }
.auth-card h1 { margin-bottom: 10px; }
.lead { color: var(--muted); line-height: 1.65; }
.warning-text { color: var(--warning); font-weight: 750; }
.stack-form { display: grid; gap: 16px; margin-top: 24px; }
.stack-form button { margin-top: 4px; padding: 12px; }
.security-note { margin: 18px 0 0; color: var(--muted); font-size: 11px; text-align: center; }

.admin-shell { display: grid; gap: 20px; width: min(1500px, calc(100% - 32px)); margin: 24px auto 70px; }
.page-heading, .admin-section { border: 1px solid var(--line); border-radius: 14px; padding: 22px; background: var(--paper); box-shadow: 0 4px 18px rgba(20, 52, 55, .05); }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 25px; }
.page-heading h1 { margin-bottom: 6px; }
.page-heading p:last-child { margin-bottom: 0; color: var(--muted); }
.page-heading .current-group { margin-top: 10px; color: var(--primary); font-size: 12px; }
.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(90px, 1fr)); gap: 8px; }
.summary-grid div { display: grid; border-radius: 10px; padding: 12px; background: #eaf4f1; text-align: center; }
.summary-grid strong { color: var(--primary); font-size: 24px; }
.summary-grid span { color: var(--muted); font-size: 11px; }
.section-heading, .subheading, .card-heading, .card-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-heading { margin-bottom: 18px; }
.section-heading > div { display: flex; align-items: center; gap: 10px; }
.section-heading > div > span { display: grid; width: 31px; height: 31px; place-items: center; border-radius: 50%; color: var(--primary); background: #dff2ed; font-size: 12px; font-weight: 900; }
.section-heading small { color: var(--muted); }
.create-form { display: grid; gap: 10px; border: 1px dashed #a9c4bd; border-radius: 11px; padding: 14px; background: #f8fbfa; }
.group-create { grid-template-columns: 1fr 2fr 1fr auto; align-items: end; }
.user-create { grid-template-columns: 1fr 1.3fr 1fr 1.5fr .8fr 1.4fr auto; align-items: end; }
.group-grid, .user-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; margin-top: 16px; }
.management-card, .user-card { border: 1px solid var(--line); border-radius: 11px; padding: 15px; background: #fbfcfc; }
.management-card.selected { border-color: var(--primary); box-shadow: inset 3px 0 var(--primary); }
.management-card.inactive, .user-card.inactive { background: #f4f4f4; }
.card-heading > div { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 8px; }
.card-heading > div .status-dot { grid-row: 1 / 3; width: 9px; height: 9px; border-radius: 50%; background: #28a276; }
.inactive .status-dot { background: #9ca5aa; }
.card-heading small { color: var(--muted); }
.status-badge { border-radius: 999px; padding: 4px 9px; color: #12654f; background: #dff2e9; font-size: 11px; font-weight: 850; }
.status-badge.inactive { color: #626c72; background: #e6e8e9; }
.member-count { margin: 12px 0 7px; color: var(--primary); font-size: 12px; font-weight: 850; }
.member-chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 31px; margin-bottom: 13px; }
.member-chips span { display: grid; border-radius: 7px; padding: 5px 8px; background: #edf3f1; font-size: 12px; }
.member-chips small { color: var(--muted); font-size: 9px; }
.member-chips em, .empty-state { color: var(--muted); font-size: 12px; }
.inline-edit { display: grid; grid-template-columns: 2fr 1fr auto; align-items: end; gap: 8px; }
.card-actions { justify-content: flex-end; margin-top: 10px; }
.card-actions form { margin: 0; }
.token-block { margin-top: 10px; border: 1px dashed var(--line); border-radius: 9px; padding: 10px 12px; background: #fdfdfb; display: grid; gap: 6px; }
.token-block .token-title { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 12px; color: #5d6b68; }
.token-block code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; }
.token-block .token-value { border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fffdf5; user-select: all; }
.token-block .token-meta { margin: 0; font-size: 11.5px; color: #6f7c79; }
.token-block form { margin: 0; justify-self: start; }
.member-group { margin-top: 24px; }
.subheading { border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.subheading h3 { margin: 0; }
.subheading span { color: var(--muted); font-size: 12px; }
.user-edit { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 13px; }
.user-edit .wide, .user-edit button { grid-column: 1 / -1; }
.delete-form { display: flex; justify-content: flex-end; margin-top: 8px; }
.device-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.device-card { display: grid; gap: 13px; }
.device-details { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px 14px; margin: 0; }
.device-details div { min-width: 0; border-bottom: 1px solid var(--line); padding-bottom: 5px; }
.device-details dt { color: var(--muted); font-size: 10px; font-weight: 800; }
.device-details dd { overflow-wrap: anywhere; margin: 2px 0 0; font-size: 12px; }
.presence-online { color: #12654f; background: #dff2e9; }
.presence-stale { color: #80500b; background: #fff0c8; }
.presence-offline, .presence-never_seen, .presence-disabled { color: #626c72; background: #e6e8e9; }
.mission-counts { display: flex; flex-wrap: wrap; gap: 5px; margin: 0; }
.mission-counts span { border-radius: 999px; padding: 4px 8px; color: var(--primary); background: #edf4f2; font-size: 10px; font-weight: 800; }
.mission-counts em { color: var(--muted); font-size: 11px; }
.notify-form { display: grid; grid-template-columns: .6fr 1fr 2fr auto; align-items: end; gap: 8px; }
.device-status-form { display: flex; justify-content: flex-end; margin: 0; }
.content-create { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; align-items: end; }
.content-create .wide { grid-column: 1 / -1; }
.content-create .span-2 { grid-column: span 2; }
.checkbox-label { display: flex; align-items: center; gap: 8px; min-height: 38px; }
.checkbox-label input { width: auto; }
.content-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.content-card { display: grid; gap: 12px; }
.content-card p { margin: 0; color: var(--muted); line-height: 1.6; }
.moderation-actions { display: flex; justify-content: flex-end; gap: 8px; }
.participant-table { overflow-x: auto; }
.participant-table table { width: 100%; border-collapse: collapse; font-size: 12px; }
.participant-table th, .participant-table td { border-bottom: 1px solid var(--line); padding: 10px; text-align: left; }
.participant-table th { color: var(--muted); background: #f7faf9; }

@media (max-width: 1180px) {
  .user-create { grid-template-columns: repeat(3, 1fr); }
  .user-create button { align-self: end; }
}
@media (max-width: 800px) {
  .site-header, .page-heading, .section-heading { align-items: stretch; flex-direction: column; }
  .account-nav { flex-wrap: wrap; }
  .account-nav > span { width: 100%; text-align: left; }
  .group-create, .user-create, .group-grid, .user-grid, .device-grid, .notify-form, .content-create, .content-grid { grid-template-columns: 1fr; }
  .content-create .wide, .content-create .span-2 { grid-column: auto; }
  .summary-grid { width: 100%; }
}
