:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-muted: #f9fafb;
  --text: #17202a;
  --muted: #5d6978;
  --border: #cfd6df;
  --border-strong: #1f2933;
  --primary: #1f6f5b;
  --primary-dark: #155443;
  --primary-soft: #e5f2ee;
  --blue: #255c99;
  --blue-soft: #edf4fb;
  --danger: #a83b3b;
  --danger-soft: #f7e7e7;
  --shadow: 0 1px 2px rgb(16 24 40 / 8%);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.45rem;
  line-height: 1.25;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
  line-height: 1.3;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 0;
  font-size: 0.92rem;
  line-height: 1.3;
  letter-spacing: 0;
}

.app-shell {
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-stack {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  min-width: 220px;
}

.storage-badge,
.save-status {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 9px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.storage-badge {
  border-color: #bad5cb;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 700;
}

.toolbar,
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar {
  align-items: center;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.toolbar-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
}

.button,
.icon-button,
.row-number {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-weight: 650;
}

.button {
  min-height: 36px;
  padding: 7px 12px;
  font-size: 0.9rem;
  line-height: 1.2;
}

.button:hover,
.icon-button:hover,
.row-number:hover {
  border-color: var(--blue);
}

.button:focus-visible,
.icon-button:focus-visible,
.row-number:focus-visible,
input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgb(37 92 153 / 22%);
  outline-offset: 1px;
}

.button-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.button-primary:hover {
  border-color: var(--primary-dark);
  background: var(--primary-dark);
}

.button-danger {
  border-color: #d8b0b0;
  color: var(--danger);
}

.button-danger:hover {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.meta-text {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.table-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.table-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 12px;
}

.table-frame {
  overflow: auto;
  background: #ffffff;
}

.work-table {
  width: 100%;
  min-width: 1580px;
  border-collapse: collapse;
  table-layout: fixed;
}

.risk-collapsed .work-table {
  min-width: 1060px;
}

.work-table th,
.work-table td {
  border: 2px solid var(--border-strong);
  vertical-align: middle;
}

.work-table th {
  height: 56px;
  padding: 8px 6px;
  background: #f7f8fa;
  color: #111827;
  font-size: 0.92rem;
  font-weight: 750;
  line-height: 1.25;
  text-align: center;
}

.work-table td {
  height: 124px;
  background: #ffffff;
}

.work-table tr.is-selected td {
  background: #f5fbf8;
}

.work-table tr.is-selected .row-number {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.col-no {
  width: 50px;
}

.col-unit {
  width: 118px;
}

.col-detail {
  width: 245px;
}

.col-hazard {
  width: 245px;
}

.col-safety {
  width: 255px;
}

.col-ppe {
  width: 145px;
}

.col-risk-category {
  width: 105px;
}

.col-severity {
  width: 86px;
}

.col-frequency {
  width: 74px;
}

.col-risk-level {
  width: 84px;
}

.col-allowed {
  width: 105px;
}

.col-progress {
  width: 195px;
}

.risk-collapsed [data-risk-column],
.risk-collapsed .risk-col {
  display: none;
}

.row-number {
  display: grid;
  width: calc(100% - 10px);
  min-height: 108px;
  place-items: center;
  margin: 8px 5px;
  padding: 0;
  font-size: 0.92rem;
}

.cell-input,
.cell-textarea,
.cell-select {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.4;
}

.cell-input,
.cell-select {
  height: 122px;
  min-height: 122px;
  padding: 0 8px;
}

.cell-textarea {
  height: 122px;
  min-height: 122px;
  resize: vertical;
  padding: 9px 8px;
}

.cell-input:focus,
.cell-textarea:focus,
.cell-select:focus {
  background: #fffdf4;
}

::placeholder {
  color: #8b95a3;
}

.empty-row td {
  height: 92px;
  padding: 20px;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
}

.modal {
  width: min(760px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  border: 0;
  border-radius: 10px;
  padding: 0;
  background: transparent;
}

#libraryDialog {
  width: min(1080px, calc(100vw - 24px));
}

.modal::backdrop {
  background: rgb(15 23 42 / 44%);
}

.modal-card {
  max-height: calc(100vh - 24px);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: 0 24px 64px rgb(15 23 42 / 22%);
}

.modal-card-wide {
  width: min(1080px, calc(100vw - 24px));
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 14px;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  font-size: 1.4rem;
  line-height: 1;
}

.modal-body {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 112px);
  overflow: auto;
  padding: 14px;
}

.modal-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel-muted);
}

.section-note {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.library-modal-body {
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 0;
  padding: 0;
}

.library-list-panel,
.library-editor-panel {
  min-height: 520px;
  padding: 14px;
}

.library-list-panel {
  border-right: 1px solid var(--border);
  background: var(--panel-muted);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.library-list {
  display: grid;
  gap: 8px;
  max-height: 448px;
  overflow: auto;
}

.library-item {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
}

.library-item:hover {
  border-color: var(--blue);
}

.library-item.is-selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.item-title {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-weight: 750;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-subtitle {
  display: -webkit-box;
  min-height: 2.7em;
  margin-top: 4px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.type-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-bottom: 6px;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 0.75rem;
  font-weight: 750;
}

.type-pill.is-safety {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.active-cell-help {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--blue-soft);
  color: #26435f;
  font-size: 0.86rem;
  line-height: 1.45;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field-span-2 {
  grid-column: 1 / -1;
}

.field span {
  color: #2d3745;
  font-size: 0.84rem;
  font-weight: 750;
  line-height: 1.3;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}

.field input,
.field select {
  min-height: 38px;
  padding: 8px 10px;
}

.field textarea {
  min-height: 168px;
  resize: vertical;
  padding: 9px 10px;
  line-height: 1.45;
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

@media (max-width: 920px) {
  .app-shell {
    padding: 10px;
  }

  .app-header,
  .table-panel-header,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-stack {
    justify-content: flex-start;
    min-width: 0;
  }

  .toolbar-divider {
    display: none;
  }

  .button-grid,
  .library-modal-body,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .library-list-panel,
  .library-editor-panel {
    min-height: auto;
  }

  .library-list-panel {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .field-span-2 {
    grid-column: auto;
  }
}
