:root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --border: #dfe3e8;
    --text: #1f2933;
    --muted: #7b8794;
    --accent: #2c5f8a;
    --accent-soft: #e8f0f7;
    --danger: #b23b3b;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ヘッダー */
.topbar {
    display: flex;
    align-items: center;
    gap: 18px;
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    padding: 8px 24px;
    min-height: 56px;
    box-shadow: var(--shadow);
}
.brand { flex: 0 0 auto; font-weight: 700; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; gap: 18px; flex: 0 0 auto; }
.mainnav a { color: var(--muted); font-size: 14px; }
.mainnav a:hover { color: var(--accent); text-decoration: none; }
.topbar-center {
    display: flex;
    justify-content: center;
    flex: 1 1 auto;
    min-width: 360px;
}
.topbar-actions {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
}
.topbar-spacer {
    flex: 1 1 auto;
}
.topbar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 920px;
    margin: 0;
}
.topbar-search input[type=search],
.topbar-search select {
    margin-top: 0;
    height: 38px;
}
.topbar-search input[type=search] {
    flex: 1 1 260px;
    min-width: 180px;
}
.topbar-search select {
    flex: 0 0 auto;
    width: auto;
    max-width: 220px;
}
.topbar-search button,
.topbar-new-customer {
    height: 38px;
    white-space: nowrap;
}
.topbar-search .clear {
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}
.account { display: flex; align-items: center; gap: 14px; flex: 0 0 auto; font-size: 14px; }
.who { color: var(--text); font-weight: 600; }
.logout { color: var(--muted); }

/* 顧客タブ */
.customer-tabs {
    display: flex;
    align-items: stretch;
    position: sticky;
    top: var(--topbar-height, 56px);
    z-index: 29;
    overflow: hidden;
    background: #eef1f4;
    border-bottom: 1px solid var(--border);
    padding: 7px 24px 0;
    min-height: 44px;
}
.customer-tabs.is-empty {
    display: none;
}
.customer-tabs-list {
    display: flex;
    align-items: stretch;
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
}
.customer-tabs-actions {
    display: flex;
    align-items: flex-start;
    flex: 0 0 auto;
    padding-left: 10px;
}
.customer-tabs-clear {
    width: 34px;
    height: 34px;
    padding: 0 6px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #d93025;
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
}
.customer-tabs-clear:hover {
    background: #fee2e2;
    color: #b42318;
}
.customer-tabs-clear:focus-visible {
    outline: 2px solid #d93025;
    outline-offset: 2px;
}
.customer-tabs-clear[hidden] {
    display: none;
}
.customer-tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 150px;
    max-width: 260px;
    height: 37px;
    padding: 0 8px 0 13px;
    background: #d7dde4;
    color: #626e7a;
    border: 1px solid var(--border);
    border-bottom-color: #cfd6dd;
    border-radius: 8px 8px 0 0;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: none;
}
.customer-tab:hover {
    background: #edf1f5;
    color: var(--text);
    text-decoration: none;
}
/* 今開いている顧客のタブ。青のベタ塗りと高さでひと目で分かるようにする */
.customer-tab.active {
    height: 42px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    border-color: #23496a;
    border-bottom-color: var(--accent);
    box-shadow: 0 -3px 8px rgba(44, 95, 138, 0.30);
    z-index: 1;
}
.customer-tab-title {
    overflow: hidden;
    text-overflow: ellipsis;
}
.customer-tab-close {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    padding: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    border: none;
    line-height: 1;
    font-size: 18px;
}
.customer-tab-close:hover {
    background: rgba(31, 41, 51, 0.12);
    color: var(--text);
}
.customer-tab.active .customer-tab-close {
    color: rgba(255, 255, 255, 0.85);
}
.customer-tab.active .customer-tab-close:hover {
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
}

/* 本文 */
.container { max-width: 1000px; margin: 28px auto; padding: 0 24px; }

.page-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 18px;
}
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 10px; }

.flash {
    background: var(--accent-soft);
    border: 1px solid #cfe0ee;
    color: #245078;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}
.error {
    background: #fbeaea;
    border: 1px solid #f0c8c8;
    color: var(--danger);
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 14px;
}
.muted { color: var(--muted); font-size: 13px; }

/* ボタン */
.btn, button {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 14px;
    cursor: pointer;
    font-family: inherit;
}
.btn:hover, button:hover { background: #244e73; text-decoration: none; }
.btn-sub {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-sub:hover { background: #f0f2f5; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #8f2f2f; }

/* カード（ログイン等） */
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px;
    box-shadow: var(--shadow);
}
.card.narrow { max-width: 380px; margin: 60px auto; }
.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

/* フォーム */
label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], input[type=search], input[type=email],
input[type=date], input[type=tel], select, textarea {
    display: block;
    width: 100%;
    margin-top: 5px;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text);
    background: #fff;
    font-family: inherit;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.note-textarea {
    height: min(58vh, 520px);
    min-height: 320px;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.note-field-label {
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 13px;
}
.note-rich-editor { margin-bottom: 14px; min-width: 0; }
.note-source[hidden], .note-toolbar[hidden], .note-format-error[hidden] { display: none; }
.note-toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.note-format-button {
    min-height: 40px;
    padding: 8px 14px;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    touch-action: manipulation;
}
.note-bold-button { font-weight: 700; }
.note-red-button, .note-red { color: #b42318; }
.note-format-button:hover:not(:disabled) { background: #eef4fa; color: var(--text); }
.note-format-button[aria-pressed="true"] { background: #e3edf7; border-color: var(--accent); box-shadow: inset 0 -2px var(--accent); }
.note-format-button:disabled { opacity: .5; cursor: default; }
.note-format-button:focus-visible, .note-link-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.note-format-hint { margin: 8px 0; color: var(--muted); font-size: 13px; }
.note-surface {
    height: min(58vh, 520px);
    min-height: 320px;
    padding: 9px 11px;
    overflow-y: auto;
    overscroll-behavior: contain;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    scroll-margin-top: calc(var(--topbar-height, 56px) + 80px);
}
.note-surface:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.note-surface[data-empty="true"]::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.note-surface strong { font-weight: 700; }
.note-format-error { margin: 8px 0; }
.note-inline-link {
    background: #e9f7ff;
    border-radius: 4px;
    text-decoration: underline;
    text-decoration-color: #0d86c8;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}
.note-link-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
.note-link-list[hidden] { display: none; }
.note-link-item {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    padding: 4px 9px;
    border: 1px solid #b8d4eb;
    border-radius: 999px;
    background: #eef7ff;
    color: #11639a;
    font-size: 13px;
    line-height: 1.4;
    text-decoration: none;
}
.note-link-item:hover {
    background: #dff0ff;
    border-color: #8fbee0;
    color: #0b4f7d;
}
.note-link-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.autosave-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #f8fafc;
    border: 1px solid #cfe0ee;
    border-radius: 8px;
    color: #245078;
    padding: 8px 10px;
    margin-bottom: 14px;
    font-size: 13px;
}
.autosave-status[hidden] { display: none; }
.autosave-discard {
    flex: 0 0 auto;
    background: transparent;
    border: 1px solid #cfe0ee;
    color: #245078;
    padding: 4px 9px;
    border-radius: 6px;
    font-size: 12px;
}
.autosave-discard:hover {
    background: var(--accent-soft);
    color: #245078;
}

/* 検索バー */
.search { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search input[type=search] { flex: 1; min-width: 220px; margin-top: 0; }
.search select { width: auto; margin-top: 0; }
.search .clear { align-self: center; color: var(--muted); font-size: 13px; }

/* 一覧テーブル */
table.list { width: 100%; border-collapse: collapse; background: var(--panel);
    border: 1px solid var(--border); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
table.list th, table.list td { text-align: left; padding: 11px 14px; font-size: 14px; border-bottom: 1px solid var(--border); }
table.list th { background: #fafbfc; color: var(--muted); font-weight: 600; font-size: 12px; }
table.list tbody tr:last-child td { border-bottom: none; }
table.list tbody tr:hover { background: #f7f9fb; cursor: pointer; }

.tag { display: inline-block; background: var(--accent-soft); color: #245078; font-size: 12px;
    padding: 2px 9px; border-radius: 999px; }
.follow { color: var(--danger); font-weight: 600; }

/* 顧客詳細 */
.detail-grid { display: grid; grid-template-columns: 130px 1fr; gap: 8px 16px; font-size: 14px; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; }
.detail-grid dd.note { white-space: pre-wrap; }
.note-display {
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.7;
    overflow-wrap: anywhere;
}
.note-display a,
.memo .body a {
    overflow-wrap: anywhere;
}
.note-editor {
    margin-top: 16px;
}
.note-editor summary {
    list-style: none;
    width: fit-content;
}
.note-editor summary::-webkit-details-marker {
    display: none;
}
.note-editor form {
    margin-top: 14px;
}

/* メモ */
.memo { border-left: 3px solid var(--accent-soft); padding: 4px 0 4px 14px; margin-bottom: 16px; }
.memo-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.memo .meta { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.memo .body { white-space: pre-wrap; font-size: 14px; }
.memo-delete {
    background: transparent;
    color: var(--danger);
    border: 1px solid #f0c8c8;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 12px;
}
.memo-delete:hover {
    background: #fbeaea;
    color: var(--danger);
}

/* ファイル結果 */
.filerow { display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 10px 0; border-bottom: 1px solid var(--border); }
.filerow .meta { color: var(--muted); font-size: 12px; }

/* 一括削除バー */
.bulkbar { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.selectall-label { margin: 0; display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.selectall-label input { width: auto; margin: 0; }
table.list td input.rowcheck { width: auto; margin: 0; }

@media (max-width: 1180px) {
    .topbar {
        flex-wrap: wrap;
        gap: 8px 14px;
    }
    .topbar-center {
        order: 3;
        flex-basis: 100%;
        min-width: 0;
    }
    .topbar-actions {
        order: 2;
    }
    .account {
        margin-left: auto;
    }
}

@media (max-width: 760px) {
    .topbar {
        padding: 8px 14px;
    }
    .topbar-search {
        flex-wrap: wrap;
    }
    .topbar-search input[type=search],
    .topbar-search select,
    .topbar-search button,
    .topbar-new-customer {
        flex: 1 1 100%;
        width: 100%;
        max-width: none;
    }
    .form-grid {
        grid-template-columns: 1fr;
    }
}
