/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-sm);
  font-family: inherit;
  cursor: pointer;
  line-height: 1.4;
}
.btn:hover { border-color: var(--ink-faint); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { color: var(--danger); border-color: var(--danger-soft); }
.btn-danger:hover { border-color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--paper); }
.btn-sm { padding: var(--sp-1) var(--sp-3); font-size: var(--text-xs); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: var(--text-xs);
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}
.field-required::after { content: " *"; color: var(--danger); }
input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { resize: vertical; min-height: 4.5em; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-4);
}
.form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 767px) {
  .form-grid, .form-grid--3 { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
}
.form-actions {
  display: flex;
  gap: var(--sp-3);
  justify-content: flex-end;
  margin-top: var(--sp-5);
  padding-top: var(--sp-4);
  border-top: 1px solid var(--line);
}
.hint { font-size: var(--text-xs); color: var(--ink-faint); }
.client-suggestions { display:flex; flex-direction:column; margin-top:4px; border:1px solid var(--line); border-radius:var(--radius-sm); overflow:hidden; }
.client-suggestions button { appearance:none; border:0; border-bottom:1px solid var(--line); background:var(--surface); color:var(--ink); font:inherit; font-size:var(--text-sm); text-align:left; padding:6px 8px; cursor:pointer; }
.client-suggestions button:last-child { border-bottom:0; }
.client-suggestions button:hover { background:var(--accent-soft); }
.error-text { font-size: var(--text-xs); color: var(--danger); }

/* ---------- Panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
}
.panel + .panel { margin-top: var(--sp-4); }
.panel__title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 var(--sp-4);
}

/* ---------- Stat tiles ---------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--sp-4) var(--sp-5);
}
.stat-tile__label { font-size: var(--text-xs); color: var(--ink-muted); }
.stat-tile__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-2xl);
  color: var(--ink);
  margin-top: 4px;
}

/* ---------- Data table -> card ---------- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  font-size: var(--text-xs);
  color: var(--ink-muted);
  font-weight: 600;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
.data-table td {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--line);
  font-size: var(--text-sm);
  vertical-align: middle;
}
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--paper); }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }

@media (max-width: 767px) {
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    margin-bottom: var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
    background: var(--surface);
  }
  .data-table td {
    border-bottom: none;
    display: flex;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: 6px 2px;
    text-align: right;
  }
  .data-table td::before {
    content: attr(data-label);
    color: var(--ink-muted);
    font-size: var(--text-xs);
    text-align: left;
  }
  .data-table td.num { text-align: right; }
}

.empty-state {
  text-align: center;
  padding: var(--sp-7) var(--sp-4);
  color: var(--ink-muted);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
  background: var(--paper);
  color: var(--ink-muted);
  white-space: nowrap;
}
.badge-good { background: var(--good-soft); color: var(--good); }
.badge-warn { background: var(--amber-soft); color: var(--amber); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-accent { background: var(--accent-soft); color: var(--accent-strong); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: hsl(var(--shadow-color) / 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--sp-6) var(--sp-4);
  overflow-y: auto;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  width: 100%;
  max-width: 640px;
  margin: auto;
}
.modal--wide { max-width: 960px; }
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
}
.modal__header h2 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  margin: 0;
}
.icon-btn {
  border: none; background: none; cursor: pointer;
  color: var(--ink-muted); font-size: var(--text-lg); line-height: 1;
  padding: 4px;
}
.icon-btn:hover { color: var(--ink); }

/* ---------- Line-item editor ---------- */
.item-row {
  display: grid;
  grid-template-columns: 2fr 1fr 0.6fr 0.6fr 1fr 1fr 1fr auto auto;
  gap: var(--sp-2);
  align-items: end;
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--line);
}
.item-row--staged { grid-template-columns: 2fr 1fr 0.6fr 0.6fr 1fr 1fr auto auto; }
.item-row__amount {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding-bottom: 9px;
}
@media (max-width: 767px) {
  .item-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "name name"
      "spec spec"
      "qty unit"
      "price tax"
      "remark remark"
      "amount remove";
    padding: var(--sp-4) 0;
  }
  .item-row > *:nth-child(1) { grid-area: name; }
  .item-row > *:nth-child(2) { grid-area: spec; }
  .item-row > *:nth-child(3) { grid-area: qty; }
  .item-row > *:nth-child(4) { grid-area: unit; }
  .item-row > *:nth-child(5) { grid-area: price; }
  .item-row > *:nth-child(6) { grid-area: tax; }
  .item-row > *:nth-child(7) { grid-area: remark; }
  .item-row__amount { grid-area: amount; align-self: center; }
  .item-row .item-row__remove { grid-area: remove; justify-self: end; align-self: center; }
}

/* ---------- Tax summary ---------- */
.tax-summary {
  margin-left: auto;
  width: min(360px, 100%);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-top: var(--sp-4);
}
.tax-summary__row {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-sm);
  padding: 4px 0;
}
.tax-summary__row.total {
  border-top: 2px solid var(--ink);
  margin-top: 6px;
  padding-top: var(--sp-2);
  font-size: var(--text-lg);
  font-weight: 700;
}
.tax-summary__row .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- Search / toolbar ---------- */
.toolbar {
  display: flex;
  gap: var(--sp-3);
  align-items: center;
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}
.toolbar .field { flex: 1; min-width: 180px; }
.toolbar-spacer { flex: 1; }

/* ---------- Sheet preview (on-screen document look) ---------- */
/* 画面上でもA4縦（210 × 297mm）の実寸比で確認し、そのままPDF化できる帳票。 */
.sheet-scroll { overflow: auto; padding-bottom: var(--sp-4); }
.sheet {
  background: #ffffff;
  color: #1c2126;
  box-sizing: border-box;
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  padding: 12mm 10mm;
  box-shadow: 0 4px 24px hsl(var(--shadow-color) / 0.18);
  font-size: 13px;
}
.document-live-preview .sheet { margin: 0; transform-origin: top left; }
.document-edit-layout { display: grid; grid-template-columns: minmax(460px, 1fr) minmax(430px, 0.95fr); align-items: start; gap: var(--sp-4); }
.document-edit-fields { min-width: 0; }
.document-edit-fields > .panel { margin-bottom: var(--sp-4); }
.document-live-preview { position: sticky; top: var(--sp-3); margin: 0; overflow: hidden; }
.document-live-preview .sheet-scroll { max-height: calc(100vh - 120px); }
@media (max-width: 1100px) {
  .document-edit-layout { grid-template-columns: 1fr; }
  .document-live-preview { position: static; }
  .document-live-preview .sheet-scroll { max-height: none; }
}
@media (min-width: 700px) {
  .sheet { padding: 16mm 14mm; }
}

.thumb {
  width: 64px; height: 64px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

/* ---------- Schedule timeline ---------- */
.tl-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); }
.tl-grid { position: relative; min-width: 100%; }
.tl-header-row, .tl-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
}
.tl-header-row { height: 32px; }
.tl-row { height: 44px; }
.tl-row:last-child { border-bottom: none; }
.tl-label-cell {
  flex: 0 0 auto;
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 0 var(--sp-3);
  display: flex;
  align-items: center;
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: 2px 0 4px hsl(var(--shadow-color) / 0.06);
}
.tl-header-row .tl-label-cell { background: var(--paper); }
.tl-track { position: relative; flex: 0 0 auto; }
.tl-overlay { position: absolute; inset: 0; pointer-events: none; }
.tl-gridline { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); }
.tl-today-line { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); opacity: 0.55; }
.tl-today-label {
  position: absolute;
  top: 2px;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--accent-strong);
  font-weight: 600;
  white-space: nowrap;
}
.tl-month-label {
  position: absolute;
  top: 8px;
  font-size: 11px;
  color: var(--ink-faint);
  white-space: nowrap;
}
.tl-dot {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid var(--surface);
  cursor: pointer;
}
.tl-dot--done { background: var(--good); }
.tl-dot--overdue { background: var(--danger); }
.tl-dot--upcoming { background: var(--accent); }
.tl-dot--planned { background: var(--line-strong); width: 9px; height: 9px; }
.tl-connector { position: absolute; top: 50%; height: 2px; transform: translateY(-50%); background: var(--line-strong); }

.tl-legend {
  display: flex;
  gap: var(--sp-4);
  flex-wrap: wrap;
  font-size: var(--text-xs);
  color: var(--ink-muted);
  margin-bottom: var(--sp-3);
}
.tl-legend__item { display: flex; align-items: center; gap: 6px; }
.tl-legend__dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* ---------- Personal schedule calendar ---------- */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
}
.cal-grid__head {
  padding: var(--sp-2) var(--sp-2);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  text-align: center;
}
.cal-grid__head.is-sun { color: var(--danger); }
.cal-grid__head.is-sat { color: var(--accent-strong); }
.cal-cell {
  min-height: 96px;
  padding: 6px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cal-cell:nth-child(7n) { border-right: none; }
.cal-cell.is-outside { background: var(--paper); opacity: 0.55; }
.cal-cell.is-today { background: var(--accent-soft); }
.cal-cell.is-sun, .cal-cell.is-holiday { background: #fff4f4; }
.cal-cell.is-sat { background: #f3f7ff; }
.cal-cell.is-sun .cal-cell__num, .cal-cell.is-holiday .cal-cell__num { color: #c63c3c; }
.cal-cell.is-sat .cal-cell__num { color: #356bc0; }
.cal-cell__holiday { font-size: 9px; font-family: var(--font-body); white-space: nowrap; }
.cal-cell__num { font-size: var(--text-xs); font-family: var(--font-mono); color: var(--ink-muted); }
.cal-cell__entries { display: flex; flex-direction: column; gap: 2px; }
.cal-entry {
  font-size: 11px;
  line-height: 1.4;
  padding: 1px 5px;
  border-radius: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-entry--event { background: var(--accent-soft); color: var(--accent-strong); }
.cal-entry--trip { background: var(--amber-soft); color: var(--amber); font-weight: 600; }
@media (max-width: 767px) {
  .cal-cell { min-height: 60px; }
  .cal-entry { font-size: 10px; }
}

/* ---------- Kanban ---------- */
.kanban-board {
  display: flex;
  gap: var(--sp-3);
  overflow-x: auto;
  padding-bottom: var(--sp-4);
}
.kanban-col {
  flex: 0 0 220px;
  background: var(--paper);
  border-radius: var(--radius-md);
  padding: var(--sp-2);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-height: 140px;
}
.kanban-col__header {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--ink-muted);
  padding: 4px 4px 4px;
}
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--text-sm);
  cursor: grab;
}
.kanban-card:active { cursor: grabbing; }
.kanban-card__title { font-weight: 600; }
.kanban-card__meta { color: var(--ink-muted); font-size: var(--text-xs); margin-top: 2px; }

.upload-box {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
}
