:root {
    --m3-surface: #fef7ff;
    --m3-on-surface: #1d1b20;
    --m3-surface-container: #f3edf7;
    --m3-primary: #6750a4;
    --m3-on-primary: #ffffff;
    --m3-secondary-container: #e8def8;
    --m3-on-secondary-container: #1d192b;
    --m3-outline: #79747e;
    --m3-error: #b3261e;
    --m3-on-error: #ffffff;
    --m3-elevation-1: 0 1px 2px 0 rgba(0, 0, 0, 0.05), 0 1px 3px 1px rgba(0, 0, 0, 0.1);
    --m3-elevation-2: 0 2px 6px 2px rgba(0, 0, 0, 0.15), 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --ui-zoom-scale: 1;
}

[data-bs-theme="dark"] {
    --m3-surface: #141218;
    --m3-on-surface: #e6e1e5;
    --m3-surface-container: #211f26;
    --m3-primary: #d0bcff;
    --m3-on-primary: #381e72;
    --m3-secondary-container: #4a4458;
    --m3-on-secondary-container: #e8def8;
    --m3-outline: #938f99;
    --m3-error: #f2b8b5;
    --m3-on-error: #601410;
}

body {
    background-color: var(--m3-surface);
    color: var(--m3-on-surface);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    min-height: calc(100vh / var(--ui-zoom-scale));
    transition: background-color 0.3s, color 0.3s;
}

.m3-surface {
    background-color: var(--m3-surface-container) !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: var(--m3-elevation-1);
}

.navbar {
    position: relative;
    z-index: 1000;
}

.navbar-brand {
    font-weight: 600;
    letter-spacing: -0.5px;
}

.zoom-level-label {
    min-width: 3.5rem;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Material Design 3 Buttons */
.m3-button-primary {
    background-color: var(--m3-primary) !important;
    color: var(--m3-on-primary) !important;
    border-radius: 12px !important;
    /* M3 uses slightly less rounded for some buttons but 100px for fab. 12-16px is good for these. */
    padding: 8px 16px !important;
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 0.9rem;
}

.m3-button-primary:hover {
    box-shadow: var(--m3-elevation-2);
    filter: brightness(1.1);
}

.m3-button-tonal {
    background-color: var(--m3-secondary-container) !important;
    color: var(--m3-on-secondary-container) !important;
    border-radius: 12px !important;
    padding: 8px 16px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.m3-button-tonal:hover {
    background-color: var(--m3-surface-container) !important;
    box-shadow: var(--m3-elevation-1);
}

.m3-button-danger {
    background-color: var(--m3-error) !important;
    color: var(--m3-on-error) !important;
    border-radius: 12px !important;
    padding: 8px 16px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.m3-button-danger:hover {
    box-shadow: var(--m3-elevation-2);
    filter: brightness(1.1);
}


.m3-input {
    background-color: var(--m3-surface-container) !important;
    color: var(--m3-on-surface) !important;
    border: 1px solid var(--m3-outline) !important;
    border-radius: 4px 4px 0 0 !important;
    border-bottom: 2px solid var(--m3-outline) !important;
}

.m3-input:focus {
    border-bottom: 2px solid var(--m3-primary) !important;
    box-shadow: none !important;
}

#main-layout {
    height: calc((100vh / var(--ui-zoom-scale)) - 60px);
    overflow: hidden;
    position: relative;
    z-index: 1;
}

#sidebar {
    width: 200px;
    height: 100%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(0, 0, 0, 0.05);
    background-color: var(--m3-surface-container) !important;
    transition: width 0.3s, padding 0.3s;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    z-index: 10;
}

#sidebar.collapsed {
    width: 60px;
}

#sidebar.collapsed .sidebar-title,
#sidebar.collapsed .group-name,
#sidebar.collapsed .group-actions,
#sidebar.collapsed #add-group-button {
    display: none !important;
}

#sidebar.collapsed .sidebar-header {
    justify-content: center !important;
    padding: 12px 0 !important;
}

#sidebar.collapsed .group-item {
    justify-content: center;
    padding: 8px 0;
}

#sidebar.collapsed .group-item::before {
    content: '•';
    font-size: 1.2rem;
}

#sidebar.collapsed .group-item.active::before {
    color: var(--m3-on-primary);
}

#group-list {
    scrollbar-width: thin;
}

.group-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    cursor: pointer;
    transition: background-color 0.2s;
    user-select: none;
    font-size: 0.9rem;
    gap: 8px;
}

.group-item:hover {
    background-color: var(--m3-secondary-container);
}

.group-item.active {
    background-color: var(--m3-primary);
    color: var(--m3-on-primary);
}

.group-name {
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.group-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.group-item:hover .group-actions {
    opacity: 1;
}

.group-action-btn {
    padding: 2px;
    background: none;
    border: none;
    color: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.group-action-btn.mode-kanban {
    color: inherit;
}

.group-action-btn:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.kanban-fixed-stage {
    display: flex;
    align-items: center;
}

.kanban-fixed-stage-label {
    display: inline-flex;
    align-items: center;
    min-height: 42px;
    width: 100%;
    padding: 0 12px;
    border-radius: 12px;
    background: var(--m3-secondary-container);
    color: var(--m3-on-secondary-container);
    font-weight: 600;
}

.kanban-step-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.kanban-step-empty {
    margin: 0;
    padding: 12px;
    border: 1px dashed var(--m3-outline);
    border-radius: 12px;
    color: color-mix(in srgb, var(--m3-on-surface) 65%, transparent);
    text-align: center;
}

#workspace {
    flex-grow: 1;
    height: 100%;
    position: relative;
    cursor: crosshair;
    z-index: 1;
    overflow: auto;
    /* Added to allow scrolling for large notes */
}

#workspace.kanban-mode {
    cursor: default;
    padding: 12px;
}

#workspace.kanban-mode::after {
    display: none;
}

.kanban-board {
    display: grid;
    grid-template-columns: repeat(var(--kanban-column-count, 3), minmax(0, 1fr));
    gap: 12px;
    width: 100%;
    min-height: 100%;
    align-items: flex-start;
}

.kanban-column {
    min-width: 0;
    width: auto;
    background: var(--m3-surface-container);
    border: 1px solid var(--m3-outline);
    border-radius: 14px;
    box-shadow: var(--m3-elevation-1);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 120px);
    overflow: hidden;
}

.kanban-column[data-column-id='todo'],
.kanban-column[data-column-role='todo'] {
    border-color: #7c4d00;
    background: #fff6dd;
}

.kanban-column[data-column-id='doing'],
.kanban-column[data-column-role='progress'] {
    border-color: #0b5394;
    background: #e8f2ff;
}

.kanban-column[data-column-id='done'],
.kanban-column[data-column-role='done'] {
    border-color: #0f6b3d;
    background: #e9f8ef;
}

.kanban-column-header {
    font-weight: 600;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    border-top-left-radius: 14px;
    border-top-right-radius: 14px;
}

.kanban-column[data-column-id='todo'] .kanban-column-header,
.kanban-column[data-column-role='todo'] .kanban-column-header {
    background: #ffe8aa;
}

.kanban-column[data-column-id='doing'] .kanban-column-header,
.kanban-column[data-column-role='progress'] .kanban-column-header {
    background: #cfe5ff;
}

.kanban-column[data-column-id='done'] .kanban-column-header,
.kanban-column[data-column-role='done'] .kanban-column-header {
    background: #cdeed8;
}

.kanban-column-body {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    min-height: 120px;
}

.kanban-column-body.drag-over {
    background: rgba(103, 80, 164, 0.08);
}

body.kanban-drop-copy-cursor,
body.kanban-drop-copy-cursor * {
    cursor: copy !important;
}

.kanban-card {
    border-radius: 12px;
    box-shadow: var(--m3-elevation-1);
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.06);
}

.kanban-card.dragging {
    opacity: 0.6;
}

.kanban-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.05);
}

.kanban-card-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.kanban-color-panel {
    height: 28px;
    gap: 3px;
}

.kanban-color-panel .color-swatch {
    width: 12px;
    height: 12px;
}

.kanban-card-actions .btn {
    width: 28px;
    height: 28px;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    border-radius: 50%;
}

.kanban-card-content {
    padding: 10px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 240px;
    overflow: auto;
    outline: none;
}

.kanban-card-content img {
    max-width: 100%;
    display: block;
}

@media (max-width: 900px) {
    .kanban-column {
        min-width: 0;
        width: auto;
    }
}

/* Ensure whitespace at the bottom/right for new note creation */
#workspace::after {
    content: '';
    display: block;
    position: absolute;
    width: 2000px;
    /* Arbitrary large size to allow scrolling beyond notes */
    height: 2000px;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: -1;
}

/* キャンバス上の操作ヒント */
.canvas-hint {
    position: fixed;
    pointer-events: none;
    background: var(--m3-surface-container);
    color: var(--m3-on-surface);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    box-shadow: var(--m3-elevation-2);
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 5000;
    white-space: nowrap;
    border: 1px solid var(--m3-outline);
}

.canvas-hint.visible {
    opacity: 0.9;
}

.note {
    position: absolute;
    width: 250px;
    background: #fffb85;
    padding: 0;
    /* Changed to 0 for Material Card look */
    border-radius: 16px;
    box-shadow: var(--m3-elevation-1);
    color: #1d1b20;
    /* Default note text color */
    cursor: default;
    resize: both;
    overflow: hidden;
    /* Changed from auto to hidden for header management */
    min-width: 230px;
    min-height: 100px;
    transition: box-shadow 0.2s;
}

.note:hover {
    box-shadow: var(--m3-elevation-2);
}

.note:active {
    cursor: default;
}

.note-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 0;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.04);
    cursor: grab;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.note-header:active {
    cursor: grabbing;
}

.note-header-main {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.note-id-container {
    display: flex;
    align-items: center;
    height: 32px;
    /* Match button height for better centering */
    flex-shrink: 0;
}

.note-title {
    min-width: 0;
    flex: 1;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-radius: 6px;
    padding: 4px 6px;
    cursor: text;
}

.note-title:hover {
    background: rgba(0, 0, 0, 0.06);
}

.note-title.is-empty {
    min-width: 48px;
}

.note-content {
    padding: 12px;
    min-height: 50px;
    white-space: pre-wrap;
    word-break: break-word;
    overflow: auto;
    height: calc(100% - 45px);
    /* Adjust based on one-row header height */
    outline: none;
    /* contenteditable のアウトラインを消す */
}

.note-content[contenteditable="true"]:focus {
    background: rgba(0, 0, 0, 0.02);
}


.color-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    /* Match button height for better centering */
    gap: 4px;
    margin: 0;
    padding: 0;
}



/* Material Symbols alignment */
.material-symbols-outlined {
    font-size: 20px;
    vertical-align: middle;
}


/* note 内の画像を枠内に収める */
.note-content img {
    max-width: 100%;
    height: auto;
    display: block;
}

.note-size {
    position: absolute;
    bottom: .3rem;
    right: .3rem;
    font-size: .65rem;
    color: rgba(0, 0, 0, 0.4);
}

/* テキストエリアに画像をドラッグした際のドロップゾーン表示 */
#note-input.drag-over {
    border: 2px dashed var(--m3-primary) !important;
    background-color: rgba(103, 80, 164, 0.1) !important;
}

/* 全画面ドロップゾーン */
#global-drop-zone {
    /* 非表示・配置 */
    position: fixed;
    top: 0;
    left: 0;
    width: calc(100vw / var(--ui-zoom-scale));
    height: calc(100vh / var(--ui-zoom-scale));
    display: none;
    z-index: 1000;
    /* テキストエリアと同じ見た目 */
    border: 4px dashed var(--m3-primary);
    background-color: rgba(103, 80, 164, 0.2);
    cursor: copy;
    justify-content: center;
    align-items: center;
    color: var(--m3-primary);
    font-size: 1.5rem;
    font-weight: bold;
    backdrop-filter: blur(4px);
}

#global-drop-zone.active {
    display: flex;
}

/* カラースウォッチ */
.color-swatch {
    width: 14px;
    height: 14px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    margin: 0;
    cursor: pointer;
    display: inline-block;
    transition: transform 0.2s, border-width 0.1s;
}

.color-swatch:hover {
    transform: scale(1.3);
}

.color-swatch.selected {
    border: 2px solid var(--m3-primary);
}


/* ボタン行を左右に配置 */
.btn-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
    align-items: center;
}

.header-right-group {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.header-actions {
    display: flex;
    gap: 0;
    /* Tighten up buttons slightly */
}

.header-actions .btn {
    width: 32px;
    height: 32px;
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50% !important;
    background: transparent !important;
    border: none !important;
    color: inherit;
    transition: background-color 0.2s;
}

.header-actions .btn:hover {
    background-color: rgba(0, 0, 0, 0.1) !important;
}

/* Modals should always be on top of notes */
.modal {
    width: calc(100vw / var(--ui-zoom-scale));
    height: calc(100vh / var(--ui-zoom-scale));
    z-index: 10000 !important;
}

.modal-backdrop {
    width: calc(100vw / var(--ui-zoom-scale));
    height: calc(100vh / var(--ui-zoom-scale));
    z-index: 9999 !important;
}

/* Badge update */
.note-id {
    background-color: var(--m3-primary) !important;
    color: var(--m3-on-primary) !important;
    padding: 2px 6px !important;
    font-size: 10px !important;
    border-radius: 4px !important;
    font-weight: bold;
}