:root {
  --bg: #f4f6f9;
  --card: #fff;
  --border: #d8dee9;
  --text: #1c1e21;
  --muted: #5f6368;
  --primary: #1a73e8;
  --primary-hover: #1558b0;
  --danger: #c5221f;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.top-bar h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.top-bar a {
  color: var(--primary);
  text-decoration: none;
}

.top-nav {
  display: flex;
  gap: 16px;
  align-items: center;
}

.top-nav a[aria-current="page"] {
  font-weight: 600;
  text-decoration: underline;
}

.top-bar a:hover {
  text-decoration: underline;
}

.folder-panel {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

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

#folder-input {
  flex: 1;
  min-width: 240px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

label {
  font-weight: 600;
  font-size: 0.9rem;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 8px;
}

.file-list-wrap {
  margin-top: 24px;
}

.file-list-wrap h2 {
  font-size: 1rem;
  margin-bottom: 10px;
}

.file-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.9rem;
}

.file-table th,
.file-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.file-table th {
  background: #eef1f6;
  font-weight: 600;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn.small {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-danger {
  background: #fce8e6;
  color: var(--danger);
  border: 1px solid #f0c8c6;
}

.btn-danger:hover {
  background: #fad2cf;
}

.work {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 20px 32px;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: stretch;
}

@media (max-width: 900px) {
  .split {
    grid-template-columns: 1fr;
  }
}

.pane {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.preview-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

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

.preview-header h2 {
  margin: 0;
  flex: 1;
  min-width: 0;
}

.preview-index {
  flex-shrink: 0;
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  padding-top: 2px;
}

.preview-index.hidden {
  display: none;
}

.form-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: calc(100vh - 120px);
}

.pane h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.preview-box {
  position: relative;
  flex: 1;
  min-height: 360px;
  background: #fafafa;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.preview-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.preview-fit-group,
.preview-rotate-group,
.preview-zoom-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.preview-fit-btn.active {
  background: var(--primary);
  color: #fff;
}

.preview-fit-btn.active:hover {
  background: var(--primary-hover);
}

.preview-controls.hidden {
  display: none;
}

.preview-zoom-label {
  min-width: 3.2rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.preview-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.preview-viewport.dragging {
  cursor: grabbing;
}

#preview-img {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: none;
  max-height: none;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
}

#preview-pdf {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: #525659;
}

.hidden {
  display: none !important;
}

.common-fields {
  display: grid;
  grid-template-columns: 2fr 1fr 2fr;
  gap: 12px;
  margin-bottom: 16px;
  align-items: end;
}

@media (max-width: 640px) {
  .common-fields {
    grid-template-columns: 1fr;
  }
}

.field label {
  display: block;
  margin-bottom: 4px;
}

.field input,
.field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-sizing: border-box;
}

.field-committee select,
.field-name input {
  font-size: 0.9rem;
}

.field-empno input {
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", "Consolas", monospace;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.rows-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.rows-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-row-del {
  background: #fce8e6;
  color: var(--danger);
  border: 1px solid #f0c8c6;
}

.btn-row-del:hover:not(:disabled) {
  background: #fad2cf;
}

.rows-title {
  font-weight: 600;
}

.preview-box .placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.table-scroll {
  overflow: auto;
  flex: 1 1 auto;
  min-height: 160px;
  max-height: min(calc(100vh - 420px), 480px);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0;
}

.edit-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef1f6;
  white-space: nowrap;
  box-shadow: 0 1px 0 var(--border);
  font-size: 0.68rem;
  line-height: 1.25;
  font-weight: 600;
}

.edit-table thead th.col-amt {
  white-space: normal;
  text-align: center;
  vertical-align: bottom;
  padding: 2px 1px;
}

.edit-table tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: #eef1f6;
  box-shadow: 0 -1px 0 var(--border);
}

.edit-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.72rem;
  table-layout: fixed;
  /* 日付列（等幅10文字想定） */
  --date-col-w: 5.5rem;
  --content-col-w: 9.5rem;
  --amt-col-w: 3.6rem;
}

.edit-table col.col-date {
  width: var(--date-col-w);
}

.edit-table col.col-amt {
  width: var(--amt-col-w);
}

.edit-table col.col-content {
  width: var(--content-col-w);
}

.edit-table tbody tr {
  cursor: pointer;
}

.edit-table tbody tr.row-selected {
  background: #e8f0fe;
}

.edit-table tbody tr.row-selected input[type="text"] {
  background: #fff;
}

.edit-table th,
.edit-table td {
  padding: 2px 3px;
  border: 1px solid var(--border);
  vertical-align: middle;
}

.edit-table input[type="text"]:not(.field-date) {
  width: 100%;
  min-width: 0;
  padding: 2px 3px;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: 0.72rem;
  line-height: 1.3;
  box-sizing: border-box;
}

.edit-table input[type="text"]:not(.field-date):focus {
  border-color: var(--primary);
  outline: none;
}

.edit-table th.col-date,
.edit-table td.col-date {
  width: var(--date-col-w);
  min-width: var(--date-col-w);
  max-width: var(--date-col-w);
  padding: 1px 2px;
  overflow: hidden;
  box-sizing: border-box;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", "Consolas", monospace;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.edit-table thead th.col-date {
  white-space: normal;
  font-family: inherit;
  font-size: 0.62rem;
  line-height: 1.2;
  vertical-align: bottom;
}

.edit-table th.col-content,
.edit-table td.col-content {
  overflow: hidden;
  box-sizing: border-box;
  max-width: var(--content-col-w);
}

.edit-table th.col-amt,
.edit-table td.col-amt {
  width: var(--amt-col-w);
  min-width: var(--amt-col-w);
  max-width: var(--amt-col-w);
  padding: 2px 1px;
  box-sizing: border-box;
}

.edit-table td.col-date input.field-date {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 1px 0;
  margin: 0;
  font: inherit;
  letter-spacing: 0;
  box-sizing: border-box;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
}

.edit-table td.col-date input.field-date:focus {
  border-color: var(--primary);
  outline: none;
  background: #fff;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  font-weight: 600;
  background: var(--card);
}

.btn-icon-add {
  color: var(--primary);
  border-color: #c6dafc;
  background: #e8f0fe;
}

.btn-icon-add:hover {
  background: #d2e3fc;
}

.btn-icon-del {
  color: var(--danger);
  border-color: #f0c8c6;
  background: #fce8e6;
  font-size: 1rem;
}

.btn-icon-del:hover {
  background: #fad2cf;
}

.status {
  margin-top: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

.status.error {
  color: var(--danger);
  white-space: pre-wrap;
}

#folder-hint.error {
  color: var(--danger);
  white-space: pre-wrap;
}

.ocr-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.checkbox-label {
  font-weight: normal;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(420px, calc(100vw - 32px));
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}

.modal-panel h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.modal-checks {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0 20px;
}

.modal-checks-sub {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: -4px 0 0 1.5rem;
  padding-left: 12px;
  border-left: 2px solid var(--border);
}

.modal-checks-sub.hidden {
  display: none;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-field-label {
  font-size: 0.9rem;
  color: var(--muted);
}

.modal-field input[type="date"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--card);
  color: var(--text);
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.form-actions {
  margin-top: 12px;
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.meta-line {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 8px;
}

.warnings {
  margin: 0 0 12px;
  padding-left: 1.2rem;
  color: var(--danger);
  font-size: 0.9rem;
}

.warnings.hidden {
  display: none;
}

.breadcrumb {
  margin: 12px 0 0;
  font-size: 0.9rem;
  flex-wrap: wrap;
  display: flex;
  align-items: center;
}

.breadcrumb.hidden {
  display: none;
}

.bc-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0 2px;
  font-size: inherit;
}

.bc-link:hover {
  text-decoration: underline;
}

.bc-sep {
  color: var(--muted);
}

.browse-wrap h2 {
  font-size: 1rem;
  margin: 20px 0 8px;
}

.browse-wrap h2:first-child {
  margin-top: 0;
}

.col-check {
  width: 36px;
  text-align: center;
}

.col-empno {
  width: 6.5rem;
  white-space: nowrap;
}

.col-fullname {
  min-width: 7rem;
  white-space: nowrap;
}

.col-committee {
  min-width: 8rem;
  max-width: 12rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-folder {
  min-width: 6rem;
  max-width: 10rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-table.show-search-folder .col-folder {
  display: table-cell;
}

.employee-search {
  margin: 0.75rem 0 0;
}

.browse-filters {
  margin: 0.75rem 0 0;
}

.browse-filters-label,
.employee-search-label {
  display: block;
  font-size: 0.875rem;
  margin-bottom: 0.35rem;
  color: var(--text-muted, #555);
}

.browse-filters-controls,
.employee-search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.browse-filters-controls input,
.employee-search-row input {
  width: 6rem;
  max-width: 100%;
}

.col-other-advance {
  width: 6.5rem;
  white-space: nowrap;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.file-table.show-other-advance-col .col-other-advance {
  display: table-cell;
}

.col-validation-errors {
  min-width: 8rem;
  max-width: 12rem;
  white-space: nowrap;
}

.file-table.show-validation-errors-col .col-validation-errors {
  display: table-cell;
}

.col-modified {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.col-action {
  width: 88px;
  text-align: right;
  white-space: nowrap;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0;
  text-align: left;
  font-size: inherit;
}

.link-btn:hover {
  text-decoration: underline;
}

.folder-row-clickable:hover {
  background: #f8f9fb;
}

.bulk-progress {
  margin: 8px 0 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
}

.bulk-progress-track {
  height: 8px;
  border-radius: 4px;
  background: #e2e8f0;
  overflow: hidden;
}

.bulk-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.2s ease;
}

.bulk-progress-text {
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: var(--text);
}

.bulk-progress-failures {
  margin: 8px 0 0;
  padding-left: 1.2rem;
  font-size: 0.85rem;
  color: #b91c1c;
}

.bulk-progress-failures li {
  margin: 4px 0;
}

.file-label {
  font-weight: normal;
  color: var(--muted);
  font-size: 0.85rem;
}

.edit-table .num,
.edit-table td.num {
  text-align: right;
}

.edit-table .amount-input {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.edit-table td.num,
.edit-table tfoot .num {
  font-variant-numeric: tabular-nums;
}

.totals-row td,
.grand-total-row td {
  background: #eef1f6;
  font-weight: 600;
}

.totals-label {
  text-align: right;
}

.grand-total {
  font-size: 1.05rem;
  color: var(--primary);
}

/* ── 社員マスタ ── */
.employees-panel {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px;
}

.employees-toolbar {
  margin-bottom: 20px;
}

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

#search-input {
  flex: 1;
  min-width: 200px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.employee-form-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
}

.employee-form-card h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

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

.field-withholding .field-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.radio-label {
  font-weight: normal;
  margin-right: 16px;
  font-size: 0.95rem;
}

.req {
  color: var(--danger);
}

.file-label-btn {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.file-label-btn input {
  display: none;
}

.link-btn-inline {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: var(--primary);
}

.import-result {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

.import-result.hidden {
  display: none;
}

#import-errors {
  margin: 8px 0;
  padding-left: 1.2rem;
  color: var(--danger);
}

.employees-table .col-action {
  white-space: nowrap;
}

.warning-link {
  color: var(--primary);
  margin-left: 4px;
}

/* ── 設定 ── */
.settings-panel {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px;
}

.settings-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.settings-card h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.settings-card .field {
  margin-bottom: 14px;
}

.settings-card .field label {
  display: block;
  margin-bottom: 4px;
}

.settings-card .field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.settings-card .biz-categories-table {
  margin: 12px 0;
}

.settings-card .biz-categories-table input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.settings-card .biz-categories-table td:first-child {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
  width: 6rem;
}

.settings-card .biz-categories-table .biz-cat-code {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  font-size: 0.85rem;
  font-family: ui-monospace, monospace;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.settings-card .biz-categories-table .col-action {
  width: 8.5rem;
  text-align: center;
  white-space: nowrap;
}

.settings-card .biz-categories-table .biz-cat-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
}

.settings-card .biz-categories-table .biz-cat-actions .btn-icon {
  min-width: 1.75rem;
}

.settings-card .biz-categories-table .biz-cat-actions .btn-danger {
  padding: 2px 6px;
  font-size: 0.75rem;
}

.settings-subheading {
  margin: 20px 0 8px;
  font-size: 1rem;
}

.settings-subheading:first-of-type {
  margin-top: 0;
}

.form-actions.inline-actions {
  margin: 8px 0 16px;
}

.yayoi-credit-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.yayoi-credit-fields .field-wide {
  grid-column: 1 / -1;
}

.yayoi-mappings-table input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.yayoi-mappings-table td:first-child {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  white-space: nowrap;
}

.yayoi-mappings-table .col-action {
  width: 8.5rem;
  text-align: center;
  white-space: nowrap;
}

.yayoi-mappings-table .yayoi-row-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
}

.hint.inline-hint {
  margin: 4px 0 0;
  font-size: 0.8rem;
}

.folder-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.folder-root-label {
  font-size: 0.9rem;
}

.folder-root-label strong {
  font-weight: 600;
}

.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-card {
  background: var(--card);
  padding: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  max-width: 400px;
  text-align: center;
}

.auth-card h1 {
  margin-top: 0;
}

.auth-card .btn {
  margin-top: 16px;
}

.auth-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  font-size: 0.9rem;
  text-align: left;
}

.auth-error-message {
  margin: 0;
  font-weight: 600;
}

.auth-error-hint {
  margin: 8px 0 0;
  color: #7f1d1d;
  font-weight: normal;
  font-size: 0.85rem;
  line-height: 1.5;
}

.auth-banner {
  margin: 0;
  padding: 12px 20px;
  background: #fff7ed;
  border-bottom: 1px solid #fed7aa;
  color: #9a3412;
}

.auth-banner.hidden {
  display: none;
}

.auth-banner-message {
  margin: 0 0 6px;
  font-weight: 600;
}

.auth-banner-hint {
  margin: 0 0 10px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.auth-banner-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
