:root {
  --green-900: #1f4d38;
  --green-800: #2d6047;
  --green-700: #3e7658;
  --green-200: #cfe7d9;
  --green-100: #eaf5ef;
  --cream: #f8f6ef;
  --border: #cfd7d2;
  --text: #1f2924;
  --muted: #66736c;
  --danger: #a33a3a;
  --warning: #9a6b14;
  --shadow: 0 8px 24px rgba(31, 77, 56, 0.09);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  font-family: "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  color: var(--text);
  background: #f4f7f5;
  line-height: 1.55;
}
a { color: var(--green-800); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--green-900);
  color: white;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.header-inner {
  max-width: 1500px;
  margin: 0 auto;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
}
.brand { color: white; text-decoration: none; font-weight: 800; letter-spacing: .02em; white-space: nowrap; }
.main-nav { display: flex; gap: 2px; flex-wrap: wrap; }
.main-nav a { color: #eaf5ef; text-decoration: none; padding: 10px 12px; border-radius: 7px; font-size: .94rem; }
.main-nav a:hover { background: rgba(255,255,255,.12); }
.user-name { margin-left: auto; font-size: .9rem; opacity: .85; white-space: nowrap; }

.container { max-width: 1180px; margin: 0 auto; padding: 28px 20px 60px; }
.wide-container { max-width: 1800px; margin: 0 auto; padding: 24px 14px 60px; }
.site-footer { text-align: center; color: var(--muted); padding: 30px 10px; font-size: .82rem; }

h1 { margin: 0 0 8px; font-size: clamp(1.5rem, 2vw, 2.1rem); line-height: 1.25; }
h2 { margin: 0 0 18px; font-size: 1.25rem; }
.lead { margin: 0; color: var(--muted); }
.page-title-row { display: flex; align-items: center; gap: 20px; justify-content: space-between; margin-bottom: 22px; }

.panel {
  background: white;
  border: 1px solid #dde5e0;
  border-radius: 14px;
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}
.narrow-panel { max-width: 720px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.warning-panel { border-left: 5px solid #d6a74e; }
.empty-state { padding: 28px; text-align: center; color: var(--muted); }

.flash { max-width: 1180px; margin: 12px auto 0; padding: 12px 16px; border-radius: 10px; font-weight: 600; }
.flash-success { background: #e7f6ec; color: #225c39; border: 1px solid #b9dfc7; }
.flash-error { background: #fff0f0; color: #8a2d2d; border: 1px solid #efc2c2; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 9px;
  min-height: 42px;
  padding: 9px 16px;
  text-decoration: none;
  font-weight: 700;
  white-space: nowrap;
}
.btn-primary { background: var(--green-700); color: white; }
.btn-primary:hover { background: var(--green-800); }
.btn-secondary { background: white; color: var(--green-800); border-color: #a9c7b6; }
.btn-secondary:hover { background: var(--green-100); }
.btn-small { min-height: 34px; padding: 5px 10px; font-size: .85rem; }
.btn-muted { background: #f3f5f4; color: #53625a; border-color: #d4dbd7; }
.btn-danger { background: #fff2f2; color: var(--danger); border-color: #e3b9b9; }

.auth-page { background: linear-gradient(145deg, #edf5ef, #f8f6ef); min-height: 100vh; }
.auth-wrap { min-height: calc(100vh - 110px); display: grid; place-items: center; padding: 30px 16px; }
.auth-card { width: min(520px, 100%); background: white; border-radius: 18px; padding: 30px; box-shadow: 0 18px 50px rgba(30,72,52,.15); }
.auth-card h1 { margin-bottom: 10px; }
.auth-card > p { color: var(--muted); margin: 0 0 24px; }
.stack-form { display: grid; gap: 17px; }
.inline-form { display: flex; align-items: end; gap: 14px; flex-wrap: wrap; }
.inline-form label { min-width: 180px; flex: 1; }
.producer-add-form label:first-of-type { min-width: 240px; }
label { display: grid; gap: 6px; font-weight: 700; font-size: .93rem; }
input, select {
  width: 100%;
  min-height: 42px;
  border: 1px solid #bfcac4;
  border-radius: 8px;
  padding: 8px 10px;
  background: white;
  color: var(--text);
}
input:focus, select:focus { outline: 3px solid rgba(62,118,88,.16); border-color: var(--green-700); }
.hint { display: block; color: var(--muted); font-size: .82rem; font-weight: 400; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; background: #f0f3f1; border-radius: 5px; padding: 2px 5px; }

.summary-cards { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 12px; margin-bottom: 22px; }
.summary-cards.compact { grid-template-columns: repeat(4, minmax(150px, 1fr)); }
.summary-cards > div { background: white; border: 1px solid #dce5df; border-radius: 12px; padding: 15px 17px; box-shadow: 0 4px 15px rgba(31,77,56,.05); }
.summary-cards span { display: block; color: var(--muted); font-size: .82rem; margin-bottom: 4px; }
.summary-cards strong { font-size: 1.3rem; }

.status-badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 10px; font-size: .82rem; font-weight: 800; white-space: nowrap; }
.status-submitted { background: #dff3e7; color: #246342; }
.status-draft { background: #fff1cf; color: #805c18; }
.status-not-started { background: #edf0ef; color: #68716c; }
.status-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }
.status-dot.status-submitted { background: #3c9663; }
.status-dot.status-draft { background: #d7a33a; }
.status-dot.status-not-started { background: #aab2ae; }

.data-table, .plan-table, .consolidated-table { width: 100%; border-collapse: separate; border-spacing: 0; background: white; }
.data-table th, .data-table td { border-bottom: 1px solid #e0e6e2; padding: 11px 12px; text-align: left; vertical-align: middle; }
.data-table th { background: #eef4f0; color: #334b3d; font-size: .86rem; white-space: nowrap; }
.data-table tbody tr:hover { background: #fafcfb; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.table-scroll { overflow: auto; max-width: 100%; }
.mini-form { display: flex; gap: 6px; align-items: center; min-width: 280px; }
.mini-form input { min-height: 34px; }

.instruction-box { background: #eef7f1; border: 1px solid #c4dfcf; border-radius: 10px; padding: 12px 15px; margin-bottom: 14px; }
.plan-toolbar { position: sticky; top: 66px; z-index: 35; display: flex; gap: 8px; align-items: center; background: rgba(244,247,245,.94); backdrop-filter: blur(8px); padding: 9px 0; }
.toolbar-spacer { flex: 1; }
.save-state { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .86rem; }
.plan-scroll { border: 1px solid #9fabA4; background: white; max-height: calc(100vh - 250px); }
.plan-table { min-width: 1540px; table-layout: fixed; font-size: .82rem; }
.plan-table th, .plan-table td { border-right: 1px solid #aab5af; border-bottom: 1px solid #aab5af; padding: 0; }
.plan-table th { background: #edf3ef; text-align: center; font-weight: 800; height: 34px; }
.plan-table thead th { position: sticky; z-index: 15; }
.plan-table thead tr:first-child th { top: 0; }
.plan-table thead tr:nth-child(2) th { top: 34px; }
.plan-table .month-head { min-width: 66px; border-left: 2px solid #687970; }
.plan-table .third-head { width: 22px; min-width: 22px; font-size: .74rem; }
.plan-table tbody td { height: 44px; background: white; }
.plan-table input { border: 0; border-radius: 0; min-height: 43px; padding: 5px 7px; font-size: .82rem; background: transparent; }
.plan-table input:focus { outline: 3px inset rgba(62,118,88,.22); }
.col-item { width: 150px; min-width: 150px; }
.col-variety { width: 170px; min-width: 170px; }
.col-area { width: 82px; min-width: 82px; }
.col-money { width: 118px; min-width: 118px; }
.col-delete { width: 54px; min-width: 54px; }
.plan-table .period-cell { width: 22px; min-width: 22px; height: 43px; border: 0; display: block; background: white; padding: 0; touch-action: none; }
.plan-table .period-cell:hover { background: #eef7f1; }
.plan-table .period-cell.selected { background: #8bc3a2; box-shadow: inset 0 0 0 1px #508568; }
.plan-table td.period-td:nth-of-type(3n + 6) { border-left: 2px solid #687970; }
.row-delete { border: 0; background: transparent; color: #a33a3a; width: 100%; height: 43px; font-size: 1.1rem; }
.row-delete:hover { background: #fff0f0; }
.footnote { color: #4e5953; font-size: .85rem; margin: 12px 2px; }

.consolidated-scroll { border: 1px solid #9ca9a2; max-height: calc(100vh - 160px); }
.consolidated-table { min-width: 1550px; table-layout: fixed; font-size: .78rem; }
.consolidated-table th, .consolidated-table td { border-right: 1px solid #aab5af; border-bottom: 1px solid #aab5af; padding: 4px 6px; height: 31px; }
.consolidated-table thead th { position: sticky; background: #e8f0eb; text-align: center; z-index: 15; }
.consolidated-table thead tr:first-child th { top: 0; }
.consolidated-table thead tr:nth-child(2) th { top: 31px; }
.consolidated-table .third-head, .period-view { width: 21px; min-width: 21px; padding: 0; }
.consolidated-table .period-view.selected { background: #8bc3a2; }
.category-row th { background: var(--green-800); color: white; text-align: left; font-size: .86rem; position: static !important; }
.subtotal-row td { background: #fff6dc; font-weight: 700; }
.grand-total-row td { background: #e3efe7; font-weight: 800; border-top: 2px solid var(--green-800); }

@media (max-width: 980px) {
  .header-inner { align-items: flex-start; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
  .main-nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .user-name { margin-left: auto; }
  .summary-cards, .summary-cards.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-title-row { align-items: flex-start; flex-direction: column; }
  .save-state { width: 100%; justify-content: space-between; }
}

@media (max-width: 600px) {
  .container, .wide-container { padding-left: 10px; padding-right: 10px; }
  .panel { padding: 16px; border-radius: 10px; }
  .summary-cards, .summary-cards.compact { grid-template-columns: 1fr 1fr; gap: 8px; }
  .summary-cards > div { padding: 11px; }
  .summary-cards strong { font-size: 1.05rem; }
  .plan-toolbar { top: 98px; overflow-x: auto; }
  .inline-form { display: grid; }
  .inline-form label { min-width: 0; }
  .auth-card { padding: 22px; }
}
