/* ========================================
   顧客管理システム - スタイルシート
   ======================================== */

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #6b7280;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --bg-primary: #f9fafb;
    --bg-secondary: #ffffff;
    --border-color: #e5e7eb;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
}

/* ========================================
   ヘッダー
   ======================================== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
    box-shadow: var(--shadow-lg);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-title {
    font-size: 1.5rem;
    font-weight: 700;
}

.header-subtitle {
    font-size: 0.9rem;
    opacity: 0.8;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-link {
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    transition: background 0.2s;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.2);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-login, .btn-logout {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.btn-login {
    background: white;
    color: var(--primary);
}

.btn-logout {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.btn-login:hover, .btn-logout:hover {
    transform: translateY(-1px);
}

/* ========================================
   メインコンテンツ
   ======================================== */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

.login-required {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}

.login-card {
    background: white;
    padding: 48px;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-card h2 {
    margin-bottom: 16px;
    color: var(--text-primary);
}

.login-card p {
    margin-bottom: 24px;
    color: var(--text-secondary);
}

/* ========================================
   ボタン
   ======================================== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger) 0%, #dc2626 100%);
    color: white;
}

.btn-danger:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-outline {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
}

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

.btn-large {
    padding: 14px 28px;
    font-size: 1rem;
}

/* ========================================
   タブナビゲーション
   ======================================== */
.tab-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    background: white;
    padding: 8px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.tab-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.tab-btn.active {
    background: var(--primary);
    color: white;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ========================================
   検索バー
   ======================================== */
.search-bar {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-input-wrapper {
    flex: 1;
    min-width: 300px;
    display: flex;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.search-input {
    flex: 1;
    padding: 12px 16px;
    border: none;
    font-size: 0.95rem;
    outline: none;
}

.search-btn {
    padding: 12px 16px;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
}

.tag-filter {
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: white;
    font-size: 0.95rem;
    min-width: 180px;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.selection-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #dbeafe;
    border-radius: 8px;
    color: var(--primary-dark);
    font-weight: 500;
    font-size: 0.9rem;
}

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

/* ステータス表示 */
.status-opened {
    color: #10b981;
    font-weight: 500;
}

.status-unopened {
    color: #f59e0b;
    font-weight: 500;
}

.status-answered {
    color: #10b981;
    font-weight: 600;
    background: #d1fae5;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.85rem;
}

.status-unanswered {
    color: #9ca3af;
    font-weight: 500;
}

/* インポート時タグ選択 */
.import-tags-section {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.import-tags-label {
    display: block;
    font-weight: 600;
    margin-bottom: 12px;
    color: #0369a1;
}

.import-tag-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 40px;
}

.import-tag-selector .tag-selector-item {
    cursor: pointer;
    transition: all 0.2s;
}

.import-tag-selector .tag-selector-item:hover {
    transform: scale(1.05);
}

.import-tag-selector .no-tags {
    color: #9ca3af;
    font-size: 0.9rem;
}

/* ========================================
   テーブル
   ======================================== */
.table-container {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 20px;
}

.customer-table {
    width: 100%;
    border-collapse: collapse;
}

.customer-table th {
    background: var(--bg-primary);
    padding: 14px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.85rem;
    border-bottom: 2px solid var(--border-color);
}

.customer-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.customer-table th.sortable:hover {
    background: var(--border-color);
}

.customer-table th .sort-icon {
    font-size: 0.75rem;
    opacity: 0.5;
    margin-left: 4px;
}

.customer-table th.sorted .sort-icon {
    opacity: 1;
    color: var(--primary);
}

.customer-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
}

.customer-table tr:hover {
    background: #f8fafc;
}

.customer-table tr.selected {
    background: #eff6ff;
}

/* ========================================
   タグバッジ
   ======================================== */
.tag-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    margin-right: 4px;
    margin-bottom: 4px;
}

.tags-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

/* ========================================
   ページネーション
   ======================================== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
}

.page-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
}

.page-btn:hover:not(:disabled) {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.page-size-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: auto;
}

.page-size-selector label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.page-size-selector select {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
}

/* ========================================
   統計サマリー
   ======================================== */
.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ========================================
   インポート
   ======================================== */
.import-section {
    background: white;
    padding: 32px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.import-section h2 {
    margin-bottom: 24px;
}

.import-step {
    margin-bottom: 32px;
}

.import-step h3 {
    margin-bottom: 16px;
    color: var(--text-primary);
}

.file-drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 48px;
    text-align: center;
    transition: all 0.2s;
    cursor: pointer;
}

.file-drop-zone:hover,
.file-drop-zone.dragover {
    border-color: var(--primary);
    background: #eff6ff;
}

.drop-zone-content {
    color: var(--text-secondary);
}

.drop-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 16px;
}

.import-note {
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.mapping-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.mapping-item {
    background: var(--bg-primary);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.mapping-item label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.mapping-item select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
}

.mapping-desc {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

/* タグ列マッピング */
.tag-column-mapping {
    background: #fefce8;
    border: 1px solid #fde047;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 24px;
}

.tag-column-mapping h4 {
    margin: 0 0 8px 0;
    color: #854d0e;
    font-size: 1rem;
}

.tag-mapping-desc {
    color: #a16207;
    font-size: 0.85rem;
    margin-bottom: 12px;
}

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

.tag-column-mapping-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: white;
    padding: 10px 12px;
    border-radius: 6px;
    border: 1px solid #fde047;
}

.tag-column-mapping-item .tag-name {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 120px;
    font-weight: 500;
}

.tag-column-mapping-item .tag-color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.tag-column-mapping-item select {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
}

.tag-column-mapping .no-tags-msg {
    color: #a16207;
    font-size: 0.9rem;
    font-style: italic;
}

.import-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.import-options {
    display: flex;
    gap: 24px;
    margin-bottom: 20px;
}

.import-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.preview-stats {
    background: var(--bg-primary);
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.preview-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

.preview-badge-new {
    background: #d1fae5;
    color: #059669;
}

.preview-badge-existing {
    background: #dbeafe;
    color: #2563eb;
}

.preview-badge-duplicate {
    background: #fef3c7;
    color: #d97706;
}

.preview-table .status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}

.preview-table .status-new {
    background: #d1fae5;
    color: #059669;
}

.preview-table .status-existing {
    background: #dbeafe;
    color: #2563eb;
}

.preview-table .status-duplicate {
    background: #fef3c7;
    color: #d97706;
}

.preview-table-container {
    max-height: 300px;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 20px;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
}

.preview-table th,
.preview-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    font-size: 0.85rem;
}

.preview-table th {
    background: var(--bg-primary);
    position: sticky;
    top: 0;
}

.import-complete {
    text-align: center;
    padding: 48px;
}

.complete-icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 16px;
}

/* ========================================
   タグ管理
   ======================================== */
.tags-section {
    background: white;
    padding: 32px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.tag-form {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.tag-input {
    flex: 1;
    min-width: 200px;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
}

.tag-color-picker {
    width: 50px;
    height: 46px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
}

.tags-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px;
}

.tag-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--bg-primary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.tag-item-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.tag-color-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
}

.tag-item-name {
    font-weight: 500;
}

.tag-item-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.tag-item-actions {
    display: flex;
    gap: 8px;
}

.tag-item-actions button {
    padding: 6px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

/* ========================================
   詳細パネル
   ======================================== */
.detail-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 450px;
    height: 100vh;
    background: white;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 1000;
    overflow-y: auto;
}

.detail-panel.active {
    transform: translateX(0);
}

.detail-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    background: var(--primary);
    color: white;
}

.detail-panel-header h2 {
    font-size: 1.2rem;
}

.close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
}

.detail-panel-content {
    padding: 24px;
}

.detail-section {
    margin-bottom: 24px;
}

.detail-section h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.detail-field {
    display: flex;
    margin-bottom: 12px;
}

.detail-field-label {
    width: 100px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.detail-field-value {
    flex: 1;
    font-weight: 500;
}

.history-list {
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    padding: 12px;
    background: var(--bg-primary);
    border-radius: 8px;
    margin-bottom: 8px;
}

.history-item-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.history-item-title {
    font-weight: 500;
    margin: 4px 0;
}

.history-item-status {
    font-size: 0.85rem;
}

/* ========================================
   モーダル
   ======================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: white;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
}

.modal-small {
    max-width: 400px;
}

.modal-header {
    padding: 20px 24px;
    background: var(--primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header-danger {
    background: var(--danger);
}

.modal-header h2 {
    font-size: 1.2rem;
}

.modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
}

.modal-body {
    padding: 24px;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 16px 24px;
    background: var(--bg-primary);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ========================================
   フォーム
   ======================================== */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.required {
    color: var(--danger);
}

.tag-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: 8px;
    min-height: 50px;
}

.tag-selector-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.tag-selector-item.selected {
    border-color: currentColor;
}

.delete-warning {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 8px;
}

/* ========================================
   ローディング
   ======================================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   ユーティリティ
   ======================================== */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-muted);
}

.empty-state {
    text-align: center;
    padding: 48px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

/* ========================================
   クリック可能な統計値
   ======================================== */
.clickable-stat {
    color: var(--primary);
    cursor: pointer;
    text-decoration: underline;
    font-weight: 600;
}

.clickable-stat:hover {
    color: var(--primary-dark);
}

/* ========================================
   送信履歴モーダル
   ======================================== */
.modal-large {
    max-width: 700px;
}

.history-modal-info {
    background: var(--bg-primary);
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.history-modal-info .customer-email {
    font-weight: 600;
    color: var(--text-primary);
}

.history-modal-info .customer-name {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.history-modal-table-container {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.history-modal-table {
    width: 100%;
    border-collapse: collapse;
}

.history-modal-table th,
.history-modal-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.history-modal-table th {
    background: var(--bg-primary);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    position: sticky;
    top: 0;
}

.history-modal-table tr:hover {
    background: #f8fafc;
}

.history-modal-table .status-opened {
    color: #10b981;
}

.history-modal-table .status-unopened {
    color: #f59e0b;
}

/* ========================================
   レスポンシブ
   ======================================== */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: 12px;
    }
    
    .search-bar {
        flex-direction: column;
    }
    
    .search-input-wrapper {
        min-width: 100%;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .detail-panel {
        width: 100%;
    }
    
    .stats-summary {
        grid-template-columns: repeat(2, 1fr);
    }
}
