@charset "UTF-8";
@import url('https://fonts.googleapis.com/css2?family=Prompt:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  --primary-blue: #0284c7;
  --primary-dark: #0369a1;
  --accent-mint: #bbf7d0;
  --accent-sky: #bfdbfe;
  --line-color: #0284c7;
  --line-width: 2.5px;
  --bg-color: #f8fafc;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --card-pill-bg: linear-gradient(135deg, #c7f9cc 0%, #bde0fe 100%);
  --card-pill-border: rgba(255, 255, 255, 0.95);
  --card-shadow: 0 8px 18px -3px rgba(3, 105, 161, 0.16), 0 2px 5px rgba(0, 0, 0, 0.04);
  --card-width: 255px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Prompt', 'Sarabun', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
}

.bg-grid {
  background-image: 
    radial-gradient(circle at 1px 1px, rgba(2, 132, 199, 0.08) 1px, transparent 0);
  background-size: 24px 24px;
}

/* App Header & Navbar */
.app-navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(226, 232, 240, 0.9);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-text h1 {
  font-size: 18px;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.2;
}

.brand-text p {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Filter Tabs */
.filter-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 30px;
  overflow-x: auto;
  max-width: 52vw;
}

.tab-btn {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  background: transparent;
  color: #475569;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  font-family: inherit;
}

.tab-btn:hover {
  color: var(--primary-blue);
  background: rgba(255, 255, 255, 0.6);
}

.tab-btn.active {
  background: #ffffff;
  color: var(--primary-blue);
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* Action Controls */
.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #0369a1);
  color: white;
  border: none;
  box-shadow: 0 2px 6px rgba(2, 132, 199, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0369a1, #075985);
}

.btn-admin {
  background: #f8fafc;
  border: 1.5px solid #0284c7;
  color: #0284c7;
  font-weight: 600;
}

.btn-admin.active {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #ffffff;
  border: none;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
  animation: pulse-admin 2s infinite;
}

@keyframes pulse-admin {
  0%, 100% { box-shadow: 0 0 10px rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 18px rgba(239, 68, 68, 0.7); }
}

/* Floating Zoom / Pan Controls */
.floating-controls {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  padding: 6px;
  gap: 4px;
  z-index: 90;
}

.ctrl-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #334155;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.ctrl-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}

/* Viewport & Canvas Area */
.canvas-viewport {
  position: absolute;
  top: 64px;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  cursor: grab;
}

.canvas-viewport.dragging {
  cursor: grabbing;
}

.canvas-content {
  position: absolute;
  transform-origin: 0 0;
  transition: transform 0.06s linear;
  min-width: 100%;
  padding: 40px 60px 180px 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Canvas Corner Logo */
.canvas-corner-logo {
  position: absolute;
  top: 25px;
  left: 35px;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 10;
  transition: transform 0.2s ease;
}

.canvas-corner-logo img {
  width: 105px;
  height: auto;
  max-height: 120px;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.14));
  transition: transform 0.2s;
}

.canvas-corner-logo:hover img {
  transform: scale(1.05);
}

.admin-logo-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 16px;
  color: white;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  padding: 6px;
}

body.admin-mode .admin-logo-overlay {
  display: flex;
}

/* Main Top Title Badge */
.main-title-pill {
  background: linear-gradient(135deg, #a7f3d0 0%, #bae6fd 100%);
  padding: 10px 48px;
  border-radius: 9999px;
  box-shadow: 0 6px 16px rgba(2, 132, 199, 0.18);
  border: 2px solid #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 38px;
}

.main-title-pill h2 {
  font-size: 26px;
  font-weight: 800;
  color: #0c4a6e;
  letter-spacing: 0.5px;
}

/* ========================================================
   TREE HIERARCHY & CONNECTORS
   ======================================================== */

.tree-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  width: 100%;
}

.v-line {
  width: var(--line-width);
  background-color: var(--line-color);
  margin: 0 auto;
}

.v-line-sm { height: 24px; }
.v-line-md { height: 32px; }
.v-line-lg { height: 40px; }

/* 🌟 Deputies Row Container (รองผู้อำนวยการ / ผู้ช่วย ผอ.) */
.deputies-row-container {
  position: relative;
  display: flex;
  justify-content: center;
  gap: 28px;
  padding-top: 24px;
}

.deputies-horizontal-bar {
  position: absolute;
  top: 0;
  height: var(--line-width);
  background-color: var(--line-color);
}

.deputy-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.deputy-column::before {
  content: '';
  position: absolute;
  top: -24px;
  height: 24px;
  width: var(--line-width);
  background-color: var(--line-color);
  left: 50%;
  transform: translateX(-50%);
}

/* ปุ่มเพิ่มผู้บริหาร (Admin Add Executive) */
.admin-add-exec-btn {
  display: none;
  margin: 14px auto 8px auto;
  padding: 8px 18px;
  border-radius: 20px;
  border: 1.5px dashed #0284c7;
  background: rgba(2, 132, 199, 0.08);
  color: #0284c7;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

body.admin-mode .admin-add-exec-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.admin-add-exec-btn:hover {
  background: rgba(2, 132, 199, 0.18);
  transform: translateY(-1px);
}

/* Sections Row */
.sections-row-container {
  position: relative;
  display: flex;
  justify-content: center;
  gap: 36px;
  margin-top: 0;
  padding-top: 24px;
}

.sections-horizontal-bar {
  position: absolute;
  top: 0;
  height: var(--line-width);
  background-color: var(--line-color);
  left: 0;
  right: 0;
}

.section-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  min-width: 260px;
}

.section-column::before {
  content: '';
  position: absolute;
  top: -24px;
  height: 24px;
  width: var(--line-width);
  background-color: var(--line-color);
  left: 50%;
  transform: translateX(-50%);
}

.single-section-view .section-column::before {
  display: none !important;
}

.section-badge {
  background: linear-gradient(135deg, #a7f3d0 0%, #bae6fd 100%);
  padding: 6px 20px;
  border-radius: 9999px;
  border: 1.5px solid #ffffff;
  box-shadow: 0 4px 10px rgba(2, 132, 199, 0.14);
  font-size: 15px;
  font-weight: 700;
  color: #065f46;
  text-align: center;
  white-space: nowrap;
  margin-bottom: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Groups */
.groups-container {
  position: relative;
  display: flex;
  justify-content: center;
  gap: 28px;
  padding-top: 26px;
  margin-top: 0;
}

.groups-horizontal-bar {
  position: absolute;
  top: 0;
  height: var(--line-width);
  background-color: var(--line-color);
}

.group-branch {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.group-branch::before {
  content: '';
  position: absolute;
  top: -26px;
  height: 26px;
  width: var(--line-width);
  background-color: var(--line-color);
  left: 50%;
  transform: translateX(-50%);
}

.group-badge {
  background: linear-gradient(135deg, #e0f2fe 0%, #dbeafe 50%, #bae6fd 100%);
  padding: 5px 18px;
  border-radius: 9999px;
  border: 1.5px solid #ffffff;
  box-shadow: 0 4px 12px rgba(2, 132, 199, 0.18);
  font-size: 13.5px;
  font-weight: 700;
  color: #0369a1;
  text-align: center;
  white-space: nowrap;
  margin-bottom: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  position: relative;
  z-index: 2;
  transition: all 0.2s ease;
}

.group-badge:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(2, 132, 199, 0.24);
}

.group-badge-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 11.5px;
  opacity: 0.8;
  padding: 0 2px;
}

.group-badge-btn:hover {
  opacity: 1;
  transform: scale(1.2);
}

.group-badge-connector {
  width: var(--line-width);
  height: 38px;
  background-color: var(--line-color);
  margin: 0 auto;
}

.staff-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  position: relative;
}

.staff-connector {
  width: var(--line-width);
  height: 32px;
  background-color: var(--line-color);
}

.admin-add-group-btn {
  display: none;
  margin-top: 20px;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px dashed #0284c7;
  background: rgba(2, 132, 199, 0.06);
  color: #0284c7;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

body.admin-mode .admin-add-group-btn {
  display: inline-flex;
}

.admin-add-group-btn:hover {
  background: rgba(2, 132, 199, 0.15);
}

/* ========================================================
   PERSONNEL CARD COMPONENT
   ======================================================== */

.person-card {
  width: var(--card-width);
  background: var(--card-pill-bg);
  border-radius: 9999px;
  padding: 38px 14px 14px 14px;
  min-height: 82px;
  position: relative;
  box-shadow: var(--card-shadow);
  border: 1.5px solid var(--card-pill-border);
  text-align: center;
  transition: all 0.2s ease-in-out;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.person-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px -4px rgba(3, 105, 161, 0.22), 0 4px 8px rgba(0, 0, 0, 0.05);
}

.card-avatar-wrapper {
  position: absolute;
  top: -38px;
  left: 50%;
  transform: translateX(-50%);
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: #ffffff;
  padding: 2.5px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.14);
}

.card-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.card-name {
  font-size: 13px;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.35;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
  padding: 0 4px;
  width: 100%;
}

.card-divider {
  width: 72%;
  height: 1px;
  background-color: rgba(3, 105, 161, 0.28);
  margin: 4px auto 5px auto;
}

.card-position {
  font-size: 11.5px;
  font-weight: 500;
  color: #0369a1;
  line-height: 1.35;
  padding: 0 4px;
  white-space: normal;
  word-break: break-word;
  width: 100%;
}

.person-card.director-card {
  width: 275px;
  padding: 44px 20px 16px 20px;
}

.person-card.director-card .card-avatar-wrapper {
  width: 86px;
  height: 86px;
  top: -44px;
}

.person-card.director-card .card-name {
  font-size: 15.5px;
}

.person-card.director-card .card-position {
  font-size: 13px;
  font-weight: 600;
}

.admin-card-actions {
  display: none;
  position: absolute;
  top: -10px;
  right: -8px;
  gap: 4px;
  z-index: 10;
}

body.admin-mode .admin-card-actions {
  display: flex;
}

.admin-action-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #ffffff;
  background: #0284c7;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s;
}

.admin-action-btn:hover {
  transform: scale(1.15);
}

.admin-action-btn.btn-del {
  background: #ef4444;
}

.admin-avatar-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  border-radius: 50%;
  color: white;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
}

body.admin-mode .admin-avatar-overlay {
  display: flex;
}

.admin-add-section-btn {
  display: none;
  margin-top: 24px;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1.5px dashed #0284c7;
  background: rgba(2, 132, 199, 0.05);
  color: #0284c7;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

body.admin-mode .admin-add-section-btn {
  display: inline-flex;
}

.admin-add-section-btn:hover {
  background: rgba(2, 132, 199, 0.12);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(5px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

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

.modal-dialog {
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  animation: modal-enter 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-enter {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: #0f172a;
}

.modal-close-btn {
  border: none;
  background: transparent;
  font-size: 20px;
  color: #64748b;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.modal-close-btn:hover {
  color: #0f172a;
  background: #f1f5f9;
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.avatar-picker-row {
  display: flex;
  align-items: center;
  gap: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f1f5f9;
}

.modal-avatar-preview {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid #0284c7;
  box-shadow: 0 4px 10px rgba(2, 132, 199, 0.2);
}

.avatar-upload-btns {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.avatar-upload-btns input[type="file"] {
  display: none;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}

.form-input, .form-select {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1.5px solid #cbd5e1;
  font-size: 14px;
  font-family: inherit;
  color: #0f172a;
  transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: #0284c7;
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
  border-radius: 0 0 20px 20px;
}

/* Image Cropper Modal */
.image-editor-dialog {
  max-width: 480px;
}

.crop-viewport-wrapper {
  position: relative;
  width: 320px;
  height: 320px;
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  background: #090d16;
  cursor: grab;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  border: 2px solid #334155;
}

.crop-viewport-wrapper.grabbing {
  cursor: grabbing;
}

#cropCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.crop-circular-guide {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.68);
  border: 2.5px dashed rgba(255, 255, 255, 0.9);
  pointer-events: none;
}

.crop-hint {
  text-align: center;
  font-size: 12px;
  color: #64748b;
  margin-top: 6px;
}

.crop-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
  background: #f8fafc;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
}

.crop-ctrl-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.crop-ctrl-label {
  font-size: 12.5px;
  font-weight: 600;
  color: #334155;
  width: 95px;
  white-space: nowrap;
}

.crop-slider {
  flex: 1;
  accent-color: #0284c7;
  cursor: pointer;
}

.crop-ctrl-val {
  font-size: 12px;
  font-weight: 600;
  color: #0284c7;
  width: 44px;
  text-align: right;
}

.crop-btn-group {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 8px;
  border-top: 1px solid #e2e8f0;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
}

/* Toast */
.toast-msg {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #0f172a;
  color: white;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 2000;
  pointer-events: none;
}

.toast-msg.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Print */
@media print {
  .app-navbar, .floating-controls, .admin-card-actions, .admin-add-section-btn, .admin-add-group-btn, .admin-add-exec-btn, .group-badge-btn, .admin-logo-overlay {
    display: none !important;
  }
  body {
    background: white;
    overflow: visible;
  }
  .canvas-viewport {
    position: static;
    overflow: visible;
  }
  .canvas-content {
    position: static;
    transform: none !important;
    padding: 20px 0;
  }
}
