:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --brand: #3457d5;
  --brand-hover: #2941ad;
  --success: #16a34a;
  --error: #dc2626;
  --warn: #d97706;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f26;
    --border: #2b2f38;
    --text: #e7e9ee;
    --text-muted: #9096a3;
    --brand: #5b7cfa;
    --brand-hover: #7c96fb;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Pretendard, Roboto, sans-serif;
  line-height: 1.5;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); }

.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.auth-card h1 {
  font-size: 1.4rem;
  margin: 0 0 4px;
}

.auth-card .subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.field input:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  background: var(--brand);
  color: white;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { background: var(--brand-hover); }

.btn-block { width: 100%; }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-danger { background: var(--error); }

.link-row {
  margin-top: 18px;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.flashes { margin-bottom: 16px; }

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 0.88rem;
}

.flash-error { background: rgba(220, 38, 38, 0.12); color: var(--error); }
.flash-success { background: rgba(22, 163, 74, 0.12); color: var(--success); }
.flash-info { background: rgba(52, 87, 213, 0.12); color: var(--brand); }

/* App shell */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-left { display: flex; align-items: center; gap: 28px; }

.brand {
  font-weight: 700;
  font-size: 1.05rem;
}

.tabs { display: flex; gap: 4px; }

.tab {
  padding: 8px 14px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.tab:hover { background: var(--bg); color: var(--text); }

.tab.active {
  background: rgba(52, 87, 213, 0.12);
  color: var(--brand);
}

.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 0.88rem; color: var(--text-muted); }

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge-admin { background: rgba(217, 119, 6, 0.15); color: var(--warn); }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 24px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.page-header h1 { font-size: 1.3rem; margin: 0; }

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

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.status-pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-pending, .status-provisioning { background: rgba(217, 119, 6, 0.15); color: var(--warn); }
.status-running, .status-approved, .status-active { background: rgba(22, 163, 74, 0.15); color: var(--success); }
.status-rejected, .status-failed { background: rgba(220, 38, 38, 0.15); color: var(--error); }

.inline-form { display: inline; }

/* Per-row action buttons (table's last column) -- a resource row can now
   carry 2-3 of these side by side (터미널/로그/삭제 etc.), so they need a
   flex wrapper with consistent spacing instead of ad-hoc inline margins,
   and a smaller size than the full .btn (which is sized for standalone
   page-level CTAs like "+ EC2 생성"). */
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.progress-bar {
  width: 140px;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--brand);
}

.new-resource-form {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.new-resource-form input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.section-note {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 20px;
}

/* Segmented control -- a nicer stand-in for a plain radio-button group.
   Markup: alternating <input type="radio"> + <label for="..."> pairs inside
   a .segmented-control wrapper; the input stays a real (keyboard/AT
   accessible) radio, just visually hidden, and its <label> is styled as one
   segment of the control. */
.segmented-control {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.segmented-control input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.segmented-control label {
  flex: 1;
  text-align: center;
  padding: 10px 12px;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  background: var(--surface);
  transition: background 0.15s ease, color 0.15s ease;
  border-right: 1px solid var(--border);
}

.segmented-control label:last-of-type { border-right: none; }
.segmented-control label:hover { background: var(--bg); color: var(--text); }

.segmented-control input[type="radio"]:checked + label {
  background: var(--brand);
  color: white;
}

.segmented-control input[type="radio"]:disabled + label {
  opacity: 0.45;
  cursor: not-allowed;
  background: var(--surface);
}

.segmented-control input[type="radio"]:focus-visible + label {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

/* Network canvas */
.network-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.network-sidebar {
  width: 220px;
  flex-shrink: 0;
}

.network-ec2-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.network-ec2-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.88rem;
}

.network-ec2-list .btn {
  padding: 4px 10px;
  font-size: 0.78rem;
}

.network-canvas-wrap {
  flex: 1;
  position: relative;
  height: 560px;
  padding: 0;
  overflow: auto;
}

.network-canvas {
  position: relative;
  width: 100%;
  height: 100%;
}

#edge-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.network-edge, .network-edge-temp {
  stroke: var(--brand);
  stroke-width: 2;
  pointer-events: stroke;
  cursor: pointer;
}

.network-edge-temp {
  stroke-dasharray: 4 4;
  pointer-events: none;
}

.network-node {
  position: absolute;
  width: 140px;
  min-height: 56px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: grab;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  user-select: none;
}

.network-node:active { cursor: grabbing; }

.network-lb-box {
  width: auto;
  min-width: 180px;
  max-width: 640px;
  border: 2px dashed var(--brand);
  background: color-mix(in srgb, var(--brand) 6%, var(--surface));
}

.network-lb-members {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  min-height: 40px;
}

/* A member keeps looking like its own EC2 block (same size/style as
   .network-node) -- the load balancer box just grows to hold it, rather
   than collapsing it down to a bare name. */
.network-lb-member {
  position: relative;
  width: 140px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.network-lb-member-remove {
  position: absolute;
  top: 4px;
  right: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 2px;
}
.network-lb-member-remove:hover { color: var(--error); }

.network-lb-empty-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: italic;
}

.network-node-name {
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.network-node-remove {
  position: absolute;
  top: 4px;
  right: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px;
}

.network-node-remove:hover { color: var(--error); }

.network-node-domain {
  font-size: 0.68rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 3px;
}

.network-node-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--brand);
  border: 2px solid var(--surface);
  cursor: crosshair;
  z-index: 3;
  /* Hidden until the box is hovered -- otherwise the dot sits on top of
     (z-index above) any edge line/arrowhead that terminates there, and
     four always-visible dots per box clutters a canvas with many nodes. */
  opacity: 0;
  transition: opacity 0.12s ease;
}
.network-node:hover .network-node-handle {
  opacity: 1;
}

/* One handle centered on each side of the node box, so a connection can be
   dragged from whichever side is most convenient given the other node's
   position -- not just the bottom-right corner. */
.network-node-handle-top { top: -6px; left: 50%; transform: translateX(-50%); }
.network-node-handle-right { right: -6px; top: 50%; transform: translateY(-50%); }
.network-node-handle-bottom { bottom: -6px; left: 50%; transform: translateX(-50%); }
.network-node-handle-left { left: -6px; top: 50%; transform: translateY(-50%); }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 380px;
}
