:root {
  --ink: #20201d;
  --muted: #77766f;
  --line: #e7e4dc;
  --paper: #fbfaf7;
  --white: #fff;
  --accent: #6e8f57;
  --accent-dark: #4e6f3d;
  --accent-soft: #eaf0e4;
  --warm: #f1ede4;
  --danger: #a64b43;
  --shadow: 0 18px 60px rgba(41, 40, 35, .09);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); color: var(--ink); font-family: Inter, Pretendard, "Noto Sans KR", "Malgun Gothic", sans-serif; }
body { margin: 0; min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template: 72px 1fr / 280px 1fr; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 0 30px; border-bottom: 1px solid var(--line); background: rgba(251,250,247,.92); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50% 50% 42% 58%; background: var(--accent); color: white; font-family: Georgia, serif; font-size: 21px; font-style: italic; }
.brand strong, .brand small { display: block; }
.brand strong { font-family: Georgia, serif; font-size: 21px; line-height: 1; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 9px; letter-spacing: .14em; text-transform: uppercase; }
.top-actions, .workspace-actions { display: flex; align-items: center; gap: 10px; }
.connection { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.connection i { width: 7px; height: 7px; border-radius: 50%; background: #c7a64d; box-shadow: 0 0 0 4px rgba(199,166,77,.12); }
.connection.online i { background: #6f9b64; box-shadow: 0 0 0 4px rgba(111,155,100,.12); }
.connection.offline i { background: #b75c55; box-shadow: 0 0 0 4px rgba(183,92,85,.12); }

.sidebar { border-right: 1px solid var(--line); background: #f5f3ee; padding: 22px 14px; overflow-y: auto; }
.sidebar-heading { display: flex; justify-content: space-between; align-items: center; padding: 0 10px 12px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.text-button { border: 0; background: none; color: var(--accent-dark); font-size: 11px; }
.application-list { display: grid; gap: 7px; }
.application-item { width: 100%; border: 1px solid transparent; background: transparent; text-align: left; border-radius: 12px; padding: 13px 14px; color: var(--ink); transition: .18s ease; }
.application-item:hover { background: rgba(255,255,255,.72); }
.application-item.active { background: var(--white); border-color: var(--line); box-shadow: 0 6px 22px rgba(50,48,40,.05); }
.application-item strong, .application-item span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.application-item strong { font-size: 14px; }
.application-item span { margin-top: 5px; color: var(--muted); font-size: 12px; }
.application-item small { display: inline-flex; margin-top: 10px; padding: 3px 7px; background: var(--warm); border-radius: 20px; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
.list-empty { padding: 24px 12px; color: var(--muted); font-size: 12px; line-height: 1.7; }

.main { min-width: 0; }
.empty-state { min-height: calc(100vh - 72px); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 24px; text-align: center; background: radial-gradient(circle at 50% 35%, #fff 0, rgba(255,255,255,0) 38%); }
.empty-visual { width: 104px; height: 104px; display: grid; place-items: center; margin-bottom: 24px; border: 1px solid #dfe5d8; border-radius: 48% 52% 58% 42%; background: var(--accent-soft); transform: rotate(-5deg); }
.empty-visual span { color: var(--accent-dark); font-size: 34px; transform: rotate(5deg); }
.eyebrow { margin: 0 0 10px; color: var(--accent-dark); font-size: 10px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; }
.empty-state h1 { margin: 0; font-family: Georgia, "Noto Sans KR", serif; font-weight: 400; font-size: clamp(36px, 5vw, 62px); line-height: 1.16; letter-spacing: -.04em; }
.empty-state > p:not(.eyebrow) { max-width: 560px; margin: 22px auto 30px; color: var(--muted); line-height: 1.8; }

.workspace { max-width: 1240px; margin: 0 auto; padding: 46px 46px 100px; }
.workspace-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.title-line { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.workspace-header h1 { margin: 10px 0 7px; font-family: Georgia, "Noto Sans KR", serif; font-size: clamp(28px, 4vw, 42px); font-weight: 400; letter-spacing: -.035em; }
.workspace-header p { margin: 0; color: var(--muted); font-size: 13px; }
.status-badge { padding: 5px 9px; border-radius: 20px; background: var(--accent-soft); color: var(--accent-dark); font-size: 9px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.status-badge.planned { background: #eee9d9; color: #7d682f; }
.status-badge.approved { background: #e5e8f3; color: #4c587f; }
.status-badge.completed { background: #e2eee7; color: #35624b; }

.tabs { display: flex; gap: 2px; margin: 40px 0 28px; border-bottom: 1px solid var(--line); }
.tab { padding: 14px 22px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: #9a9890; font-size: 12px; font-weight: 600; }
.tab.active { color: var(--ink); border-color: var(--accent); }
.tab-panel { animation: reveal .25s ease; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } }
.intro-card { display: flex; align-items: flex-end; justify-content: space-between; gap: 36px; margin-bottom: 22px; padding: 25px 28px; border-radius: 16px; background: var(--accent-soft); }
.intro-card h2 { margin: 0; font-family: Georgia, "Noto Sans KR", serif; font-weight: 400; font-size: 25px; }
.intro-card > p { max-width: 470px; margin: 0; color: #64705b; font-size: 13px; line-height: 1.7; }
.analysis-intro { background: #f0ecdf; }
.result-intro { background: #e7ece8; }

.content-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel, .output-panel { border: 1px solid var(--line); border-radius: 16px; background: var(--white); box-shadow: 0 2px 0 rgba(40,40,34,.015); overflow: hidden; }
.full-panel { margin-top: 18px; }
.panel-heading, .output-heading { min-height: 65px; display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-heading > div { display: flex; align-items: center; gap: 10px; }
.panel-heading h2, .output-heading h2 { margin: 0; font-size: 14px; }
.count { width: 25px; height: 25px; display: grid; place-items: center; border-radius: 8px; background: var(--warm); color: var(--muted); font-size: 10px; }
.add-button { border: 0; background: none; color: var(--accent-dark); font-size: 11px; font-weight: 600; }
.card-list { min-height: 160px; display: grid; align-content: start; }
.data-card { position: relative; padding: 17px 18px; border-bottom: 1px solid var(--line); }
.data-card:last-child { border-bottom: 0; }
.data-card h3 { max-width: calc(100% - 70px); margin: 0 0 7px; font-size: 13px; line-height: 1.5; }
.data-card p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.6; }
.data-card .card-menu { position: absolute; top: 13px; right: 13px; display: flex; gap: 3px; }
.mini-button { border: 0; padding: 5px 7px; border-radius: 6px; background: transparent; color: #98968f; font-size: 10px; }
.mini-button:hover { background: var(--warm); color: var(--ink); }
.source-chip { display: inline-flex; margin-top: 10px; padding: 4px 7px; border-radius: 6px; background: #f0ede7; color: #77736c; font-size: 9px; }
.source-chip.confirmed { background: var(--accent-soft); color: var(--accent-dark); }
.source-chip.forbidden { background: #f5e7e5; color: var(--danger); }
.material-grid { display: grid; grid-template-columns: repeat(3, 1fr); min-height: 120px; }
.material-grid .data-card { border-right: 1px solid var(--line); }
.empty-list { padding: 34px 20px; color: #aaa79e; text-align: center; font-size: 11px; }

.sticky-action { position: sticky; bottom: 18px; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 24px; padding: 15px 16px 15px 21px; border: 1px solid rgba(222,218,208,.9); border-radius: 15px; background: rgba(255,255,255,.9); box-shadow: var(--shadow); backdrop-filter: blur(14px); }
.sticky-action strong, .sticky-action span { display: block; }
.sticky-action strong { font-size: 13px; }
.sticky-action div span { margin-top: 3px; color: var(--muted); font-size: 10px; }
.output-panel { min-height: 420px; }
.output-heading span { color: var(--muted); font-size: 10px; }
.output-content { min-height: 350px; margin: 0; padding: 28px; background: white; color: #3e3d38; font: 13px/1.85 Pretendard, "Noto Sans KR", "Malgun Gothic", sans-serif; white-space: pre-wrap; word-break: keep-all; overflow-x: auto; }
.output-content:empty::before { content: "아직 생성된 내용이 없습니다."; color: #aaa79e; }
.output-content.final { font-size: 14px; }

.primary, .secondary, .danger-ghost, .icon-button { min-height: 40px; border-radius: 10px; padding: 0 17px; border: 1px solid transparent; font-size: 12px; font-weight: 600; }
.primary { background: var(--ink); color: white; box-shadow: 0 7px 20px rgba(32,32,29,.13); }
.primary:hover { background: var(--accent-dark); }
.primary:disabled { cursor: not-allowed; opacity: .45; }
.secondary { border-color: var(--line); background: white; color: var(--ink); }
.danger-ghost { background: transparent; color: var(--danger); }
.icon-button { width: 40px; padding: 0; border-color: var(--line); background: transparent; color: var(--muted); font-size: 16px; }
.compact { min-height: 34px; padding: 0 13px; font-size: 11px; }

.dialog { width: min(560px, calc(100vw - 28px)); max-height: calc(100vh - 36px); padding: 0; border: 0; border-radius: 18px; background: var(--paper); box-shadow: 0 30px 100px rgba(30,29,25,.25); }
.dialog.wide { width: min(760px, calc(100vw - 28px)); }
.dialog.small { width: min(480px, calc(100vw - 28px)); }
.dialog::backdrop { background: rgba(30,30,27,.38); backdrop-filter: blur(5px); }
.dialog form { max-height: calc(100vh - 36px); overflow-y: auto; padding: 26px; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 23px; }
.dialog-heading h2 { margin: 0; font-family: Georgia, "Noto Sans KR", serif; font-size: 27px; font-weight: 400; }
.dialog-close { width: 32px; height: 32px; border: 0; border-radius: 50%; background: var(--warm); color: var(--muted); font-size: 20px; }
.dialog label { display: grid; gap: 7px; margin-bottom: 15px; color: #55534d; font-size: 11px; font-weight: 600; }
.form-grid { display: grid; gap: 0 14px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
input, textarea, select { width: 100%; border: 1px solid #dedbd2; border-radius: 9px; outline: none; background: white; color: var(--ink); font-size: 12px; transition: .15s; }
input, select { height: 42px; padding: 0 12px; }
textarea { resize: vertical; padding: 11px 12px; line-height: 1.6; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(110,143,87,.1); }
.check-label { display: flex !important; grid-template-columns: none !important; align-items: center; flex-direction: row; font-weight: 400 !important; }
.check-label input { width: 15px; height: 15px; }
.check-label.confirm { padding: 12px; border-radius: 9px; background: var(--accent-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 25px; padding-top: 20px; border-top: 1px solid var(--line); }
.dialog-copy { margin: -8px 0 20px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.dialog code { padding: 2px 5px; border-radius: 4px; background: var(--warm); font-size: 11px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; max-width: 380px; padding: 13px 17px; border-radius: 11px; background: var(--ink); color: white; box-shadow: var(--shadow); font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(12px); transition: .22s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }
.loading { position: fixed; inset: 0; z-index: 90; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(251,250,247,.88); backdrop-filter: blur(8px); }
.loading strong { margin-top: 18px; font-family: Georgia, "Noto Sans KR", serif; font-size: 22px; font-weight: 400; }
.loading small { margin-top: 8px; color: var(--muted); }
.spinner { width: 38px; height: 38px; border: 2px solid #dfe5d8; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .app-shell { grid-template: 66px auto 1fr / 1fr; }
  .topbar { padding: 0 18px; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 14px; overflow-x: auto; }
  .sidebar-heading { display: none; }
  .application-list { display: flex; }
  .application-item { min-width: 180px; }
  .workspace { padding: 30px 22px 90px; }
  .content-grid { grid-template-columns: 1fr; }
  .material-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 620px) {
  .brand small, .connection { display: none; }
  .topbar { padding: 0 12px; }
  .workspace-header, .intro-card, .sticky-action { align-items: stretch; flex-direction: column; }
  .workspace-actions { width: 100%; }
  .workspace-actions button { flex: 1; }
  .workspace { padding: 24px 14px 80px; }
  .tabs { overflow-x: auto; }
  .tab { flex: 0 0 auto; padding: 13px 16px; }
  .material-grid, .form-grid.two { grid-template-columns: 1fr; }
  .material-grid .data-card { border-right: 0; }
  .sticky-action { bottom: 8px; }
  .sticky-action .primary { width: 100%; }
  .dialog form { padding: 20px; }
}
