/* Design tokens — color, type, spacing. Defined on bare :root first,
   then redefined for OS dark mode and for an explicit data-theme choice. */
:root {
  /* --- color: light (default) --- */
  --ink: #1c2126;
  --ink-muted: #5b6470;
  --ink-faint: #8b93a0;
  --paper: #f4f7fb;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --line: #e1e0da;
  --line-strong: #c9c8c0;
  --accent: #14616b;
  --accent-strong: #0c474f;
  --accent-soft: #e2eeee;
  --accent-ink: #ffffff;
  --amber: #b9791f;
  --amber-soft: #f6ead2;
  --good: #2f7d5a;
  --good-soft: #e1f0e6;
  --danger: #b3454b;
  --danger-soft: #f5e2e2;
  --shadow-color: 220 20% 20%;
  --calendar-sunday: #ad2335;
  --calendar-sunday-bg: #fbd8de;
  --calendar-saturday: #2054ac;
  --calendar-saturday-bg: #dce9ff;

  /* --- type --- */
  --font-display: "Shippori Mincho", "Hiragino Mincho ProN", serif;
  --font-body: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-md: 1.0625rem;
  --text-lg: 1.25rem;
  --text-xl: 1.625rem;
  --text-2xl: 2rem;

  /* --- spacing / shape --- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --nav-w: 232px;
  --topbar-h: 56px;
  --bottombar-h: 60px;
}

/* アプリは端末のダークモードに左右されない明るい配色に固定。 */
:root[data-theme="light"] { color-scheme: light; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #ecebe6;
    --ink-muted: #a9b0b8;
    --ink-faint: #767e88;
    --paper: #16191c;
    --surface: #1d2124;
    --surface-raised: #23282c;
    --line: #33383c;
    --line-strong: #454b50;
    --accent: #4fb3ab;
    --accent-strong: #7ecfc7;
    --accent-soft: #1f3336;
    --accent-ink: #0b1213;
    --amber: #dba75a;
    --amber-soft: #3a2f1a;
    --good: #6cbf93;
    --good-soft: #1c2f24;
    --danger: #e0898d;
    --danger-soft: #3a2225;
    --shadow-color: 220 30% 2%;
  }
}

:root[data-theme="dark"] {
  --ink: #ecebe6;
  --ink-muted: #a9b0b8;
  --ink-faint: #767e88;
  --paper: #16191c;
  --surface: #1d2124;
  --surface-raised: #23282c;
  --line: #33383c;
  --line-strong: #454b50;
  --accent: #4fb3ab;
  --accent-strong: #7ecfc7;
  --accent-soft: #1f3336;
  --accent-ink: #0b1213;
  --amber: #dba75a;
  --amber-soft: #3a2f1a;
  --good: #6cbf93;
  --good-soft: #1c2f24;
  --danger: #e0898d;
  --danger-soft: #3a2225;
  --shadow-color: 220 30% 2%;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }

a { color: var(--accent); }

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.app-shell {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ---------- Desktop side rail ---------- */
.side-rail {
  width: var(--nav-w);
  flex: 0 0 var(--nav-w);
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  padding: var(--sp-5) 0;
}

.side-rail__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-5) var(--sp-5);
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--sp-4);
}

.side-rail__logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  background: var(--surface);
}

.side-rail__brand-name {
  font-family: var(--font-display);
  font-size: var(--text-md);
  line-height: 1.3;
}

.side-rail nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 var(--sp-3);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-3);
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  text-decoration: none;
  font-size: var(--text-sm);
  cursor: pointer;
}

.nav-link:hover { background: var(--paper); color: var(--ink); }
.nav-link.is-active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}

.nav-link__icon { width: 18px; text-align: center; flex: none; }

.nav-section-label {
  padding: var(--sp-4) var(--sp-3) 4px;
  font-size: 11px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.nav-divider {
  height: 1px;
  background: var(--line);
  margin: var(--sp-3) var(--sp-2);
}

/* ---------- Main column ---------- */
.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: none;
}

.view {
  flex: 1;
  padding: var(--sp-6) var(--sp-6) var(--sp-7);
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}
.page-link { display:flex; align-items:center; justify-content:flex-end; gap:var(--sp-2); margin-bottom:var(--sp-3); }
.page-link__url { max-width:48ch; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
@media (max-width: 767px) { .page-link__url { display:none; } }

.view-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}

.view-header h1 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  margin: 0 0 var(--sp-1);
}

.view-header p {
  margin: 0;
  color: var(--ink-muted);
  font-size: var(--text-sm);
}

.bottom-tabs { display: none; }
.fab { display: none; }

.boot-loading, .boot-error {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--sp-6);
  text-align: center;
  color: var(--ink-muted);
  font-size: var(--text-sm);
}

/* ---------- Phone layout ---------- */
@media (max-width: 767px) {
  .side-rail { display: none; }

  .topbar {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    height: var(--topbar-h);
    padding: env(safe-area-inset-top, 0px) var(--sp-4) 0;
    padding-top: calc(env(safe-area-inset-top, 0px) + var(--sp-2));
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    position: sticky;
    top: env(safe-area-inset-top, 0px);
    z-index: 20;
  }

  .topbar__logo { width: 26px; height: 26px; border-radius: var(--radius-sm); object-fit: contain; }
  .topbar__title { font-family: var(--font-display); font-size: var(--text-md); }

  .view {
    padding: var(--sp-4) var(--sp-4) calc(var(--bottombar-h) + var(--sp-7));
  }

  .bottom-tabs {
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    height: calc(var(--bottombar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--line);
    z-index: 30;
  }

  .bottom-tabs__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--ink-faint);
    font-size: 11px;
    text-decoration: none;
    background: none;
    border: none;
    font-family: inherit;
  }

  .bottom-tabs__item.is-active { color: var(--accent-strong); }
  .bottom-tabs__icon { font-size: 18px; }

  .fab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: var(--sp-4);
    bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom, 0px) + var(--sp-4));
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-ink);
    font-size: 26px;
    border: none;
    box-shadow: 0 6px 16px hsl(var(--shadow-color) / 0.35);
    z-index: 30;
  }
}

/* Spreadsheet-style project schedule, separate from responsive data tables. */
.sg-controls { display:flex; align-items:end; gap:12px; flex-wrap:wrap; margin:16px 0 8px; }
.sg-controls label { font-size:12px; display:grid; gap:4px; }
.sg-controls input,.sg-controls select { width:auto; }
.sg-project { margin:20px 0; border:1px solid #bdcdc6; background:#fff; color:#263f36; }
.sg-title { display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:8px; padding:18px; }
.sg-title h2 { font-size:17px; margin:0; color:#233b33; }
.sg-title span { font-size:12px; }
.sg-assumption { margin:0; padding:10px 18px; background:#fff2cc; color:#765414; font-size:12px; }
.sg-scroll { overflow:auto; max-height:72vh; isolation:isolate; }
.sg-table { --sg-category-width:90px; --sg-label-width:260px; border-collapse:separate; border-spacing:0; table-layout:fixed; font-size:12px; }
.sg-table th,.sg-table td { border-right:1px solid #d5dfdb; border-bottom:1px solid #d5dfdb; padding:0; }
.sg-table thead th { background:#e8f0ec; text-align:center; height:26px; color:#294139; position:sticky; top:0; z-index:3; }
.sg-table thead tr:nth-child(2) th { top:26px; }
.sg-table thead tr:nth-child(3) th { top:52px; background:#f6f9f7; font-weight:400; }
.sg-table .sg-category { position:sticky; left:0; background:#f0f5f2; text-align:center; width:var(--sg-category-width); z-index:2; padding:8px; }
.sg-table .sg-label { position:sticky; left:var(--sg-category-width); width:var(--sg-label-width); background:white; z-index:2; padding:9px 10px; text-align:left; font-weight:400; overflow-wrap:anywhere; }
.sg-table thead .sg-category,.sg-table thead .sg-label { z-index:5; background:#e8f0ec; text-align:center; font-weight:600; }
.sg-table .sg-label small { display:block; font-size:10px; margin-top:4px; color:#596a62; }
.sg-table .sg-label small.sg-late { color:#b42318; }
.sg-table tbody + tbody tr:first-child > * { border-top:2px solid #b9cbc1; }
.sg-details { margin-top:4px; font-size:10px; color:#5c6d64; font-weight:400; }
.sg-details summary { cursor:pointer; }
.sg-details p { white-space:normal; margin:5px 0; }
.sg-details button { display:block; margin-top:6px; }
.sg-track-cell { background:repeating-linear-gradient(to right,transparent 0,transparent calc(100% / var(--sg-slots) - 1px),#d5dfdb calc(100% / var(--sg-slots) - 1px),#d5dfdb calc(100% / var(--sg-slots))); }
.sg-track { position:relative; min-height:64px; height:100%; }
.sg-bar { position:absolute; top:14px; height:36px; background:#df9949; color:#382405; display:flex; align-items:center; justify-content:center; padding:0 9px; font-weight:600; font-size:11px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; border:1px solid #a6661b; border-radius:2px; }
.sg-bar-review { border:2px dashed #9b611c; }
.sg-marker { position:absolute; top:21px; transform:translateX(-50%); z-index:1; line-height:22px; font-size:15px; text-shadow:0 0 3px white; }
.sg-marker-deadline { color:#a84222; }
.sg-marker-planned { top:0; color:#187968; }
.sg-marker-actual { top:42px; color:#176533; font-weight:bold; }
.sg-today { position:absolute; top:0; bottom:0; width:2px; background:#c25757; opacity:.5; }
.sg-note { display:block; padding:22px 14px; font-size:11px; color:#75663d; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.sg-legend { padding:12px 18px; display:flex; flex-wrap:wrap; gap:16px; font-size:11px; border-top:1px solid #d5dfdb; }
.sg-sr { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); }
@media(max-width:600px) {
  .sg-table { --sg-category-width:60px; --sg-label-width:190px; }
  .sg-table .sg-category { position:static; }
  .sg-table .sg-label { left:0; }
  .sg-title { padding:12px; }
  .sg-title h2 { font-size:14px; }
}
/* ---------- 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); }
.card-consent { display:flex; align-items:flex-start; gap:10px; font-size:var(--text-sm); cursor:pointer; }
.card-consent input[type="checkbox"] { flex:0 0 18px; width:18px; height:18px; margin:2px 0 0; padding:0; accent-color:var(--accent); }

/* ---------- 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; }
/* Keep the explicit schedule table mode tabular on phones as well. */
@media (max-width: 768px) {
  .data-table.schedule-table { display: table; min-width: 680px; }
  .data-table.schedule-table thead { display: table-header-group; }
  .data-table.schedule-table tbody { display: table-row-group; }
  .data-table.schedule-table tr { display: table-row; }
  .data-table.schedule-table td { display: table-cell; width: auto; }
  .data-table.schedule-table td::before { display: none; }
}
.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; }
.read-only-view button { display:none !important; }

/* ---------- 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, minmax(0, 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(--calendar-sunday); background: var(--calendar-sunday-bg); }
.cal-grid__head.is-sat { color: var(--calendar-saturday); background: var(--calendar-saturday-bg); }
.cal-cell {
  min-width: 0;
  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-sat { background: var(--calendar-saturday-bg); }
.cal-cell.is-sun, .cal-cell.is-holiday { background: var(--calendar-sunday-bg); }
.cal-cell.is-sat .cal-cell__num { color: var(--calendar-saturday); font-weight: 700; }
.cal-cell.is-sun .cal-cell__num, .cal-cell.is-holiday .cal-cell__num { color: var(--calendar-sunday); font-weight: 700; }
.cal-cell.is-today { box-shadow: inset 0 0 0 2px var(--accent); }
.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); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.cal-cell__entries { display: flex; flex-direction: column; gap: 2px; min-width:0; }
.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; }

.client-toolbar { flex-wrap: wrap; align-items: flex-end; }
.read-only-view .client-toolbar button, .read-only-view .client-name-link, .read-only-view .client-detail-close { display: inline-flex !important; }
.read-only-view .client-photo-open { display: flex !important; }
.client-search { flex: 1 1 240px; min-width: 0; }
.client-view-switch { display: flex; gap: 6px; flex-wrap: wrap; }
.client-photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 16px; margin-top: 16px; }
.client-company-group { margin-top:24px; }
.client-company-heading { margin:0 0 12px; padding:10px 12px; background:var(--surface); border-left:4px solid var(--accent-strong); font-size:18px; overflow-wrap:anywhere; }
.client-company-heading small { font-size:13px; color:var(--ink-muted); margin-left:8px; white-space:nowrap; }
.client-photo-card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); overflow: hidden; }
.client-photo-open { display: flex; flex-direction: column; gap: 8px; width: 100%; padding: 12px; border: 0; background: transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.client-photo-frame { display: flex; align-items: center; justify-content: center; width: 100%; aspect-ratio: 1.65; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.client-photo-frame img { width: 100%; height: 100%; object-fit: contain; }
.client-photo-empty { color: var(--ink-muted); font-size: var(--text-sm); }
.client-photo-name { font-weight: 600; overflow-wrap: anywhere; }
.client-photo-contact { color: var(--ink-muted); font-size: var(--text-sm); overflow-wrap: anywhere; }
.client-photo-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 12px 12px; }
.client-name-link { border: 0; padding: 4px 0; background: transparent; color: inherit; font: inherit; text-align: left; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; overflow-wrap: anywhere; }
.client-photo-open:focus-visible, .client-name-link:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: -2px; }
@media (max-width: 480px) {
  .client-toolbar .client-search { flex-basis: 100%; }
  .client-view-switch { width: 100%; }
  .client-view-switch .btn { flex: 1; }
}

.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;
}

/* A real grid at every viewport width; never convert these cells into mobile cards. */
.equipment-heading { display:flex; align-items:center; justify-content:space-between; gap:16px; flex-wrap:wrap; margin:16px 0; }
.equipment-heading h2 { margin:0 0 6px; }
.equipment-heading p { margin:0; color:var(--text-muted); font-size:13px; }
.equipment-source { display:flex; gap:10px; margin:12px 0; flex-wrap:wrap; }
.equipment-source input { flex:1; min-width:230px; }
.equipment-scroll { overflow:auto; max-height:72vh; border:1px solid var(--line-strong); background:var(--surface); }
.equipment-table { table-layout:fixed; width:1740px; border-collapse:separate; border-spacing:0; font-size:13px; }
.equipment-table th,.equipment-table td { padding:10px 12px; border-right:1px solid var(--line); border-bottom:1px solid var(--line); white-space:pre-wrap; overflow-wrap:anywhere; text-align:left; vertical-align:top; background:var(--surface); }
.equipment-table thead th { position:sticky; top:0; z-index:4; background:#245844; color:white; white-space:nowrap; padding:14px 12px; }
.equipment-table thead .equipment-status-head { background:#316e55; }
.equipment-table tbody td,.equipment-table tbody th { background:var(--surface); }
.equipment-table tbody.equipment-not-started td,.equipment-table tbody.equipment-not-started th { background:#e3e5e7; color:#38414a; }
.equipment-table tbody+tbody tr:first-child>* { border-top:2px solid var(--line-strong); }
.equipment-table .equipment-start { position:sticky; left:0; z-index:3; text-align:center; }
.equipment-start input { width:20px; height:20px; cursor:pointer; accent-color:#245844; }
.equipment-start small { display:block; margin-top:8px; }
.equipment-table .equipment-number { position:sticky; left:80px; z-index:2; }
.equipment-table .equipment-name { position:sticky; left:170px; z-index:2; font-weight:600; box-shadow:2px 0 0 var(--line-strong); }
.equipment-table thead th:first-child { left:0; z-index:5; }
.equipment-table thead th:nth-child(2) { left:80px; z-index:5; }
.equipment-table thead th:nth-child(3) { left:170px; z-index:5; }
.equipment-table .badge { white-space:pre-wrap; }
.equipment-warning { display:block; color:#a15b00; font-weight:400; margin-top:8px; }
.equipment-support-notes { font-size:12px; line-height:1.65; margin:10px 0 0; white-space:pre-wrap; font-weight:400; }
.equipment-table .equipment-changed { background:#fff1ac!important; color:#332500; box-shadow:inset 4px 0 #df9300; }
.equipment-change-detail { margin-top:8px; color:#825400; font-size:12px; font-weight:400; white-space:pre-wrap; }
.equipment-change-detail summary { cursor:pointer; font-weight:600; }
.equipment-change-bar { display:flex; gap:12px; align-items:center; flex-wrap:wrap; padding:12px 0; }
.equipment-change-bar input { width:auto; }
.equipment-removed { border-left:4px solid #df9300; padding:10px; margin:12px 0; }
.wall-review-panel { border:1px solid var(--line); border-radius:8px; padding:12px 16px; margin:14px 0; }
.wall-review-item { padding:12px; margin:10px 0; border-left:4px solid #639176; border-radius:4px; }
.wall-review-item p { margin:6px 0; }
.wall-review-item select { max-width:620px; display:block; margin:8px 0; }
.wall-cell-alert { font-size:12px; white-space:normal; padding:8px; border-left:4px solid; line-height:1.6; }
.wall-mismatch { background:#ffe3e1; color:#8e201c; border-color:#b83228; }
.wall-review { background:#fff2cb; color:#715000; border-color:#d29c26; }
@media (max-width:640px) { .equipment-table .equipment-name,.equipment-table thead th:nth-child(3) { position:static; box-shadow:none; } }
@media print { .equipment-scroll { max-height:none; overflow:visible; } .equipment-table { width:100%; font-size:8px; } .equipment-table th,.equipment-table td { position:static!important; padding:4px; } }

/* 見積書などの書類そのもののスタイル。画面プレビュー(.sheet内)にも印刷にも使う。 */
.purchase-pdf-import label:has(> input[type="checkbox"]) { display:flex; align-items:center; gap:8px; }
.purchase-pdf-import input[type="checkbox"] { flex:0 0 16px; width:16px; height:16px; min-height:0; margin:0; padding:0; }
.doc-sheet, .invoice-direct-sheet {
  /* 帳票の数字は、中央に点や斜線がない0を使う。画面・印刷で共通。 */
  --font-mono: Arial, "Helvetica Neue", "Meiryo", sans-serif;
  font-variant-numeric: lining-nums tabular-nums;
}
.doc-sheet {
  font-family: var(--font-body);
  color: #1c2126;
}
.doc-sheet--excel { font-family: "Yu Gothic", "Meiryo", sans-serif; }

.doc-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  border-bottom: 2px solid #1c2126;
  padding-bottom: 12px;
  margin-bottom: 16px;
}
.doc-head--excel { position:relative; min-height:126px; border-bottom: 0; padding-bottom: 4px; margin-bottom: 10px; }

.doc-title {
  font-family: var(--font-display);
  font-size: 26px;
  letter-spacing: 0.14em;
  margin: 0 0 10px;
}
.doc-title--excel { position:absolute; top:0; left:0; right:0; font-family: "MS Mincho", "Yu Mincho", serif; font-weight: 700; letter-spacing: 0.35em; font-size: 24px; text-align:center; }
.doc-head--excel .doc-meta { margin-top:48px; }

.doc-meta { font-size: 12px; border-collapse: collapse; }
.doc-meta th { text-align: left; color: #5b6470; font-weight: 500; padding: 2px 10px 2px 0; }
.doc-meta td { padding: 2px 0; font-family: var(--font-mono); }

.doc-company { text-align: right; font-size: 12px; min-width: 230px; }
.doc-company__logo { max-height: 42px; max-width: 170px; object-fit: contain; margin: 0 auto 6px 0; display: block; }
.doc-company__logo--sunfortia { object-position: center; }
.doc-company__seal-wrap { position: relative; display: inline-block; }
.doc-company__name { font-size: 14px; font-weight: 700; padding-right: 4px; }
.doc-company__seal { position: absolute; width: 56px; height: 56px; right: -18px; top: 0; opacity: 0.92; transform: none; }
.doc-company__line { color: #333; }
.doc-total-layout { display:grid; grid-template-columns:62% 1fr; align-items:center; margin-bottom:18px; }
.doc-total-layout .doc-total-banner { width:auto; margin:0; }
.doc-amount-stamps { justify-self:end; display:flex; gap:4px; margin:0; }
.doc-amount-stamps span { width:44px; height:44px; border:1px solid #555; display:flex; align-items:center; justify-content:center; background:#fff; }
.doc-amount-stamps img { width:40px; height:40px; object-fit:contain; }
/* Compensate for the whitespace in the supplied Kohara seal without altering its pixels. */
.doc-amount-stamps span:last-child, .invoice-direct-stamps span:last-child { overflow:hidden; }
.doc-amount-stamps span:last-child img, .invoice-direct-stamps span:last-child img { transform:scale(2.1); }
/* 拡大した印影の白背景より手前に枠線を描く。 */
.doc-amount-stamps > span, .invoice-direct-stamps > span { position:relative; isolation:isolate; }
.doc-sheet .doc-amount-stamps > span, .invoice-direct-sheet .invoice-direct-stamps > span { border-color:transparent; }
.doc-amount-stamps > span::after, .invoice-direct-stamps > span::after {
  content:""; position:absolute; inset:0; border:1px solid #555;
  box-sizing:border-box; z-index:1; pointer-events:none;
}

.doc-addressee {
  font-size: 17px;
  font-weight: 700;
  margin-top: 10px;
  border-bottom: 1px solid #1c2126;
  display: inline-block;
  padding-bottom: 4px;
}

.doc-lead { margin: 10px 0 18px; font-size: 13px; }

.doc-subject { margin-bottom: 14px; font-size: 13px; }
.doc-subject span { color: #5b6470; margin-right: 10px; }

.doc-total-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #e2eeee;
  border: 1px solid #14616b;
  border-radius: 6px;
  padding: 10px 18px;
  margin-bottom: 18px;
}
.doc-total-layout .doc-total-banner { margin-bottom:0; }
.doc-sheet--excel .doc-total-banner { background: #fff; border: 2px solid #1c2126; border-radius: 0; padding: 8px 14px; }
.doc-total-banner strong {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
}

.doc-items-scroll { overflow-x: auto; margin-bottom: 12px; }
.doc-items { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
.doc-items th, .doc-items td { border-bottom: 1px solid #ccc; padding: 6px 8px; vertical-align: middle; }
.doc-items th { background: #f5f4f0; text-align: left; }
.doc-sheet--excel .doc-items th, .doc-sheet--excel .doc-items td { border: 1px solid #777; }
.doc-sheet--excel .doc-items th { background: #f2f2f2; text-align: center; font-weight: 700; }
.doc-sheet--excel .doc-items td { height: 27px; }
.doc-col-name { width: 38%; } .doc-col-qty { width: 9%; } .doc-col-unit { width: 9%; } .doc-col-price { width: 15%; } .doc-col-amount { width: 16%; } .doc-col-note { width: 13%; }
.doc-items__spec { display:block; margin-top:2px; color:#555; font-size:10px; font-weight:400; line-height:1.25; }
.doc-items__blank td { height:27px; }
.doc-items td.num, .doc-items th.num { text-align: right; }

@media print {
  .doc-items-scroll { overflow-x: visible; }
  .doc-items { min-width: 0; }
}

.doc-terms { display: flex; flex-direction: column; gap: 4px; font-size: 12px; margin: 10px 0; }
.doc-terms span { display: inline-block; width: 92px; color: #5b6470; }

.doc-notes {
  font-size: 12px;
  white-space: pre-wrap;
  border-top: 1px dashed #ccc;
  padding-top: 10px;
  margin-top: 6px;
}

.doc-revision-note {
  text-align: right;
  font-size: 11px;
  color: #b9791f;
  margin-top: 14px;
}

.doc-bank {
  font-size: 12px;
  background: #f5f4f0;
  border-radius: 6px;
  padding: 10px 14px;
  margin: 10px 0;
  line-height: 1.7;
}
.doc-sheet--excel .doc-bank { border: 1px solid #777; border-radius: 0; background: #fff; padding: 8px 10px; }
.doc-bank span { display: block; color: #5b6470; font-size: 11px; margin-bottom: 2px; }
.doc-bank__row { display:flex; align-items:baseline; }
.doc-bank .doc-bank__row > span { flex:0 0 58px; width:58px; margin:0 6px 0 0; }
.doc-bank__account { margin-left:64px; white-space:nowrap; }
.doc-bank__holder { margin-left:64px; overflow-wrap:anywhere; }
.doc-invoice-summary { width: 250px; margin: 10px 0 10px auto; border-collapse: collapse; font-size: 12px; }
.doc-invoice-summary th, .doc-invoice-summary td { border: 1px solid #777; padding: 5px 8px; }
.doc-invoice-summary th { width: 42%; text-align: center; background: #f2f2f2; }
.doc-invoice-summary td { text-align: right; font-family: var(--font-mono); }
.doc-invoice-summary .total th, .doc-invoice-summary .total td { font-weight: 700; border-top: 2px solid #222; }
.doc-special-notes { margin-top: 10px; padding: 8px 10px; border: 1px solid #777; font-size: 12px; line-height: 1.6; white-space: pre-wrap; }

/* 請求書は、参考のExcelと同じく上下の帯・横長の金額欄・明細罫線で構成する。 */
.doc-sheet--invoice { padding:0 10mm 8mm; font-family:"Yu Gothic", "Meiryo", sans-serif; color:#171717; }
.doc-invoice-accent { height:7mm; margin:0 -10mm 8mm; background:#e9b260; }
.doc-invoice-accent--bottom { margin:8mm -10mm -8mm; }
.doc-sheet.doc-sheet--billing { box-sizing:border-box; min-height:297mm; display:flex; flex-direction:column; }
.doc-sheet.doc-sheet--billing > * { flex-shrink:0; }
.doc-sheet--billing > .doc-invoice-accent--bottom { margin-top:auto; }
.doc-sheet--billing > .doc-invoice-accent--bottom { border-top:6mm solid #fff; box-sizing:content-box; }
.doc-invoice-title-row { position:relative; min-height:17mm; text-align:center; }
.doc-invoice-title-row h1 { display:inline-block; margin:0; padding:2px 26px; border-bottom:2px solid #777; font:700 19px "MS Mincho", "Yu Mincho", serif; }
.doc-invoice-title-row span { position:absolute; right:0; top:4px; font-size:11px; }
.doc-invoice-upper { display:grid; grid-template-columns:54% 46%; min-height:68mm; border-top:1px solid #aaa; }
.doc-invoice-recipient, .doc-invoice-issuer { position:relative; padding:7px 8px; }
.doc-invoice-recipient { font-size:11px; }
.doc-invoice-addressee { display:inline-block; min-width:85%; padding:5px 0; border-bottom:1px solid #222; font-size:15px; font-weight:700; }
.doc-sheet--billing .doc-invoice-addressee { font-size:17px; }
.doc-sheet--billing .invoice-direct-addressee { font-size:17px !important; }
.doc-invoice-recipient p { margin:10px 0; }
.doc-invoice-subject { margin:7px 0; font-size:11px; }
.doc-sheet--billing .doc-invoice-subject { border-left:2px solid #c6b190; padding:3px 0 3px 9px; margin-bottom:24.6px; }
.doc-sheet--billing .invoice-direct-subject { border-left:2px solid #c6b190; padding-left:9px; margin-bottom:17.6px; }
.doc-sheet--billing .invoice-greeting { display:block; margin-bottom:0.5em; }
.doc-sheet--billing .doc-invoice-upper,
.doc-sheet--billing .invoice-direct-top { position:relative; }
.doc-sheet--billing .invoice-bank-right { position:absolute; top:51mm; right:8px; width:calc(46% - 20px); padding:0; font-size:11px; }
.doc-sheet--billing .invoice-bank-right .doc-bank { margin:0; min-height:43px; padding:7px 10px; border:1px solid #777; border-radius:0; background:#fff; font-size:10px; line-height:1.7; }
.doc-sheet--billing .invoice-bank-right .doc-bank span { display:inline-block; width:58px; margin:0 6px 0 0; color:#333; font-size:10px; }
.doc-invoice-issuer { border-left:1px solid #777; padding-left:12px; }
.doc-invoice-issuer .doc-company { min-width:0; text-align:left; font-size:11px; line-height:1.42; }
.doc-invoice-issuer .doc-company__logo { width:170px; max-width:100%; height:46px; max-height:none; object-position:left center; margin:7px 0 2px; }
.doc-invoice-issuer .doc-company__seal-wrap { display:block; margin-top:5px; }
.doc-invoice-issuer .doc-company__name { font-size:17px; }
.doc-invoice-issuer .doc-company__seal { width:58px; height:58px; right:8px; top:0; }
.doc-invoice-upper .doc-bank { margin:10px 0 0; min-height:43px; padding:7px 10px; border:1px solid #777; border-radius:0; background:#fff; font-size:10px; line-height:1.7; }
.doc-invoice-upper .doc-bank span { display:inline-block; width:58px; margin:0 6px 0 0; color:#333; font-size:10px; }
.doc-invoice-amount { position:relative; display:flex; align-items:center; justify-content:center; gap:22px; min-height:13mm; margin:5mm 17mm 5mm 20mm; border-bottom:2px solid #555; font-weight:700; }
.doc-invoice-amount strong { font:700 19px var(--font-mono); }
.doc-invoice-amount em { font-size:11px; font-style:normal; }
.doc-invoice-amount .doc-amount-stamps { position:absolute; left:calc(100% + 8px); margin:0; }
.doc-invoice-items { width:100%; border-collapse:collapse; table-layout:fixed; font-size:10px; }
.doc-invoice-items th, .doc-invoice-items td { height:25px; padding:0 5px; border:1px solid #555; vertical-align:middle; }
.doc-invoice-items thead th { height:27px; background:#f2c9aa; text-align:center; font-weight:700; }
.doc-invoice-items .num { text-align:right; font-family:var(--font-mono); }
.doc-invoice-items .doc-items__blank td { height:25px; }
.doc-invoice-items tfoot th { text-align:right; padding-right:8px; font-weight:400; }
.doc-invoice-items tfoot .total th, .doc-invoice-items tfoot .total td { font-weight:700; }
.doc-invoice-due { min-height:9mm; padding:4px 2px; border:1px solid #777; border-top:0; font-size:10px; }
.doc-sheet--invoice .doc-special-notes { min-height:13mm; margin:0; border-top:0; font-size:10px; }
.doc-sheet--invoice .doc-notes { min-height:15mm; margin:0; padding:7px; border:1px solid #777; border-top:0; font-size:10px; }

@media print {
  .doc-invoice-upper { min-height:65mm; }
  .doc-invoice-items th, .doc-invoice-items td { height:24px; }
}

/* 請求書の帳票直接入力。PDF出力用の完成帳票と同じA4・罫線構成で入力する。 */
.invoice-direct-sheet { padding: 0 10mm 8mm; font-family: "Yu Gothic", "Meiryo", sans-serif; color:#171717; }
.invoice-direct-sheet input, .invoice-direct-sheet select, .invoice-direct-sheet textarea { box-sizing:border-box; width:100%; min-height:26px; padding:3px 5px; color:#171717; background:#fff; border:0; border-bottom:1px solid #777; border-radius:0; font:inherit; }
.invoice-direct-sheet textarea { min-height:46px; resize:vertical; }
.invoice-direct-accent { height:7mm; margin:0 -10mm 8mm; background:#e9b260; }
.invoice-direct-sheet > .invoice-direct-accent:last-child { margin:8mm -10mm -8mm; }
.invoice-direct-heading { position:relative; min-height:17mm; text-align:center; }
.invoice-direct-heading h2 { display:inline-block; margin:0; padding:2px 26px; border-bottom:2px solid #777; font:700 19px "MS Mincho", "Yu Mincho", serif; }
.invoice-direct-heading input { position:absolute; right:0; top:2px; width:122px; text-align:right; }
.invoice-direct-top { display:grid; grid-template-columns:54% 46%; min-height:68mm; border-top:1px solid #aaa; }
.invoice-direct-top > div { position:relative; padding:7px 8px; }
.invoice-direct-recipient label, .invoice-direct-top label { display:block; font-size:10px; color:#555; }
.invoice-direct-addressee { font-size:15px !important; font-weight:700; }
.invoice-direct-top p { margin:10px 0; font-size:11px; }
.doc-sheet--billing .doc-invoice-recipient > p,
.doc-sheet--billing .invoice-direct-top p { line-height:1.6; margin-top:calc(8mm + 3.2em); margin-bottom:calc(10px + 1.6em); }
.invoice-direct-issuer { border-left:1px solid #777; padding-left:12px !important; }
.invoice-direct-issuer select { width:62%; font-size:11px; }
.invoice-direct-logo { display:block; width:148px; height:40px; object-fit:contain; object-position:left center; margin:7px 0 2px; }
.invoice-direct-company { font-size:10px; line-height:1.42; max-width:210px; }
.invoice-direct-seal { position:absolute; width:58px; height:58px; object-fit:contain; right:165px; top:85px; }
.invoice-direct-amount { position:relative; display:flex; align-items:center; justify-content:center; gap:22px; min-height:13mm; margin:5mm 17mm 5mm 20mm; border-bottom:2px solid #555; font-weight:700; }
.invoice-direct-amount strong { font:700 19px var(--font-mono); }
.invoice-direct-amount em { font-size:11px; font-style:normal; }
.invoice-direct-stamps { position:absolute; left:calc(100% + 8px); display:flex; gap:4px; }
.invoice-direct-stamps span { display:grid; place-items:center; width:42px; height:42px; border:1px solid #555; font-size:9px; color:#555; }
.invoice-direct-stamps img { width:38px; height:38px; object-fit:contain; }
.invoice-direct-items { width:100%; border-collapse:collapse; table-layout:fixed; font-size:10px; }
.invoice-col-name { width:47%; }
.invoice-col-qty, .invoice-col-unit { width:7%; }
.invoice-col-price { width:13%; }
.invoice-col-amount { width:15%; }
.invoice-col-remark { width:11%; }
.invoice-direct-items th, .invoice-direct-items td { border:1px solid #555; padding:0; height:20px; vertical-align:middle; }
.invoice-direct-items thead th { height:24px; background:#f2c9aa; text-align:center; font-weight:700; }
.invoice-direct-items input { min-height:19px; height:100%; font-size:10px; }
.invoice-direct-items td:first-child > input { display:inline-block; width:67%; }
.invoice-direct-items td small { display:inline-block; width:29%; vertical-align:middle; }
.invoice-direct-items td small input { padding-top:0; font-size:9px; color:#555; }
.invoice-direct-items td:first-child { position:relative; }
.invoice-item-delete { position:absolute; right:2px; bottom:1px; padding:1px 3px; font-size:10px; line-height:1; opacity:.55; }
.invoice-item-delete:hover { opacity:1; }
.invoice-direct-items .num { text-align:right; padding:0 5px; font-family:var(--font-mono); }
.invoice-direct-items tfoot th { text-align:right; padding-right:8px; font-weight:400; }
.invoice-direct-items tfoot .total th, .invoice-direct-items tfoot .total td { font-weight:700; }
.invoice-direct-footer { margin-top:0; border:1px solid #777; border-top:0; padding:7px; font-size:10px; }
.invoice-direct-footer label { display:block; margin-top:5px; font-weight:700; }
.invoice-direct-footer select, .invoice-direct-footer input { display:inline-block; width:auto; margin-right:6px; }
.invoice-direct-footer textarea { border:1px solid #ddd; }
.invoice-direct-meta { display:flex; gap:6px; margin-top:7px; }
.invoice-direct-meta select { flex:1; }

/* 入力画面と保存済み帳票で、会社情報・押印位置・列幅を共有する。 */
.doc-invoice-issuer-content .doc-company { min-width:0; text-align:left; font-size:11px; line-height:1.42; }
.doc-invoice-issuer-content .doc-company__logo { width:170px; max-width:100%; height:46px; max-height:none; object-position:left center; margin:7px 0 2px; }
.doc-invoice-issuer-content .doc-company__seal-wrap { display:block; margin-top:5px; }
.doc-invoice-issuer-content .doc-company__name { font-size:17px; }
.doc-invoice-issuer-content .doc-company__seal, .doc-invoice-issuer .doc-company__seal { width:58px; height:58px; left:90px; right:auto; top:-2mm; }
.doc-invoice-items .doc-col-name, .invoice-col-name { width:47%; }
.doc-invoice-items .doc-col-qty, .doc-invoice-items .doc-col-unit, .invoice-col-qty, .invoice-col-unit { width:6%; }
.doc-invoice-items .doc-col-price, .invoice-col-price { width:13%; }
.doc-invoice-items .doc-col-amount, .invoice-col-amount { width:15%; }
.doc-invoice-items .doc-col-note, .invoice-col-remark { width:13%; }
.doc-invoice-items td { overflow-wrap:anywhere; }
.doc-invoice-amount, .invoice-direct-amount { margin-left:0; margin-right:30mm; gap:12px; }
.doc-invoice-amount .doc-amount-stamps, .invoice-direct-stamps { left:auto; right:-30mm; }
.invoice-direct-stamps span { width:44px; height:44px; }
.invoice-direct-items th, .invoice-direct-items td, .doc-invoice-items th, .doc-invoice-items td, .doc-invoice-items .doc-items__blank td { height:25px; }
.sheet:has(> .doc-sheet--invoice) { padding:0; }
.invoice-direct-top .doc-bank { margin:10px 0 0; min-height:43px; padding:7px 10px; border:1px solid #777; border-radius:0; background:#fff; font-size:10px; line-height:1.7; }
.invoice-direct-top .doc-bank span { display:inline-block; width:58px; margin:0 6px 0 0; color:#333; font-size:10px; }
@media print {
  .doc-invoice-items tr { break-inside:avoid; }
  .doc-invoice-items thead { display:table-header-group; }
  .doc-invoice-items tfoot { display:table-row-group; }
  .doc-invoice-accent, .doc-invoice-items th { print-color-adjust:exact; -webkit-print-color-adjust:exact; }
}
.invoice-registration-fields { width:210mm; box-sizing:border-box; margin:14px 0 0; }
.order-customer-stamp { font-size:11px; line-height:1.5; }
.doc-order-site { display:flex; align-items:baseline; gap:12px; border-bottom:1px solid #777; min-height:24px; margin:0 0 10px; padding:3px 0; font-size:11px; overflow-wrap:anywhere; }
.doc-order-site > :first-child { flex:0 0 auto; }
.doc-order-site > :last-child { flex:1; min-width:0; }
/* 請求書（入力・保存・印刷）も発注書と同じ角印配置に統一。 */
.doc-sheet--billing .doc-invoice-issuer .doc-company__seal,
.doc-sheet--billing .doc-invoice-issuer-content .doc-company__seal,
.doc-sheet--acceptance .doc-invoice-issuer .doc-company__seal,
.doc-sheet--purchase-order .doc-invoice-issuer .doc-company__seal,
.doc-sheet--purchase-order .doc-invoice-issuer-content .doc-company__seal { width:74px; height:74px; left:158px; right:auto; top:0; }
.order-rubber-space { position:relative; min-height:35mm; border:1px solid #777; padding:6px 18mm 6px 6px; color:#666; }
.order-rubber-space span { font-size:10px; }
.order-seal-mark { position:absolute; right:6mm; bottom:7mm; font-size:18px; line-height:1; font-weight:400; color:#333; }
.order-set-page + .order-set-page { margin-top:24px; }
@media print {
  .order-set-page + .order-set-page { break-before:page; page-break-before:always; margin-top:0; }
}
.invoice-registration-fields__grid { display:grid; grid-template-columns:repeat(3, 1fr); gap:12px; }
.invoice-registration-fields label { display:grid; gap:5px; font-size:12px; color:var(--text-muted); }
.invoice-registration-fields select { width:100%; }

.doc-signature-row {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid #ccc;
  font-size: 13px;
}

@media print {
  @page {
    size: A4;
    margin: 12mm 10mm;
  }
  @page invoice {
    size: A4;
    margin: 0;
  }
  body.invoice-pdf-export, .sheet:has(> .doc-sheet--billing) { page: invoice; }
  body.invoice-pdf-export { margin:0 !important; padding:0 !important; }
  .doc-sheet.doc-sheet--billing { page: invoice; width:210mm; min-height:var(--invoice-print-height, 296.808mm); zoom:var(--invoice-print-scale, 0.94); }

  .no-print { display: none !important; }
  /* 発行元の選択UIは編集専用。印刷には会社情報だけを残す。 */
  .invoice-direct-issuer > label,
  .invoice-direct-issuer > select { display: none !important; }

  body, .view, .sheet-scroll { background: #ffffff !important; }

  .view {
    padding: 0 !important;
    max-width: none !important;
  }

  .sheet {
    box-shadow: none !important;
    width: auto !important;
    min-height: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
    color: #000000 !important;
  }

  .sheet * {
    color: inherit;
  }

  /* Center the scaled invoice independently of the full-bleed page footer. */
  .sheet:has(> .doc-sheet.doc-sheet--billing) {
    box-sizing: border-box;
    width: 210mm !important;
    padding: 5mm 0 0 !important;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .sheet > .doc-sheet.doc-sheet--billing { flex: none; }
  /* Keep the header's layout space, but paint both bands at page scale. */
  .sheet > .doc-sheet--billing > .doc-invoice-accent:not(.doc-invoice-accent--bottom) { visibility: hidden; }
  .sheet > .doc-sheet--billing > .doc-invoice-accent--bottom { display: none; }
  .sheet:has(> .doc-sheet.doc-sheet--billing)::before,
  .sheet:has(> .doc-sheet.doc-sheet--billing)::after {
    content: "";
    position: fixed;
    left: 0;
    right: 0;
    height: 7mm;
    background: #e9b260;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
  .sheet:has(> .doc-sheet.doc-sheet--billing)::before { top: 0; }
  .sheet:has(> .doc-sheet.doc-sheet--billing)::after { bottom: 0; }

  .print-only { display: block !important; }
}

.print-only { display: none; }
