:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1f2630;
  --border: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --primary: #4f8cff;
  --primary-hover: #3a78ee;
  --danger: #f85149;
  --success: #3fb950;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic",
               "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 14px;
  min-height: 100vh;
  display: flex; flex-direction: column;
}

.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs a, .tabs .placeholder {
  padding: 8px 14px; border-radius: 6px;
  text-decoration: none; color: var(--text);
}
.tabs a:hover { background: var(--surface-2); }
.tabs .placeholder { color: var(--muted); cursor: not-allowed; }
.user { color: var(--muted); }
.user a { color: var(--primary); text-decoration: none; }

.container {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px;
}

h1 { font-size: 22px; margin: 0 0 16px; }

.flashes { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 8px; }
.flash-error { background: rgba(248,81,73,0.15); border: 1px solid var(--danger); }
.flash-success { background: rgba(63,185,80,0.15); border: 1px solid var(--success); }
.flash-info { background: rgba(79,140,255,0.12); border: 1px solid var(--primary); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.card-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.card-value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.card-value.muted { color: var(--muted); font-size: 16px; font-weight: 400; }
.card-sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

.login-card { max-width: 380px; margin: 60px auto; }
.form-card { max-width: 480px; }
.form-card label, .login-card label {
  display: block; margin-bottom: 12px;
}
.form-card label.inline { display: flex; align-items: center; gap: 8px; }
/* Every free-text-ish input (as opposed to checkbox/radio, which keep
   their native appearance) shares one look. Listed explicitly rather than
   a blanket `input` selector so checkbox/radio/hidden/submit are never
   accidentally caught — WTForms renders DateField as type=date,
   IntegerField as type=number, so both need to be here too, not just the
   literal type="text" inputs hand-written in templates. */
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], input[type=tel], input[type=search], input[type=url],
select {
  width: 100%; padding: 8px 10px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  margin-top: 4px;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

button, .button {
  padding: 8px 16px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  cursor: pointer; font-size: 14px; text-decoration: none; display: inline-block;
}
button.primary, .button.primary {
  background: var(--primary); border-color: var(--primary); color: #fff;
}
button.primary:hover, .button.primary:hover { background: var(--primary-hover); }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left;
}
.data-table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

.statusbar {
  padding: 8px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  display: flex; gap: 20px;
}

.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.muted-small { color: var(--muted); font-size: 12px; }
textarea { width: 100%; padding: 8px 10px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; font-size: 14px; font-family: inherit; margin-top: 4px; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row label { flex: 1; min-width: 200px; }

.totals {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px; margin: 16px 0; padding: 12px;
  background: var(--surface-2); border-radius: 6px;
}
.totals strong { font-size: 18px; }

.stale-tag {
  background: rgba(248,81,73,0.2); color: var(--danger);
  padding: 2px 6px; border-radius: 4px; font-size: 11px; font-weight: 700;
}

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.badge-draft { background: rgba(139,148,158,0.2); color: var(--muted); }
.badge-sent { background: rgba(79,140,255,0.2); color: var(--primary); }
.badge-accepted { background: rgba(63,185,80,0.2); color: var(--success); }
.badge-expired { background: rgba(248,81,73,0.2); color: var(--danger); }
.badge-pending { background: rgba(139,148,158,0.2); color: var(--muted); }
.badge-submitted { background: rgba(79,140,255,0.2); color: var(--primary); }
.badge-approved { background: rgba(63,185,80,0.2); color: var(--success); }
.badge-rejected { background: rgba(248,81,73,0.2); color: var(--danger); }
.badge-lead { background: rgba(139,148,158,0.2); color: var(--muted); }
.badge-quote { background: rgba(79,140,255,0.2); color: var(--primary); }
.badge-negotiation { background: rgba(255,177,66,0.2); color: #ffb142; }
.badge-closed_won { background: rgba(63,185,80,0.2); color: var(--success); }
.badge-closed_lost { background: rgba(248,81,73,0.2); color: var(--danger); }

.kanban {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px;
  margin-top: 16px; align-items: start;
}
.kanban-col {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; min-height: 200px;
}
.kanban-head {
  font-weight: 600; padding: 4px 6px 8px; border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.kanban-body { display: flex; flex-direction: column; gap: 8px; min-height: 100px; }
.kanban-body.drop-hover { background: rgba(79,140,255,0.08); border-radius: 6px; }
.kanban-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; cursor: grab;
}
.kanban-card.dragging { opacity: 0.4; }
.kanban-card a { color: var(--text); text-decoration: none; font-weight: 600; }
.kanban-card a:hover { color: var(--primary); }
.kanban-empty { text-align: center; padding: 20px; }

.timeline { margin: 16px 0; }
.timeline-item {
  display: grid; grid-template-columns: 110px 1fr; gap: 16px;
  padding-bottom: 16px;
  border-left: 2px solid var(--border); margin-left: 80px; padding-left: 16px;
  position: relative;
}
.timeline-item:before {
  content: ""; position: absolute;
  left: -6px; top: 14px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary);
}
.timeline-date { font-size: 12px; color: var(--muted); padding-top: 12px; text-align: right; }
.timeline-card { margin: 0; }
.diff-block {
  background: var(--surface-2); border-radius: 4px;
  padding: 8px 10px; font-size: 11px; line-height: 1.4;
  max-height: 240px; overflow: auto;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  white-space: pre-wrap; word-break: break-all;
}
.action-list { margin: 8px 0 0; padding-left: 18px; }
.action-list li { line-height: 1.6; }

@media (max-width: 640px) {
  .timeline-item { grid-template-columns: 1fr; margin-left: 16px; }
  .timeline-date { text-align: left; padding-top: 0; }
}

@media (max-width: 900px) {
  .kanban { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 12px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .user { font-size: 12px; }
}

/* DealReg sheet-sync UI (Plan B / personal-edition) */
.dealreg-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sync-status { font-size: 13px; color: var(--muted); }
.sync-status.sync-off { color: var(--warn, #d9822b); }

/* ---- 전역 "작업 중" 오버레이 (busy.js) ---- */
/* Slow actions (AI 초안, Drive 조회, PDF 생성) otherwise look like a freeze. */
.busy-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
}
.busy-overlay[hidden] { display: none; }
.busy-box {
  background: var(--surface-2, #21262d);
  border: 1px solid var(--border, #30363d);
  border-radius: 10px; padding: 24px 32px; text-align: center;
  min-width: 240px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.busy-spinner {
  width: 34px; height: 34px; margin: 0 auto 14px;
  border: 3px solid var(--border, #30363d);
  border-top-color: var(--primary, #2f81f7);
  border-radius: 50%;
  animation: busy-spin 0.8s linear infinite;
}
@keyframes busy-spin { to { transform: rotate(360deg); } }
.busy-msg { font-size: 15px; color: var(--text, #e6edf3); }
.busy-elapsed { margin-top: 6px; }
