/* ========================================
   マスターデータ管理画面 - スタイルシート
   視認性を重視したデザイン
   ======================================== */

/* カラーパレット */
:root {
  --primary-color: #1469a8;
  --primary-hover: #0f5d96;
  --secondary-color: #64748b;
  --secondary-hover: #475569;
  --danger-color: #dc2626;
  --danger-hover: #b91c1c;
  --success-color: #16a34a;
  --success-hover: #15803d;
  --warning-color: #ea580c;
  --warning-hover: #c2410c;
  
  --bg-white: #ffffff;
  --bg-gray-50: #f9fafb;
  --bg-gray-100: #f3f4f6;
  --bg-gray-200: #e5e7eb;
  
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-white: #ffffff;
  
  --border-color: #e5e7eb;
  --border-hover: #d1d5db;
  
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.10), 0 1px 2px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 8px 18px -10px rgba(15, 23, 42, 0.28), 0 4px 10px -6px rgba(15, 23, 42, 0.18);
  --shadow-lg: 0 18px 40px -18px rgba(15, 23, 42, 0.40), 0 10px 22px -12px rgba(15, 23, 42, 0.24);
  --shadow-xl: 0 28px 56px -28px rgba(15, 23, 42, 0.55), 0 18px 30px -18px rgba(15, 23, 42, 0.30);
}

/* リセット */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', Meiryo, sans-serif;
  background: var(--bg-gray-50);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ========================================
   ヘッダー
   ======================================== */
.header {
  background: var(--surface-titlebar, var(--surface-header, var(--bg-white)));
  color: var(--titlebar-text, var(--text-primary));
  padding: 1rem 2rem;
  box-shadow: var(--shadow-sm);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 1.25rem;
}

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

.header-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 1rem;
}

.header-tools {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.header-user {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  background: var(--bg-gray-100);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.nav-link {
  color: var(--titlebar-text, var(--text-secondary));
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  transition: all 0.3s ease;
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  letter-spacing: 0.01em;
  border: 1px solid var(--titlebar-link-border, transparent);
}

.nav-link:hover {
  background: var(--titlebar-link-bg, var(--bg-gray-100));
  color: var(--titlebar-text, var(--text-primary));
}

.nav-link.active {
  background: var(--titlebar-link-hover-bg, color-mix(in srgb, var(--primary-color) 12%, white));
  color: var(--titlebar-text, var(--primary-color));
}

/* ========================================
   メインコンテンツ
   ======================================== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1rem 2rem;
  width: 100%;
}

.access-warning {
  padding: 1rem 1.5rem;
  background: rgba(234, 88, 12, 0.1);
  border: 1px solid rgba(234, 88, 12, 0.35);
  color: var(--warning-color);
  border-radius: 12px;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* ========================================
   アクションバー
   ======================================== */
.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--surface-input, var(--bg-white));
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.action-group {
  display: flex;
  gap: 0.75rem;
}

/* ボタン共通スタイル */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
}

.btn-header {
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  background: var(--bg-white);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  box-shadow: none;
}

.btn-header:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-header-accent {
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  color: var(--text-white);
  border: none;
}

.btn-header-accent:hover:not(:disabled) {
  background: linear-gradient(135deg, #0284c7, #1d4ed8);
}

.btn-header-secondary {
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: var(--text-white);
  border: none;
}

.btn-header-secondary:hover:not(:disabled) {
  background: linear-gradient(135deg, #ea580c, #c2410c);
}

.btn-header-special {
  background: linear-gradient(135deg, #0f766e, #0e7490);
  color: var(--text-white);
  border: none;
}

.btn-header-special:hover:not(:disabled) {
  background: linear-gradient(135deg, #115e59, #155e75);
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

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

.btn-icon {
  font-size: 1rem;
}

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

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

.btn-secondary {
  background: var(--secondary-color);
  color: var(--text-white);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--secondary-hover);
}

.btn-danger {
  background: var(--danger-color);
  color: var(--text-white);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-import {
  background: var(--success-color);
  color: var(--text-white);
}

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

.btn-export {
  background: var(--warning-color);
  color: var(--text-white);
}

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

/* 未保存警告バッジ */
.btn-save-badge {
  position: relative;
}

.btn-save-badge::after {
  content: '!';
  position: absolute;
  top: -8px;
  right: -8px;
  width: 20px;
  height: 20px;
  background: var(--danger-color);
  color: var(--text-white);
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }
}

/* ========================================
   マスター選択
   ======================================== */
.master-selector-panel {
  display: flex;
  align-items: end;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--surface-input, var(--bg-white));
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.selector-group {
  min-width: 280px;
}

.selector-label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
  font-weight: 700;
}

.selector-input {
  width: 100%;
  height: 44px;
}

.selector-hint {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-gray-100);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.55rem 0.8rem;
}

/* ========================================
   フィルターバー
   ======================================== */
.filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--surface-input, var(--bg-white));
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.search-box {
  position: relative;
  flex: 1;
  max-width: 400px;
}

.search-input {
  width: 100%;
  padding: 0.75rem 2.5rem 0.75rem 1rem;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.875rem;
  transition: all 0.3s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-icon {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
}

.filter-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.record-count {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  background: var(--bg-gray-100);
  border-radius: 6px;
}

.maintenance-status {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  background: var(--bg-gray-100);
  border-radius: 6px;
}

.maintenance-status.error {
  color: var(--danger-color);
}

/* ========================================
   データテーブル
   ======================================== */
.table-container {
  background: var(--bg-white);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  overflow: auto;
  flex: 1;
  max-height: calc(100vh - 400px);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table thead {
  background: var(--bg-gray-100);
  color: var(--text-primary);
  position: sticky;
  top: 0;
  z-index: 20;
}

.data-table th {
  padding: 1rem;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  background: var(--bg-gray-100);
  position: sticky;
  top: 0;
  z-index: 20;
}

.data-table th:first-child {
  width: 50px;
  text-align: center;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border-color);
  transition: all 0.2s ease;
}

.data-table tbody tr:hover {
  background: var(--table-row-hover-bg, var(--bg-gray-50));
}

.data-table tbody tr.selected {
  background: var(--table-row-selected-bg, rgba(37, 99, 235, 0.1));
}

.data-table td {
  padding: 1rem;
  color: var(--text-primary);
}

.data-table td:first-child {
  text-align: center;
}

/* チェックボックス */
.checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary-color);
}

/* ========================================
   モーダル
   ======================================== */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.3s ease;
}

.modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-content {
  background: var(--bg-white);
  border-radius: 16px;
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--surface-header, var(--bg-white));
  color: var(--text-primary);
  border-left: 4px solid var(--primary-color);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-close {
  background: var(--bg-gray-100);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 2rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  line-height: 1;
}

.modal-close:hover {
  background: var(--bg-white);
  border-color: var(--primary-color);
  color: var(--primary-color);
  transform: rotate(90deg);
}

.modal-body {
  padding: 2rem;
  overflow-y: auto;
  max-height: calc(90vh - 180px);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--border-color);
  background: var(--surface-display, var(--bg-gray-50));
}

.role-admin-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.role-admin-hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.role-admin-input {
  width: 100%;
}

/* ========================================
   編集フォーム
   ======================================== */
.edit-form {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.form-label.required::after {
  content: ' *';
  color: var(--danger-color);
}

.form-hint {
  font-size: 0.75rem;
  color: #6b7280;
  margin-top: 0.25rem;
}

.form-input,
.form-select,
.form-textarea {
  padding: 0.75rem;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.875rem;
  font-family: inherit;
  transition: all 0.3s ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-textarea {
  resize: vertical;
  min-height: 100px;
}

.form-error {
  font-size: 0.75rem;
  color: var(--danger-color);
  margin-top: 0.25rem;
}

.input-invalid {
  border-color: var(--danger-color) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

/* ========================================
   インポートセクション
   ======================================== */
.import-section {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.file-upload {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.file-input {
  display: none;
}

.file-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 3rem;
  border: 2px dashed var(--border-color);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  background: var(--bg-gray-50);
}

.file-label:hover {
  border-color: var(--primary-color);
  background: rgba(37, 99, 235, 0.05);
}

.file-icon {
  font-size: 3rem;
}

.file-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.file-name {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-align: center;
}

.import-preview {
  border-top: 1px solid var(--border-color);
  padding-top: 2rem;
}

.import-preview h3 {
  margin-bottom: 1rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.preview-info {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.preview-count {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--success-color);
  padding: 0.5rem 1rem;
  background: rgba(22, 163, 74, 0.1);
  border-radius: 6px;
}

.preview-error {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--danger-color);
  padding: 0.5rem 1rem;
  background: rgba(220, 38, 38, 0.1);
  border-radius: 6px;
}

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

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.preview-table th {
  background: var(--bg-gray-100);
  padding: 0.75rem;
  text-align: left;
  font-weight: 600;
  position: sticky;
  top: 0;
  border-bottom: 2px solid var(--border-color);
}

.preview-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.preview-table tr:hover {
  background: var(--bg-gray-50);
}

/* ========================================
   レスポンシブ対応
   ======================================== */
@media (max-width: 1024px) {
  .edit-form {
    grid-template-columns: 1fr;
  }
  
  .action-bar {
    flex-direction: column;
    gap: 1rem;
  }
  
  .action-group {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 768px) {
  .main-content {
    padding: 0 1rem;
  }
  
  .header {
    padding: 1rem;
  }
  
  .header-content {
    flex-direction: column;
    gap: 1rem;
  }
  
  .master-selector-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .selector-group {
    min-width: 0;
    width: 100%;
  }

  .selector-hint {
    margin-left: 0;
  }
  
  .filter-bar {
    flex-direction: column;
    gap: 1rem;
  }
  
  .search-box {
    max-width: 100%;
  }
  
  .data-table {
    font-size: 0.75rem;
  }
  
  .data-table th,
  .data-table td {
    padding: 0.75rem 0.5rem;
  }
  
  .modal-content {
    width: 95%;
  }
  
  .modal-body {
    padding: 1rem;
  }
}

/* ========================================
   一括編集
   ======================================== */
.bulk-edit-info {
  background: var(--surface-display, var(--bg-gray-50));
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

.bulk-edit-info p {
  margin: 0.5rem 0;
  color: var(--text-primary);
}

.bulk-edit-info strong {
  color: var(--primary-color);
  font-size: 1.1rem;
}

.bulk-note {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-style: italic;
}

/* ========================================
   一括編集
   ======================================== */
.bulk-edit-info {
  background: var(--bg-gray-50);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
}

.bulk-edit-info p {
  margin: 0.5rem 0;
  color: var(--text-primary);
}

.bulk-edit-info strong {
  color: var(--primary-color);
  font-size: 1.1rem;
}

.bulk-note {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-style: italic;
}