:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #fff;
  --surface-soft: #eef3f1;
  --ink: #18211f;
  --muted: #65736f;
  --line: #d9e1df;
  --primary: #0f766e;
  --primary-dark: #0a5d57;
  --accent: #e83d62;
  --danger: #b42318;
  --blue: #2f6fd3;
  --shadow: 0 18px 42px rgba(26, 40, 37, 0.1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
  letter-spacing: 0;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  position: sticky;
  top: 0;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #fbfcfc;
}

.brand {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
  font-weight: 800;
}

.brand h1, .brand p, .topbar h2, .topbar p, .panel h3, .panel h4 { margin: 0; }
.brand h1 { font-size: 18px; line-height: 1.25; }
.brand p, .eyebrow, .sidebar-footer p, .muted { color: var(--muted); }
.brand p, .eyebrow, .sidebar-footer p { font-size: 12px; }

.nav-tabs { display: grid; gap: 8px; }
.nav-tab, .button, .segment {
  border: 1px solid transparent;
  border-radius: 8px;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.nav-tab {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}

.nav-tab:hover, .nav-tab.active {
  border-color: var(--line);
  background: var(--surface-soft);
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.sidebar-footer strong { display: block; margin-top: 4px; font-size: 14px; }
.workspace { min-width: 0; padding: 28px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.topbar h2 { margin-top: 4px; font-size: 28px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border-color: var(--line);
  color: var(--ink);
  background: var(--surface);
  font-weight: 700;
  text-decoration: none;
}

.button:hover { border-color: #b8c6c2; background: #f8faf9; }
.button.primary { border-color: var(--primary); color: #fff; background: var(--primary); }
.button.primary:hover { border-color: var(--primary-dark); background: var(--primary-dark); }
.button.ghost { background: transparent; }
.button.danger { color: var(--danger); }
.button.small { min-height: 34px; padding: 0 10px; font-size: 13px; }

.view { display: none; }
.view.active { display: block; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric, .panel, .invoice-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric { min-height: 118px; padding: 18px; }
.metric p { margin: 0; color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 12px; font-size: 28px; }
.metric span { display: block; margin-top: 8px; color: var(--muted); font-size: 12px; }
.metric.danger-alert {
  border-color: #f4aaa2;
  background: #fff3f1;
}
.metric.danger-alert p,
.metric.danger-alert strong,
.metric.danger-alert span {
  color: var(--danger);
}

.content-grid { display: grid; gap: 18px; }
.content-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.content-grid.split { grid-template-columns: minmax(320px, 0.72fr) minmax(460px, 1.28fr); align-items: start; }
.billing-layout { grid-template-columns: minmax(320px, 0.48fr) minmax(520px, 1fr); align-items: start; }
.panel { padding: 18px; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.panel-header.spaced { margin-top: 22px; }
.panel h3 { font-size: 18px; }
.panel h4 { font-size: 14px; }

.status-pill, .tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #fafbfb;
  font-size: 12px;
  white-space: nowrap;
}
.tag.good { border-color: #a7d7c5; color: #0f5132; background: #eef8f3; }
.tag.warn { border-color: #f0c98d; color: #7a3f05; background: #fff7e8; }
.tag.danger { border-color: #f4aaa2; color: var(--danger); background: #fff3f1; }

.form-grid { display: grid; gap: 13px; }
label { display: grid; gap: 6px; color: #34423f; font-size: 13px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}
input, select { min-height: 40px; padding: 0 10px; }
textarea { min-height: 86px; padding: 10px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(15, 118, 110, 0.15);
  border-color: var(--primary);
}
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.form-actions, .row-actions, .invoice-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.segment { min-height: 32px; padding: 0 10px; border: 0; border-radius: 0; background: transparent; color: var(--muted); font-size: 13px; }
.segment.active { color: #fff; background: var(--primary); }

.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 720px; border-collapse: collapse; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; }
td { font-size: 14px; }

.list { display: grid; gap: 12px; }
.list.compact { gap: 8px; }
.list-item {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}
.list-item header { display: flex; justify-content: space-between; gap: 12px; }
.list-item h4 { margin: 0; font-size: 15px; }
.list-item p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.55; }

.contract-app {
  display: grid;
  grid-template-columns: minmax(560px, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.contract-main { overflow: hidden; }
.upload-zone {
  min-height: 150px;
  place-items: center;
  padding: 22px;
  border: 2px dashed #c7d1ce;
  border-radius: 999px;
  background: #fafbfb;
  text-align: center;
}
.upload-zone input { display: none; }
.upload-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: var(--primary);
  font-weight: 900;
}
.upload-zone small { color: var(--muted); }

.contract-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin: 18px -18px 0;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f8faf9;
}
.tool-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
}
.tool-line { display: inline-block; width: 88px; height: 2px; background: #f2c230; }
.tool-seal {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid #f2c230;
  border-radius: 999px;
  color: #7a3f05;
}

.contract-editor {
  display: grid;
  justify-content: center;
  padding: 28px;
  background: #f6f7f7;
}
.editor-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  width: min(760px, 100%);
  margin-bottom: 12px;
}
.pdf-stage {
  position: relative;
  width: min(760px, 72vw);
  min-height: 980px;
  border: 1px solid var(--line);
  background: white;
  box-shadow: 0 8px 22px rgba(25, 35, 32, 0.08);
  overflow: hidden;
}
#pdfObject {
  display: none;
  width: 100%;
  height: 980px;
  border: 0;
}
.pdf-stage.has-pdf #pdfObject { display: block; }
.pdf-stage.has-pdf .pdf-placeholder { display: none; }
.pdf-placeholder {
  display: grid;
  align-content: center;
  gap: 14px;
  min-height: 980px;
  padding: 96px 118px;
  color: #53615e;
  line-height: 1.8;
}
.pdf-placeholder h4 {
  color: #7894a0;
  font-size: 28px;
  font-weight: 500;
  text-align: center;
}
.sample-line { margin-top: 18px; }

.annotation-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.annotation {
  position: absolute;
  display: grid;
  gap: 4px;
  min-width: 136px;
  min-height: 42px;
  padding: 8px;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  cursor: move;
  pointer-events: auto;
  user-select: none;
}
.annotation.self { border-color: var(--primary); }
.annotation.locked {
  cursor: default;
  border-style: solid;
  background: rgba(255, 255, 255, 0.96);
}
.annotation .ann-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.annotation input, .annotation select {
  min-height: 28px;
  padding: 0 6px;
  font-size: 12px;
}
.annotation input:disabled {
  color: #7d8b88;
  background: #f3f6f5;
}
.annotation .ann-body { font-size: 14px; font-weight: 800; }
.annotation.seal {
  min-width: 86px;
  min-height: 86px;
  place-items: center;
  border-radius: 8px;
}
.annotation.seal .ann-body {
  display: grid;
  width: 62px;
  height: 62px;
  place-items: center;
  border: 1px solid #d94c4c;
  border-radius: 999px;
  color: #a32929;
  line-height: 1.15;
  text-align: center;
  word-break: keep-all;
}
.ann-remove, .ann-lock {
  position: absolute;
  top: -10px;
  display: grid;
  height: 22px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  font-size: 12px;
}
.ann-remove {
  right: -10px;
  width: 22px;
}
.ann-lock {
  left: -10px;
  min-width: 42px;
  padding: 0 8px;
  color: var(--primary);
  font-weight: 800;
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
}

.integration-box {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}
.integration-box p { margin: 0; line-height: 1.6; }
.readiness-list {
  display: grid;
  gap: 8px;
}
.readiness-item {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}
.readiness-item strong { font-size: 13px; }
.readiness-item span { color: var(--muted); font-size: 12px; line-height: 1.5; }
.readiness-item.ok { border-color: #a7d7c5; background: #eef8f3; }
.readiness-item.warn { border-color: #f0c98d; background: #fff7e8; }

.business-card-preview {
  display: grid;
  gap: 8px;
}
.business-card-preview img {
  width: min(100%, 360px);
  max-height: 220px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.business-card-preview p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}
.thumb-grid img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.invoice-preview { min-height: 680px; padding: 30px; }
.invoice-paper { min-height: 620px; }
.invoice-head {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 22px;
  border-bottom: 2px solid var(--ink);
}
.invoice-head h3 { margin: 0; font-size: 28px; }
.invoice-meta { display: grid; gap: 6px; margin-top: 18px; color: var(--muted); font-size: 13px; }
.invoice-total { margin: 26px 0; padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: #f8faf9; }
.invoice-total span { color: var(--muted); font-size: 13px; }
.invoice-total strong { display: block; margin-top: 4px; font-size: 32px; }
.invoice-share {
  display: grid;
  gap: 6px;
  margin: 0 0 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  overflow-wrap: anywhere;
}
.invoice-share.missing {
  border-color: #f4aaa2;
  color: var(--danger);
  background: #fff3f1;
}
.invoice-preview table { min-width: 0; }
.mail-preview { margin-top: 18px; padding: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfc; }
.mail-preview textarea { min-height: 140px; margin-top: 10px; }

.empty {
  padding: 18px;
  border: 1px dashed #bdc9c6;
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfc;
  font-size: 14px;
  line-height: 1.6;
}
.plain-list { margin: 0; padding-left: 20px; color: var(--muted); line-height: 1.8; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid #b8c6c2;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1280px) {
  .app-shell, .contract-app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; min-height: auto; }
  .nav-tabs { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .nav-tab { text-align: center; }
  .content-grid.two, .content-grid.split, .billing-layout, .metric-grid { grid-template-columns: 1fr; }
  .pdf-stage { width: min(760px, 92vw); }
}

@media (max-width: 640px) {
  .workspace, .sidebar { padding: 16px; }
  .topbar, .panel-header, .invoice-head { align-items: stretch; flex-direction: column; }
  .nav-tabs, .field-row { grid-template-columns: 1fr; }
  .contract-editor { padding: 16px; }
  .pdf-placeholder { padding: 56px 28px; }
  .topbar h2 { font-size: 24px; }
  .invoice-preview { padding: 18px; }
}

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .panel, .invoice-actions, .toast { display: none !important; }
  .app-shell, .workspace, .billing-layout { display: block; padding: 0; }
  .view { display: none !important; }
  #billingView { display: block !important; }
  .invoice-preview { border: 0; box-shadow: none; min-height: auto; }
}
