:root {
  color-scheme: light;
  --ink: #15233b;
  --muted: #51617a;
  --line: #d9e2ed;
  --blue: #2247be;
  --surface: #f1f5fa;
  --warning: #84401f;
  font: 14px/1.55 "Pretendard", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  color: var(--ink);
  background: var(--surface);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; }
h1, h2, p, ol, ul, dl, dd { margin: 0; }
button, input, select, textarea { font: inherit; }
button, summary { cursor: pointer; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
button { border: 1px solid var(--line); border-radius: 5px; padding: 7px 12px; color: var(--ink); background: white; font-weight: 600; }
button:hover:not(:disabled) { border-color: var(--blue); }
button:disabled { opacity: .55; cursor: not-allowed; }
.quiet { background: transparent; color: var(--blue); }
.primary { color: white; background: var(--blue); border-color: var(--blue); }
.primary:hover:not(:disabled) { background: #16348f; }

.mast {
  min-height: 58px;
  padding: 8px max(16px, calc((100vw - 1360px)/2));
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: white;
}
.mast .identity { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.identity strong {
  font: 800 20px/1 "Pretendard", system-ui, sans-serif;
  letter-spacing: -.04em;
  padding-right: 10px;
  border-right: 1px solid var(--line);
  color: var(--ink);
}
.identity span { color: var(--muted); font-size: 13px; font-weight: 500; }
.home-link {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: #f8fafd;
}
.home-link:hover { border-color: var(--blue); color: var(--blue); }

.demo-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.role-seg {
  display: inline-flex;
  align-items: center;
  background: #eef3fa;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}
.role-seg button {
  border: none;
  background: transparent;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 4px;
}
.role-seg button.active {
  background: white;
  color: var(--blue);
  box-shadow: 0 1px 2px rgba(21, 35, 59, 0.08);
}
.role-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 11px;
  background: #dbe6ff;
  color: var(--blue);
  font-variant-numeric: tabular-nums;
}
.tool-btn {
  font-size: 12px;
  padding: 5px 10px;
}

.guide-bar {
  background: #eef3fc;
  border-bottom: 1px solid #d5e1f5;
  padding: 8px max(16px, calc((100vw - 1360px)/2));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  font-size: 12.5px;
  color: #243757;
}
.guide-bar strong { color: var(--blue); font-weight: 700; margin-right: 6px; }
.guide-cta {
  font-size: 12px;
  font-weight: 600;
  color: var(--blue);
  text-decoration: none;
  white-space: nowrap;
}
.guide-cta:hover { text-decoration: underline; }

#notice {
  position: fixed;
  z-index: 10;
  inset: auto 16px 16px auto;
  background: #172743;
  color: white;
  padding: 10px 14px;
  border-radius: 6px;
  max-width: min(560px, calc(100vw - 32px));
  box-shadow: 0 8px 24px rgba(21, 35, 59, 0.18);
}
#notice.error { background: #852f27; }
dialog:modal { max-height: 90vh; }

.login {
  width: min(430px, calc(100% - 36px));
  margin: 8vh auto 0;
  padding: 28px;
  background: white;
  border: 1px solid var(--line);
  border-top: 4px solid var(--blue);
  border-radius: 7px;
}
.login p.login-desc { margin-top: 8px; font-size: 13px; color: var(--muted); line-height: 1.55; }
.login form { margin-top: 18px; }
.login button { margin-top: 14px; width: 100%; }
.quick-accounts {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 6px;
}
.quick-accounts button { margin-top: 0; font-size: 12px; background: #f6f9fe; }

.workspace {
  width: min(1360px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(240px, .72fr) minmax(0, 3fr);
  align-items: start;
  min-height: calc(100vh - 96px);
}
.queue { padding: 20px 16px; }
.queue-actions { display: flex; justify-content: space-between; gap: 6px; margin-bottom: 16px; }
.queue-actions button { font-size: 12px; white-space: nowrap; }
.queue-list-head { display: flex; justify-content: space-between; align-items: end; gap: 4px; margin-bottom: 6px; }
.queue-list-head label { margin-top: 0; }
.queue-list-head button, #price-inventory button { padding: 2px 6px; font-size: 11px; }
#price-inventory button { margin-left: 6px; }
#rate-form { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 8px; }
#queue-items { list-style: none; margin: 9px 0 0; padding: 0; }
#queue-items button {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  text-align: left;
  margin-bottom: 4px;
  padding: 8px 10px;
  overflow-wrap: anywhere;
}
#queue-items button:hover, #queue-items button[aria-current] { border-color: #bfcdee; background: #e7effe; }
#queue-items span { display: block; margin-top: 2px; font-weight: 400; font-size: 11.5px; color: var(--muted); }

#document {
  min-width: 0;
  min-height: 100%;
  background: white;
  border-inline: 1px solid var(--line);
  padding: 22px clamp(16px, 3vw, 38px) 32px;
}
.doc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}
#document-number { font: 700 12px Consolas, monospace; color: var(--blue); margin-bottom: 3px; }
h1 { font-size: clamp(22px, 2.6vw, 32px); line-height: 1.25; letter-spacing: -.04em; overflow-wrap: anywhere; }
h2 { font-size: 17px; letter-spacing: -.03em; }
#document-state {
  flex: none;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
}
#document-state[data-status="approved"] { color: #174d46; background: #e7f5f3; border-color: #bdded8; }
#document-state[data-status="review"] { color: var(--blue); background: #edf2ff; border-color: #cfe0ff; }
.callout { background: #fff1e5; color: var(--warning); padding: 8px 12px; margin-top: 11px; border-radius: 4px; }
.intro-grid { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 18px; }
label { display: block; font-size: 12px; font-weight: 600; margin-top: 10px; }
input, select, textarea {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 7px 9px;
  margin-top: 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
}
input:disabled, textarea:disabled, select:disabled { background: #f4f6fa; color: #3f4e67; opacity: 1; }
textarea { resize: vertical; }
.date-grid, .master-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px 12px; }
.inquiry-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.inquiry-actions button { font-size: 12px; padding: 6px 10px; }

.lines-section { margin-top: 18px; }
.section-head, .dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-head > div { display: flex; gap: 6px; }
.line {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-left: 3px solid #93a8df;
  border-radius: 5px;
  padding: 10px 12px;
}
.line.issue { border-left-color: #ce8156; background: #fffcfa; }
.line-title { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; overflow-wrap: anywhere; }
.line-title button { font-size: 11px; padding: 3px 8px; }
.amount { font-weight: 700; color: var(--blue); font-variant-numeric: tabular-nums; }
.flag { font-weight: 700; color: var(--warning); font-size: 12px; }
.muted { color: var(--muted); font-size: 12px; }
.line-fields { display: grid; grid-template-columns: 1fr .7fr 1fr 1.7fr; gap: 9px; margin-top: 4px; }
#price-hint { margin-top: 7px; }
.empty { padding: 20px 12px; border: 1px dashed var(--line); border-radius: 5px; margin-top: 8px; color: var(--muted); }
.totals {
  margin: 16px 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 5px;
  overflow: hidden;
}
.totals > div { padding: 10px 12px; background: #f4f7fc; overflow-wrap: anywhere; }
.totals dt { color: var(--muted); font-size: 12px; }
.totals dd { font-weight: 800; font-size: clamp(15px, 2vw, 22px); font-variant-numeric: tabular-nums; margin-top: 2px; }
.totals > div:last-child dd { color: var(--blue); }
.form-actions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: flex-end; margin-top: 12px; }
.form-actions p { margin-right: auto; }
#history { margin-top: 22px; padding-top: 12px; border-top: 1px solid var(--line); }
#events { list-style: none; padding: 0; margin-top: 8px; }
#events li { padding: 6px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
#events span { margin-left: 10px; color: var(--muted); font-size: 11.5px; }
#events p { margin-top: 2px; font-size: 12.5px; color: #2b3b55; }
dialog {
  border: 1px solid #aabbd4;
  border-radius: 7px;
  padding: 18px;
  width: min(640px, calc(100vw - 26px));
  box-shadow: 0 20px 60px #18253c42;
  color: var(--ink);
}
dialog::backdrop { background: #15233b80; }
dialog details { margin-top: 14px; padding-top: 8px; border-top: 1px solid var(--line); }
dialog summary { font-weight: 700; }
dialog .master-grid > button { align-self: end; }
#basis { line-height: 1.75; padding-top: 10px; overflow-wrap: anywhere; font-size: 13.5px; }
.source { padding: 8px 10px; background: #eaf1ff; border-radius: 4px; margin: 6px 0; white-space: pre-wrap; font-size: 12.5px; }
#return-form button { margin-top: 8px; }
#price-inventory { padding-left: 18px; font-size: 12px; overflow-wrap: anywhere; line-height: 1.7; }
#master-info { color: var(--blue); margin-top: 6px; font-size: 12.5px; font-weight: 600; }

@media (max-width: 820px) {
  .workspace { grid-template-columns: minmax(0,1fr); }
  .queue { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .queue-actions { justify-content: flex-start; margin-bottom: 8px; }
  #queue-items { max-height: 150px; overflow-y: auto; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 4px; }
  #queue-items button { margin-bottom: 0; }
}
@media (max-width: 520px) {
  .intro-grid { grid-template-columns: 1fr; gap: 4px; }
  .line-fields { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
