/* =============================================
   生産計画表 - メインスタイル
   ============================================= */

:root {
  --color-primary:    #2563eb;
  --color-success:    #16a34a;
  --color-info:       #0891b2;
  --color-danger:     #dc2626;
  --color-warning:    #d97706;
  --color-bg:         #f0f4f8;
  --color-surface:    #ffffff;
  --color-border:     #cbd5e1;
  --color-text:       #1e293b;
  --color-muted:      #64748b;

  --color-planned-bg:  #eff6ff;
  --color-planned-txt: #1d4ed8;
  --color-actual-bg:   #f0fdf4;
  --color-actual-txt:  #15803d;
  --color-assignee-bg: #fefce8;
  --color-assignee-txt:#a16207;

  --color-over:        #bbf7d0;
  --color-under:       #fecaca;
  --color-weekend-sat: #e0f2fe;
  --color-weekend-sun: #fee2e2;
  --color-holiday:     #fef9c3;

  --header-h: 64px;
  --footer-h: 40px;
  --frozen-col1-w: 72px;
  --frozen-col2-w: 160px;
  --frozen-col3-w: 56px;
  --cell-w: 52px;
  --row-h: 28px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.12);
  --radius:   6px;
  --transition: .15s ease;
}

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

body {
  font-family: 'Noto Sans JP', 'Hiragino Kaku Gothic Pro', Meiryo, sans-serif;
  font-size: 13px;
  background: var(--color-bg);
  color: var(--color-text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---- Header ---- */
#main-header {
  height: var(--header-h);
  background: var(--color-surface);
  border-bottom: 2px solid var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  z-index: 100;
}

#app-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-primary);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
#app-title i { font-size: 18px; }

#header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.date-field {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 4px 10px;
}
.date-field label {
  font-size: 11px;
  color: var(--color-muted);
  font-weight: 500;
  white-space: nowrap;
}
.date-field input[type="date"] {
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--color-text);
  font-family: inherit;
  outline: none;
  cursor: pointer;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter var(--transition), transform var(--transition);
  white-space: nowrap;
}
.btn:hover  { filter: brightness(1.08); transform: translateY(-1px); }
.btn:active { filter: brightness(.95); transform: translateY(0); }
.btn i { font-size: 11px; }

.btn-primary   { background: var(--color-primary); color: #fff; }
.btn-success   { background: var(--color-success); color: #fff; }
.btn-info      { background: var(--color-info);    color: #fff; }
.btn-danger    { background: var(--color-danger);  color: #fff; }
.btn-secondary { background: #e2e8f0; color: var(--color-text); }

/* ---- Main / Table wrapper ---- */
#main-content {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

#table-wrapper {
  flex: 1;
  overflow: auto;
  position: relative;
  background: var(--color-surface);
  margin: 8px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

/* ---- Loading overlay ---- */
#loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 200;
  border-radius: var(--radius);
  transition: opacity .3s;
}
#loading-overlay.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 36px; height: 36px;
  border: 4px solid #e2e8f0;
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Table ---- */
#production-table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  table-layout: fixed;
}

#production-table th,
#production-table td {
  border: 1px solid #d1d5db;
  text-align: center;
  vertical-align: middle;
  padding: 0 3px;
  height: var(--row-h);
  white-space: nowrap;
  font-size: 12px;
}

/* ---- Sticky columns ---- */
.col-process {
  position: sticky;
  left: 0;
  z-index: 30;
  width: var(--frozen-col1-w);
  min-width: var(--frozen-col1-w);
  max-width: var(--frozen-col1-w);
  background: #f8fafc;
  font-weight: 700;
  writing-mode: vertical-lr;
  letter-spacing: 2px;
  font-size: 12px;
}
.col-product {
  position: sticky;
  left: var(--frozen-col1-w);
  z-index: 30;
  width: var(--frozen-col2-w);
  min-width: var(--frozen-col2-w);
  max-width: var(--frozen-col2-w);
  background: #f8fafc;
  text-align: left;
  padding: 0 8px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-rowtype {
  position: sticky;
  left: calc(var(--frozen-col1-w) + var(--frozen-col2-w));
  z-index: 30;
  width: var(--frozen-col3-w);
  min-width: var(--frozen-col3-w);
  max-width: var(--frozen-col3-w);
  background: #f8fafc;
  font-weight: 600;
  font-size: 11px;
}

/* sticky-col shadow effect */
.col-process::after,
.col-product::after,
.col-rowtype::after {
  content: '';
  position: absolute;
  top: 0; right: -4px; bottom: 0;
  width: 4px;
  background: linear-gradient(to right, rgba(0,0,0,.06), transparent);
  pointer-events: none;
}
.col-rowtype::after { display: block; }

/* ---- Header rows ---- */
thead th {
  background: #1e3a5f;
  color: #fff;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 20;
}
thead .col-process,
thead .col-product,
thead .col-rowtype {
  background: #1e3a5f;
  color: #fff;
  z-index: 40;
}

/* Date header row */
.th-date {
  font-size: 12px;
  font-weight: 700;
  width: var(--cell-w);
  min-width: var(--cell-w);
  max-width: var(--cell-w);
  background: #2d4f7c;
}
.th-date.weekend-sat { background: #1e5a8a !important; }
.th-date.weekend-sun { background: #7c2d2d !important; }
.th-date.holiday     { background: #7c6b1e !important; }

/* Weekday row */
.th-weekday {
  font-size: 11px;
  width: var(--cell-w);
  background: #34619e;
}
.th-weekday.weekend-sat { background: #1e6aaa; }
.th-weekday.weekend-sun { background: #aa2424; }
.th-weekday.holiday     { background: #aa8824; }

/* ---- Data rows ---- */
tr.row-planned   td { background: var(--color-planned-bg); }
tr.row-actual    td { background: var(--color-actual-bg);  }
tr.row-assignee  td { background: var(--color-assignee-bg);}

tr.row-planned   .col-rowtype { color: var(--color-planned-txt);  background: #dbeafe; }
tr.row-actual    .col-rowtype { color: var(--color-actual-txt);   background: #dcfce7; }
tr.row-assignee  .col-rowtype { color: var(--color-assignee-txt); background: #fef9c3; }

/* Sticky columns in data rows must keep their bg */
tr.row-planned   .col-process,
tr.row-planned   .col-product { background: #dbeafe; }
tr.row-actual    .col-process,
tr.row-actual    .col-product { background: #dcfce7; }
tr.row-assignee  .col-process,
tr.row-assignee  .col-product { background: #fef9c3; }

/* Separator row between products */
tr.row-separator td {
  height: 4px;
  background: #94a3b8;
  padding: 0;
  border: none;
}

/* Process group separator */
tr.row-process-sep td {
  height: 6px;
  background: #1e3a5f;
  padding: 0;
  border: none;
}

/* Weekend / holiday columns */
td.weekend-sat { background: var(--color-weekend-sat) !important; }
td.weekend-sun { background: var(--color-weekend-sun) !important; }
td.holiday     { background: var(--color-holiday)     !important; }

/* Achievement coloring */
td.cell-over  { background: var(--color-over)  !important; }
td.cell-under { background: var(--color-under) !important; }

/* Editable cells */
td.editable {
  cursor: text;
  transition: background var(--transition);
}
td.editable:hover { outline: 2px solid var(--color-primary); outline-offset: -2px; }
td.editable.editing { outline: 2px solid var(--color-primary); outline-offset: -2px; background: #fff !important; }

td.editable input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-size: 12px;
  font-family: inherit;
  color: var(--color-text);
  outline: none;
}

/* Delete button cell */
.cell-actions {
  width: 32px;
  min-width: 32px;
}
.btn-delete-row {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 11px;
  transition: color var(--transition), background var(--transition);
}
.btn-delete-row:hover { color: var(--color-danger); background: #fee2e2; }

/* Process name in data rows */
.process-label {
  font-size: 11px;
  letter-spacing: 1px;
}

/* ---- Footer / Status bar ---- */
#status-bar {
  height: var(--footer-h);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 12px;
  color: var(--color-muted);
  flex-shrink: 0;
}

#legend { display: flex; gap: 12px; align-items: center; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
}
.legend-item::before {
  content: '';
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,.15);
}
.legend-item.planned::before  { background: var(--color-planned-bg); }
.legend-item.actual::before   { background: var(--color-actual-bg); }
.legend-item.assignee::before { background: var(--color-assignee-bg); }
.legend-item.over::before     { background: var(--color-over); }
.legend-item.under::before    { background: var(--color-under); }

/* ---- Modals ---- */
.modal { position: fixed; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
}

.modal-box {
  position: relative;
  background: var(--color-surface);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  width: 420px;
  max-width: 95vw;
  animation: fadeUp .2s ease;
}
.modal-box-sm { width: 340px; }

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--color-border);
}
.modal-header h2 { font-size: 15px; font-weight: 700; color: var(--color-text); display: flex; align-items: center; gap: 8px; }
.modal-close { background: none; border: none; font-size: 16px; color: var(--color-muted); cursor: pointer; padding: 4px; border-radius: 4px; line-height: 1; }
.modal-close:hover { background: #f1f5f9; color: var(--color-text); }

.modal-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--color-muted); }
.form-group input {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--color-text);
  outline: none;
  transition: border-color var(--transition);
}
.form-group input:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--color-border);
}

/* ---- Toast notification ---- */
#toast-container {
  position: fixed;
  bottom: 56px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 600;
}
.toast {
  background: #1e293b;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn .2s ease, fadeOut .4s ease 2.6s forwards;
  box-shadow: var(--shadow-md);
}
.toast.success { border-left: 4px solid var(--color-success); }
.toast.error   { border-left: 4px solid var(--color-danger);  }
.toast.info    { border-left: 4px solid var(--color-info);    }
@keyframes slideIn  { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeOut  { to   { opacity: 0; transform: translateX(20px); } }

/* ---- Scrollbar ---- */
#table-wrapper::-webkit-scrollbar { width: 8px; height: 8px; }
#table-wrapper::-webkit-scrollbar-track { background: #f1f5f9; }
#table-wrapper::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 4px; }
#table-wrapper::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  #app-title { font-size: 16px; }
  .date-field { padding: 3px 7px; }
  .btn { padding: 5px 10px; font-size: 11px; }
  :root { --cell-w: 44px; --frozen-col2-w: 120px; }
}
