/* ============================================
   ダイキョー統合管理システム - 共通スタイル
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@300;400;500;700&display=swap');

:root {
  --primary: #1a1a2e;
  --primary-light: #16213e;
  --accent: #0f3460;
  --accent-light: #1a5276;
  --highlight: #e94560;
  --success: #27ae60;
  --warning: #f39c12;
  --info: #3498db;
  --danger: #e74c3c;
  --text-primary: #ecf0f1;
  --text-secondary: #bdc3c7;
  --text-dark: #2c3e50;
  --bg-body: #0a0a1a;
  --bg-card: #1a1a2e;
  --bg-card-hover: #222240;
  --bg-input: #16213e;
  --border-color: #2c3e6e;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* ============ ナビゲーション ============ */
.sys-nav {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.sys-nav-brand {
  color: var(--text-primary);
  font-size: 1.2rem;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 2px;
}

.sys-nav-brand:hover {
  color: var(--highlight);
}

.sys-nav-menu {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.sys-nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: var(--transition);
  white-space: nowrap;
}

.sys-nav-link:hover,
.sys-nav-link.active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.sys-nav-user {
  color: var(--text-secondary);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sys-nav-user .badge {
  background: var(--highlight);
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
}

#logout-btn {
  background: transparent;
  border: 1px solid var(--highlight);
  color: var(--highlight);
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  transition: var(--transition);
}

#logout-btn:hover {
  background: var(--highlight);
  color: white;
}

/* ============ メインコンテンツ ============ */
.sys-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.sys-page-title {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sys-page-title .icon {
  font-size: 1.5rem;
  color: var(--highlight);
}

/* ============ カード ============ */
.sys-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border-color);
  transition: var(--transition);
}

.sys-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--accent-light);
}

.sys-card-header {
  background: linear-gradient(135deg, var(--accent) 0%, var(--primary-light) 100%);
  padding: 1rem 1.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sys-card-body {
  padding: 1.5rem;
}

/* ============ フォーム ============ */
.sys-form-group {
  margin-bottom: 1rem;
}

.sys-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.sys-label .required {
  background: var(--highlight);
  color: white;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 0.3rem;
  font-weight: 400;
}

.sys-input,
.sys-select,
.sys-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  transition: var(--transition);
}

.sys-input:focus,
.sys-select:focus,
.sys-textarea:focus {
  outline: none;
  border-color: var(--info);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.sys-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.5;
}

.sys-textarea {
  resize: vertical;
  min-height: 80px;
}

.sys-input-sm {
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
}

.sys-input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sys-input-group .separator {
  color: var(--text-secondary);
  font-weight: 500;
}

.sys-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-primary);
  margin-right: 1rem;
}

.sys-checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--info);
}

/* ============ ボタン ============ */
.sys-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  font-family: inherit;
  white-space: nowrap;
}

.sys-btn:active {
  transform: scale(0.97);
}

.sys-btn-primary {
  background: linear-gradient(135deg, var(--info) 0%, var(--accent) 100%);
  color: white;
}

.sys-btn-primary:hover {
  filter: brightness(1.15);
  color: white;
}

.sys-btn-success {
  background: linear-gradient(135deg, var(--success) 0%, #219653 100%);
  color: white;
}

.sys-btn-success:hover {
  filter: brightness(1.15);
  color: white;
}

.sys-btn-danger {
  background: linear-gradient(135deg, var(--danger) 0%, #c0392b 100%);
  color: white;
}

.sys-btn-danger:hover {
  filter: brightness(1.15);
  color: white;
}

.sys-btn-warning {
  background: linear-gradient(135deg, var(--warning) 0%, #e67e22 100%);
  color: white;
}

.sys-btn-warning:hover {
  filter: brightness(1.15);
  color: white;
}

.sys-btn-dark {
  background: linear-gradient(135deg, #2c3e50 0%, #1a252f 100%);
  color: white;
}

.sys-btn-dark:hover {
  filter: brightness(1.3);
  color: white;
}

.sys-btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.sys-btn-outline:hover {
  border-color: var(--info);
  color: var(--info);
}

.sys-btn-sm {
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
}

.sys-btn-lg {
  padding: 0.8rem 2rem;
  font-size: 1rem;
}

.sys-btn-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ============ テーブル ============ */
.sys-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
}

.sys-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.sys-table thead th {
  background: linear-gradient(135deg, var(--accent) 0%, var(--primary-light) 100%);
  color: var(--text-primary);
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.sys-table tbody td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.sys-table tbody tr {
  transition: var(--transition);
}

.sys-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.sys-table tbody tr:last-child td {
  border-bottom: none;
}

/* ============ バッジ ============ */
.sys-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
}

.sys-badge-success {
  background: rgba(39, 174, 96, 0.2);
  color: #2ecc71;
}

.sys-badge-warning {
  background: rgba(243, 156, 18, 0.2);
  color: #f39c12;
}

.sys-badge-danger {
  background: rgba(231, 76, 60, 0.2);
  color: #e74c3c;
}

.sys-badge-info {
  background: rgba(52, 152, 219, 0.2);
  color: #3498db;
}

.sys-badge-dark {
  background: rgba(44, 62, 80, 0.3);
  color: #bdc3c7;
}

/* ============ ダッシュボードグリッド ============ */
.sys-menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
}

.sys-menu-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  text-decoration: none;
  color: var(--text-primary);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.sys-menu-item:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--info);
  color: var(--text-primary);
}

.sys-menu-item .icon {
  font-size: 2rem;
  color: var(--info);
}

.sys-menu-item .label {
  font-weight: 600;
  font-size: 1rem;
}

.sys-menu-item .desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.sys-menu-item.admin-only {
  border-color: var(--highlight);
}

.sys-menu-item.admin-only .icon {
  color: var(--highlight);
}

/* ============ ログイン画面 ============ */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--bg-body) 0%, var(--primary) 50%, var(--accent) 100%);
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 3rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
}

.login-title {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.login-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}

.login-error {
  background: rgba(231, 76, 60, 0.15);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.85rem;
  margin-bottom: 1rem;
  display: none;
}

/* ============ カレンダー ============ */
.sys-calendar {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
  width: 100%;
}

.sys-calendar-header {
  background: var(--accent);
  color: var(--text-primary);
  text-align: center;
  padding: 0.5rem;
  font-weight: 600;
  font-size: 0.85rem;
}

.sys-calendar-header.sun {
  color: #e74c3c;
}

.sys-calendar-header.sat {
  color: #3498db;
}

.sys-calendar-cell {
  background: var(--bg-card);
  min-height: 80px;
  min-width: 0;
  padding: 0.3rem;
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.sys-calendar-cell:hover {
  background: var(--bg-card-hover);
  border-color: var(--info);
}

.sys-calendar-cell .day-num {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.sys-calendar-cell.today {
  border-color: var(--highlight);
  background: rgba(233, 69, 96, 0.1);
}

.sys-calendar-cell.other-month {
  opacity: 0.3;
}

.sys-calendar-cell .event {
  font-size: 0.65rem;
  background: rgba(52, 152, 219, 0.3);
  color: var(--info);
  padding: 1px 4px;
  border-radius: 3px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

/* ============ モーダル ============ */
.sys-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 1rem;
}

.sys-modal-overlay.active {
  display: flex;
}

.sys-modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}

.sys-modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.sys-modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.sys-modal-close:hover {
  color: var(--highlight);
}

.sys-modal-body {
  padding: 1.5rem;
}

.sys-modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ============ アラート ============ */
.sys-alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.sys-alert-success {
  background: rgba(39, 174, 96, 0.15);
  border: 1px solid var(--success);
  color: #2ecc71;
}

.sys-alert-danger {
  background: rgba(231, 76, 60, 0.15);
  border: 1px solid var(--danger);
  color: #e74c3c;
}

.sys-alert-info {
  background: rgba(52, 152, 219, 0.15);
  border: 1px solid var(--info);
  color: #3498db;
}

/* ============ グリッド ============ */
.sys-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.sys-col {
  flex: 1;
  min-width: 0;
}

.sys-col-2 {
  flex: 0 0 calc(50% - 0.5rem);
}

.sys-col-3 {
  flex: 0 0 calc(33.33% - 0.67rem);
}

.sys-col-4 {
  flex: 0 0 calc(25% - 0.75rem);
}

.sys-col-auto {
  flex: 0 0 auto;
}

/* ============ 印刷用 ============ */
@media print {

  .sys-nav,
  .no-print {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  .sys-card {
    box-shadow: none;
    border: 1px solid #ddd;
  }

  .sys-table thead th {
    background: #f5f5f5;
    color: black;
  }

  .sys-main {
    max-width: 100%;
    padding: 0;
  }
}

/* ============ レスポンシブ & モバイルファースト ============ */
@media (max-width: 768px) {

  /* --- 基本設定 --- */
  html {
    font-size: 16px;
  }

  /* iOSでの拡大防止 */

  .sys-main {
    padding: 1rem 0.5rem;
  }

  /* --- ナビゲーション (ハンバーガーメニュー) --- */
  .sys-nav {
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
    position: sticky;
    top: 0;
    max-height: 60px;
    /* メニュー閉時 */
    overflow: hidden;
    transition: max-height 0.3s ease-out;
  }

  .sys-nav.active {
    max-height: 500px;
    /* メニュー開時: 十分な高さ */
    overflow-y: auto;
  }

  .sys-nav-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  /* ハンバーガーボタン (JSで注入) */
  .sys-nav-toggle {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 30px;
    height: 24px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1001;
  }

  .sys-nav-toggle span {
    width: 100%;
    height: 3px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: all 0.3s;
  }

  /* メニューリスト */
  .sys-nav-menu {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    margin-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1rem;
  }

  .sys-nav-link {
    padding: 1rem;
    border-radius: var(--radius-sm);
    text-align: left;
    font-size: 1rem;
  }

  .sys-nav-user {
    width: 100%;
    justify-content: space-between;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  /* --- タッチ操作最適化 (44px以上) --- */
  .sys-btn,
  .sys-input,
  .sys-select {
    min-height: 44px;
    font-size: 1rem;
  }

  .sys-btn-sm {
    min-height: 36px;
    padding: 0.5rem 1rem;
  }

  /* --- テーブル → カード変換 --- */
  /* .mobile-card-table クラスがついているテーブルに適用、または全ての.sys-tableに適用するか？ */
  /* 汎用的に .sys-table に適用すると副作用が大きいので、JSで制御しやすいように一旦スタイル定義する */

  .sys-table thead {
    display: none;
  }

  .sys-table tbody tr {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    padding: 1rem;
    box-shadow: var(--shadow);
  }

  .sys-table tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    text-align: right;
    /* 値は右寄せ */
  }

  .sys-table tbody td:last-child {
    border-bottom: none;
    justify-content: flex-end;
    /* アクションボタン用 */
    padding-top: 1rem;
  }

  /* data-label 属性を使って見出しを表示 */
  .sys-table tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--text-secondary);
    text-align: left;
    margin-right: 1rem;
    font-size: 0.85rem;
  }

  /* 入力フォームの調整 */
  .sys-row {
    flex-direction: column;
    gap: 1rem;
  }

  .sys-col-2,
  .sys-col-3,
  .sys-col-4 {
    width: 100%;
    flex: none;
  }

  /* モーダル */
  .sys-modal {
    width: 95%;
    max-height: 95vh;
  }

  /* --- カレンダー (Mobile) --- */

  /* Toggle Buttons Container */
  .view-toggle-group {
    display: flex !important;
    /* Show on mobile */
  }

  /* Default Grid View (Smartphone Optimized) - When .mobile-list-view is NOT present */
  .sys-calendar {
    /* Keep grid layout but optimize for small screens */
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 2px;
  }

  .sys-calendar-header {
    font-size: 0.75rem;
    /* Smaller header text */
    padding: 0.3rem 0;
    display: block !important;
    /* Force show headers in grid view */
  }

  .sys-calendar-cell {
    min-height: 80px;
    /* Allow cells to be tall */
    padding: 2px;
  }

  .sys-calendar-cell .day-num {
    font-size: 0.9rem;
    margin-bottom: 2px;
  }

  .sys-calendar-cell .event {
    font-size: 0.6rem;
    padding: 2px;
    white-space: normal;
    /* Allow text wrapping in narrow columns */
    line-height: 1.2;
    margin-bottom: 2px;
  }

  .sys-calendar-cell .mobile-dow {
    display: none !important;
    /* Hide DoW in grid view to save space */
  }

  /* --- List View Mode (Active when .mobile-list-view class is added) --- */
  .sys-calendar.mobile-list-view {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .sys-calendar.mobile-list-view .sys-calendar-header {
    display: none !important;
    /* Hide standard headers in list view */
  }

  .sys-calendar.mobile-list-view .sys-calendar-cell {
    min-height: auto;
    display: block;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
  }

  .sys-calendar.mobile-list-view .sys-calendar-cell.other-month {
    display: none;
    /* Hide other month days in list view */
  }

  .sys-calendar.mobile-list-view .sys-calendar-date-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3rem;
  }

  .sys-calendar.mobile-list-view .mobile-dow {
    display: inline-block !important;
    /* Show DoW in list view */
  }

  .sys-calendar.mobile-list-view .event {
    font-size: 0.8rem;
    padding: 0.4rem;
    margin-bottom: 0.3rem;
    height: auto;
    white-space: normal;
  }
}

/* ============ アニメーション ============ */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.sys-fade-in {
  animation: fadeIn 0.4s ease-out;
}

/* ============ トースト通知 ============ */
.sys-toast {
  position: fixed;
  top: 80px;
  right: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.5rem;
  box-shadow: var(--shadow-lg);
  z-index: 3000;
  animation: fadeIn 0.3s ease-out;
  font-size: 0.85rem;
}

.sys-toast.success {
  border-left: 4px solid var(--success);
}

.sys-toast.error {
  border-left: 4px solid var(--danger);
}

.sys-toast.info {
  border-left: 4px solid var(--info);
}