:root {
    --primary: #F3A3B5; /* Logo Pink */
    --primary-hover: #E88EA2;
    --secondary: #B8D383; /* Logo Green */
    --accent-blue: #A0D8E5; /* Logo Blue */
    --accent-orange: #F7C16C; /* Logo Orange */
    --bg-main: #FFF9FA; /* Very light pink tint */
    --bg-card: #ffffff;
    --text-main: #5C4B4F; /* Darker warm gray */
    --text-muted: #8E7C80;
    --border: #F7E4E8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
}

button {
    border: none;
    outline: none;
    background: none;
    font-family: inherit;
    cursor: pointer;
}

#app {
    display: flex;
    height: 100vh;
}

/* サイドバー */
sidebar {
    width: 360px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 1.25rem;
    margin-bottom: 16px;
    color: var(--primary);
}

.cm-selector label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 8px;
    color: var(--text-muted);
}

.cm-selector select {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.patient-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.patient-card {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
}

.patient-card:hover {
    border-color: var(--primary);
    background: #f9fafb;
}

.patient-card.active {
    border-color: var(--primary);
    background: #eff6ff;
}

.patient-card.has-saves {
    background-color: #f0fdf4;
    border-left: 4px solid #10b981;
}

.patient-card h3 {
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.patient-card .meta {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.badge-visit, .badge-save, .badge-family {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
}

.badge-visit {
    background-color: #EBF8FA;
    color: #4A90A2;
    border: 1px solid var(--accent-blue);
}

.badge-save {
    background-color: #F4F9EB;
    color: #6B8E23;
    border: 1px solid var(--secondary);
}

.badge-family {
    background-color: #FFF9F0;
    color: #D68A00;
    border: 1px solid var(--accent-orange);
}

/* メインコンテンツ */
main {
    flex: 1;
    overflow: hidden; /* メイン自体はスクロールさせず、中身を広げる */
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

#input-panel {
    flex: 1; /* 親のmainの中でいっぱいに広がる */
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    padding: 20px;
    min-height: 0; /* flex子要素が縮めるようにする */
}

.input-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

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

.history-container {
    margin-bottom: 20px;
    padding: 12px;
    background: #f1f5f9;
    border-radius: 8px;
}

.history-container label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 8px;
    display: block;
}

.history-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.history-tag {
    padding: 6px 12px;
    border-radius: 6px;
    background-color: #f1f5f9;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: all 0.2s;
    white-space: nowrap;
}

.history-tag.is-manual {
    background-color: #f0fdf4;
    color: #15803d;
    border-color: #bbf7d0;
}

.history-tag:hover {
    background-color: #e2e8f0;
    transform: translateY(-1px);
}

.history-tag.active {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 2px 4px rgba(79, 70, 229, 0.3);
}

.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-muted);
}

input[type="date"], textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.small-textarea {
    min-height: 80px;
}

.flex-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.flex-row textarea {
    flex: 1;
}

.snippet-tag {
    padding: 6px 12px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-main);
}

.snippet-tag:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: #f5f3ff;
}

.snippet-tag.primary {
    background-color: #f5f3ff;
    color: var(--primary);
    border-color: var(--primary);
    font-weight: 600;
}

.snippet-tag.active {
    background-color: var(--primary);
    color: white;
    border: 1px solid var(--primary); /* 背景色と一致させる */
    outline: none;
    box-shadow: none;
}

.snippet-tag.active:hover {
    color: white;
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}

.snippet-tag:focus {
    outline: none;
}

.clear-btn {
    padding: 4px 8px;
    background-color: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    border-radius: 4px;
    font-size: 10px;
    cursor: pointer;
    font-weight: 600;
    margin-left: 8px;
    transition: all 0.2s;
}

.clear-btn:hover {
    background-color: #fecaca;
    border-color: #fca5a5;
}

.hidden {
    display: none;
}

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

.snippets.vertical {
    flex-direction: column;
    min-width: 150px;
}

.snippets.mini .snippet-tag {
    padding: 4px 10px;
    font-size: 11px;
}

.panel-actions {
    margin-top: 24px;
    text-align: right;
}

.primary-btn {
    padding: 10px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

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

.field-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

/* トースト通知 */
#toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #1f2937;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    display: none;
    z-index: 1000;
}

#toast.show {
    display: block;
}

/* スイッチ */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px; width: 16px;
    left: 2px; bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider { background-color: #10b981; }
input:checked + .slider:before { transform: translateX(20px); }
