:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --stripe: #eef1f5;
  --border: #e2e5ea;
  --text: #1c1f26;
  --muted: #6b7280;
  --accent: #d63384;
  --accent-soft: #fbe4ef;
  --active: #1a9c6f;
  --active-soft: #e3f7ef;
  --cancelled: #d84343;
  --cancelled-soft: #fcebeb;
  --stale: #c8860a;
  --stale-soft: #fdf1dc;
  --field-bg: #fbfbfc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .06), 0 1px 8px rgba(20, 20, 30, .04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 320px;
}

.login-box h1 {
  font-size: 18px;
  margin: 0 0 20px;
}

.login-box label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0 4px;
}

.login-box select, .login-box input, select, input:not([type="checkbox"]):not([type="radio"]), textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
}

input[type="checkbox"], input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

button {
  cursor: pointer;
  font-family: inherit;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
}

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

.btn-primary:hover { opacity: .9; }

.login-box .btn-primary {
  width: 100%;
  margin-top: 18px;
  padding: 10px;
}

#error-msg {
  color: var(--cancelled);
  font-size: 12px;
  margin-top: 8px;
  min-height: 14px;
}

#app { display: none; min-height: 100vh; }
#app.visible { display: flex; }

nav#sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
}

nav#sidebar h2 {
  font-size: 14px;
  padding: 0 16px 12px;
  margin: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

nav#sidebar .tab {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 16px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 13px;
  border-left: 3px solid transparent;
}

nav#sidebar .tab:hover { background: var(--bg); }
nav#sidebar .tab.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  font-weight: 600;
}

nav#sidebar .user-info {
  padding: 12px 16px 0;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

nav#sidebar .user-info button { margin-top: 8px; }

main#content {
  flex: 1;
  padding: 24px 28px;
  max-width: 100%;
  overflow-x: auto;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.view-header h1 { font-size: 18px; margin: 0; }

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: center;
}

.toolbar select, .toolbar input:not([type="checkbox"]) {
  width: auto;
  min-width: 120px;
}

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
  max-height: calc(100vh - 160px);
}

table { border-collapse: collapse; width: 100%; font-size: 13px; white-space: nowrap; }

th, td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  background: var(--panel);
  color: var(--muted);
  font-weight: 600;
  z-index: 1;
  cursor: pointer;
}

tbody tr:nth-child(even) td { background: var(--stripe); }
tr:hover td { background: var(--accent-soft) !important; }

tr.row-stale td { background: var(--stale-soft); }
tr.row-stale:hover td { background: var(--accent-soft) !important; }

td input, td select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 7px;
  background: var(--field-bg);
  color: var(--text);
  font-size: 13px;
}

td input:hover, td select:hover { border-color: var(--accent); }
td input:focus, td select:focus { border-color: var(--accent); background: var(--panel); outline: none; box-shadow: 0 0 0 2px var(--accent-soft); }

.content-cell {
  min-width: 110px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 10px) center, calc(100% - 5px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 20px !important;
}

.content-cell::placeholder { color: var(--border); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--muted);
}

.legend-chip { display: flex; align-items: center; gap: 6px; }

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  flex-shrink: 0;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge.active { background: var(--active-soft); color: var(--active); }
.badge.cancelled { background: var(--cancelled-soft); color: var(--cancelled); }
.badge.stale { background: var(--stale-soft); color: var(--stale); }

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.stat-card .label { font-size: 12px; color: var(--muted); }
.stat-card .value { font-size: 24px; font-weight: 700; margin-top: 4px; }

.checkbox-cell { text-align: center; }
.checkbox-cell input { width: auto; }

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12px;
}

.pill button {
  border: none;
  background: none;
  color: var(--cancelled);
  font-size: 13px;
  padding: 0;
}

.pill[draggable="true"] { cursor: grab; }
.pill.dragging { opacity: .4; }
.pill-handle { color: var(--border); font-size: 13px; cursor: grab; }

.add-row-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  z-index: 100;
}

.toast.show { opacity: 1; }

.help-text {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
  white-space: pre-line;
}

.loading { color: var(--muted); padding: 20px; }

/* ── 権限モード: 編集系コントロールを無効化・非表示 ──
   editable      = マスター権限のみ編集可（作業者・閲覧のみは無効化）
   worker-editable = マスター+作業者が編集可（閲覧のみだけ無効化。最終更新日フィールド用）
   master-only   = マスター権限のみ表示（作業者・閲覧のみは非表示） */
.viewer-mode .editable, .worker-mode .editable {
  pointer-events: none;
  background: var(--bg) !important;
  color: var(--muted);
}
.viewer-mode .worker-editable {
  pointer-events: none;
  background: var(--bg) !important;
  color: var(--muted);
}
.viewer-mode .master-only, .worker-mode .master-only { display: none !important; }

.viewer-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--stale-soft);
  color: var(--stale);
  font-size: 11px;
  font-weight: 600;
}
