/* ==========================================================
   共通スタイル（回答者画面・管理画面）
   ========================================================== */

:root {
    --color-primary: #1d5a85;
    --color-primary-dark: #154466;
    --color-primary-soft: #e6eff6;
    --color-accent: #d9822b;
    --color-bg: #f3f5f7;
    --color-surface: #ffffff;
    --color-text: #1f2933;
    --color-muted: #5f6b78;
    --color-border: #d8dee4;
    --color-ai: #6b4fbb;
    --color-ai-soft: #f1edfb;
    --color-danger: #b42318;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
    --header-height: 56px;
    --banner-height: 32px;
    --content-width: 760px;
    --admin-width: 1180px;
    font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.7;
    -webkit-text-size-adjust: 100%;
}

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

[hidden] {
    display: none !important;
}

.mock-banner {
    height: var(--banner-height);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    background: #fff4e5;
    color: #8a4b00;
    font-size: 12px;
    border-bottom: 1px solid #f3d9b1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-header {
    height: var(--header-height);
    background: var(--color-primary);
    color: #fff;
}

.app-header__inner {
    max-width: var(--content-width);
    height: 100%;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.page-admin .app-header__inner {
    max-width: var(--admin-width);
}

.app-header__brand {
    color: #fff;
    font-weight: 700;
    font-size: 17px;
    text-decoration: none;
    letter-spacing: 0.02em;
}

.app-header__link {
    color: #fff;
    font-size: 13px;
    opacity: 0.85;
}

.app-header__actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.app-header__button {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 999px;
    padding: 2px 12px;
    color: #fff;
    font-size: 13px;
    cursor: pointer;
}

.login-form {
    max-width: 380px;
    margin: 48px auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-form__title {
    margin: 0;
    font-size: 20px;
}

.login-form__error {
    margin: 0;
    color: var(--color-danger);
    font-size: 14px;
}

.app-main {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 0 16px;
}

/* ---------- ボタン ---------- */

.btn-primary,
.btn-secondary,
.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 8px 20px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s, opacity 0.15s;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border: 1px solid var(--color-primary);
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-dark);
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-primary);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-primary-soft);
}

.btn-danger {
    background: var(--color-surface);
    color: var(--color-danger);
    border: 1px solid #f0c4c0;
}

.btn-text {
    background: none;
    border: none;
    padding: 4px 0;
    color: var(--color-primary);
    font-size: 14px;
    cursor: pointer;
}

/* ==========================================================
   回答者画面：テーマ選択
   ========================================================== */

.hero {
    padding: 36px 0 12px;
}

.hero__title {
    margin: 0 0 12px;
    font-size: clamp(24px, 6vw, 32px);
    line-height: 1.4;
    color: var(--color-primary-dark);
}

.hero__lead {
    margin: 0 0 16px;
    color: var(--color-muted);
}

.hero__points {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.hero__points li {
    padding: 2px 12px;
    border-radius: 999px;
    background: var(--color-primary-soft);
    color: var(--color-primary-dark);
    font-size: 13px;
}

.section-title {
    margin: 28px 0 12px;
    font-size: 16px;
    color: var(--color-muted);
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 12px;
    padding-bottom: 48px;
}

.theme-card {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 18px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s;
}

.theme-card:hover {
    border-color: var(--color-primary);
    transform: translateY(-1px);
}

.theme-card:focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 2px;
}

.theme-card__icon {
    flex: 0 0 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-md);
    background: var(--color-primary-soft);
    font-size: 26px;
}

.theme-card__body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.theme-card__title {
    font-weight: 700;
    font-size: 17px;
}

.theme-card__summary {
    color: var(--color-muted);
    font-size: 13px;
}

.theme-card__arrow {
    color: var(--color-primary);
    font-weight: 700;
}

.top-footer {
    margin: 0;
    padding-bottom: 48px;
    font-size: 13px;
    text-align: center;
}

.top-footer a {
    color: var(--color-muted);
}

/* ---------- 静的な説明ページ（プライバシーポリシー等） ---------- */

.doc {
    max-width: var(--content-width);
    margin: 0 auto;
    padding: 24px 16px 64px;
}

.doc h1 {
    font-size: 24px;
    color: var(--color-primary-dark);
}

.doc h2 {
    margin-top: 32px;
    font-size: 18px;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 4px;
}

.doc .draft-note {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    background: #fff4e5;
    color: #8a4b00;
    font-size: 14px;
}

/* ==========================================================
   回答者画面：チャット
   ========================================================== */

.page-respondent.is-chatting .app-main {
    padding: 0;
}

.view-chat {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - var(--header-height) - var(--banner-height));
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--color-border);
}

.chat-header__title {
    font-weight: 700;
}

.progress {
    height: 4px;
    background: var(--color-primary-soft);
}

.progress__bar {
    width: 0;
    height: 100%;
    background: var(--color-accent);
    transition: width 0.3s ease;
}

.chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
}

.msg--bot,
.msg--ai {
    align-self: flex-start;
}

.msg--user {
    align-self: flex-end;
    align-items: flex-end;
}

.msg__label {
    margin: 0 0 2px 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--color-ai);
}

.msg__bubble {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 15px;
}

.msg--bot .msg__bubble {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-top-left-radius: var(--radius-sm);
}

.msg--ai .msg__bubble {
    background: var(--color-ai-soft);
    border: 1px solid #d9cff5;
    border-top-left-radius: var(--radius-sm);
}

.msg--user .msg__bubble {
    background: var(--color-primary);
    color: #fff;
    border-top-right-radius: var(--radius-sm);
}

.msg--typing .msg__bubble {
    display: flex;
    gap: 4px;
    padding: 14px 16px;
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-muted);
    opacity: 0.4;
    animation: typing 1s infinite ease-in-out;
}

.dot:nth-child(2) {
    animation-delay: 0.15s;
}

.dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes typing {
    0%, 100% { opacity: 0.25; transform: translateY(0); }
    50% { opacity: 0.9; transform: translateY(-3px); }
}

.summary-list {
    margin: 8px 0 0;
    white-space: normal;
}

.summary-list dt {
    margin-top: 8px;
    font-size: 12px;
    color: var(--color-muted);
}

.summary-list dd {
    margin: 0;
    font-weight: 600;
    white-space: pre-wrap;
}

/* ---------- 入力エリア ---------- */

.chat-input {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
}

.chat-input:empty {
    display: none;
}

.input-hint {
    margin: 0 0 8px;
    font-size: 12px;
    color: var(--color-muted);
}

.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.quick-replies:last-child {
    margin-bottom: 0;
}

.chip {
    min-height: 40px;
    padding: 6px 16px;
    border: 1px solid var(--color-primary);
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--color-primary);
    font-size: 14px;
    cursor: pointer;
}

.chip:hover:not(:disabled) {
    background: var(--color-primary-soft);
}

.chip--toggle[aria-pressed="true"],
.chip--toggle[aria-pressed="true"]:hover:not(:disabled) {
    background: var(--color-primary);
    color: #fff;
}

.chip:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.text-form__area {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    resize: vertical;
    min-height: 80px;
    font-size: 16px;
}

.text-form__area:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 0;
    border-color: transparent;
}

.text-form__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
}

.text-form__count {
    font-size: 12px;
    color: var(--color-muted);
}

.text-form__actions {
    display: flex;
    gap: 8px;
}

.end-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* ==========================================================
   管理画面
   ========================================================== */

.page-admin .app-main {
    max-width: var(--admin-width);
    padding-bottom: 48px;
}

.admin-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin: 24px 0 16px;
}

.admin-title h1 {
    margin: 0;
    font-size: 22px;
}

.admin-title p {
    margin: 0;
    font-size: 13px;
    color: var(--color-muted);
}

.panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    margin-bottom: 16px;
}

.panel__title {
    margin: 0 0 12px;
    font-size: 15px;
}

.panel__title--inline {
    margin: 0;
}

.panel--spaced {
    margin-top: 16px;
}

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    align-items: end;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--color-muted);
}

.field select,
.field input {
    min-height: 40px;
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    font-size: 14px;
    color: var(--color-text);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 14px 18px;
}

.stat__label {
    font-size: 12px;
    color: var(--color-muted);
}

.stat__value {
    font-size: 28px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.3;
}

.stat__unit {
    margin-left: 2px;
    font-size: 14px;
    font-weight: 400;
    color: var(--color-muted);
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px;
}

.chart-grid .panel {
    margin-bottom: 0;
}

.chart-note {
    margin: -8px 0 12px;
    font-size: 12px;
    color: var(--color-muted);
}

.bar-row {
    display: grid;
    grid-template-columns: minmax(90px, 38%) 1fr 64px;
    align-items: center;
    gap: 10px;
    padding: 3px 0;
    font-size: 13px;
}

.bar-row__label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-row__track {
    height: 14px;
    border-radius: 3px;
    background: var(--color-primary-soft);
    overflow: hidden;
}

.bar-row__fill {
    display: block;
    height: 100%;
    background: var(--color-primary);
    border-radius: 3px;
}

.bar-row__value {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--color-muted);
}

.empty {
    margin: 0;
    padding: 16px 0;
    color: var(--color-muted);
    font-size: 14px;
    text-align: center;
}

.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.table-toolbar__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

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

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

.data-table th,
.data-table td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    vertical-align: top;
}

.data-table th {
    background: var(--color-bg);
    font-weight: 600;
    color: var(--color-muted);
    white-space: nowrap;
}

.data-table td.nowrap {
    white-space: nowrap;
}

.data-table .excerpt {
    max-width: 420px;
    color: var(--color-text);
}

.badge {
    display: inline-block;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge--mock {
    background: #eef0f2;
    color: var(--color-muted);
}

.badge--api,
.badge--local {
    background: #e3f4ea;
    color: #1b6b3a;
}

/* ---------- 詳細ダイアログ ---------- */

.detail-dialog {
    width: min(720px, calc(100vw - 32px));
    max-height: calc(100dvh - 48px);
    padding: 0;
    border: none;
    border-radius: var(--radius-md);
    box-shadow: 0 20px 40px rgba(16, 24, 40, 0.25);
}

.detail-dialog::backdrop {
    background: rgba(16, 24, 40, 0.45);
}

.detail-dialog__header {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.detail-dialog__header h2 {
    margin: 0;
    font-size: 16px;
}

.detail-dialog__body {
    padding: 16px 20px 24px;
}

.detail-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 16px;
    margin: 0 0 16px;
    font-size: 14px;
}

.detail-meta dt {
    color: var(--color-muted);
}

.detail-meta dd {
    margin: 0;
}

.detail-log {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    border-radius: var(--radius-md);
    background: var(--color-bg);
}

/* ---------- スマホ表示の調整 ---------- */

@media (max-width: 480px) {
    .theme-grid {
        grid-template-columns: 1fr;
    }

    .chart-grid {
        grid-template-columns: 1fr;
    }

    .msg {
        max-width: 92%;
    }

    .text-form__footer {
        flex-direction: column;
        align-items: stretch;
    }

    .text-form__actions {
        justify-content: flex-end;
    }
}
