:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --line: #e4e8f0;
  --paper: #ffffff;
  --canvas: #f4f6fb;
  --brand: #3157d5;
  --brand-dark: #2444ad;
  --brand-soft: #edf1ff;
  --success: #12805c;
  --danger: #c6384f;
  --warning: #a86500;
  font-family: Pretendard, "Noto Sans KR", Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--canvas); }
body { min-height: 100%; margin: 0; color: var(--ink); background: radial-gradient(circle at 82% 4%, #e6ecff 0, transparent 26rem), var(--canvas); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-header { position: sticky; top: 0; z-index: 20; min-height: 68px; padding: 12px max(22px, env(safe-area-inset-left)); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; border-bottom: 1px solid rgba(228,232,240,.9); background: rgba(255,255,255,.88); backdrop-filter: blur(18px); }
.brand { display: inline-flex; align-items: center; gap: 10px; width: fit-content; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; color: #fff; background: var(--brand); border-radius: 11px; font-weight: 900; }
.brand strong, .brand small { display: block; line-height: 1.05; }
.brand small { margin-top: 3px; color: var(--muted); font-size: 9px; letter-spacing: .16em; }
.header-title { font-weight: 800; }
.back-link { justify-self: end; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 700; }

.page-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 48px 0 90px; }
.hero { display: flex; justify-content: space-between; align-items: end; gap: 32px; margin-bottom: 34px; }
.eyebrow { display: block; margin-bottom: 10px; color: var(--brand); font-size: 11px; font-weight: 900; letter-spacing: .16em; }
.hero h1 { margin: 0; max-width: 740px; font-size: clamp(34px, 5vw, 58px); line-height: 1.08; letter-spacing: -.045em; }
.hero h1 em { color: var(--brand); font-style: normal; }
.hero p { margin: 18px 0 0; color: var(--muted); font-size: 16px; }

.primary-button, .secondary-button, .danger-button, .small-button { border: 0; border-radius: 12px; cursor: pointer; font-weight: 800; transition: transform .15s, background .15s, opacity .15s; }
.primary-button { min-height: 48px; padding: 0 20px; color: white; background: var(--brand); box-shadow: 0 10px 24px rgba(49,87,213,.22); }
.primary-button:hover { background: var(--brand-dark); transform: translateY(-1px); }
.secondary-button { min-height: 46px; padding: 0 18px; color: #344054; background: #eef1f6; }
.danger-button { min-height: 46px; padding: 0 18px; color: white; background: var(--danger); }
.small-button { padding: 8px 12px; color: var(--brand); background: var(--brand-soft); }
button:disabled { cursor: wait; opacity: .55; transform: none !important; }

.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.summary-card { position: relative; overflow: hidden; min-height: 126px; padding: 23px; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); box-shadow: 0 10px 30px rgba(16,24,40,.045); }
.summary-card::after { content: ""; position: absolute; right: -25px; bottom: -35px; width: 100px; height: 100px; border-radius: 50%; background: var(--brand-soft); }
.summary-card span { color: var(--muted); font-size: 13px; font-weight: 700; }
.summary-card strong { display: block; margin-top: 12px; font-size: 32px; letter-spacing: -.04em; }
.summary-card small { margin-left: 4px; color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 4px; margin: 34px 0 20px; padding: 5px; width: fit-content; max-width: 100%; overflow-x: auto; scrollbar-width: none; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.72); }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { white-space: nowrap; padding: 11px 16px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; cursor: pointer; font-weight: 800; }
.tabs button.is-active { color: var(--ink); background: #fff; box-shadow: 0 3px 12px rgba(16,24,40,.09); }
.tabs span { display: inline-grid; min-width: 20px; height: 20px; margin-left: 5px; place-items: center; border-radius: 10px; color: white; background: var(--danger); font-size: 11px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin: 22px 0 13px; }
.section-heading h2 { margin: 0; font-size: 21px; letter-spacing: -.025em; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.document-list { display: grid; gap: 10px; }
.document-card { width: 100%; display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 17px 18px; border: 1px solid var(--line); border-radius: 16px; color: inherit; text-align: left; background: var(--paper); cursor: pointer; box-shadow: 0 6px 20px rgba(16,24,40,.035); }
.document-card:hover { border-color: #bac6f3; transform: translateY(-1px); }
.doc-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 15px; color: var(--brand); background: var(--brand-soft); font-size: 19px; font-weight: 900; }
.doc-main { min-width: 0; }
.doc-main strong, .doc-main span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-main strong { font-size: 15px; }
.doc-main span { margin-top: 6px; color: var(--muted); font-size: 12px; }
.doc-meta { display: grid; justify-items: end; gap: 7px; color: var(--muted); font-size: 11px; }
.status { padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 900; }
.status.pending { color: var(--warning); background: #fff5dc; }
.status.approved { color: var(--success); background: #e8f7f1; }
.status.rejected { color: var(--danger); background: #ffedf0; }
.status.withdrawn { color: #596273; background: #edf0f4; }

.template-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.template-card { display: flex; min-height: 190px; padding: 22px; flex-direction: column; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); }
.template-card.is-off { opacity: .62; }
.template-top { display: flex; justify-content: space-between; align-items: center; }
.template-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 13px; color: white; background: linear-gradient(135deg, #3157d5, #6f88e8); font-weight: 900; }
.template-card h3 { margin: 18px 0 6px; font-size: 17px; }
.template-card p { margin: 0; flex: 1; color: var(--muted); font-size: 13px; line-height: 1.55; }
.template-actions { display: flex; gap: 8px; margin-top: 18px; }
.template-actions button { flex: 1; }

.empty-state { padding: 62px 24px; border: 1px dashed #cdd3df; border-radius: 18px; color: var(--muted); text-align: center; background: rgba(255,255,255,.55); }
.error-state { color: var(--danger); border-color: #f3b7c1; background: #fff7f8; }

.sheet-dialog { width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: 0; border: 0; background: transparent; }
.sheet-dialog::backdrop { background: rgba(17,24,39,.45); backdrop-filter: blur(4px); }
.sheet-card { position: fixed; top: 0; right: 0; width: min(600px, 100%); height: 100dvh; display: flex; flex-direction: column; border: 0; background: white; box-shadow: -20px 0 50px rgba(16,24,40,.16); animation: slide-in .2s ease-out; }
.wide-sheet { width: min(720px, 100%); }
@keyframes slide-in { from { transform: translateX(30px); opacity: .6; } }
.sheet-header { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 24px 26px 20px; border-bottom: 1px solid var(--line); }
.sheet-header h2 { margin: 0; font-size: 23px; letter-spacing: -.03em; }
.sheet-header .eyebrow { margin-bottom: 5px; }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 12px; color: var(--muted); background: #f1f3f7; cursor: pointer; font-size: 24px; }
.sheet-body { flex: 1; padding: 24px 26px 36px; overflow-y: auto; }
.sheet-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 26px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: white; }
.direct-line { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; padding: 14px 16px; border-radius: 13px; color: var(--brand); background: var(--brand-soft); font-size: 13px; }
.direct-line span { color: var(--muted); }
.field { display: grid; gap: 8px; margin-bottom: 18px; color: #344054; font-size: 13px; font-weight: 800; }
.field b { margin-left: 3px; color: var(--danger); font-size: 10px; }
.field input, .field textarea, .field select { width: 100%; padding: 12px 13px; border: 1px solid #cfd5df; border-radius: 11px; outline: none; color: var(--ink); background: white; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(49,87,213,.11); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }
.detail-cell { padding: 14px; border-radius: 12px; background: #f6f7fa; }
.detail-cell span, .value-block span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 800; }
.detail-cell strong { font-size: 13px; }
.value-block { margin-bottom: 12px; padding: 15px; border: 1px solid var(--line); border-radius: 12px; }
.value-block p { margin: 0; white-space: pre-wrap; line-height: 1.6; font-size: 14px; }
.decision-box { margin-top: 22px; padding: 16px; border-radius: 13px; background: #f7f8fb; }
.timeline { margin-top: 24px; padding-left: 16px; border-left: 2px solid #dfe5f2; }
.timeline div { margin: 0 0 17px; }
.timeline strong, .timeline small { display: block; }
.timeline small { margin-top: 3px; color: var(--muted); }

.builder-heading { display: flex; justify-content: space-between; align-items: center; margin: 24px 0 11px; }
.field-builder { display: grid; gap: 10px; }
.builder-row { display: grid; grid-template-columns: minmax(0, 1fr) 130px auto auto; gap: 8px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: #f8f9fb; }
.builder-row input[type="text"], .builder-row select { min-width: 0; padding: 10px; border: 1px solid #d5dae3; border-radius: 9px; background: white; }
.builder-row label { display: flex; gap: 5px; align-items: center; color: var(--muted); font-size: 11px; }
.remove-field { width: 34px; height: 34px; border: 0; border-radius: 9px; color: var(--danger); background: #ffedf0; cursor: pointer; }
.toggle-row { display: flex; align-items: center; gap: 9px; margin-top: 18px; color: #344054; font-size: 13px; font-weight: 700; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 16px); padding: 12px 18px; border-radius: 11px; color: white; background: #1d2939; opacity: 0; pointer-events: none; transition: .2s; box-shadow: 0 12px 30px rgba(16,24,40,.22); }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .app-header { min-height: 60px; padding-inline: 14px; }
  .brand span:last-child { display: none; }
  .page-shell { width: min(100% - 28px, 1180px); padding: 28px 0 70px; }
  .hero { display: block; }
  .hero h1 { font-size: 35px; }
  .hero p { font-size: 14px; }
  .hero > .primary-button { width: 100%; margin-top: 22px; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-card:last-child { grid-column: 1 / -1; }
  .summary-card { min-height: 105px; padding: 18px; }
  .summary-card strong { font-size: 22px; line-height: 1.25; word-break: keep-all; }
  .tabs { width: 100%; }
  .tabs button { flex: 1; padding-inline: 10px; }
  .document-card { grid-template-columns: 44px minmax(0, 1fr); padding: 14px; }
  .doc-icon { width: 44px; height: 44px; }
  .doc-meta { grid-column: 2; grid-row: 2; display: flex; justify-content: space-between; width: 100%; }
  .template-grid { grid-template-columns: 1fr; }
  .sheet-card { top: auto; bottom: 0; height: min(88dvh, 820px); border-radius: 22px 22px 0 0; animation-name: slide-up; }
  @keyframes slide-up { from { transform: translateY(30px); opacity: .6; } }
  .sheet-header { padding: 20px 18px 16px; }
  .sheet-body { padding: 20px 18px 30px; }
  .sheet-footer { padding: 13px 18px calc(13px + env(safe-area-inset-bottom)); }
  .sheet-footer button { flex: 1; }
  .detail-grid { grid-template-columns: 1fr; }
  .builder-row { grid-template-columns: 1fr 104px auto; }
  .builder-row label { grid-column: 1 / 3; }
}
