/* リセット & ベーススタイル */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
        sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

/* ログイン画面 */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    background: white;
    padding: 2rem 3rem;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    margin-bottom: 2rem;
    color: #333;
    font-size: 2rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #555;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

.form-group textarea {
    resize: vertical;
    font-family: inherit;
}

.error-message {
    background-color: #fee;
    color: #c33;
    padding: 0.75rem;
    border-radius: 5px;
    margin-bottom: 1rem;
    border: 1px solid #fcc;
}

.conflict-error {
    background-color: #fff3cd;
    color: #856404;
    padding: 1rem;
    border-radius: 5px;
    margin-bottom: 1rem;
    border: 1px solid #ffc107;
}

.conflict-error p {
    margin-bottom: 0.5rem;
}

.btn-primary {
    background-color: #667eea;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
    width: 100%;
}

.btn-primary:hover:not(:disabled) {
    background-color: #5568d3;
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-refresh {
    background-color: #ffc107;
    color: #856404;
    border: 1px solid #ffc107;
    padding: 0.5rem 1rem;
    border-radius: 5px;
    cursor: pointer;
    font-weight: 500;
}

.btn-refresh:hover {
    background-color: #ffca2c;
}

/* メインアプリケーション */
.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header {
    background: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
}

.app-title {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    justify-self: flex-start;
}

.app-title-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.app-header h1 {
    color: #333;
    font-size: 1.5rem;
}

.btn-new-card {
    background-color: #667eea;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
    justify-self: center;
}

.btn-new-card:hover {
    background-color: #5568d3;
}

.header-new-card {
    justify-self: center;
}

.btn-logout {
    background: transparent;
    color: #667eea;
    border: 1px solid rgba(102, 126, 234, 0.8);
    padding: 0.65rem 1.3rem;
    border-radius: 5px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s;
    justify-self: end;
}

.btn-logout:hover {
    background: #667eea;
    color: #fff;
    border-color: #667eea;
}

.app-main {
    flex: 1;
    padding: 2.5rem 2rem 2rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.cards-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 12px;
    border-radius: 12px;
    background: linear-gradient(135deg, #ffffff 0%, #f7f9fb 100%);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
    position: sticky;
    top: 0;
    z-index: 2;
    overflow-x: auto;
    white-space: nowrap;
    backdrop-filter: blur(6px);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.control-label {
    font-size: 12px;
    font-weight: 700;
    color: #556;
    padding-left: 8px;
}

.control-input {
    min-width: 240px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid #e5eaf0;
    outline: none;
    background: #fff;
    font-size: 0.95rem;
}

.control-input:focus {
    border-color: #8cb4ff;
    box-shadow: 0 0 0 3px rgba(140, 180, 255, 0.25);
}

.control-select {
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid #e5eaf0;
    background: #fff;
    font-weight: 600;
    color: #334;
    min-width: 160px;
}

.segmented-control {
    display: inline-flex;
    border: 1px solid #e5eaf0;
    border-radius: 999px;
    overflow: hidden;
    backdrop-filter: blur(4px);
}

.segmented-control-btn {
    padding: 8px 14px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    background: transparent;
    color: #334;
    transition: all 0.2s ease;
}

.segmented-control-btn.is-active {
    color: #fff;
}

.segmented-control-btn--all.is-active {
    background: linear-gradient(135deg, #607d8b, #90a4ae);
}

.segmented-control-btn--increase.is-active {
    background: linear-gradient(135deg, #1e88e5, #42a5f5);
}

.segmented-control-btn--decrease.is-active {
    background: linear-gradient(135deg, #e53935, #ef5350);
}

.segmented-control-btn--entry.is-active {
    background: linear-gradient(135deg, #00695c, #26a69a);
}

.segmented-control-btn--updated.is-active {
    background: linear-gradient(135deg, #5c6bc0, #7986cb);
}

/* カードコンテナ */
.cards-container-wrapper {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 2rem;
}

.scroll-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.9);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 2rem;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s;
    backdrop-filter: blur(8px);
}

.scroll-btn:hover {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(102, 126, 234, 0.5);
    color: #667eea;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.scroll-btn-left {
    left: 1rem;
}

.scroll-btn-right {
    right: 1rem;
}

.cards-container {
    display: flex;
    gap: 1.5rem;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 1rem 4rem;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    height: 100%;
    align-items: flex-start;
    /* スクロールバー非表示（各ブラウザ） */
    -ms-overflow-style: none;     /* IE, Edge */
    scrollbar-width: none;        /* Firefox */
    cursor: grab;
    touch-action: pan-y;
    will-change: scroll-position;
}

.cards-container::-webkit-scrollbar {
    display: none; /* Chrome, Safari */
    height: 0;
}

.cards-container::-webkit-scrollbar-track {
    background: transparent;
}

.cards-container::-webkit-scrollbar-thumb {
    background: transparent;
}

.cards-container::-webkit-scrollbar-thumb:hover {
    background: transparent;
}

.cards-container.grabbing {
    cursor: grabbing;
    user-select: none;
    touch-action: none;
}

/* カード */
.card {
    min-width: 300px;
    max-width: 300px;
    /* background: white; インラインスタイルで上書きされるため削除 */
    border-radius: 10px;
    position: relative;
    padding: 1.5rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    border: none;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    height: 428px; /* 2行分（約3em）分だけ高くする */
    overflow: hidden; /* 内容が溢れた場合は非表示 */
}

.card-close {
    position: absolute;
    top: 8px;
    right: 8px;
    left: auto;
    border: none;
    background: transparent;
    color: #bbb;
    cursor: pointer;
    z-index: 2;
    padding: 0;
    font-size: 18px;
    line-height: 1;
    transition: color 0.2s;
}

.card-close:hover {
    color: #666;
}

.confirm-popup {
    position: absolute;
    top: 36px;
    right: 8px;
    left: auto;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 6px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    z-index: 3;
    min-width: 180px;
}

.confirm-message {
    font-size: 0.9rem;
    color: #333;
    margin-bottom: 8px;
}

.confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.btn-danger {
    background-color: #e57373;
    color: white;
    border: none;
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
}

.btn-danger:hover {
    background-color: #d32f2f;
}

.btn-cancel-small {
    background: #f7f7f7;
    color: #333;
    border: 1px solid #eee;
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
}

.btn-cancel-small:hover {
    background: #e0e0e0;
}

.card:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid transparent;
}

.card-type {
    font-size: 0.85rem;
    font-weight: 600;
    color: #666;
    display: inline-block;
}

.card-status {
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.25rem 0.75rem;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.5);
}

.card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
	/* テキストの下端が欠けないように overflow は可視に */
	overflow: visible;
}

.card-title {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: #333;
    font-weight: 600;
    white-space: nowrap;           /* 1行で省略表示 */
    overflow: hidden;
    text-overflow: ellipsis;
	line-height: 1.6;              /* 下側が欠けないように行高を広めに */
	padding-bottom: 2px;           /* 微小な下余白で欠け対策 */
}

.card-info {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 1rem;
}

.card-info div {
    margin-bottom: 0.5rem;
}

.card-notes {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 0.9rem;
    overflow: hidden;
}

.card-notes strong {
    display: block;
    margin-bottom: 0.5rem;
    color: #333;
}

.card-notes p {
    color: #666;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.6; /* 行間をやや広めにして可読性を確保 */
    height: calc(1.6em * 5); /* ちょうど5行分の可視領域 */
    overflow-y: auto; /* この領域のみスクロール可能に（ホイール対応） */
    -webkit-overflow-scrolling: touch;
    padding-right: 2px; /* スクロール領域の余白を最小限に */
	padding-bottom: calc(1.6em * 3.5); /* 最下行が完全に見えるよう、約3.5行分の余白 */
    overscroll-behavior: contain; /* 親へのスクロール伝播を抑制 */
    box-sizing: content-box; /* 高さに余白を含めない（可視領域を正確に5行に） */
}

/* 進捗状況スクロールのスクロールバーを非表示にしてホイールのみで操作 */
.notes-scroll {
    scrollbar-width: none;        /* Firefox: 非表示 */
    -ms-overflow-style: none;     /* IE/Edge: 非表示 */
}
.notes-scroll::-webkit-scrollbar { /* Chrome/Safari: 非表示 */
    display: none;
    width: 0;
    height: 0;
}

.card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.btn-edit,
.btn-delete {
    flex: 1;
    padding: 0.5rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.btn-edit {
    background-color: #667eea;
    color: white;
}

.btn-edit:hover {
    background-color: #5568d3;
}

.btn-delete {
    background-color: #f44336;
    color: white;
}

.btn-delete:hover {
    background-color: #d32f2f;
}

/* 空の状態 */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: #666;
}

.empty-state p {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

/* モーダル */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-content {
    background: white;
    border-radius: 10px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid #eee;
}

.modal-header h2 {
    color: #333;
    font-size: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #999;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s;
}

.modal-close:hover {
    background: #f5f5f5;
    color: #333;
}

.modal-content form {
    padding: 1.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #eee;
}

.btn-cancel {
    flex: 1;
    background: #f5f5f5;
    color: #333;
    border: 1px solid #ddd;
    padding: 0.75rem;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-cancel:hover {
    background: #e0e0e0;
}

.modal-actions .btn-primary {
    flex: 1;
}

/* ローディング */
.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-size: 1.2rem;
    color: #666;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .app-header {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .btn-new-card {
        width: 100%;
    }

    .btn-logout {
        width: 100%;
        text-align: center;
    }

    .scroll-btn {
        width: 40px;
        height: 40px;
        font-size: 1.5rem;
    }

    .scroll-btn-left {
        left: 0.5rem;
    }

    .scroll-btn-right {
        right: 0.5rem;
    }

    .cards-container {
        padding: 1rem 3rem;
    }

    .card {
        min-width: 280px;
        max-width: 280px;
    }

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

    .modal-content {
        max-width: 100%;
        margin: 1rem;
    }
}

@media (max-width: 480px) {
    .cards-container {
        padding: 1rem 2.5rem;
    }

    .card {
        min-width: 250px;
        max-width: 250px;
    }
}

