:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --accent: #1e3a5f;
  --accent-light: #2d5583;
  --success: #059669;
  --danger: #dc2626;
  --warn: #d97706;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--accent-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- レイアウト ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  padding: 20px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar__brand {
  padding: 0 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  margin-bottom: 12px;
}
.sidebar__brand strong { display: block; font-size: 15px; letter-spacing: .04em; }
.sidebar__brand span { font-size: 11px; opacity: .65; }
.sidebar__section {
  padding: 14px 20px 6px;
  font-size: 11px;
  letter-spacing: .08em;
  opacity: .5;
}
.sidebar a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 20px;
  color: rgba(255,255,255,.82);
  font-size: 13.5px;
}
.sidebar a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar a.is-active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.sidebar__dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }

.main { flex: 1; min-width: 0; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; }
.content { padding: 24px 28px 60px; max-width: 1400px; }

/* ---------- パーツ ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.card__head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card__head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.card__body { padding: 18px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  transition: .12s;
  white-space: nowrap;
}
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-light); color: #fff; }
.btn--danger { color: var(--danger); border-color: #f3d0d0; }
.btn--danger:hover { background: #fdf2f2; }
.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--ghost { border-color: transparent; background: transparent; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: #374151; }
.field .hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }
input[type=text], input[type=password], input[type=date], input[type=number],
input[type=email], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13.5px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(45,85,131,.25);
  border-color: var(--accent-light);
}
textarea { resize: vertical; min-height: 70px; }
.grid { display: grid; gap: 14px; }
.grid--2 { grid-template-columns: 1fr 1fr; }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) {
  .grid--2, .grid--3, .grid--4 { grid-template-columns: 1fr; }
  .sidebar { width: 64px; }
  .sidebar__brand span, .sidebar a span, .sidebar__section { display: none; }
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--text-muted); font-size: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid #f0f1f4; vertical-align: middle; }
tbody tr:hover { background: #fafbfc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge--draft    { background: #f1f3f5; color: #6b7280; }
.badge--issued   { background: #e0edff; color: #1d4ed8; }
.badge--sent     { background: #fff3e0; color: #b45309; }
.badge--paid     { background: #dcfce7; color: #047857; }
.badge--canceled { background: #fee2e2; color: #b91c1c; }

.flash { padding: 12px 16px; border-radius: 6px; margin-bottom: 18px; font-size: 13.5px; }
.flash--success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash--error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
  border-left: 3px solid var(--accent);
}
.stat__label { font-size: 12px; color: var(--text-muted); }
.stat__value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat__sub { font-size: 11.5px; color: var(--text-muted); }
@media (max-width: 900px) { .stat-grid { grid-template-columns: 1fr 1fr; } }

.empty { padding: 40px; text-align: center; color: var(--text-muted); font-size: 13px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.toolbar .field { margin-bottom: 0; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-form { display: inline; }

/* ---------- 明細エディタ ---------- */
.lines { width: 100%; table-layout: fixed; }
.lines th { background: #fafbfc; }
.lines td { padding: 5px 6px; }
.lines input, .lines select { padding: 6px 8px; font-size: 13px; }
.lines .handle { cursor: grab; color: #c0c5cc; text-align: center; user-select: none; }
.lines tr.dragging { opacity: .4; }
.line-amount { font-variant-numeric: tabular-nums; text-align: right; padding-right: 10px; font-weight: 600; }

.totals { margin-left: auto; width: 340px; }
.totals dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; }
.totals dt { color: var(--text-muted); font-size: 13px; }
.totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 18px; font-weight: 700; border-top: 2px solid var(--accent); padding-top: 8px; margin-top: 6px; }
.totals .grand dt { color: var(--text); font-size: 15px; }

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a5f, #0f1f33);
  padding: 20px;
}
.login-card {
  background: #fff; padding: 34px; border-radius: 12px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p.sub { color: var(--text-muted); font-size: 12.5px; margin: 0 0 22px; }
