:root {
  --navy: #0d1b2a;
  --ink: #1c2430;
  --muted: #5d6b7c;
  --line: #e2e6ed;
  --paper: #f3f5f7;
  --card: #fff;
  --gold: #b7893a;
  --gold-soft: #f8f1de;
  --ok: #0f6e4c;
  --ok-bg: #e7f6ef;
  --bad: #8a1f1f;
  --bad-bg: #fdecec;
  --shadow: 0 10px 30px rgba(13, 27, 42, 0.06);
  font-family: "Segoe UI", "Malgun Gothic", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.mark {
  width: 18px; height: 18px; border-radius: 4px; background: #e2c27a; display: inline-block; flex: none;
}
.brand-lockup { display: flex; gap: 10px; align-items: center; }
.brand-lockup strong { display: block; font-size: 16px; }
.brand-lockup span { display: block; color: var(--muted); font-size: 12px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(480px, 100%); background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px; box-shadow: var(--shadow);
}
.login-card .stack { display: grid; gap: 8px; margin-top: 18px; }
.login-card .stack .btn { width: 100%; }
.principles { margin: 18px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.principles li + li { margin-top: 6px; }
.principles.compact { margin-top: 16px; }
.fine { color: var(--muted); font-size: 12px; line-height: 1.5; }

.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: var(--navy); color: #fff; padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.side .brand-lockup span, .side .brand-lockup strong { color: #fff; }
.side nav { display: grid; gap: 4px; margin-top: 22px; }
.nav-btn {
  text-align: left; border: 0; background: transparent; color: #d5dce6; border-radius: 8px; padding: 10px 12px;
}
.nav-btn.on { background: rgba(226, 194, 122, 0.16); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }

.body { min-width: 0; }
.banner { background: var(--gold-soft); color: #5c4a1f; padding: 10px 20px; font-size: 13px; border-bottom: 1px solid #e4d3a1; }
.top {
  display: flex; justify-content: space-between; gap: 16px; align-items: center;
  padding: 14px 22px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2;
}
.switcher { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.switcher strong { color: var(--ink); font-size: 15px; }
.switcher select { min-width: 220px; }
.user { display: flex; gap: 10px; align-items: center; }
.user span { color: var(--muted); font-size: 13px; }
main { padding: 22px; max-width: 1120px; }
main.main-content-wrapper { max-width: none; padding: 0; display: flex; flex-direction: column; min-width: 0; height: 100%; }
.page-head { margin-bottom: 14px; }
.page-head h1 { font-size: 22px; }
.page-head p, .meta, .note, .muted { color: var(--muted); }
.meta, .note { margin: 8px 0 14px; font-size: 13px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; margin-bottom: 14px; }
.widgets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.card.wide { grid-column: 1 / -1; }
.kpi .k, .card .k { color: var(--muted); font-size: 13px; }
.v { font-size: 28px; font-weight: 800; margin: 6px 0; }
.s { color: var(--muted); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

.btn {
  border: 0; background: var(--navy); color: #fff; border-radius: 8px; min-height: 36px; padding: 0 14px; font-weight: 700;
}
.btn.ghost { background: #fff; color: var(--navy); border: 1px solid #d5dbe3; }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 12px; }
.btn.text { background: transparent; color: var(--navy); }
.btn:disabled { opacity: 0.5; cursor: default; }

.flash { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.flash.error { background: var(--bad-bg); color: var(--bad); }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, select {
  width: 100%; min-height: 36px; border: 1px solid #d5dbe3; border-radius: 8px; padding: 0 10px; background: #fff;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.form-grid .wide, .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.check input { width: auto; min-height: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 10px 16px; }
.row-between, .row-gap, .toolbar { display: flex; gap: 10px; align-items: end; justify-content: space-between; flex-wrap: wrap; }
.toolbar { margin-bottom: 12px; align-items: center; }
.seg { display: inline-flex; padding: 3px; background: #eceff3; border-radius: 999px; }
.seg button { border: 0; background: transparent; border-radius: 999px; min-height: 30px; padding: 0 12px; }
.seg button.on { background: #fff; box-shadow: 0 1px 2px rgba(13, 27, 42, 0.08); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 13px; }
th { color: var(--muted); font-size: 12px; font-weight: 700; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 8px; font-size: 12px; font-weight: 700; background: #eef2f6; }
.badge.hq { background: #e8eef6; color: var(--navy); }
.badge.master { background: var(--gold-soft); color: #6b5314; }
.badge.open { background: #fff6e8; color: #8a5a10; }
.badge.invoiced { background: var(--ok-bg); color: var(--ok); }
.badge.void { background: #f1f2f4; color: var(--muted); }
.empty h2 { margin-bottom: 8px; }

@media (max-width: 800px) {
  .shell { display: block; }
  .side {
    position: static; height: auto; display: flex; flex-direction: column;
    align-items: stretch; gap: 10px; padding: 12px 12px 8px;
  }
  .side .brand-lockup { flex: none; }
  .side .brand-lockup strong { white-space: nowrap; }
  .side nav { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 0; }
  .nav-btn { white-space: nowrap; flex: none; }
  .nav-btn.on { box-shadow: inset 0 -3px 0 var(--gold); }
  .top, main { padding-left: 14px; padding-right: 14px; }
  .top { flex-wrap: wrap; align-items: flex-start; }
  .switcher { flex: 1 1 180px; }
  .switcher select { min-width: 0; width: 100%; }
  .widgets, .form-grid { grid-template-columns: 1fr; }
  .card.wide { grid-column: auto; }
  .user { flex-wrap: wrap; }
}

body.erp-frame-on {
  height: 100vh;
  overflow: hidden;
  background: #f5f5f3;
  color: #0d1b2a;
  font-family: Pretendard, "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 14px;
}
body.erp-frame-on #app { height: 100%; }
.erp-frame { display: flex; width: 100%; height: 100%; min-width: 0; }
.main-sidebar {
  width: 248px; background: #141418; color: #fff; display: flex; flex-direction: column;
  padding: 24px 16px 16px; flex: none; position: relative; overflow: hidden; height: 100%;
}
.main-sidebar::after {
  content: ''; position: absolute; bottom: -60px; right: -60px; width: 200px; height: 200px;
  background: #e8384f; border-radius: 50%; opacity: 0.04; pointer-events: none;
}
.logo-area { padding: 8px 12px 24px; border-bottom: 1px solid rgba(255,255,255,0.07); margin-bottom: 16px; flex: none; }
.logo-area img { height: 32px; width: auto; display: block; filter: brightness(0) invert(1); opacity: 0.92; }
.nav-primary { flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; }
.nav-section-label {
  font-size: 10px; font-weight: 700; letter-spacing: 1.8px; text-transform: uppercase;
  color: rgba(255,255,255,0.28); padding: 0 12px; margin: 8px 0 6px;
}
.nav-item + .nav-section-label { margin-top: 16px; }
button.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  color: rgba(255,255,255,0.55); background: transparent; border: 0;
  padding: 11px 14px; border-radius: 10px; font-size: 13.5px; font-weight: 500;
  margin-bottom: 2px; position: relative;
}
button.nav-item:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.85); }
button.nav-item.active {
  background: #fff; color: #141418; font-weight: 700;
  box-shadow: 0 6px 18px rgba(0,0,0,0.28), inset 0 1px 0 rgba(255,255,255,0.05);
}
button.nav-item.active .nav-icon { stroke: #b8975a; }
button.nav-item.active::before {
  content: ''; position: absolute; left: -16px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 58%; background: #b8975a; border-radius: 0 3px 3px 0;
}
.nav-icon { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-ref-wrap { margin-top: 0; padding-top: 16px; flex: none; }
.nav-ref-head {
  display: flex; align-items: center; gap: 8px; color: rgba(255,255,255,0.42);
  font-size: 12.5px; font-weight: 600; padding: 0 2px 10px;
}
.nav-ref-head svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 1.8; flex: none; }
.nav-ref-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
button.nav-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 7px; width: 100%; min-height: 70px; padding: 10px 3px 9px;
  border-radius: 10px; background: rgba(255,255,255,0.055); border: 1px solid transparent; color: inherit;
}
button.nav-tile:hover { background: rgba(255,255,255,0.1); }
button.nav-tile.active { background: rgba(232,56,79,0.16); border-color: rgba(232,56,79,0.3); }
.nav-tile-icon { width: 28px; height: 28px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.nav-tile-icon svg { width: 14px; height: 14px; stroke: #fff; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-tile-label { font-size: 11px; font-weight: 600; color: rgba(255,255,255,0.9); text-align: center; line-height: 1.2; }
.sidebar-footer {
  margin-top: 12px; padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.07);
  display: flex; justify-content: flex-end; align-items: center; flex: none;
}
button.sidebar-logout {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent;
  color: rgba(255,255,255,0.72); font-size: 12px; font-weight: 600; padding: 6px 8px; border-radius: 8px;
}
button.sidebar-logout:hover { background: rgba(255,255,255,0.08); color: #fff; }
button.sidebar-logout .nav-icon { width: 16px; height: 16px; }
.top-bar {
  background: #fff; padding: 0 28px; height: 60px; display: flex; justify-content: space-between;
  align-items: center; flex: none; border-bottom: 1px solid #e4e7ee; gap: 12px;
}
.top-bar-left, .top-action-area { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top-bar .switcher { display: flex; align-items: center; gap: 8px; margin: 0; }
.top-bar .switcher select { width: 180px; min-width: 0; min-height: 34px; }
.user-chip {
  display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px;
  border: 1px solid #e4e7ee; border-radius: 20px; max-width: 280px;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: #0d1b2a; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex: none;
}
.user-chip-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.user-chip-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip-email { font-size: 10.5px; color: #9aa1b2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.view-section {
  flex: 1; min-height: 0; overflow: auto; background: #f5f5f3;
  padding: clamp(20px, 2vw, 36px) clamp(24px, 2.4vw, 48px) 48px;
}
.erp-nav-toggle { display: none; }
.erp-nav-backdrop { display: none; }
.erp-nav-toggle svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }

@media (max-width: 1280px) {
  .erp-nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; padding: 0; flex: none;
    border: 1px solid #e4e7ee; border-radius: 10px; background: #fff; color: #0d1b2a;
  }
  body.erp-frame-on .main-sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 40;
    transform: translateX(-105%); transition: transform 0.2s ease;
  }
  body.erp-frame-on.nav-open .main-sidebar { transform: translateX(0); box-shadow: 12px 0 40px rgba(0,0,0,0.28); }
  body.erp-frame-on.nav-open .erp-nav-backdrop { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(13,27,42,0.4); }
}
@media (max-width: 480px) {
  .user-chip-meta { display: none; }
  .user-chip { padding: 4px; }
}
