:root {
  --ink: #1a1f24;
  --ink-soft: #3a4450;
  --muted: #6a7580;
  --line: #d3dae2;
  --paper: #f2f5f8;
  --panel: #ffffff;
  --accent: #0d5c7a;
  --accent-deep: #084358;
  --accent-soft: #e2f0f5;
  --warn: #b45309;
  --danger: #b42318;
  --ok: #0f6b46;
  --shadow: 0 12px 40px rgba(26, 31, 36, 0.08);
  --radius: 10px;
  --font: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 8% -8%, #d7e8f0 0%, transparent 55%),
    linear-gradient(180deg, #eef2f5 0%, #e6ebf0 100%);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: rgba(15, 30, 40, 0.45);
  backdrop-filter: blur(4px);
}
.login-overlay[hidden] { display: none; }
.login-card {
  width: min(400px, calc(100vw - 32px));
  background: var(--panel);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.login-brand { font-size: 12px; letter-spacing: 0.08em; color: var(--accent); font-weight: 700; }
.login-card h1 { margin: 6px 0 8px; font-size: 22px; }
.field { margin: 14px 0; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-size: 13px; margin: 8px 0; }
.login-hint { margin-top: 14px; }

.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.app[hidden] { display: none; }
.sidebar {
  background: #0c3a4d; color: #e8f2f6;
  padding: 22px 16px;
  display: flex; flex-direction: column; gap: 18px;
}
.brand-kicker { font-size: 11px; letter-spacing: .12em; opacity: .8; }
.brand h1 { margin: 4px 0; font-size: 18px; }
.brand p { margin: 0; font-size: 12px; opacity: .75; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  text-align: left; border: 0; border-radius: 8px;
  padding: 10px 12px; background: transparent; color: inherit;
}
.nav-item:hover { background: rgba(255,255,255,.08); }
.nav-item.active { background: #1480a0; font-weight: 700; }
.role-box { border-top: 1px solid rgba(255,255,255,.15); padding-top: 12px; font-size: 13px; }
.role-box label { font-size: 11px; opacity: .7; }
.role-user { font-weight: 700; margin: 4px 0; }
.role-meta { opacity: .75; font-size: 12px; margin-bottom: 10px; }

.main { padding: 22px 28px 48px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.topbar h2 { margin: 0; font-size: 22px; }
.sub { margin: 4px 0 0; color: var(--muted); }
.badge-row { display: flex; gap: 8px; flex-wrap: wrap; }
.badge {
  background: var(--accent-soft); color: var(--accent-deep);
  border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700;
}

.btn {
  background: var(--accent); color: #fff; border: 0;
  border-radius: 8px; padding: 8px 14px; font-weight: 600;
}
.btn:hover { background: var(--accent-deep); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.3); }
.btn.danger { background: var(--danger); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.panel h3, .panel h4 { margin: 0 0 10px; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--accent-soft); border-radius: 10px; padding: 14px; }
.stat .n { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; }
table.data th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }
.table-wrap { overflow: auto; }

.flash { padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; }
.flash.ok { background: #e7f6ee; color: var(--ok); }
.flash.err { background: #fdecea; color: var(--danger); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.status-pill { display: inline-block; border-radius: 999px; padding: 2px 8px; font-size: 12px; font-weight: 700; }
.status-pill.draft { background: #eef2f5; }
.status-pill.issued { background: #e2f0f5; color: var(--accent-deep); }
.status-pill.sent { background: #e7f6ee; color: var(--ok); }
.status-pill.paid { background: #e7f6ee; color: var(--ok); }
.status-pill.void { background: #fdecea; color: var(--danger); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: end; }
.filters label { font-size: 12px; color: var(--muted); display: block; }
.filters input, .filters select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }

.lines-table input { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; }
.totals { display: flex; justify-content: flex-end; gap: 24px; font-variant-numeric: tabular-nums; margin-top: 10px; }
.totals strong { font-size: 18px; }

.empty { color: var(--muted); padding: 24px; text-align: center; }
code { font-family: var(--mono); font-size: 12px; }

.seal-screen { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.seal-preview-wrap {
  width: 140px; height: 140px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafbfc;
  display: grid; place-items: center;
  overflow: hidden;
}
.seal-preview-wrap.empty { color: var(--muted); font-size: 13px; border-style: dashed; }
.seal-preview { width: 100%; height: 100%; object-fit: contain; }

.csv-cols { font-size: 12px; color: var(--muted); }
.csv-result { margin-top: 12px; padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.csv-result.ok { background: #e7f6ee; color: var(--ok); }
.csv-result.err { background: #fdecea; color: var(--danger); }
.csv-errors { margin: 8px 0 0; padding-left: 18px; }
.csv-errors li { margin: 2px 0; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
