:root {
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-primary-soft: #eff6ff;
}

body {
    margin: 0;
    background: #f3f5f7;
    font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
        "Yu Gothic", sans-serif;
    color: #222;
}

.container {
    width: 90%;
    max-width: 850px;
    margin: 40px auto;
}

.header {
    text-align: center;
    margin-bottom: 30px;
}

.header h1 {
    margin: 0;
    font-size: 42px;
}

.header p {
    color: #666;
    margin-top: 10px;
}

.search-area {
    margin-bottom: 25px;
}

.search-row {
    display: flex;
    gap: 10px;
}

.search-row input {
    flex: 1;
    font-size: 18px;
    padding: 14px;
    border-radius: 10px;
    border: 1px solid #ccc;
}

.add-button {
    width: 60px;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    border-radius: 10px;
    background: var(--color-primary);
    color: white;
    text-decoration: none;
}

.panel {
    background: white;
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.panel h2 {
    margin-top: 0;
    font-size: 20px;
}

.empty-text {
    color: #777;
}

.memory-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.memory-item {
    display: block;
    margin-bottom: 12px;
    padding: 14px;
    border-radius: 10px;
    background: #f8fafc;
    color: inherit;
    text-decoration: none;
    border: 1px solid #e1e5ea;
}

.memory-separator {
    display: none;
}

.memory-item:hover,
.memory-item:focus-visible {
    border-color: #93b4f5;
    background: var(--color-primary-soft);
    outline: none;
}

.memory-item:focus-visible {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .24);
}

.memory-title {
    color: var(--color-primary);
    text-decoration: underline;
    font-weight: bold;
    font-size: 18px;
    margin-bottom: 6px;
}

.memory-preview {
    color: #555;
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 8px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
}

.memory-preview--list {
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

.memory-preview--search {
    -webkit-line-clamp: 3;
    line-clamp: 3;
}

.search-list-toggle {
    margin-top: 22px;
    text-align: center;
}

.search-list-toggle--top {
    margin: 0 0 16px;
    text-align: left;
}

.search-sort-control {
    margin: -4px 0 16px;
    color: #52606d;
    font-size: 14px;
}

.search-sort-control strong {
    color: #1d4ed8;
}

.search-match-reason {
    color: #666;
    font-size: 13px;
    margin-bottom: 3px;
}

mark.search-match {
    padding: 0 .08em;
    border-radius: 2px;
    background: #fff09a;
    color: inherit;
}

.memory-date {
    color: #888;
    font-size: 13px;
}

.raw-content {
    white-space: pre-wrap;
    background: #f8fafc;
    border: 1px solid #e1e5ea;
    border-radius: 8px;
    padding: 14px;
    line-height: 1.7;
}

.status-bar {
    background: white;
    border-radius: 12px;
    padding: 14px 18px;
    margin-bottom: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bottom-links {
    display: flex;
    justify-content: space-between;
    margin-top: 24px;
}

.bottom-links a,
.container > p a {
    color: var(--color-primary);
    text-decoration: none;
}

.knowledge-form {
    background: white;
    border-radius: 12px;
    padding: 22px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
}

.knowledge-form label {
    display: block;
    margin-bottom: 18px;
    font-weight: bold;
}

.edit-input-guidance {
    padding-bottom: 16px;
}

.input-safety-note {
    margin: 0;
    color: #52606d;
    font-size: 14px;
    line-height: 1.45;
}

.knowledge-form input,
.knowledge-form textarea {
    width: 100%;
    box-sizing: border-box;
    margin-top: 8px;
    padding: 12px;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 8px;
}

.knowledge-form textarea {
    min-height: 220px;
    resize: vertical;
}

.knowledge-form .edit-memory-content {
    /* Desktop uses a stable, generous writing area.  Touch-device sizing is
       applied below so it cannot reduce the Mac layout. */
    height: 500px;
    min-height: 500px;
    max-height: 500px;
    margin-bottom: 16px;
    line-height: 1.7;
    overflow-y: auto;
    resize: none;
}

.knowledge-form .edit-memory-content-label {
    margin-bottom: 0;
}

.knowledge-form .new-memory-content {
    /* Desktop uses the full composing area.  Touch-device sizing below keeps
       phone and tablet controls practical without changing this layout. */
    height: 540px;
    min-height: 540px;
    max-height: 540px;
    margin-bottom: 16px;
    line-height: 1.7;
    overflow-y: auto;
    resize: none;
}

.new-memory-save-dock {
    display: flex;
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
    border: 1px solid #dbe4f0;
    border-radius: 12px;
    background: rgba(255, 255, 255, .96);
}

.new-memory-save-dock .save-button {
    flex: 1 1 0;
    width: auto;
}

.new-memory-save-dock .new-memory-cancel {
    display: flex;
    flex: 1 1 0;
    align-items: center;
    justify-content: center;
    min-height: 50px;
    box-sizing: border-box;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid #b8c4d3;
    border-radius: 10px;
    color: #34465a;
    background: #fff;
    font-size: 16px;
    text-decoration: none;
}

.new-memory-save-dock .new-memory-cancel:hover {
    background: #f4f7fa;
}

.knowledge-form .new-memory-content::placeholder {
    color: #8796ab;
    opacity: 1;
}

.save-button {
    width: 100%;
    padding: 14px;
    font-size: 18px;
    border: none;
    border-radius: 10px;
    background: var(--color-primary);
    color: white;
    cursor: pointer;
}

.edit-save-actions {
    display: flex;
    align-items: stretch;
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
    border: 1px solid #dbe4f0;
    border-radius: 12px;
    background: rgba(255, 255, 255, .96);
}

.edit-save-actions .save-button {
    flex: 1 1 0;
    width: auto;
}

.edit-memory-cancel {
    display: flex;
    flex: 1 1 0;
    align-items: center;
    justify-content: center;
    min-height: 50px;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid #b8c4d3;
    border-radius: 10px;
    color: #34465a;
    background: #fff;
    font-size: 16px;
    text-decoration: none;
}

.edit-memory-cancel:hover {
    background: #f4f7fa;
}

.edit-previous-toggle {
    flex: 1 1 0;
    min-width: 0;
    border: 1px solid #9db9e8;
    border-radius: 10px;
    padding: 12px 14px;
    background: #f5f9ff;
    color: #174ea6;
    font: inherit;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

.edit-previous-toggle:hover {
    background: #e8f1ff;
}

.edit-previous-panel {
    margin: 0 0 14px;
    padding: 14px;
    border: 1px solid #d8e3f5;
    border-radius: 10px;
    background: #f8fbff;
}

.edit-previous-panel h2 {
    margin: 0;
    font-size: 16px;
}

.edit-previous-panel p {
    margin: 6px 0 10px;
    color: #52606d;
    font-size: 14px;
}

.edit-previous-panel .raw-content {
    margin: 0;
}

.copy-draft-button {
    width: 100%;
    margin-top: 14px;
    padding: 12px 14px;
    border: 1px solid var(--color-primary);
    border-radius: 10px;
    background: white;
    color: var(--color-primary);
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
}

.copy-draft-button:hover {
    background: #eef4ff;
}

.copy-draft-status {
    min-height: 1.5em;
    margin: 8px 0 0;
    color: #216e39;
    font-size: 14px;
}

.detail-copy-status:empty {
    display: none;
}

.detail-copy-status.copy-success {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.detail-copy-status.copy-error {
    display: block;
    flex-basis: 100%;
    color: #b42318;
}

.route-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.route-form label {
    padding: 12px 14px;
    border: 1px solid #e1e5ea;
    border-radius: 10px;
    background: #f8fafc;
    cursor: pointer;
}

.route-form label:hover {
    background: #eef4ff;
}

.route-form input {
    margin-right: 8px;
}

.route-form .save-button {
    margin-top: 6px;
}

.route-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 18px;
    border: 1px solid #e1e5ea;
    border-radius: 10px;
    margin-bottom: 10px;
    background: #f8fafc;
    color: #222;
    text-decoration: none;
    font-size: 18px;
}

.route-item:hover {
    background: #eef4ff;
}

.route-item.disabled {
    color: #888;
    cursor: default;
}

.draft-item {
    padding: 12px 14px;
    border: 1px solid #e1e5ea;
    border-radius: 10px;
    background: #f8fafc;
    margin-bottom: 10px;
    font-size: 16px;
}

.draft-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.draft-item {
    display: block;
    padding: 12px 14px;
    border: 1px solid #e1e5ea;
    border-radius: 10px;
    background: #f8fafc;
    color: #222;
    text-decoration: none;
}

.draft-item:hover {
    background: #eef4ff;
}

.instruction-textarea {
    width: 100%;
    min-height: 100px;
    box-sizing: border-box;
    padding: 12px;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 8px;
    resize: vertical;
    margin-bottom: 14px;
}

.email-subject-input {
    width: 100%;
    height: 46px;
    box-sizing: border-box;
    padding: 10px 12px;
    font-size: 16px;
    border: 1px solid #ccc;
    border-radius: 8px;
    margin-bottom: 14px;
}

/* =========================
   共通ヘッダー
========================= */

.global-header {
    display: flex;
    align-items: center;
    gap: 12px;

    margin-bottom: 24px;
}

.home-link {
    text-decoration: none;
    font-weight: bold;
    color: #222;

    white-space: nowrap;
}

.global-search {
    flex: 1;

    display: flex;
    gap: 8px;
}

.global-search input {
    flex: 1;

    padding: 10px 14px;

    border: 1px solid #ddd;
    border-radius: 8px;

    font-size: 15px;
}

.global-search button {
    padding: 10px 18px;

    border: none;
    border-radius: 8px;

    background: var(--color-primary);
    color: white;

    font-size: 16px;
    font-weight: 700;
    line-height: 1.25;

    cursor: pointer;
}

.global-search button:hover {
    background: var(--color-primary-hover);
}

.global-add-button {
    width: 42px;
    height: 42px;

    display: flex;
    justify-content: center;
    align-items: center;

    text-decoration: none;

    border-radius: 8px;

    background: var(--color-primary);
    color: white;

    font-size: 28px;
    font-weight: bold;
}












/* =========================
   共通ヘッダー Version 2
========================= */

.global-header {
    display: flex;
    align-items: center;
    gap: 12px;

    margin-bottom: 24px;
}

.global-search {
    flex: 1;
}

.global-search input {
    width: 100%;
    box-sizing: border-box;

    padding: 14px 16px;

    font-size: 16px;

    border: 1px solid #ddd;
    border-radius: 10px;
}

.global-add-button {
    width: 50px;
    height: 50px;

    display: flex;
    justify-content: center;
    align-items: center;

    text-decoration: none;

    border-radius: 10px;

    background: var(--color-primary);
    color: white;

    font-size: 30px;
    font-weight: bold;
}


/* =========================
   詳細画面 操作バー
========================= */

.action-bar {
    display: flex;
    gap: 8px;

    margin: 12px 0 20px;
}

.action-bar a,
.action-bar .detail-utility-button {
    box-sizing: border-box;
    min-height: 40px;
    padding: 8px 12px;

    text-decoration: none;

    border: 1px solid #ddd;
    border-radius: 8px;

    color: #333;
    background: #f8f8f8;

    font: inherit;
    font-size: 14px;
    font-weight: 400;
    cursor: pointer;
}

.action-bar a:hover,
.action-bar .detail-utility-button:hover {
    background: #eeeeee;
}

.action-bar a.danger-link {
    border-color: #d92d20;
    color: #b42318;
}

.action-bar a.danger-link:hover {
    background: #fff1f0;
}

.danger-panel {
    border: 2px solid #d92d20;
}

.danger-panel h1 {
    margin-top: 0;
    color: #b42318;
    font-size: 24px;
}

.delete-memory-title {
    padding: 12px;
    border-radius: 8px;
    background: #fff1f0;
    font-weight: bold;
    overflow-wrap: anywhere;
}

.deletion-summary {
    line-height: 1.8;
}

.delete-confirm-check {
    display: block;
    margin-bottom: 18px;
    line-height: 1.6;
}

.delete-error {
    color: #b42318;
    font-weight: bold;
}

.danger-button {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 10px;
    background: #d92d20;
    color: white;
    font-size: 18px;
    cursor: pointer;
}

.danger-button:hover {
    background: #b42318;
}

/* =========================
   按針 選択項目の説明文
========================= */

.route-item-detail {
    gap: 18px;
}

.route-text {
    min-width: 0;

    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 5px;
}

.route-title {
    font-size: 18px;
    font-weight: 600;
    line-height: 1.4;
}

.route-description {
    color: #6f7782;

    font-size: 13px;
    font-weight: normal;
    line-height: 1.55;

    white-space: normal;
}

.route-arrow {
    flex-shrink: 0;

    color: #444;
    font-size: 18px;
}

.route-item.disabled .route-description,
.route-item.disabled .route-arrow {
    color: #aaa;
}

.route-item.disabled:hover {
    background: #f8fafc;
}

@media (max-width: 600px) {
    .route-item-detail {
        padding: 14px;
        gap: 12px;
    }

    .route-title {
        font-size: 17px;
    }

    .route-description {
        font-size: 12px;
    }
}
.login-panel {
    max-width: 440px;
    margin: 80px auto 0;
}

.login-error {
    color: #b42318;
    font-weight: bold;
}

.login-panel .save-button {
    margin-top: 16px;
}

/* 共通ヘッダー：検索・追加と補助リンクを2段に分離 */
.global-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.global-header-main {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.global-header-main .global-search {
    flex: 1;
    min-width: 0;
}

.global-header-links {
    display: flex;
    justify-content: flex-start;
    gap: 18px;
    font-size: 14px;
}

.global-header-links a,
.global-logout-button {
    white-space: nowrap;
}

.global-logout-form {
    margin: 0;
}

.global-logout-button {
    border: 0;
    padding: 0;
    background: none;
    color: LinkText;
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

/* 記憶詳細画面：題名・操作・本文を一つの記録カードにまとめる */
.detail-record {
    padding: 0;
}

.detail-record-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px;
    border-bottom: 1px solid #e1e5ea;
}

.detail-record-header .header {
    min-width: 0;
    margin: 0;
    text-align: left;
}

.header h1.detail-title {
    color: #26374a;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
}

.detail-record-header .action-bar {
    flex: none;
    margin: 0;
}

.detail-record .raw-content {
    margin: 18px;
}

.detail-record-meta {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 0 18px 18px;
    color: #64748b;
    font-size: 13px;
}

/* トップ画面：補助リンクを検索欄直下に配置 */

/* 新規追加画面：保存せず元の画面へ戻る */
.new-memory-cancel {
    display: inline-block;
    margin-top: 16px;
}

/* 記憶詳細画面：元の一覧・検索結果へ戻る */
.detail-back-link {
    margin-bottom: 16px;
}

.action-bar .copy-memory-button.is-copied,
.action-bar .copy-memory-button.is-copied:hover {
    border-color: #18794e;
    background: #dff7e8;
    color: #145a36;
    box-shadow: inset 0 2px 4px rgba(20, 90, 54, .18);
    transform: translateY(1px);
}

.memory-item--list {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    column-gap: 16px;
    margin-bottom: 6px;
    padding: 12px 14px;
    border: 1px solid #e1e5ea;
    border-radius: 10px;
    background: #f8fafc;
}

.memory-item--list .memory-title {
    margin-bottom: 0;
}

.memory-item--list .memory-date {
    margin: 0;
    font-size: 13px;
    white-space: nowrap;
}

.detail-page--focused .global-header,
.detail-page--focused .detail-back-link,
.detail-page--focused .detail-record-meta {
    display: none;
}

.detail-page--focused .detail-record {
    overflow: hidden;
}

.detail-page--focused .action-bar a,
.detail-page--focused .copy-memory-button,
.detail-page--focused .detail-copy-status {
    display: none;
}

.detail-page--focused .detail-title {
    margin: 0 0 12px;
    font-size: 14px;
}

.detail-page--focused .raw-content {
    /* Focused reading uses the outer card as its only frame. */
    margin: 0;
    padding: 18px;
    border: 0;
    border-radius: 0;
    font-size: 17px;
    line-height: 1.9;
}

@media (max-width: 600px) {
    .action-bar {
        flex-wrap: wrap;
    }

    .action-bar .detail-utility-button {
        min-height: 40px;
    }

    .detail-record-header {
        display: block;
    }

    .detail-record-header .action-bar {
        margin: 12px 0 0;
    }

    .detail-record-meta {
        display: block;
    }

    .detail-record-meta span {
        display: block;
    }

    .detail-record-meta span + span {
        margin-top: 4px;
    }

    .detail-copy-status {
        flex-basis: 100%;
    }

    .edit-save-actions {
        gap: 8px;
        flex-wrap: wrap;
    }

    .edit-previous-toggle {
        flex: 1 0 100%;
        order: -1;
        min-width: 116px;
        padding: 12px 10px;
        font-size: 15px;
    }
}

/* Touch devices use the visible viewport so the writing area is useful without
   letting the controls drift too far away.  This block never applies to Mac. */
@media (hover: none) and (pointer: coarse) {
    .knowledge-form .edit-memory-content {
        height: clamp(260px, calc(100vh - 510px), 500px);
        height: clamp(260px, calc(100dvh - 510px), 500px);
        min-height: 260px;
    }

    .knowledge-form .new-memory-content {
        height: clamp(300px, calc(100vh - 460px), 540px);
        height: clamp(300px, calc(100dvh - 460px), 540px);
        min-height: 300px;
    }
}

/* Landscape tablets are normally used as a writing surface.  Give them a
   wider composing area than a phone, but keep desktop's upper limit. */
@media (hover: none) and (pointer: coarse) and (min-width: 700px) and (max-height: 900px) {
    .knowledge-form .edit-memory-content {
        height: clamp(320px, calc(100dvh - 460px), 500px);
        min-height: 320px;
    }

    .knowledge-form .new-memory-content {
        height: clamp(360px, calc(100dvh - 420px), 540px);
        min-height: 360px;
    }
}

/* 記憶一覧：利用頻度の低い管理用リンク */
.search-management-links {
    margin-bottom: 12px;
    font-size: 14px;
}

/* インクリメンタル検索の試験表示 */
.incremental-search-results {
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: white;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .12);
    overflow: hidden;
}

.incremental-search-status,
.incremental-search-guidance {
    padding: 9px 12px;
    color: #64748b;
    font-size: 12px;
    background: #f8fafc;
}

.incremental-search-status {
    border-bottom: 1px solid #e2e8f0;
}

.incremental-search-guidance {
    border-top: 1px solid #e2e8f0;
}

.incremental-search-item {
    display: block;
    padding: 11px 12px;
    border-bottom: 1px solid #edf2f7;
    color: #1e293b;
    text-decoration: none;
    cursor: pointer;
}

.incremental-search-item:hover,
.incremental-search-item:focus-visible {
    background: #eff6ff;
    outline: none;
}

.incremental-search-item:last-child {
    border-bottom: 0;
}

.incremental-search-item p {
    margin: 5px 0;
    color: #475569;
    font-size: 13px;
    line-height: 1.5;
}

.incremental-search-reason {
    color: #64748b;
    font-size: 12px;
}

.incremental-search-empty {
    padding: 14px 12px;
    color: #64748b;
}
