@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700;900&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --sidebar-w: 300px;
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.4);
  --accent-primary: #4f46e5;
  --accent-primary-gradient: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  --accent-secondary: #f43f5e;
  --accent-success: #10b981;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --bg-app: #f1f5f9;
  --transition-smooth: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-premium: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
  --bg-login: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Roboto', sans-serif;
  background: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
}

#app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar Responsive */
.sidebar {
  width: var(--sidebar-w);
  background: var(--glass-bg);
  backdrop-filter: blur(15px);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 1000;
  transition: var(--transition-smooth);
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.sidebar-title {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--accent-primary);
  letter-spacing: -0.5px;
  text-transform: uppercase;
}

.project-list {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
}

.project-item {
  padding: 12px 16px;
  border-radius: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: var(--transition-smooth);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid transparent;
}

.project-item:hover {
  background: white;
  color: var(--accent-primary);
  border-color: var(--glass-border);
  transform: translateX(4px);
}

.project-item.active {
  background: white;
  color: var(--accent-primary);
  box-shadow: var(--shadow-premium);
  border-color: var(--accent-primary);
}

.project-item.active i {
  color: var(--accent-primary);
}

.project-item i {
  transition: var(--transition-smooth);
  font-size: 1.1rem;
}

.spin {
  animation: spin 1s linear infinite;
  display: inline-block;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.sidebar-footer {
  padding: 20px;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 32px;
  transition: var(--transition-smooth);
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

.mobile-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-main);
  cursor: pointer;
}

/* Cards */
.premium-card {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-premium);
  margin-bottom: 24px;
  height: 100%;
  transition: var(--transition-smooth);
}

.premium-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -10px rgba(0, 0, 0, 0.1);
}

.card-header-premium {
  padding: 18px 24px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.03);
  font-weight: 800;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.card-body-premium {
  padding: 24px;
}

/* Input Group Fix */
.input-group>.premium-input {
  flex: 1 1 auto;
  width: 1%;
  /* Allow flex-grow to take over */
}

/* Inputs */
.premium-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  background: #fff;
  font-size: 0.9rem;
  transition: var(--transition-smooth);
}

.premium-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Output Area */
.template-output-premium {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 24px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  line-height: 1.7;
  white-space: pre-wrap;
  min-height: 500px;
  color: #334155;
  cursor: text;
  box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.03);
  overflow-wrap: break-word;
  word-wrap: break-word;
  word-break: break-word;
}

/* Status */
.sync-status {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.sync-status.ok {
  color: var(--accent-success);
}

.sync-status.pending {
  color: var(--accent-secondary);
  animation: blink 1s infinite;
}

@keyframes blink {
  50% {
    opacity: 0.5;
  }
}

/* Responsive Media Queries */
@media (max-width: 992px) {
  .sidebar {
    left: calc(-1 * var(--sidebar-w));
  }

  .sidebar.show {
    left: 0;
    box-shadow: 20px 0 50px rgba(0, 0, 0, 0.1);
  }

  .main-content {
    margin-left: 0;
    padding: 16px;
  }

  .mobile-toggle {
    display: block !important;
  }

  .mobile-header {
    display: flex !important;
    position: sticky;
    top: 0;
    z-index: 900;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0,0,0,0.06);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    z-index: 999;
  }

  .sidebar-overlay.show {
    display: block;
  }
}

/* Form layouts on mobile */
@media (max-width: 480px) {
  .top-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}

.btn-premium-solid {
  background: var(--accent-primary-gradient);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 100px;
  font-weight: 700;
  font-size: 0.85rem;
  transition: var(--transition-smooth);
}

.btn-premium-solid:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-icon-premium {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 8px;
  transition: var(--transition-smooth);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.btn-icon-premium:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--accent-primary);
}

/* Tree View */
.tree-container {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
}

.folder-item {
  margin-bottom: 4px;
}

.folder-header {
  padding: 7px 10px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text-main);
  transition: var(--transition-smooth);
  min-width: 0;          /* Quan trọng: cho phép con thu hẹp */
}

.folder-header:hover {
  background: rgba(0, 0, 0, 0.04);
}

.folder-header i.bi-chevron-right {
  font-size: 0.65rem;
  flex-shrink: 0;
  transition: transform 0.25s;
}

/* Drag & Drop */
.drag-handle {
  cursor: grab;
  padding: 0 4px;
  color: #cbd5e1;
  flex-shrink: 0;
  transition: color 0.2s;
  display: flex;
  align-items: center;
}

.drag-handle:hover {
  color: var(--accent-primary);
}

.sortable-ghost {
  opacity: 0.4;
  background: #e2e8f0 !important;
}

.sortable-chosen {
  background: white;
  box-shadow: var(--shadow-premium);
  z-index: 10;
}

.folder-header.open i.bi-chevron-right {
  transform: rotate(90deg);
}

.folder-content {
  padding-left: 8px;
  margin-left: 20px;
  border-left: 1px dashed rgba(0, 0, 0, 0.1);
}

.folder-actions {
  display: flex;
  align-items: center;
  opacity: 0;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.folder-header:hover .folder-actions {
  opacity: 1;
}

/* Folder Actions Dropdown */
.folder-dropdown {
  position: relative;
  display: inline-block;
}

.folder-dropdown-trigger {
  padding: 4px 8px;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s;
}

.folder-dropdown-trigger:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--accent-primary);
}

.folder-dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 10px; /* Xuất hiện ngang tầm icon */
  background: white;
  min-width: 190px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: 12px;
  padding: 8px;
  z-index: 2000;
  flex-direction: column;
  gap: 2px;
}

.folder-dropdown:hover .folder-dropdown-menu {
  display: flex;
}

.folder-dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
}

.folder-dropdown-item:hover {
  background: #f1f5f9;
  color: var(--accent-primary);
  transform: translateX(3px);
}

.folder-dropdown-item i {
  font-size: 1.05rem;
  width: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Tên folder/item: co được, hiển đủ text không bị cắt */
.folder-header > span,
.folder-header > .folder-name {
  flex: 1;
  min-width: 0;            /* Cho phép co lại */
  white-space: normal;     /* Cho xuống dòng thay vì cắt */
  word-break: break-word;
  line-height: 1.3;
}

/* project-item (cấp dưới folder) */
.project-item {
  padding: 8px 12px;
  border-radius: 10px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: var(--transition-smooth);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  align-items: flex-start; /* Align top khi text xuống dòng */
  gap: 10px;
  border: 1px solid transparent;
  min-width: 0;
}

.project-item > span,
.project-item > .item-name {
  flex: 1;
  min-width: 0;
  white-space: normal;
  word-break: break-word;
  line-height: 1.35;
}

.project-item i {
  flex-shrink: 0;
  margin-top: 2px; /* Align icon khi text nhiều dòng */
  transition: var(--transition-smooth);
  font-size: 1rem;
}

/* Swal Tag Management Styles */
.swal-tag-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.swal-tag-label {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  color: #64748b;
  margin-bottom: 4px;
}

.swal-tag-badge {
  display: inline-block;
  padding: 2px 8px;
  background: #e2e8f0;
  color: #475569;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  margin: 2px;
  cursor: default;
}

/* Login Overlay */
.auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-login);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

.login-card {
  background: white;
  padding: 40px;
  border-radius: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.login-logo {
  font-size: 2rem;
  font-weight: 900;
  color: var(--accent-primary);
  margin-bottom: 30px;
}

.tag-premium {
  display: inline-block;
  padding: 4px 10px;
  background: #eff6ff;
  color: #4f46e5;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 700;
  margin: 2px;
  cursor: pointer;
  transition: var(--transition-smooth);
  border: 1px solid rgba(79, 70, 229, 0.05);
}

.tag-premium:hover {
  background: #e0e7ff;
  transform: translateY(-1px);
}

.tags-container {
  max-height: 250px;
  overflow-y: auto;
  padding-right: 5px;
}

.tags-container::-webkit-scrollbar {
  width: 4px;
}

.tags-container::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 10px;
}

.tag-section-title {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 15px 0 8px 0;
  padding-bottom: 5px;
  border-bottom: 1px dashed rgba(0, 0, 0, 0.05);
}

.tag-section-title:first-child {
  margin-top: 0;
}

/* Inline Tag Badge in Labels */
.premium-label span {
  font-family: 'JetBrains Mono', monospace;
  background: #f1f5f9;
  color: var(--accent-primary);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition-smooth);
  border: 1px solid rgba(0, 0, 0, 0.03);
}

.premium-label span:hover {
  background: var(--accent-primary);
  color: white;
  transform: translateY(-1px);
}