:root {
    --bg: #f5f8fb;
    /* 淡い色調に変更 */
    --panel: #ffffff;
    --text: #0f172a;
    --muted: #475569;
    --line: #cbd5e1;
    --accent: #2c5282;
    /* アクセントも少し青系統に */
    --accent-soft: #e2e8f0;
}

* {
    box-sizing: border-box;
}

body.admin-page {
    margin: 0;
    font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
    color: var(--text);
    background: var(--bg);
    display: block;
    /* styles.cssのflexを上書き */
}

/* styles.cssのbody paddingを上書きするため強めに設定 */
body.admin-page {
    padding: 0 !important;
    min-height: 100vh;
}

.container {
    width: 98vw;
    max-width: none;
    margin: 24px auto 40px;
}

h1,
h2,
h3,
p {
    margin: 0;
}

.headline {
    margin-bottom: 18px;
}

.headline h1 {
    font-size: 28px;
}

.headline p {
    margin-top: 6px;
    color: var(--muted);
}

.auth-status {
    margin-top: 8px;
    display: inline-block;
    padding: 4px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #f8fafc;
    color: #334155;
    font-size: 12px;
}

.top-control {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.auth-status-top {
    margin-top: 0;
    min-width: 190px;
    max-width: 260px;
    white-space: pre-line;
    line-height: 1.25;
}

.auth-status-top.success {
    border-color: #86efac;
    background: #f0fdf4;
    color: #166534;
}

.auth-status-top.error {
    border-color: #fecaca;
    background: #fef2f2;
    color: #b91c1c;
}

.account-menu-wrap {
    position: relative;
}

.account-menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    max-width: 320px;
    padding: 8px 12px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #0f172a;
    border-radius: 999px;
}

.account-menu-btn:hover {
    opacity: 1;
    background: #f8fafc;
}

.account-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.account-email {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 600;
}

.account-menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 180px;
    padding: 8px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 16px 32px rgba(15, 23, 42, 0.12);
    z-index: 20;
    display: grid;
    gap: 4px;
}

.account-menu-item {
    display: block;
    width: 100%;
    padding: 10px 12px;
    text-align: left;
    border: none;
    background: transparent;
    color: #0f172a;
    border-radius: 8px;
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
}

.account-menu-item:hover {
    background: #f8fafc;
    opacity: 1;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    /* 少し立体感を追加 */
    border-radius: 8px;
    /* 丸みを追加 */
    overflow: hidden;
    /* 角丸のため */
}

.stack {
    display: grid;
    gap: 16px;
}

button {
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    border-radius: 4px;
    transition: opacity 0.2s;
}

button:hover {
    opacity: 0.9;
}

button.secondary {
    background: #fff;
    color: var(--accent);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.notice {
    padding: 10px 12px;
    border: 1px solid var(--line);
    background: #f8fafc;
    color: var(--muted);
    font-size: 14px;
    border-radius: 4px;
}

.error {
    color: #b91c1c;
}

.success {
    color: #166534;
}

.hidden {
    display: none !important;
}

.sheet-ui {
    border: 1px solid var(--line);
    background: #fff;
}

.sheet-row {
    display: grid;
    grid-template-columns: 110px 1fr;
    border-bottom: 1px solid var(--line);
}

.sheet-row:last-child {
    border-bottom: none;
}

.sheet-label {
    background: #f8fafc;
    padding: 12px;
    border-right: 1px solid var(--line);
    font-weight: 700;
    font-size: 14px;
}

.sheet-value {
    padding: 10px;
    overflow: hidden;
    /* コンテナをはみ出さないように */
}

.title-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.title-work-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    padding: 4px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.title-work-status.editing {
    background: #fef3c7;
    border-color: #fbbf24;
    color: #92400e;
}

.title-work-status.saved {
    background: #ecfdf5;
    border-color: #86efac;
    color: #166534;
}

.title-work-note {
    color: #64748b;
    font-size: 12px;
}

.sheet-ui input[type="text"],
.sheet-ui select,
.sheet-ui textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: transparent;
    border-radius: 4px;
    box-shadow: none;
    padding: 8px;
    font: inherit;
}

.sheet-grid {
    width: 100%;
    border-collapse: collapse;
    /* セルの隙間を無くす */
}

.sheet-grid th,
.sheet-grid td {
    border: 1px solid var(--line);
    /* 境界線のみにする */
    vertical-align: top;
    padding: 0;
    font-size: 14px;
    height: 1px;
    /* TRICK: allows percentage height on children in table layout */
}

.sheet-grid th {
    background: #f8fafc;
    text-align: center;
    vertical-align: middle;
    /* Centered headers as requested */
    height: 40px;
}

.th-resizer {
    resize: horizontal;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    min-width: 100%;
    box-sizing: border-box;
    padding: 0 4px;
}

/* Allow resizing row height via the first column (#) */
.sheet-grid td:first-child {
    resize: vertical;
    overflow: hidden;
    height: auto;
    /* override 1px height */
    padding: 8px;
    /* give number some breathing room */
    text-align: center;
    vertical-align: middle;
}

.sheet-grid tbody td {
    background: #fff;
    padding: 0;
}

.td-center {
    vertical-align: middle !important;
    text-align: center !important;
    padding: 4px !important;
}

.sheet-grid tbody tr:hover td {
    background: #f8fafc;
}

.sheet-grid-wrap {
    width: 100%;
    overflow-x: auto;
    /* 横スクロールを許可 */
    border: 1px solid var(--line);

    /* Force scrollbar visibility on macOS/iOS */
    -webkit-overflow-scrolling: touch;
}

/* Custom Webkit Scrollbar to ensure it's always visible */
.sheet-grid-wrap::-webkit-scrollbar {
    -webkit-appearance: none;
    height: 10px;
}

.sheet-grid-wrap::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    border: 2px solid #fff;
}

.sheet-grid-wrap::-webkit-scrollbar-track {
    background-color: #f1f1f1;
    border-radius: 8px;
}

/* V2は13項目に増えたため、全体の最小幅をさらに広くする（横スクロール前提） */
.admin-sheet-grid {
    min-width: 1500px;
}

/* 左端の番号、設問列を固定したい場合の設定 */
.admin-sheet-grid thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    /* Use the same background as other headers */
    background: #f8fafc;
}

.sheet-grid input[type="text"],
.sheet-grid select,
.sheet-grid textarea {
    width: 100%;
    height: 100%;
    /* Fill the entire cell exactly */
    box-sizing: border-box;
    border: none;
    /* Remove border entirely to rely on TD border */
    padding: 6px;
    background: transparent;
    font-size: 13px;
    font-family: inherit;
    display: block;
    resize: none;
    overflow: auto;
}

/* Specific to textareas so they have a baseline height */
.sheet-grid textarea {
    min-height: 48px;
    white-space: pre-wrap;
}

.sheet-grid input:focus,
.sheet-grid select:focus,
.sheet-grid textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    /* Inner outline like Excel */
    background: #fff;
    z-index: 10;
    position: relative;
}

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

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

.admin-actions {
    align-items: center;
}

.list-table {
    width: 100%;
    border-collapse: collapse;
}

.list-table th,
.list-table td {
    border: 1px solid var(--line);
    padding: 8px 10px;
    text-align: left;
}

.list-table th {
    background: #f8fafc;
    text-align: center;
    font-weight: bold;
}

.list-table .actions {
    flex-wrap: nowrap;
}

.admin-page .list-table .actions button {
    flex: 0 1 auto !important;
    white-space: nowrap;
}

.admin-list-wrap {
    width: 100%;
    overflow-x: auto;
}

.admin-list-wrap .list-table {
    min-width: 760px;
}

.admin-page .sheet-label {
    min-width: 110px;
}

.admin-page .remove-row {
    min-width: 34px;
    padding: 6px 8px;
    font-weight: 700;
    background: #fee2e2;
    color: #b91c1c;
    border-color: #fca5a5;
}

.admin-page .remove-row:hover {
    background: #fecaca;
}

.qr-box {
    display: grid;
    gap: 10px;
    align-items: start;
}

.qr-result-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.qr-box img {
    width: 180px;
    height: 180px;
    border: 1px solid var(--line);
    background: white;
}

.qr-result-row #copyQrBtn {
    align-self: center;
}

@media (max-width: 900px) {
    .top-control {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .auth-status-top {
        max-width: 100%;
    }

    .sheet-row {
        grid-template-columns: 1fr;
    }

    .sheet-label {
        border-right: none;
        border-bottom: 1px solid var(--line);
    }

    .container {
        width: min(100%, 96vw);
    }

    .admin-page .sheet-value {
        padding: 8px;
    }

    .admin-page .actions button {
        flex: 1 1 48%;
    }
}

@media (max-width: 640px) {
    .headline h1 {
        font-size: 24px;
    }

    .list-table th:nth-child(3),
    .list-table td:nth-child(3) {
        display: none;
    }

    .admin-page .actions button {
        flex: 1 1 100%;
    }
}

/* AI Image Generation Styles */
.image-cell-wrap {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 100%;
    padding: 4px;
    box-sizing: border-box;
}

.image-preview-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-preview {
    width: 60px;
    height: 45px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    transition: filter 0.2s;
}

.image-preview:hover {
    filter: brightness(0.9);
}

.clear-image-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #e74c3c;
    color: white;
    border: 2px solid white;
    font-size: 12px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.clear-image-btn:hover {
    background: #c0392b;
}

.ai-image-btn,
.upload-image-btn {
    padding: 4px 6px;
    font-size: 11px;
    writing-mode: vertical-rl;
    text-orientation: upright;
    letter-spacing: 2px;
    border-radius: 4px;
    line-height: 1.2;
    min-height: 54px;
}

.image-upload-input {
    display: none !important;
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
}

/* Image Modal Styles */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active {
    display: flex;
}

.image-modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.image-modal-content img {
    max-width: 600px;
    max-height: 80vh;
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
    background: #fff;
    object-fit: contain;
}

.image-modal-actions {
    margin-top: 12px;
    display: flex;
    justify-content: center;
}

.modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    color: white;
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
    user-select: none;
}

.modal-close:hover {
    color: #ccc;
}

/* Custom Prompt Modal Styles */
.prompt-modal-content {
    background: #fff;
    padding: 24px;
    border-radius: 12px;
    width: 90%;
    max-width: 440px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    gap: 16px;
    position: relative;
    cursor: default;
}

.prompt-modal-content h3 {
    margin: 0;
    font-size: 1.25rem;
    color: #1e293b;
}

.prompt-modal-content p {
    margin: 0;
    font-size: 0.95rem;
    color: #475569;
    line-height: 1.5;
}

.prompt-modal-content textarea {
    width: 100%;
    resize: vertical;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    box-sizing: border-box;
}

.prompt-modal-content textarea:focus {
    outline: 2px solid var(--accent);
    border-color: transparent;
}

.prompt-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 8px;
}

.prompt-modal-actions button {
    padding: 8px 24px;
    font-size: 14px;
    flex: 0 1 auto;
}

.prompt-config-help {
    margin: 0;
    color: #475569;
    font-size: 13px;
}

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

.prompt-config-quickrow select {
    min-width: 240px;
}

.prompt-config-editor {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px;
    background: #f8fafc;
}

.prompt-config-editor-title {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    color: #334155;
}

.prompt-config-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.prompt-config-toolbar label {
    font-size: 13px;
    color: #334155;
    font-weight: 700;
}

.prompt-config-yaml {
    width: 100%;
    min-height: 360px;
    font-family: "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px;
    background: #f8fafc;
}
