:root {
  --primary: #183b32;
  --on-primary: #ffffff;
  --secondary: #53645b;
  --tertiary: #b88222;
  --accent: #2f7a69;
  --danger: #b13f4a;
  --warning: #a76520;
  --success: #28724f;
  --background: #f5f7f3;
  --surface: #ffffff;
  --surface-muted: #ecf1ed;
  --outline: #d7ddd7;
  --text: #17201a;
  --text-muted: #66746b;
}

* { box-sizing: border-box; }

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

button, .button, input, select, textarea {
  font: inherit;
}

button, .button {
  border: 1px solid var(--outline);
  background: var(--surface);
  color: var(--text);
  min-height: 38px;
  padding: 0 14px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  cursor: pointer;
}

button:hover, .button:hover {
  border-color: #b9c3ba;
}

.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

.center-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(47, 122, 105, .12), transparent 34%),
    linear-gradient(315deg, rgba(184, 130, 34, .14), transparent 28%),
    var(--background);
}

.login-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 18px 60px rgba(23, 32, 26, .08);
}

.login-card.wide {
  width: min(720px, 100%);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-row h1, .topbar h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 750;
}

.brand-row p, .muted, .crumb, .empty-state span {
  color: var(--text-muted);
}

.brand-tile {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: transparent;
  color: #12271f;
  border-radius: 8px;
  font-weight: 850;
  overflow: hidden;
}

.brand-tile.small {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
}

.brand-tile img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.stack {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--outline);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.notice {
  padding: 12px 14px;
  border-radius: 8px;
  margin: 12px 0;
  border: 1px solid var(--outline);
  background: var(--surface-muted);
}

.notice.danger {
  border-color: #efc4c9;
  color: #822b35;
  background: #fae8ea;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 264px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 18px 14px;
  background: #13271f;
  color: #f2f8f4;
  display: flex;
  flex-direction: column;
}

.product {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 4px 6px 18px;
}

.product strong, .product span {
  display: block;
}

.product span {
  color: #c6d7ce;
  font-size: 12px;
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, .12);
}

.nav-section {
  display: grid;
  gap: 4px;
  padding-top: 6px;
}

.nav-section > span {
  color: #9bb3a7;
  font-size: 11px;
  font-weight: 800;
  padding: 8px 10px 2px;
}

.nav-item {
  border: 0;
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  justify-content: flex-start;
  background: transparent;
  color: #dfece5;
}

.nav-item span {
  flex: 1;
  text-align: left;
}

.nav-item.active, .nav-item:hover {
  background: rgba(255, 255, 255, .09);
  color: #ffffff;
}

.workspace {
  min-width: 0;
}

.topbar {
  min-height: 74px;
  padding: 16px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--outline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.crumb {
  display: block;
  font-size: 12px;
  font-weight: 700;
}

.userbox {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.userbox span, .userbox small {
  display: block;
}

.userbox small {
  color: var(--text-muted);
}

.icon-button {
  width: 38px;
  padding: 0;
}

.icon-button.danger {
  color: var(--danger);
}

.content {
  padding: 24px 28px 36px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.metric, .panel, .quick-action {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 8px;
}

.metric {
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.metric strong {
  display: block;
  font-size: 22px;
  line-height: 1.3;
  margin-top: 4px;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.quick-action {
  justify-content: flex-start;
  min-height: 78px;
  padding: 16px;
  text-align: left;
}

.quick-action span, .quick-action small {
  display: block;
}

.quick-action small {
  color: var(--text-muted);
  font-size: 12px;
}

.dual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.panel {
  padding: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.compact-table {
  display: grid;
  gap: 6px;
}

.compact-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--outline);
}

.compact-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.searchbox {
  flex: 1 1 320px;
  max-width: 520px;
  position: relative;
}

.searchbox svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.searchbox input {
  padding-left: 36px;
}

.table-panel {
  padding: 0;
  overflow: hidden;
}

.data-table-wrap {
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--outline);
  white-space: nowrap;
  vertical-align: middle;
}

.data-table th {
  background: var(--surface-muted);
  color: #34433a;
  font-size: 12px;
}

.text-button {
  min-height: 30px;
  padding: 0 9px;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.text-button.as-link {
  text-decoration: none;
}

.text-button.danger {
  color: var(--danger);
}

.row-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.badge.ok {
  color: #145537;
  background: #e4f3eb;
}

.badge.warn {
  color: #7c4618;
  background: #f8ebd6;
}

.badge.muted {
  color: var(--text-muted);
  background: #edf0ee;
}

.approval-summary {
  min-width: 150px;
  display: grid;
  gap: 4px;
  white-space: normal;
}

.approval-pill {
  display: inline-flex;
  width: fit-content;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.approval-pill.ok {
  color: #145537;
  background: #e4f3eb;
}

.approval-pill.warn {
  color: #7c4618;
  background: #f8ebd6;
}

.approval-pill.danger {
  color: #822b35;
  background: #fae8ea;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
}

.empty-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--text-muted);
  text-align: center;
  padding: 28px;
}

.empty-state strong {
  color: var(--text);
  font-size: 16px;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(18, 28, 22, .42);
  display: grid;
  place-items: center;
  padding: 18px;
}

.dialog {
  width: min(920px, 100%);
  max-height: min(860px, calc(100vh - 36px));
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(17, 31, 23, .22);
}

.dialog.narrow {
  width: min(560px, 100%);
}

.dialog header {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  padding: 18px 20px;
  border-bottom: 1px solid var(--outline);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.dialog h2 {
  margin: 0;
}

.record-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px 20px 20px;
}

.record-form .span-2 {
  grid-column: 1 / -1;
}

.record-form .check {
  display: flex;
  align-items: center;
  align-self: end;
  min-height: 38px;
  gap: 8px;
}

.record-form .check input {
  width: auto;
  min-height: 0;
}

.approval-form {
  display: grid;
  gap: 12px;
  padding: 18px 20px 20px;
}

.approval-form .check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border: 1px solid var(--outline);
  border-radius: 6px;
  padding: 9px 10px;
}

.approval-form .check input {
  width: auto;
  min-height: 0;
}

.approval-form .check span,
.approval-form .check small {
  display: block;
}

.approval-form .check small {
  color: var(--text-muted);
  font-weight: 600;
}

.approval-form footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
}

.account-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 18px;
  align-items: start;
}

.account-panel {
  display: grid;
  gap: 14px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.panel-heading h2 {
  margin: 2px 0 0;
}

.account-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.account-form label:first-child,
.account-form footer {
  grid-column: 1 / -1;
}

.account-form footer {
  display: flex;
  justify-content: flex-end;
}

.line-items-editor {
  border: 1px solid var(--outline);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.line-items-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.line-items-head strong {
  font-size: 15px;
}

.line-items-grid {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(220px, 1.5fr) minmax(120px, .75fr) minmax(130px, .75fr) 38px;
  gap: 8px;
  align-items: start;
}

.line-items-grid.header-row {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
}

.line-items-grid textarea {
  min-height: 38px;
}

.line-items-summary {
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  border-top: 1px solid var(--outline);
  padding-top: 10px;
}

.line-items-summary span {
  color: var(--text-muted);
}

.line-items-summary strong {
  color: var(--text);
  margin-left: 5px;
}

.record-form footer {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
}

pre {
  white-space: pre-wrap;
  max-height: 220px;
  overflow: auto;
  background: var(--surface-muted);
  border: 1px solid var(--outline);
  border-radius: 6px;
  padding: 12px;
}

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dual { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .sidebar-bottom { margin-top: 10px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .content { padding: 18px; }
  .metric-grid, .quick-grid, .record-form, .account-grid, .account-form { grid-template-columns: 1fr; }
  .record-form .span-2 { grid-column: auto; }
  .account-form label:first-child, .account-form footer { grid-column: auto; }
  .line-items-grid { grid-template-columns: 1fr; }
  .line-items-grid.header-row { display: none; }
  .line-items-grid .icon-button { justify-self: end; }
  .line-items-summary { justify-content: flex-start; }
}
