:root {
  --ink: #101816;
  --ink-soft: #5a6862;
  --line: rgba(16, 24, 22, 0.12);
  --panel: #f4f7f5;
  --surface: #ffffff;
  --accent: #0b7a5a;
  --accent-deep: #06563f;
  --accent-soft: #d8f0e6;
  --danger: #b42318;
  --font: "Pretendard Variable", Pretendard, "Noto Sans KR", sans-serif;
  --display: "Space Grotesk", "Instrument Sans", var(--font);
  --row: 34px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.4;
  background: linear-gradient(180deg, #e9efeb 0%, #f3f6f4 100%);
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--ink-soft); }

.boot {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  color: var(--ink-soft);
}
.boot-mark, .brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #0b7a5a, #149e74);
  color: #fff;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.7rem;
}
.brand-mark { width: 28px; height: 28px; }

.app {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 6px 8px;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 6px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  gap: 8px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.brand strong {
  font-family: var(--display);
  font-size: 1.15rem;
  letter-spacing: -0.03em;
}
.brand em {
  font-style: normal;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 0.28rem 0.55rem;
  line-height: 1.2;
  white-space: nowrap;
}
.btn-dark {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.btn-danger {
  background: #fff5f4;
  border-color: rgba(180, 35, 24, 0.22);
  color: var(--danger);
}
.btn-sm { padding: 0.25rem 0.5rem; font-size: 13px; }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
  padding-inline: 0.3rem;
}

.flash {
  padding: 0.45rem 0.7rem;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 13.5px;
}
.flash.error { background: #fdecea; color: var(--danger); }

.quick-form {
  display: grid;
  grid-template-columns: auto 118px 170px 140px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #eef6f2;
}
.extract-drop {
  border: 1px dashed rgba(11, 122, 90, 0.45);
  border-radius: 8px;
  background: #f4fbf7;
  min-height: var(--row);
  padding: 0.25rem 0.4rem;
  display: grid;
  place-content: center;
  text-align: center;
  cursor: pointer;
  line-height: 1.15;
}
.extract-drop strong {
  font-size: 12px;
  color: var(--accent-deep);
}
.extract-drop span {
  font-size: 10.5px;
  color: var(--ink-soft);
}
.extract-drop.dragover,
.extract-drop.busy {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.extract-hint {
  grid-column: 1 / -1;
  font-size: 12.5px;
  color: var(--accent-deep);
  padding: 0 2px 2px;
}
.quick-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent-deep);
  white-space: nowrap;
  padding-inline: 4px;
}
.quick-form input,
.search,
.contact-form input,
.edit-form input,
.edit-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.4rem 0.5rem;
  background: var(--surface);
  min-height: var(--row);
}
.quick-form button {
  min-height: var(--row);
  padding-inline: 1rem;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 240px minmax(320px, 0.95fr) minmax(0, 1.35fr);
  gap: 6px;
}

.col {
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.list-col { background: var(--panel); }

.search {
  margin: 6px;
  width: calc(100% - 12px);
}

.client-list {
  overflow: auto;
  padding: 4px;
  display: grid;
  gap: 2px;
  align-content: start;
}
.client-item {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0.45rem 0.55rem;
  background: transparent;
  text-align: left;
}
.client-item:hover { background: rgba(11, 122, 90, 0.07); }
.client-item.active {
  background: var(--surface);
  border-color: rgba(11, 122, 90, 0.28);
}
.client-item strong {
  display: block;
  font-size: 14.5px;
  font-weight: 650;
}
.client-item span {
  display: block;
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.detail-scroll {
  min-height: 0;
  overflow: auto;
  padding: 6px;
  display: grid;
  gap: 6px;
  align-content: start;
}
.detail-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
  padding: 2px 2px 4px;
}
.title-wrap { min-width: 0; }
.title-wrap h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.15rem;
  letter-spacing: -0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.title-wrap .muted {
  display: block;
  margin-top: 2px;
  font-size: 12.5px;
}
.detail-actions { display: flex; gap: 4px; flex-shrink: 0; }

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 6px;
  display: grid;
  gap: 5px;
}
.card-h h2 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent-deep);
}

.kv {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
}
.kv > div {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 0.35rem 0.4rem;
  border-bottom: 1px solid rgba(16, 24, 22, 0.06);
}
.kv span { color: var(--ink-soft); font-size: 12.5px; }
.kv b {
  font-weight: 550;
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.4;
}

.edit-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}
.edit-form textarea[name="address"] {
  min-height: 4.6em;
  resize: vertical;
  line-height: 1.45;
}
.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
}

.contact-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.contact-form #contact-submit { grid-column: 1 / 2; }
.contact-form #contact-cancel { grid-column: 2 / 3; }
.contact-form:not(.is-editing) #contact-submit { grid-column: 1 / -1; }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  max-height: 180px;
}
.dense-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.dense-table th,
.dense-table td {
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid rgba(16, 24, 22, 0.07);
  text-align: left;
  vertical-align: middle;
}
.dense-table th {
  position: sticky;
  top: 0;
  background: #eef3f0;
  color: var(--ink-soft);
  font-weight: 650;
  font-size: 12px;
  z-index: 1;
  white-space: nowrap;
}
.dense-table td {
  word-break: break-word;
}
.dense-table td:last-child {
  text-align: right;
  white-space: nowrap;
  width: 1%;
}
.dense-table tbody tr:hover { background: rgba(11, 122, 90, 0.04); }
.dense-table tbody tr.contact-row {
  cursor: pointer;
}
.dense-table tbody tr.contact-row.is-editing {
  background: var(--accent-soft);
}
.dense-table .empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 0.7rem;
}

.files-block { display: grid; gap: 6px; }
.drop-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.dropzone {
  border: 1px dashed rgba(11, 122, 90, 0.4);
  border-radius: 8px;
  padding: 6px 4px;
  text-align: center;
  background: #f0f7f3;
  cursor: pointer;
  display: grid;
  place-content: center;
  gap: 1px;
  min-height: 42px;
}
.dropzone strong { font-size: 12.5px; }
.dropzone span { font-size: 11.5px; color: var(--ink-soft); }
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.kind-badge {
  display: inline-block;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 11.5px;
  margin-right: 4px;
}

.timeline-col { padding: 6px; gap: 6px; }
.timeline-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.timeline-bar h2 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent-deep);
}
.summary-line { font-size: 12.5px; }
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 12.5px;
  color: var(--ink-soft);
}
.chip.active {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-deep);
  font-weight: 650;
}

.timeline-list {
  min-height: 0;
  overflow: auto;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.timeline-item {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid rgba(16, 24, 22, 0.07);
}
.timeline-item:hover { background: rgba(11, 122, 90, 0.04); }
.timeline-item .src {
  font-size: 12.5px;
  color: var(--accent-deep);
  font-weight: 700;
}
.timeline-item .when {
  font-size: 11.5px;
  color: var(--ink-soft);
}
.timeline-item h3 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.timeline-item p {
  margin: 1px 0 0;
  font-size: 12.5px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.timeline-item .status {
  font-size: 12px;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  background: #eef3f0;
  white-space: nowrap;
}

.empty-state {
  margin: auto;
  color: var(--ink-soft);
  font-size: 14px;
  text-align: center;
  padding: 20px;
}
.empty-state.soft { font-size: 13px; }

@media (max-width: 1100px) {
  .quick-form {
    grid-template-columns: 1fr 1fr;
  }
  .quick-label,
  .extract-drop { grid-column: 1 / -1; }
  .quick-form input[name="address"],
  .quick-form button { grid-column: 1 / -1; }
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 220px minmax(360px, 1fr) minmax(320px, 1fr);
  }
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; overflow: visible; }
}

@media (max-width: 720px) {
  .quick-form { grid-template-columns: 1fr; }
}
