/* ===== リセット & ベース ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Hiragino Sans", "Meiryo", sans-serif;
  font-size: 13px;
  background: #F4F1FB;
  color: #26215C;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== ヘッダー ===== */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #26215C;
  color: #fff;
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-title { font-size: 17px; letter-spacing: 0.05em; font-weight: 700; }

.header-actions { display: flex; gap: 8px; }

/* ===== メイン ===== */
main { flex: 1; padding: 16px 20px 80px; display: flex; flex-direction: column; gap: 14px; }

/* ===== サマリカード ===== */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.card {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  text-align: center;
}

.card-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  color: #555;
}

.card-label { font-size: 11px; color: #888; margin-top: 6px; }

.card-active .card-value { color: #1976d2; }
.card-soon   .card-value { color: #f57f17; }
.card-over   .card-value { color: #c62828; }

/* ===== フィルターバー ===== */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
}

.filter-bar input[type="text"] {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
}

.filter-bar select {
  padding: 7px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  background: #fff;
}

/* ===== テーブル ===== */
.table-container {
  flex: 1;
  overflow-y: auto;
  max-height: calc(100vh - 310px);
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #EBE8F8;
  padding: 9px 10px;
  text-align: left;
  font-weight: 700;
  white-space: nowrap;
  border-bottom: 2px solid #C5C0E8;
  font-size: 12px;
}

.th-sort {
  cursor: pointer;
  user-select: none;
}

.th-sort:hover { background: #d5d9f0; }

.sort-icon {
  display: inline-block;
  margin-left: 4px;
  color: #9fa8da;
  font-size: 10px;
  vertical-align: middle;
}

.th-sort.sort-asc  .sort-icon::after { content: "▲"; color: #534AB7; }
.th-sort.sort-desc .sort-icon::after { content: "▼"; color: #534AB7; }
.th-sort:not(.sort-asc):not(.sort-desc) .sort-icon::after { content: "⇅"; }

.th-actions { width: 60px; }

tbody td {
  padding: 8px 10px;
  border-top: 1px solid #eee;
  vertical-align: middle;
}

tbody tr:hover td { background: #f5f5ff; }

.td-name { min-width: 160px; max-width: 240px; word-break: break-all; }

.empty-msg {
  text-align: center;
  padding: 48px;
  color: #aaa;
  background: #fff;
}

/* ===== 納期アラート ===== */
.due-soon { color: #f57f17; font-weight: 600; }
.due-over { color: #c62828; font-weight: 600; }

.due-days {
  display: block;
  font-size: 11px;
  font-weight: 400;
  margin-top: 2px;
  line-height: 1;
}

.due-days.ok    { color: #888; }
.due-days.soon  { color: #f57f17; }
.due-days.over  { color: #c62828; }

/* ===== ステータスバッジ ===== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-受注   { background: #e3f2fd; color: #1565c0; }
.badge-設計中 { background: #e8f5e9; color: #2e7d32; }
.badge-製造中 { background: #fff3e0; color: #e65100; }
.badge-検査中 { background: #f3e5f5; color: #6a1b9a; }
.badge-出荷待ち { background: #EBE8F8; color: #3C3489; }
.badge-完了   { background: #eeeeee; color: #616161; }

/* ===== 状態インラインドロップダウン ===== */
.status-select {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  font-family: inherit;
}
.status-select:hover,
.status-select:focus { border-color: rgba(0,0,0,0.2); }

.status-select.s-受注    { background: #e3f2fd; color: #1565c0; }
.status-select.s-設計中  { background: #e8f5e9; color: #2e7d32; }
.status-select.s-製造中  { background: #fff3e0; color: #e65100; }
.status-select.s-検査中  { background: #f3e5f5; color: #6a1b9a; }
.status-select.s-出荷待ち { background: #EBE8F8; color: #3C3489; }
.status-select.s-完了    { background: #eeeeee; color: #616161; }

/* ===== ボタン ===== */
.btn {
  padding: 7px 14px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.btn-primary            { background: #534AB7; color: #fff; }
.btn-primary:hover      { background: #3C3489; }
.btn-secondary          { background: #e0e0e0; color: #333; }
.btn-secondary:hover    { background: #bdbdbd; }
.btn-danger             { background: #ffebee; color: #c62828; border: 1px solid #ef9a9a; }
.btn-danger:hover       { background: #ffcdd2; border-color: #e57373; }
.btn-sm                 { padding: 5px 10px; font-size: 12px; }
.btn:disabled           { opacity: 0.4; cursor: not-allowed; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  padding: 2px 4px;
  opacity: 0.7;
}
.btn-icon:hover { opacity: 1; }

/* ===== バージョンボタン ===== */
.btn-version {
  position: fixed;
  bottom: 14px;
  left: 14px;
  background: rgba(0,0,0,0.12);
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 11px;
  color: #555;
  cursor: pointer;
  z-index: 90;
}
.btn-version:hover { background: rgba(0,0,0,0.2); }

/* ===== フィードバックバー ===== */
.feedback-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.feedback-label { font-size: 12px; color: #888; white-space: nowrap; }

.feedback-bar input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
}

/* ===== モーダル ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border-radius: 8px;
  padding: 28px;
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 300;
  box-shadow: 0 6px 32px rgba(0,0,0,0.22);
}

.modal-wide { width: 960px; }

.modal h2 { font-size: 16px; margin-bottom: 16px; }

.modal-subtitle { font-size: 13px; color: #666; margin-bottom: 14px; }

.modal-hint {
  font-size: 12px;
  color: #666;
  background: #f5f5f5;
  padding: 8px 12px;
  border-radius: 4px;
  margin-bottom: 12px;
}

.modal-hint code { font-family: monospace; color: #333; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ===== フォームグリッド ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: #555;
}

.form-grid label.full { grid-column: 1 / -1; }

.form-grid input,
.form-grid select,
.form-grid textarea {
  padding: 7px 9px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}

.form-grid textarea {
  resize: vertical;
  min-height: 72px;
}

.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  outline: none;
  border-color: #534AB7;
  box-shadow: 0 0 0 2px rgba(83,74,183,0.15);
}

.req { color: #e53935; }

/* ===== 工番セル ===== */
.td-kbn { white-space: nowrap; }

.kbn-unset {
  font-size: 11px;
  color: #999;
  background: repeating-linear-gradient(
    45deg,
    #fff9c4,
    #fff9c4 3px,
    #fffde7 3px,
    #fffde7 7px
  );
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid #f9a825;
  white-space: nowrap;
}

/* ===== 備考セル ===== */
.td-note {
  max-width: 0; /* overflow hidden trick */
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #888;
  font-size: 12px;
}

/* ===== 盤チェックリスト ===== */
.check-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.check-list li label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  padding: 6px 0;
}

.check-list li label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ===== CSV プレビュー ===== */
.csv-file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.csv-filename { font-size: 12px; color: #666; }

#csv-input {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 12px;
  font-family: monospace;
  resize: vertical;
}

.csv-preview {
  margin-top: 12px;
  font-size: 12px;
}

.csv-preview p { margin-bottom: 8px; color: #555; }

.csv-preview table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.csv-preview th,
.csv-preview td {
  border: 1px solid #ddd;
  padding: 4px 8px;
  text-align: left;
}

.csv-preview th { background: #f5f5f5; }

/* ===== 備考セル ===== */
.td-note {
  min-width: 80px;
  max-width: 140px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.td-note:hover { background: #f0f4ff; }

.note-text {
  font-size: 12px;
  color: #555;
}

.note-empty {
  font-size: 11px;
  color: #bbb;
  user-select: none;
}

/* ===== 備考ポップアップ ===== */
.note-popup {
  position: fixed;
  z-index: 400;
  background: #fff;
  border: 1px solid #C5C0E8;
  border-radius: 8px;
  padding: 12px;
  width: 260px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.18);
}

.note-popup-header {
  font-size: 12px;
  font-weight: 700;
  color: #534AB7;
  margin-bottom: 8px;
}

#note-popup-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
  min-height: 72px;
}

#note-popup-input:focus {
  outline: none;
  border-color: #534AB7;
  box-shadow: 0 0 0 2px rgba(83,74,183,0.15);
}

.note-popup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
}

/* ===== 進捗バー ===== */
.td-progress {
  min-width: 80px;
  cursor: pointer;
}

.prog-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.prog-wrap:hover .prog-bar-bg {
  outline: 2px solid #534AB7;
  border-radius: 4px;
}

.prog-bar-bg {
  flex: 1;
  height: 10px;
  background: #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
}

.prog-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.2s;
}

.prog-pct {
  font-size: 11px;
  color: #666;
  white-space: nowrap;
  min-width: 28px;
  text-align: right;
}

.prog-edit {
  display: flex;
  align-items: center;
  gap: 6px;
}

.prog-slider {
  flex: 1;
  width: 100%;
  accent-color: #534AB7;
  cursor: pointer;
}

.prog-slider-val {
  font-size: 11px;
  color: #333;
  font-weight: 600;
  white-space: nowrap;
  min-width: 28px;
  text-align: right;
}

/* ===== メイン画面 ===== */
#hub-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.hub-main {
  padding: 32px 24px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.hub-heading {
  font-size: 15px;
  color: #666;
  margin-bottom: 24px;
  font-weight: 600;
}

.hub-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.hub-card {
  width: 200px;
  background: #fff;
  border-radius: 10px;
  padding: 24px 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  border: 2px solid transparent;
  transition: transform 0.15s, box-shadow 0.15s;
}

.hub-card-active {
  border-color: #534AB7;
  cursor: pointer;
}

.hub-card-active:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(83,74,183,0.18);
}

.hub-card-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hub-card-icon { font-size: 32px; line-height: 1; }

.hub-card-name {
  font-size: 14px;
  font-weight: 700;
  color: #333;
}

.hub-card-desc {
  font-size: 11px;
  color: #888;
  line-height: 1.5;
  flex: 1;
}

.hub-card-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  width: fit-content;
  margin-top: 4px;
}

.hub-badge-active  { background: #e8f5e9; color: #2e7d32; }
.hub-badge-planned { background: #f5f5f5; color: #999; }

/* ===== ← メイン画面 ボタン ===== */
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-back {
  color: rgba(255,255,255,0.8);
  font-size: 12px;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-back:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

/* ===== ログイン画面 ===== */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #F4F1FB;
}

.login-card {
  background: #fff;
  border-radius: 10px;
  padding: 40px 36px;
  width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.12);
}

.login-logo {
  font-size: 18px;
  font-weight: 700;
  color: #26215C;
  text-align: center;
  margin-bottom: 8px;
}

.login-subtitle {
  font-size: 11px;
  color: #aaa;
  text-align: center;
  margin-bottom: 24px;
  line-height: 1.5;
}

.login-form-group {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 16px;
}

.login-form-group label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: #555;
}

.login-form-group input,
.login-form-group select {
  padding: 9px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}

.login-form-group input:focus,
.login-form-group select:focus {
  outline: none;
  border-color: #534AB7;
  box-shadow: 0 0 0 2px rgba(83,74,183,0.15);
}

.login-error {
  color: #c62828;
  font-size: 12px;
  padding: 6px 10px;
  background: #ffebee;
  border-radius: 4px;
  margin-bottom: 10px;
}

.login-btn-wrap .btn {
  width: 100%;
  padding: 10px;
}

/* ===== API エラーバナー ===== */
.api-error-banner {
  background: #fff3e0;
  color: #e65100;
  border: 1px solid #ffb74d;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
}

/* ===== ヘッダー：ユーザー情報 ===== */
.header-userinfo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: rgba(255,255,255,0.85);
  margin-left: 8px;
  padding-left: 12px;
  border-left: 1px solid rgba(255,255,255,0.2);
}

/* ===== 改定履歴 ===== */
.version-log h3 {
  font-size: 14px;
  margin: 14px 0 6px;
  color: #333;
}

.version-log h3:first-child { margin-top: 0; }

.vdate { font-size: 12px; color: #888; font-weight: 400; margin-left: 8px; }

.version-log ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.version-log li { font-size: 13px; color: #555; }

/* ===== ダークモード ===== */
html.dark body { background: #0F0B1A; color: #EEEDFE; }
html.dark header { background: #110D30; }
html.dark .card, html.dark table { background: #1A1440; }
html.dark thead th { background: #1E1850; border-bottom-color: #3D3880; color: #EEEDFE; }
html.dark tbody td { border-top-color: #2D2860; color: #EEEDFE; }
html.dark tbody tr:hover td { background: #1E1850; }
html.dark .hub-card { background: #1A1440; color: #EEEDFE; }
html.dark .hub-card-name { color: #EEEDFE; }
html.dark .hub-card-desc { color: #AFA9EC; }
html.dark .hub-heading { color: #AFA9EC; }
html.dark #login-screen { background: #0F0B1A; }
html.dark .login-card { background: #1A1440; }
html.dark .login-logo { color: #EEEDFE; }
html.dark .login-subtitle { color: #7F77DD; }
html.dark .login-form-group label { color: #AFA9EC; }
html.dark .login-form-group input,
html.dark .login-form-group select {
  background: #0F0B1A; border-color: #534AB7; color: #EEEDFE;
}
html.dark .login-error { background: #2A0A0A; color: #FF8080; }
html.dark .modal { background: #1A1440; color: #EEEDFE; }
html.dark .modal h2 { color: #EEEDFE; }
html.dark .modal-hint { background: #0F0B1A; color: #AFA9EC; }
html.dark .modal-overlay { background: rgba(0,0,0,0.65); }
html.dark .form-grid input,
html.dark .form-grid select,
html.dark .form-grid textarea,
html.dark .form-row input,
html.dark .form-row select {
  background: #0F0B1A; border-color: #534AB7; color: #EEEDFE;
}
html.dark .filter-bar input,
html.dark .filter-bar select { background: #1A1440; border-color: #534AB7; color: #EEEDFE; }
html.dark .btn-secondary { background: #2D2860; color: #EEEDFE; }
html.dark .btn-secondary:hover { background: #3D3880; }
html.dark .btn-theme { background: transparent; border: 1px solid rgba(255,255,255,0.3); color: #fff; }
html.dark .api-error-banner { background: #2A1800; color: #FFA733; border-color: #7A4800; }
html.dark .feedback-bar { background: #1A1440; }
html.dark .feedback-bar input { background: #0F0B1A; border-color: #534AB7; color: #EEEDFE; }
html.dark .note-popup { background: #1A1440; border-color: #534AB7; }
html.dark .note-popup-header { color: #7F77DD; }
html.dark #note-popup-input { background: #0F0B1A; border-color: #534AB7; color: #EEEDFE; }
html.dark .profile-card { background: #1A1440; border-color: #2D2860; }
html.dark .profile-card h2 { color: #EEEDFE; border-bottom-color: #2D2860; }
html.dark .profile-row { border-bottom-color: #2D2860; }
html.dark .profile-label { color: #AFA9EC; }
html.dark .profile-value { color: #EEEDFE; }
html.dark .users-table th { background: #1E1850; color: #EEEDFE; }
html.dark .users-table td { border-bottom-color: #2D2860; color: #EEEDFE; }
html.dark .users-table tbody tr:hover { background: #1E1850; }
html.dark .form-row label { color: #AFA9EC; }
html.dark .form-hint { color: #7F77DD; }
html.dark .perm-check-row { border-bottom-color: #2D2860; color: #EEEDFE; }
html.dark .perm-check-row .perm-status { color: #7F77DD; }
html.dark .login-logo svg text { fill: #EEEDFE; }
