* {
  box-sizing: border-box;
}

/* 文字サイズ切替 (#83): font-size は rem 指定とし、html のクラスで基準を切り替える */
html { font-size: 16px; }
html.font-scale-sm { font-size: 14px; }
html.font-scale-md { font-size: 16px; }
html.font-scale-lg { font-size: 18px; }

.font-scale-switch { display: inline-flex; align-items: center; gap: 4px; margin-right: 8px; font-size: 0.75rem; color: #d7e7ff; }
.font-scale-switch button {
  width: auto;
  padding: 4px 10px;
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #d7e7ff;
  border-radius: 6px;
}
.font-scale-switch button:hover { background: rgba(255, 255, 255, 0.3); }
.font-scale-switch button.active { background: #ffffff; color: #123a6d; font-weight: 600; }

body {
  margin: 0;
  font-family: "Segoe UI", sans-serif;
  background: #f5f7fb;
  color: #1e2430;
}

header {
  background: #123a6d;
  color: #fff;
  padding: 16px 24px;
}

header h1 {
  margin: 0 0 4px;
  font-size: 1.375rem;
}

header p {
  margin: 0;
  font-size: 0.8125rem;
}

.header-link {
  color: #d7e7ff;
}

.header-link:hover {
  color: #ffffff;
}

.global-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 12px; }
.global-nav a { color: #d7e7ff; text-decoration: none; font-size: 0.8125rem; padding: 6px 14px; border-radius: 6px; }
.global-nav a:hover { background: rgba(255, 255, 255, 0.14); color: #ffffff; }
.global-nav a.active { background: #ffffff; color: #123a6d; font-weight: 600; }
.global-nav .nav-spacer { flex: 1; }

.section-nav {
  position: sticky; top: 0; z-index: 100;
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 8px 16px; margin: -16px -16px 0;
  background: #ffffff; border-bottom: 1px solid #d4deec;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}
.section-nav a { color: #124e96; text-decoration: none; font-size: 0.8125rem; padding: 5px 12px; border-radius: 6px; }
.section-nav a:hover { background: #e8eef7; }
.section-anchor { scroll-margin-top: 56px; }
html { scroll-behavior: smooth; }

.master-tabs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px;
  margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid #d4deec;
}
.tab-group-label { font-size: 0.6875rem; color: #697586; font-weight: 600; padding: 0 4px; }
.tab-group-label:not(:first-child) { margin-left: 10px; }
.master-tabs .tab-btn { width: auto; padding: 6px 12px; background: #e8eef7; color: #1e2430; border: 1px solid #c8d2e1; border-radius: 6px; font-size: 0.8125rem; }
.master-tabs .tab-btn:hover { background: #d7e2f2; }
.master-tabs .tab-btn.active { background: #124e96; border-color: #124e96; color: #ffffff; font-weight: 600; }

main {
  padding: 16px;
  display: grid;
  gap: 16px;
}

.grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.card {
  background: #fff;
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.excel-card {
  border: 1px solid #b8c7db;
  border-radius: 4px;
  box-shadow: none;
}

h2 { margin-top: 0; }
h3 { margin-bottom: 8px; }

form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

form button {
  grid-column: 1 / -1;
  justify-self: center;
  width: 33%;
  min-width: 140px;
  margin: 10px 0 6px;
}
/* フレックス配置のアクションボタン (モーダル・エディタ) には上記の縮小を適用しない */
.modal-actions button,
.editor-actions button {
  width: auto;
  min-width: 0;
  flex: 1 1 auto;
  margin: 0;
}

input, select, button {
  width: 100%;
  padding: 8px;
  border: 1px solid #c8d2e1;
  border-radius: 6px;
  font-size: 0.8125rem;
}

button {
  border: none;
  background: #124e96;
  color: #fff;
  cursor: pointer;
}
button:hover { background: #0e3f7a; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

th, td {
  border-bottom: 1px solid #e2e8f0;
  padding: 6px;
  text-align: left;
}
th { background: #ecf2fa; }

#toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: #123a6d;
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.2s;
}
#toast.show { opacity: 1; }

th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable::after { content: "⇅"; margin-left: 4px; font-size: 0.625rem; opacity: 0.35; }
th.sortable.sort-asc::after { content: "▲"; opacity: 1; }
th.sortable.sort-desc::after { content: "▼"; opacity: 1; }

.calendar-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.calendar-toolbar label { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8125rem; }
.calendar-toolbar button, .preset-toolbar button { width: auto; flex: 0 0 auto; white-space: nowrap; padding: 8px 14px; }
.toolbar-group { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.toolbar-group + .toolbar-group { padding-left: 10px; border-left: 1px solid #c8d2e1; }
.preset-toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.excel-legend { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 6px 0 10px; font-size: 0.75rem; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; border: 1px solid #c7d4e6; background: #fff; padding: 2px 8px; }
.legend-weekday { background: #ffffff; }
.legend-sat { background: #eef5ff; }
.legend-sun { background: #fff0f0; }
.legend-bar { width: 10px; height: 10px; display: inline-block; }
.legend-bar.crush { background: #2e90fa; }
.legend-bar.pack { background: #f79009; }
.legend-bar.sieve { background: #12b76a; }

.calendar-table-wrap { overflow-x: auto; border: 1px solid #9fb2cc; }
.calendar-table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: 0.6875rem; table-layout: fixed; }
.calendar-table th, .calendar-table td { border: 1px solid #b8c7db; vertical-align: top; padding: 4px; min-width: 170px; }
.calendar-table th { background: #d9e2f3; text-align: center; position: sticky; top: 0; z-index: 2; }
.weekday-label { font-size: 0.625rem; margin-top: 2px; }
.worker-header { min-width: 110px !important; max-width: 110px; position: sticky; left: 0; z-index: 3 !important; background: #e7edf8 !important; text-align: left !important; }
.section-header { min-width: 120px !important; max-width: 120px; background: #d9e2f3 !important; text-align: left !important; }
.weekday-col { background: #ffffff; }
.sat-col { background: #eef5ff !important; }
.sun-col { background: #fff0f0 !important; }

.timeline-cell { position: relative; min-height: 34px; }
.timeline-grid {
  position: absolute; inset: 0;
  background-image: repeating-linear-gradient(to right, rgba(150, 166, 188, 0.35) 0, rgba(150, 166, 188, 0.35) 1px, transparent 1px, transparent calc(100% / 14));
  pointer-events: none;
}
.timeline-bar {
  position: absolute;
  height: 30px;
  border: 1px solid #5f6f89;
  background: #fff;
  overflow: hidden;
  padding: 2px 4px;
  font-size: 0.625rem;
  line-height: 1.1;
  cursor: grab;
}
.task-crush { border-left: 4px solid #2e90fa; }
.task-pack { border-left: 4px solid #f79009; }
.task-sieve { border-left: 4px solid #12b76a; }

.muted { color: #697586; font-size: 0.75rem; }
.shift-type-employee { background: #e8f1ff; }
.shift-type-part-time { background: #fdf3d9; }
.shift-work-default { border-left: 4px solid #98a2b3; }
.shift-work-ns { border-left: 4px solid #1da2d8; background: #e8f8ff; }
.shift-work-01 { border-left: 4px solid #d4cc00; background: #fffbd6; }
.shift-work-type1 { border-left: 4px solid #0b2c77; background: #e9eef9; }
.shift-work-assembly { border-left: 4px solid #8bc34a; background: #f1fae7; }
.shift-work-assembly-witness { border-left: 4px solid #009688; background: #e0f4f2; }
.shift-work-pack-main { border-left: 4px solid #ff0000; background: #ffeaea; }
.shift-work-wash { border-left: 4px solid #f4b400; background: #fff6dd; }
.shift-work-pack-prep { border-left: 4px solid #e7b98a; background: #fff4ea; }
.shift-work-sieve { border-left: 4px solid #12b76a; background: #e9f9f0; }
.legend-bar.shift-work-ns { background: #1da2d8; }
.legend-bar.shift-work-01 { background: #d4cc00; }
.legend-bar.shift-work-type1 { background: #0b2c77; }
.legend-bar.shift-work-assembly { background: #8bc34a; }
.legend-bar.shift-work-assembly-witness { background: #009688; }
.legend-bar.shift-work-pack-main { background: #ff0000; }
.legend-bar.shift-work-wash { background: #f4b400; }
.legend-bar.shift-work-pack-prep { background: #e7b98a; }
.legend-bar.shift-work-sieve { background: #12b76a; }
.shift-day-off-cell { background: repeating-linear-gradient(45deg, #e4e7ec, #e4e7ec 6px, #f2f4f7 6px, #f2f4f7 12px) !important; cursor: pointer; }
.day-off-label { color: #667085; font-size: 0.625rem; font-weight: bold; white-space: nowrap; }
.production-plan-header { background: #eef7ff; }
.production-plan-cell { background: #f7fbff; font-size: 0.6875rem; padding: 4px 6px !important; }
.plan-badge { display: inline-block; border: 1px solid #b6c8e2; border-radius: 4px; padding: 1px 6px; margin: 1px 2px; background: #fff; white-space: nowrap; }
.plan-badge-crush { border-left: 4px solid #2e90fa; }
.plan-badge-sieve { border-left: 4px solid #12b76a; }
.plan-badge-pack { border-left: 4px solid #f79009; }

.shift-date-cell { min-width: 110px !important; background: #eef2f8 !important; text-align: center !important; }
.shift-hour-header { min-width: 72px !important; font-size: 0.625rem; }
.shift-hour-cell { min-width: 72px !important; vertical-align: middle !important; padding: 2px !important; position: relative; overflow: visible !important; cursor: pointer; }
.shift-hour-block {
  font-size: 0.625rem; line-height: 1.1; border: 1px solid #5f6f89; padding: 2px 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; justify-content: space-between; position: absolute; top: 2px;
  /* 30 分単位 (#47): セル内オフセットは --offset-hours (0 or 0.5) で表現 */
  left: calc((100% * var(--offset-hours, 0)) + 2px);
  width: calc((100% * var(--span-hours, 1)) - 4px); z-index: 4; cursor: grab;
}
.shift-resize-handle { margin-left: 4px; font-weight: bold; cursor: ew-resize; }
body.shift-resizing { cursor: ew-resize !important; }
body.shift-moving { cursor: grabbing !important; user-select: none; }

.editor-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.editor-overlay.hidden { display: none; }
.editor-panel { width: min(520px, 92vw); background: #ffffff; border: 1px solid #a8b8cf; border-radius: 6px; padding: 14px; }
.editor-panel form { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.editor-actions { grid-column: 1 / -1; display: flex; gap: 8px; }

.orders-filter { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.orders-filter input, .orders-filter select, .orders-filter button { max-width: 200px; }
.orders-filter label { display: inline-flex; flex-direction: column; gap: 4px; font-size: 0.75rem; }

/* 売上（日次）の合計表示 (#85) */
.sales-total { font-size: 0.875rem; font-weight: 600; color: #123a6d; margin: 0 0 8px; }

/* 担当者スキルの複数選択チェックボックスとバッジ表示 (#82) */
.checkbox-group {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid #c8d2e1;
  border-radius: 6px;
}
.checkbox-group legend { font-size: 0.75rem; color: #697586; padding: 0 4px; }
.checkbox-item { display: inline-flex; align-items: center; gap: 4px; font-size: 0.8125rem; white-space: nowrap; }
.checkbox-item input[type="checkbox"] { width: auto; }
.skill-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid #b6c8e2;
  border-radius: 12px;
  padding: 2px 4px 2px 8px;
  margin: 2px;
  background: #eef2f8;
  font-size: 0.75rem;
  white-space: nowrap;
}
.skill-badge button {
  width: auto;
  padding: 0 5px;
  margin: 0;
  background: none;
  border: none;
  color: #b42318;
  font-size: 0.75rem;
  line-height: 1.2;
  cursor: pointer;
}
.skill-badge button:hover { background: #fde8e6; border-radius: 50%; }

.btn-secondary { background: #64748b; }
.btn-secondary:hover { background: #475569; }
.btn-danger { background: #b42318; }
.btn-danger:hover { background: #912018; }

.modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 1100; }
.modal.open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.45); }
.modal-panel { position: relative; width: min(520px, 92vw); max-height: 90vh; overflow: auto; background: #fff; border-radius: 10px; padding: 16px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15); }
.modal-summary { font-size: 0.8125rem; color: #475569; margin: 0 0 12px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.row-inactive { opacity: 0.55; }
.date-cell .link-date-btn { padding: 0; border: none; background: none; color: #124e96; text-decoration: underline; cursor: pointer; font: inherit; }
.date-empty { color: #94a3b8; }
/* 必須工程が未登録のとき赤字で登録を促す (#103) */
.date-missing { color: #b42318; font-weight: 700; }
/* 全工程登録済み＋制約OKの受注行は薄緑でハイライト (#102) */
#orders-table tbody tr.order-complete > td { background: #e7f6ec; }
td.date-cell { vertical-align: top; }

.order-board-date-stack { display: flex; flex-direction: column; gap: 6px; min-width: 140px; }
.order-board-shift-sub { font-size: 0.6875rem; line-height: 1.35; color: #334155; }
.shift-seg { margin: 0; }
.shift-seg-label { font-weight: 600; color: #475569; margin-right: 4px; }
.shift-warn { margin-top: 4px; color: #b42318; font-size: 0.6875rem; font-weight: 600; }
.date-cell .link-date-btn { padding: 0; border: none; background: none; color: #124e96; text-decoration: underline; cursor: pointer; font: inherit; }
.date-cell .link-date-btn:hover { color: #0e3f7a; }

/* 大日程の依頼Noから工程計画編集を開くリンク (#75) */
.plan-edit-btn { padding: 0; border: none; background: none; color: #124e96; text-decoration: underline; cursor: pointer; font: inherit; }
.plan-edit-btn:hover { color: #0e3f7a; }

.login-card { max-width: 420px; margin: 0 auto; }
.login-form { grid-template-columns: 1fr; }
.login-error { color: #b42318; font-size: 0.8125rem; margin: 0 0 10px; }
.login-hint { margin-top: 10px; }

@media (max-width: 1100px) {
  .grid-two { grid-template-columns: 1fr; }
}

/* --- A4印刷（工程表・シフト表） --- */
.print-only {
  display: none;
}

@media print {
  @page {
    size: A4 landscape;
    margin: 8mm;
  }

  header,
  form,
  button,
  .section-nav,
  .calendar-toolbar,
  .excel-legend,
  #shift-legend,
  #toast,
  .editor-overlay,
  .modal,
  #calendar-summary,
  #shift-summary,
  main > section:not(:last-of-type) {
    display: none !important;
  }

  .print-only {
    display: block;
    font-size: 13px;
    font-weight: bold;
    margin-bottom: 4mm;
  }

  body {
    background: #fff;
  }

  main {
    padding: 0;
    gap: 0;
  }

  .card {
    box-shadow: none;
    border: none;
    padding: 0;
    border-radius: 0;
  }

  .calendar-table-wrap {
    overflow: visible;
    border: none;
  }

  .calendar-table {
    width: 100%;
    font-size: 7px;
    border-collapse: collapse;
  }

  .calendar-table th,
  .calendar-table td {
    padding: 1px 2px;
  }

  .timeline-bar,
  .shift-hour-block {
    font-size: 6px;
  }

  .shift-resize-handle {
    display: none !important;
  }

  .plan-badge {
    font-size: 6px;
    padding: 0 2px;
  }

  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* --- 閲覧のみ（viewer）ロールの編集UI制御 --- */
body.role-viewer main form { display: none !important; }
body.role-viewer [data-cust-save],
body.role-viewer [data-cust-delete],
body.role-viewer [data-prod-save],
body.role-viewer [data-prod-delete],
body.role-viewer [data-worker-save],
body.role-viewer [data-cp-delete],
body.role-viewer [data-skill-delete],
body.role-viewer [data-ws-delete],
body.role-viewer [data-constraint-delete],
body.role-viewer .open-plan-btn,
body.role-viewer #board-plan-delete-btn { display: none !important; }
body.role-viewer .link-date-btn,
body.role-viewer .plan-edit-btn { pointer-events: none; color: inherit; text-decoration: none; background: none; border: none; }
body.role-viewer table input,
body.role-viewer table select { pointer-events: none; background: transparent; border: 1px solid transparent; }
body.role-viewer .calendar-day-cell,
body.role-viewer .timeline-bar,
body.role-viewer .shift-hour-cell,
body.role-viewer .shift-hour-block,
body.role-viewer .shift-day-off-cell { pointer-events: none; }
body.role-viewer .shift-resize-handle { display: none !important; }
