:root {
  --green: #00a95f;
  --green-dark: #00893f;
  --green-light: #e6f7ee;
  --red: #e0483e;
  --bg: #f4f6f5;
  --sidebar-bg: #1f2b26;
  --sidebar-hover: #2c3a34;
  --text: #26332c;
  --text-muted: #6b7a72;
  --border: #dfe6e2;
  --white: #ffffff;
  --radius: 8px;
}

* { box-sizing: border-box; }

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

a { color: inherit; text-decoration: none; }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  color: #cfe0d8;
  flex-shrink: 0;
  padding: 0 0 24px;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 20px 20px;
  color: var(--white);
  font-size: 18px;
  font-weight: 700;
  border-bottom: 1px solid #33423c;
  margin-bottom: 8px;
}

.sidebar-close, .hamburger { display: none; }

.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 90;
}
.sidebar-overlay.open { display: block; }

.sidebar .brand .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--green);
  display: inline-block;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  font-size: 14px;
  color: #cfe0d8;
  border-left: 3px solid transparent;
}

.sidebar nav a:hover { background: var(--sidebar-hover); color: var(--white); }

.sidebar nav a.active {
  background: var(--sidebar-hover);
  color: var(--white);
  border-left-color: var(--green);
  font-weight: 600;
}

.sidebar nav .section-label {
  padding: 18px 20px 6px;
  font-size: 11px;
  letter-spacing: .05em;
  color: #7d9089;
  text-transform: uppercase;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; }

.content { padding: 24px 28px 48px; flex: 1; }

.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
  font-weight: 600;
}
.flash.success { background: var(--green-light); color: var(--green-dark); border: 1px solid #b7e6cd; }
.flash.error { background: #fdeceb; color: var(--red); border: 1px solid #f5c6c2; }

.panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}
.panel .panel-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel .panel-header h2 { font-size: 15px; margin: 0; font-weight: 700; }
.panel .panel-body { padding: 16px 20px; overflow-x: auto; }

table { width: 100%; min-width: max-content; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td.wrap { white-space: normal; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; background: #fafbfa; }
tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; border-top: 2px solid var(--text); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--green);
  background: var(--green);
  color: var(--white);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn.secondary { background: var(--white); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: #f0f2f1; }
.btn.danger { background: var(--white); color: var(--red); border-color: #f5c6c2; }
.btn.danger:hover { background: #fdeceb; }
.btn.small { padding: 5px 12px; font-size: 12px; }

.btn-row { display: flex; gap: 10px; margin-top: 20px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.draft { background: #eef0ef; color: var(--text-muted); }
.badge.issued { background: var(--green-light); color: var(--green-dark); }

form .field { margin-bottom: 16px; }
form label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
form input[type=text], form input[type=email], form input[type=date], form input[type=number],
form select, form textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: var(--white);
  color: var(--text);
}
form textarea { resize: vertical; min-height: 70px; }
form .row { display: flex; gap: 16px; }
form .row > .field { flex: 1; }
form .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.filter-bar { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar .field { margin-bottom: 0; min-width: 150px; }
.filter-bar label { display:block; font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.filter-bar input, .filter-bar select { padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }

.items-table { min-width: 0; table-layout: fixed; }
.items-table th, .items-table td { padding: 6px 8px; white-space: normal; }
.items-table select, .items-table input { padding: 6px 8px; font-size: 13px; width: 100%; box-sizing: border-box; }
.items-table .remove-line { cursor: pointer; color: var(--red); font-weight: 700; border: none; background: none; font-size: 16px; }

.section-title { font-size: 13px; font-weight: 700; color: var(--text-muted); margin: 22px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.section-title:first-child { margin-top: 0; }

.notice-banner {
  background: #fff4e0; border: 1px solid #f0d9ab; color: #8a5a00;
  padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: 13px;
}
.notice-banner a { text-decoration: underline; font-weight: 600; }

.invoice-sheet {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  max-width: 800px;
}
.invoice-sheet .invoice-head { display: flex; justify-content: space-between; margin-bottom: 10px; }
.invoice-sheet h1 { font-size: 26px; margin: 0 0 6px; letter-spacing: .1em; }
.invoice-sheet .meta { font-size: 13px; color: var(--text-muted); line-height: 1.8; }
.invoice-sheet .to { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.invoice-sheet .subject { font-size: 14px; color: var(--text-muted); margin-bottom: 20px; }
.invoice-sheet .grand-total-bar {
  background: var(--green-light); border: 1px solid #b7e6cd; border-radius: 6px;
  padding: 14px 18px; display: flex; justify-content: space-between; align-items: center;
  margin: 20px 0; font-size: 15px; font-weight: 700; color: var(--green-dark);
}
.invoice-sheet .grand-total-bar .amount { font-size: 24px; }
.invoice-sheet table { margin: 20px 0; }
.invoice-sheet .totals { margin-left: auto; width: 280px; }
.invoice-sheet .totals div { display: flex; justify-content: space-between; padding: 6px 0; }
.invoice-sheet .totals .grand { font-size: 18px; font-weight: 700; border-top: 2px solid var(--text); padding-top: 10px; margin-top: 4px; }
.invoice-sheet .bank-info { margin-top: 30px; font-size: 13px; line-height: 1.8; }
.invoice-sheet .from-block { text-align: right; font-size: 13px; line-height: 1.7; }

@media (max-width: 860px) {
  .hamburger {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 32px; height: 32px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    flex-shrink: 0;
  }
  .hamburger span {
    display: block; width: 100%; height: 2px;
    background: var(--text); border-radius: 2px;
  }

  .sidebar-close {
    display: block;
    margin-left: auto;
    background: none; border: none;
    color: #cfe0d8; font-size: 26px; line-height: 1;
    cursor: pointer;
  }

  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform .25s ease;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }

  .topbar {
    padding: 12px 16px;
    gap: 12px;
    flex-wrap: wrap;
  }
  .topbar h1 { font-size: 16px; flex: 1; }
  .topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
  .topbar-actions:empty { display: none; }

  .content { padding: 16px; }

  .panel .panel-header { padding: 12px 14px; flex-wrap: wrap; gap: 8px; }
  .panel .panel-body { padding: 12px 14px; }

  table { font-size: 12.5px; }
  th, td { padding: 8px 10px; }

  form .row { flex-direction: column; gap: 0; }

  .filter-bar { gap: 10px; }
  .filter-bar .field { min-width: 0; flex: 1 1 140px; }

  .btn-row { flex-wrap: wrap; }

  .invoice-sheet { padding: 20px; }
  .invoice-sheet .invoice-head { flex-direction: column; gap: 16px; }
  .invoice-sheet .from-block { text-align: left; }
  .invoice-sheet .totals { width: 100%; max-width: 320px; }
}

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main, .content { padding: 0; margin: 0; }
  body { background: var(--white); }
  .invoice-sheet { border: none; box-shadow: none; }
}
