:root {
  --md-primary: #6750a4;
  --md-on-primary: #fff;
  --surface: #fff;
  --bg: #f7f6fb;
  --outline: rgba(16, 24, 40, 0.08);
  --elev: 0 6px 18px rgba(99, 102, 241, 0.08);
  --radius: 14px;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, Arial;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(180deg, var(--bg), #eef2ff);
  min-height: 100vh;
  color: #0f172a;
}

#zoomPercent, #zoomInBtn, #zoomOutBtn, #fitBtn {
  width: 38px;
  height: 38px;
  font-size: 1.2rem;
  color: #fff;
  background: rgba(40, 40, 60, 0.18);
  border-radius: 8px;
  border: 1.5px solid #e7e4ef;
  box-shadow: 0 2px 8px rgba(40, 40, 60, 0.08);
  outline: none;
  font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
  font-weight: 500;
  text-align: center;
  margin: 0;
  padding: 0;
  transition: border 0.18s, box-shadow 0.18s, background 0.18s;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#zoomPercent:focus {
  border-color: #6750a4;
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.12);
  background: #fff;
  color: #222;
}

#fitBtn {
  font-size: 0.95rem;
  height: 38px;
  width: 38px;
  margin-top: 6px;
}

#fitBtn:hover, #zoomInBtn:hover, #zoomOutBtn:hover, #zoomPercent:focus {
  background: #ede7f6;
  color: #2c5364;
  border-color: #6750a4;
}

.navbar {
  width: 100vw;
  background: linear-gradient(90deg, #6750a4 0%, #5b2ea6 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  box-sizing: border-box;
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.08);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-logo {
  display: flex;
  align-items: center;
  margin-right: 16px;
}

.navbar-title-group {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.navbar-title {
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: 0px;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.12);
}

.navbar-action-link {
  cursor: pointer;
  margin-right: 2em;
  color: #fff;
  text-decoration: none;
  font-weight: 400;
  transition: color 0.2s;
  font-size: 1em;
  letter-spacing: 0.02em;
  background: none;
  border: none;
  outline: none;
  padding: 0;
  display: inline-block;
  vertical-align: middle;
}

.navbar-action-link:hover {
  color: #ffe082;
  text-decoration: underline;
}

#menuBtn {
  font-size: 1em !important;
  font-weight: 400 !important;
  letter-spacing: 0.02em !important;
  background: none !important;
  color: #fff !important;
  border: none !important;
  padding: 0 !important;
  margin-right: 2em !important;
  display: inline-block !important;
  vertical-align: middle !important;
  transition: color 0.2s !important;
}

#menuBtn:hover {
  color: #ffe082 !important;
  transform: scale(1.13);
}

#menuDropdown button {
  font-size: 12px !important;
  padding: 20px !important;
  background: none !important;
  color: #5b2ea6 !important;
  border: none !important;
  text-align: left !important;
  width: 100% !important;
  font-family: 'Inter', 'Segoe UI', Arial, sans-serif !important;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}

#menuDropdown button:hover {
  background: #ede7f6 !important;
  color: #2c5364 !important;
}

.container {
  display: flex;
  gap: 20px;
  padding: 18px 28px;
}

.left {
  width: 380px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--elev);
  padding: 14px;
  border: 1px solid var(--outline);
}

textarea {
  width: 100%;
  height: 300px;
  border-radius: 10px;
  border: 1px solid #e7e4ef;
  padding: 12px;
  font-family: monospace;
  font-size: 13px;
  color: #0f172a;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.btn {
  background: var(--md-primary);
  color: var(--md-on-primary);
  border: none;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}

.btn.ghost {
  background: transparent;
  color: var(--md-primary);
  border: 1px solid var(--outline);
}

.btn.secondary {
  background: #4a3d72;
}

.small {
  padding: 6px 8px;
  font-size: 13px;
}

.canvas {
  flex: 1;
}

#viewport {
  height: calc(100vh - 140px);
  min-height: 320px;
  border-radius: 16px;
  background: linear-gradient(180deg, #fff, #fbfbff);
  border: 1px solid var(--outline);
  overflow: auto;
  padding: 18px;
  position: relative;
  touch-action: none;
  user-select: none;
  cursor: grab;
}

#viewport.grabbing {
  cursor: grabbing;
}

#surface {
  position: relative;
  transform-origin: 0 0;
  padding-bottom: 60px;
}

.table-card {
  position: absolute;
  width: 320px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--elev);
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, 0.04);
  cursor: grab;
}

.table-card.dragging {
  cursor: grabbing;
  opacity: 0.95;
}

.table-head {
  background: linear-gradient(90deg, var(--md-primary), #5b2ea6);
  color: var(--md-on-primary);
  padding: 10px 12px;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.table-head .left {
  display: flex;
  gap: 8px;
  align-items: center;
}

.table-body {
  padding: 10px 12px 22px;
  font-size: 13px;
  overflow: hidden;
  position: relative;
  transition: max-height 160ms ease;
}

.table-body.collapsed {
  max-height: 168px;
}

.table-body.expanded {
  max-height: 2000px;
}

.table-body::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.95));
  pointer-events: none;
}

.table-body.expanded::after {
  display: none;
}

.col {
  display: flex;
  align-items: center;
  padding: 6px 0;
}

.key-icon {
  width: 14px;
  height: 14px;
  margin-right: 8px;
  display: inline-block;
}

.handle {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--md-primary);
  box-shadow: 0 1px 6px rgba(8, 6, 30, 0.08);
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: auto;
}

.handle.source {
  right: -6px;
  top: 50%;
}

.handle.target {
  left: -6px;
  top: 50%;
}

svg.line-layer {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}

.hint {
  font-size: 12px;
  color: #6b7280;
  margin-top: 8px;
}

footer {
  padding: 18px 28px;
  color: #475569;
}

.card-toolbar {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--outline);
  padding: 6px;
  border-radius: 10px;
  box-shadow: var(--elev);
  display: flex;
  gap: 8px;
  z-index: 50;
}

.fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 56px;
  height: 56px;
  border-radius: 28px;
  background: var(--md-primary);
  color: var(--md-on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 30px rgba(103, 80, 164, 0.2);
  cursor: pointer;
  z-index: 60;
  border: none;
}

.fab:hover {
  transform: translateY(-3px);
}

.icon-btn {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  color: var(--md-on-primary);
  border: none;
  cursor: pointer;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.modal-backdrop {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(9, 10, 16, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 70;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 18px;
  width: 640px;
  box-shadow: 0 20px 50px rgba(10, 12, 30, 0.2);
}

.form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.form-row input, .form-row select {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #e7e4ef;
}

.col-list {
  max-height: 260px;
  overflow: auto;
  border: 1px dashed #eef0f8;
  padding: 8px;
  border-radius: 8px;
  background: #fbfbff;
}

@media (max-width: 1000px) {
  .container {
    flex-direction: column;
  }
  .left {
    width: 100%;
  }
  .canvas {
    width: 100%;
  }
  #viewport {
    height: 480px;
    min-height: 320px;
    max-width: 100vw;
  }
  .card {
    padding: 8px;
  }
  textarea {
    height: 180px;
    font-size: 12px;
  }
  .btn, .btn.secondary, .btn.ghost {
    padding: 6px 10px;
    font-size: 13px;
  }
}

@media (max-width: 700px) {
  .navbar {
    flex-direction: column;
    align-items: stretch;
    padding: 8px 8px;
  }
  .navbar-actions {
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
  }
  .navbar-logo {
    margin-bottom: 4px;
  }
  .navbar-title {
    font-size: 0.98rem;
  }
}

@media (max-width: 600px) {
  .container {
    padding: 8px;
    gap: 8px;
  }
  .card {
    padding: 6px;
  }
  .left {
    width: 100%;
  }
  #viewport {
    height: 320px;
    min-height: 180px;
    max-width: 100vw;
  }
  textarea {
    height: 100px;
    font-size: 11px;
  }
  .btn, .btn.secondary, .btn.ghost {
    padding: 4px 8px;
    font-size: 12px;
  }
}