:root {
  --ink: #17201d;
  --muted: #69736e;
  --line: #dfe5e1;
  --paper: #ffffff;
  --canvas: #f4f6f4;
  --forest: #173f32;
  --forest-2: #245c49;
  --coffee: #a96e3b;
  --cream: #f5eee5;
  --danger: #a63b3b;
  --warning: #96641d;
  --success: #276749;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(24, 42, 35, .08);
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; color: var(--ink); background: var(--canvas); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", "Yu Gothic UI", sans-serif; line-height: 1.55; }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, .button { touch-action: manipulation; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 25px 18px 18px; background: #102d24; color: #fff; overflow-y: auto; }
.brand { display: flex; gap: 11px; align-items: center; margin: 0 8px 32px; color: #fff; text-decoration: none; letter-spacing: .02em; }
.brand-mark { display: inline-grid; place-items: center; flex: 0 0 auto; width: 36px; height: 36px; color: #fff; background: var(--coffee); border-radius: 50% 50% 44% 56% / 42% 52% 48% 58%; font-family: Georgia, serif; font-size: 21px; font-weight: 700; }
.brand strong, .auth-brand strong { display: block; font-family: Georgia, serif; font-size: 21px; }
.brand small, .auth-brand small { display: block; opacity: .64; font-size: 9px; letter-spacing: .2em; }
.nav-label { margin: 25px 12px 7px; color: #86a398; font-size: 10px; font-weight: 700; letter-spacing: .18em; }
.nav-item { display: block; margin: 2px 0; padding: 10px 12px; color: #d9e5e0; border-radius: 8px; text-decoration: none; font-size: 14px; }
.nav-item:hover, .nav-item:focus-visible { background: rgba(255,255,255,.08); color: #fff; outline: none; }
.nav-item.active { color: #fff; background: rgba(169,110,59,.28); box-shadow: inset 3px 0 var(--coffee); }
.sidebar-user { margin-top: auto; padding: 18px 10px 2px; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar-user strong, .sidebar-user small { display: block; }
.sidebar-user small { margin-top: 1px; color: #9eb1aa; font-size: 12px; }
.language-form { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.language-form select { min-height: 32px; width: auto; max-width: 120px; padding: 4px 7px; font-size: 12px; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
.link-button { padding: 8px 0 0; color: #d6e0dc; border: 0; background: none; cursor: pointer; font-size: 12px; text-decoration: underline; }
.page-shell { min-width: 0; }
.topbar { height: 92px; display: flex; align-items: center; gap: 16px; padding: 16px 34px; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 1px 0 0; font-size: 22px; line-height: 1.2; }
.eyebrow { margin: 0; color: var(--coffee); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.role-badge { margin-left: auto; padding: 5px 9px; color: var(--forest); background: #e4eee9; border-radius: 999px; font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.menu-button { display: none; border: 0; background: transparent; font-size: 25px; cursor: pointer; }
.page-content { width: min(1440px, 100%); margin: 0 auto; padding: 28px 34px 64px; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.metric-card { min-height: 142px; padding: 21px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 3px 14px rgba(24,42,35,.04); }
.metric-card p { margin: 0; color: var(--muted); font-size: 13px; }
.metric-card strong { display: block; margin: 11px 0 4px; color: var(--forest); font-family: Georgia, serif; font-size: clamp(28px, 3vw, 38px); line-height: 1.1; }
.metric-card span { color: #8f9994; font-size: 9px; font-weight: 800; letter-spacing: .14em; }
.metric-card.accent { color: #fff; background: var(--forest); border-color: var(--forest); }
.metric-card.accent p, .metric-card.accent strong { color: #fff; }
.metric-card.accent span { color: #aec3bb; }
.metric-link { color: inherit; text-decoration: none; transition: border-color .12s ease, box-shadow .12s ease; }
.metric-link:hover, .metric-link:focus-visible { border-color: var(--forest-2); box-shadow: 0 5px 18px rgba(24,42,35,.1); outline: none; }
.compact-metrics { margin-bottom: 0; }

.panel { margin-bottom: 22px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 4px 18px rgba(24,42,35,.04); overflow: hidden; }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 19px 22px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 2px 0 0; font-size: 18px; }
.panel-body { padding: 22px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; padding: 16px 22px; border-bottom: 1px solid var(--line); background: #fafbfa; }
.toolbar label { flex: 1 1 150px; margin: 0; }
.toolbar .wide { flex-basis: 260px; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 39px; padding: 8px 14px; color: var(--forest); background: #fff; border: 1px solid #cbd6d1; border-radius: 8px; cursor: pointer; font-weight: 700; font-size: 13px; line-height: 1.2; text-decoration: none; }
.button:hover, .button:focus-visible { border-color: var(--forest-2); outline: 3px solid rgba(36,92,73,.12); }
.button-primary { color: #fff; background: var(--forest); border-color: var(--forest); }
.button-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.button-muted { color: #56615c; background: #f5f7f6; }
.button-block { width: 100%; }
.button-small { min-height: 32px; padding: 5px 10px; font-size: 12px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 11px 14px; color: #66716c; background: #fafbfa; border-bottom: 1px solid var(--line); font-size: 10px; letter-spacing: .06em; text-align: left; white-space: nowrap; }
td { padding: 13px 14px; border-bottom: 1px solid #edf0ee; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcfdfc; }
.number { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.table-link { color: var(--forest-2); font-weight: 750; text-decoration: none; }
.table-link:hover { text-decoration: underline; }
.empty-state { padding: 35px; color: var(--muted); text-align: center; }
.status { display: inline-block; padding: 3px 8px; color: #44504a; background: #edf1ef; border-radius: 999px; font-size: 10px; font-weight: 800; text-transform: uppercase; }
.status-sent { color: #24517a; background: #e7f1f8; }
.status-accepted { color: #276749; background: #e4f3e9; }
.status-rejected { color: #923a3a; background: #fae8e8; }
.status-expired { color: #675c52; background: #eee9e4; }
.status-confirmed, .status-preparing { color: #24517a; background: #e7f1f8; }
.status-shipped, .status-completed { color: #276749; background: #e4f3e9; }
.status-cancelled, .status-warning { color: #923a3a; background: #fae8e8; }
.status-draft { color: #725518; background: #fff4d7; }
.status-issued { color: #176442; background: #e8f6ef; }
.status-active, .status-paid, .status-sync-complete { color: #276749; background: #e4f3e9; }
.status-unpaid, .status-not-shipped, .status-sync-not-started { color: #675c52; background: #eee9e4; }
.status-sync-pending { color: #96641d; background: #fff3d7; }
.inactive { color: var(--muted); opacity: .7; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px 20px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; color: #46504b; font-size: 12px; font-weight: 700; }
label > input, label > select, label > textarea, .field-control { width: 100%; margin-top: 6px; }
input, select, textarea { min-height: 41px; padding: 9px 11px; color: var(--ink); background: #fff; border: 1px solid #cfd8d4; border-radius: 7px; }
textarea { min-height: 92px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--forest-2); outline: 3px solid rgba(36,92,73,.12); }
input[type="checkbox"] { min-height: 0; width: auto; }
.check-label { display: flex; align-items: center; gap: 8px; padding-top: 22px; }
.form-help { margin: 5px 0 0; color: var(--muted); font-size: 11px; font-weight: 400; }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 5px; }
.section-title { margin: 8px 0 2px; padding-bottom: 9px; border-bottom: 1px solid var(--line); font-size: 15px; }
.danger-zone { border-color: #eed1d1; }
.danger-zone .panel-header { background: #fffafa; }

.alert { margin-bottom: 18px; padding: 12px 15px; border: 1px solid; border-radius: 8px; font-size: 13px; }
.alert-success { color: var(--success); background: #eef8f2; border-color: #bcdcc9; }
.alert-danger { color: var(--danger); background: #fff2f2; border-color: #e9baba; }
.alert-warning { color: var(--warning); background: #fff8e9; border-color: #ead3a0; }
.field-error { margin: 4px 0 0; color: var(--danger); font-size: 11px; }

.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; }
.detail-item { padding: 14px 18px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.detail-item:nth-child(3n) { border-right: 0; }
.detail-item dt { color: var(--muted); font-size: 11px; }
.detail-item dd { margin: 4px 0 0; font-size: 14px; white-space: pre-wrap; }
.cost-panel { border-color: #e7d8c9; }
.cost-panel .panel-header { background: #fdf9f5; }

.guest-body { min-height: 100vh; background: radial-gradient(circle at 15% 15%, #305b4d 0, #153c30 35%, #102d24 100%); }
.guest-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px; }
.auth-card { width: min(430px, 100%); padding: 36px; background: rgba(255,255,255,.98); border-radius: 16px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 42px; color: var(--forest); }
.auth-heading h1 { margin: 5px 0 7px; font-size: 28px; }
.auth-heading > p:last-child { margin: 0 0 24px; color: var(--muted); font-size: 13px; }
.stack-form { display: grid; gap: 17px; }
.auth-note { margin: 22px 0 0; color: #808a85; font-size: 10px; text-align: center; }
.error-card { text-align: center; }
.error-code { margin: 0; color: var(--coffee); font-family: Georgia, serif; font-size: 64px; }
.error-card h1 { margin: 0 0 24px; font-size: 18px; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.inline-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.summary-box { margin-left: auto; width: min(420px, 100%); }
.summary-row { display: flex; justify-content: space-between; gap: 20px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.summary-row.total { padding-top: 12px; color: var(--forest); border-bottom: 0; font-size: 20px; font-weight: 800; }
.quote-lines input, .quote-lines select { min-width: 90px; }
.quote-lines .product-select { min-width: 240px; }
.quote-lines .line-amount { white-space: nowrap; font-weight: 700; }
.invoice-lines input, .invoice-lines select, .invoice-lines textarea { min-width: 86px; }
.invoice-lines textarea { min-width: 220px; min-height: 58px; }
.stock-cell { min-width: 220px; }
.stock-values { display: block; white-space: nowrap; font-size: 11px; }
.stock-warning { display: none; max-width: 240px; margin-top: 4px; color: var(--danger); font-size: 10px; line-height: 1.35; }
.stock-warning.visible { display: block; }
.stock-low { color: var(--danger); font-weight: 800; }
.stock-positive { color: var(--success); font-weight: 800; }
.low-stock-row { background: #fff8f8; }
.low-stock-row:hover { background: #fff2f2; }
.print-note { color: var(--muted); font-size: 11px; }
.dashboard-list-note { color: var(--muted); font-size: 12px; }
.operation-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.operation-card { padding: 18px; border: 1px solid var(--line); border-radius: 10px; background: #fafbfa; }
.operation-card h3 { margin: 0 0 15px; font-size: 16px; }
.operation-card form { display: grid; gap: 13px; }
.operation-details { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 12px 0 0; }
.operation-details dt { color: var(--muted); font-size: 11px; }
.operation-details dd { margin: 0; }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-item:nth-child(3n) { border-right: 1px solid var(--line); }
  .detail-item:nth-child(2n) { border-right: 0; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 20; left: -270px; width: 248px; transition: left .18s ease; box-shadow: 12px 0 30px rgba(0,0,0,.2); }
  .sidebar.open { left: 0; }
  .menu-button { display: inline-block; }
  .topbar { height: 76px; padding: 12px 17px; }
  .topbar h1 { font-size: 18px; }
  .page-content { padding: 18px 14px 48px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { min-height: 116px; padding: 15px; }
  .metric-card strong { font-size: 25px; }
  .panel-header { align-items: flex-start; padding: 15px; }
  .form-grid { grid-template-columns: 1fr; }
  .operation-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-item, .detail-item:nth-child(2n), .detail-item:nth-child(3n) { border-right: 0; }
  .auth-card { padding: 27px 22px; }
}

@media (max-width: 430px) {
  .metric-grid { grid-template-columns: 1fr; }
  .role-badge { display: none; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .button { width: 100%; }
}
