:root {
  color-scheme: light;
  --ink: #1d2a35;
  --muted: #66737d;
  --line: #dce3e8;
  --surface: #ffffff;
  --background: #f4f7f8;
  --primary: #176b69;
  --primary-dark: #0f504e;
  --accent: #e7f3f1;
  --warning: #fff3d6;
  --danger: #a63d3d;
  --done: #eef1f2;
  font-family: "Segoe UI", "Yu Gothic UI", Meiryo, sans-serif;
  color: var(--ink);
  background: var(--background);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--background); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); margin: 0; }
.eyebrow { color: var(--primary); font-size: .72rem; font-weight: 800; letter-spacing: .14em; margin: 0 0 .45rem; }
.error { color: var(--danger); min-height: 1.4rem; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(100%, 430px); padding: clamp(1.5rem, 5vw, 2.5rem); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 15px 45px rgba(27, 45, 54, .08); }
.login-card h1 { font-size: clamp(1.7rem, 5vw, 2.4rem); margin: 0 0 .5rem; }
.login-card form { display: grid; gap: .5rem; margin-top: 1.7rem; }
.login-card label, label { font-size: .88rem; font-weight: 700; }
.demo-hint { color: var(--muted); font-size: .78rem; margin: 1rem 0 0; }

.app-view { min-height: 100vh; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 1.1rem clamp(1rem, 4vw, 3rem); }
.topbar h1 { font-size: 1.45rem; margin: 0; }
.user-menu { display: flex; align-items: center; gap: 1rem; font-size: .88rem; }
.main-nav { display: flex; gap: .4rem; padding: 1rem clamp(1rem, 4vw, 3rem) 0; background: var(--surface); border-bottom: 1px solid var(--line); }
.nav-button { color: var(--muted); background: transparent; border: 0; border-bottom: 3px solid transparent; padding: .7rem 1rem; font-weight: 800; }
.nav-button.active { color: var(--primary); border-bottom-color: var(--primary); }

.screen { width: min(1250px, 100%); margin: 0 auto; padding: 2rem clamp(1rem, 4vw, 3rem) 4rem; }
.screen-heading { display: flex; justify-content: space-between; align-items: end; gap: 1rem; margin-bottom: 1.5rem; }
.screen-heading h2 { font-size: clamp(1.55rem, 3vw, 2.2rem); margin: 0 0 .3rem; }
.toolbar, .form-actions, .section-heading { display: flex; align-items: center; gap: .7rem; }
.toolbar label { display: flex; align-items: center; gap: .5rem; white-space: nowrap; }
.panel, .order-card, .work-row, .change-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.panel { padding: 1.25rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
label { display: grid; gap: .4rem; }
input, select, textarea { width: 100%; color: var(--ink); background: var(--surface); border: 1px solid #becbd2; border-radius: 8px; padding: .68rem .75rem; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(23, 107, 105, .16); border-color: var(--primary); }
textarea { resize: vertical; }
.wide { width: 100%; }
.primary, .secondary, .ghost, .danger, .icon-button { border-radius: 8px; padding: .67rem 1rem; border: 1px solid transparent; font-weight: 800; }
.primary { color: white; background: var(--primary); }
.primary:hover { background: var(--primary-dark); }
.secondary { color: var(--primary-dark); background: var(--accent); border-color: #c5e1dd; }
.ghost { color: var(--muted); background: transparent; border-color: var(--line); }
.danger { color: var(--danger); background: #fff5f5; border-color: #efcaca; }
.icon-button { color: var(--muted); background: transparent; border: 0; font-size: 1.7rem; line-height: 1; padding: .2rem .5rem; }
.section-heading { justify-content: space-between; margin: 1.5rem 0 .8rem; }
.section-heading h3 { margin: 0; font-size: 1rem; }
.form-actions { justify-content: flex-end; margin-top: 1.5rem; }

.item-editor { display: grid; gap: .65rem; }
.item-editor-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 150px auto; gap: .65rem; align-items: end; }
.item-editor-row .remove-item { height: 42px; }
.summary-row { display: flex; flex-wrap: wrap; gap: .7rem; margin-bottom: 1rem; }
.summary-chip { background: var(--accent); color: var(--primary-dark); border-radius: 999px; padding: .45rem .8rem; font-size: .84rem; font-weight: 800; }
.summary-chip.new-summary { background: #e5efff; color: #24568e; }
.summary-chip.warning { background: var(--warning); color: #805b00; }
.order-list, .work-list, .change-list { display: grid; gap: .8rem; }
.order-card { overflow: hidden; }
.order-card.cancelled { border-color: #e4b6b6; }
.order-card-header { display: flex; justify-content: space-between; align-items: start; gap: 1rem; padding: 1rem 1.15rem; background: #fbfcfc; border-bottom: 1px solid var(--line); }
.order-number { font-size: 1.05rem; font-weight: 900; }
.order-meta { display: flex; flex-wrap: wrap; gap: .35rem .8rem; color: var(--muted); font-size: .83rem; margin-top: .3rem; }
.order-actions { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: flex-end; }
.badge { display: inline-flex; align-items: center; gap: .3rem; border-radius: 999px; padding: .3rem .6rem; background: var(--accent); color: var(--primary-dark); font-size: .75rem; font-weight: 800; white-space: nowrap; }
.badge.done { background: var(--done); color: #5b676f; }
.badge.new { background: #e5efff; color: #24568e; }
.badge.cancelled { background: #fde8e8; color: var(--danger); }
.badge.unread { background: var(--warning); color: #805b00; }
.order-items { padding: .3rem .7rem .7rem; }
.detail-row { display: grid; grid-template-columns: minmax(0, 1fr) 130px 100px 110px; gap: .7rem; align-items: center; padding: .72rem .45rem; border-bottom: 1px solid #edf1f2; }
.detail-row:last-child { border-bottom: 0; }
.detail-row.done { color: #78838a; background: var(--done); }
.detail-row .quantity { text-align: right; font-variant-numeric: tabular-nums; }
.notes { color: var(--muted); font-size: .85rem; padding: .4rem .45rem .1rem; white-space: pre-wrap; }

.filter-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.work-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1rem; align-items: center; padding: 1rem; }
.work-row.done { order: 2; color: #78838a; background: var(--done); }
.work-row-main { min-width: 0; }
.work-row-title { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; font-weight: 900; }
.work-row-meta { display: flex; flex-wrap: wrap; gap: .4rem 1rem; color: var(--muted); font-size: .82rem; margin-top: .35rem; }
.work-row-actions { display: flex; align-items: center; gap: .7rem; }
.status-button { min-width: 100px; }
.change-list { margin-top: 2rem; }
.change-list h3 { margin: 0; }
.change-card { padding: 1rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; border-left: 4px solid #e2ad39; }
.change-card p { margin: .2rem 0; }
.change-detail { color: var(--muted); font-size: .85rem; }
.message { position: fixed; z-index: 5; right: 1rem; bottom: 1rem; max-width: min(90vw, 420px); padding: .8rem 1rem; border-radius: 10px; background: var(--ink); color: white; box-shadow: 0 8px 20px rgba(0,0,0,.15); }
.message.error-message { background: var(--danger); }

.modal { border: 0; padding: 0; background: transparent; max-width: min(720px, calc(100% - 2rem)); width: 100%; }
.modal::backdrop { background: rgba(17, 30, 38, .55); }
.modal-card { max-height: 90vh; overflow: auto; background: var(--surface); border-radius: 16px; padding: 1.5rem; }
.modal-heading { display: flex; justify-content: space-between; align-items: start; margin-bottom: 1.2rem; }
.modal-heading h2 { margin: 0; }

@media (max-width: 700px) {
  .topbar, .screen-heading { align-items: flex-start; flex-direction: column; }
  .topbar { gap: .8rem; }
  .user-menu { width: 100%; justify-content: space-between; }
  .main-nav { overflow-x: auto; }
  .toolbar { width: 100%; }
  .toolbar label { flex: 1; }
  .form-grid, .filter-panel { grid-template-columns: 1fr; }
  .item-editor-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 110px auto; }
  .order-card-header { flex-direction: column; }
  .order-actions { justify-content: flex-start; }
  .detail-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .detail-row .quantity, .detail-row .status-cell { text-align: left; }
  .detail-row .status-cell { grid-column: 1 / -1; }
  .item-editor-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .item-editor-row .remove-item { width: fit-content; }
  .work-row { grid-template-columns: 1fr; }
  .work-row-actions { justify-content: space-between; }
  .change-card { align-items: flex-start; flex-direction: column; }
}
