/* --- RESET & BIẾN CƠ BẢN --- */
:root {
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --bg-secondary: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border-color: #e2e8f0;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;

  --accent-amber: #f59e0b;
  --accent-amber-light: #fffbeb;
  --accent-amber-border: #fcd34d;

  --accent-purple: #7c3aed;
  --accent-purple-light: #f5f3ff;

  --accent-green: #10b981;
  --accent-green-light: #ecfdf5;

  --danger: #ef4444;
  --danger-light: #fef2f2;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 10px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- HEADER --- */
.app-header {
  background-color: #0f172a;
  color: #ffffff;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 28px;
  background: rgba(255, 255, 255, 0.1);
  padding: 6px;
  border-radius: 8px;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.app-subtitle {
  font-size: 0.8rem;
  color: #94a3b8;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.model-selector-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-label {
  font-size: 0.825rem;
  color: #cbd5e1;
}

.model-box {
  display: flex;
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  overflow: hidden;
}

.model-box input {
  background: transparent;
  border: none;
  color: #f8fafc;
  padding: 6px 10px;
  font-size: 0.825rem;
  width: 140px;
  outline: none;
}

.model-box select {
  background: #334155;
  border: none;
  color: #f8fafc;
  padding: 6px 10px;
  font-size: 0.825rem;
  outline: none;
  cursor: pointer;
  max-width: 180px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1e293b;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  border: 1px solid #334155;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.status-dot.online { background-color: #10b981; box-shadow: 0 0 6px #10b981; }
.status-dot.busy { background-color: #f59e0b; box-shadow: 0 0 6px #f59e0b; }
.status-dot.offline { background-color: #ef4444; }

.queue-badge {
  background: #3b82f6;
  color: white;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.75rem;
}

/* --- KHU VỰC NHẬP LỆNH --- */
.command-section {
  padding: 16px 24px;
}

.command-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.command-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
}

.command-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: #1e293b;
}

.quick-examples {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.example-pill {
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}
.example-pill:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: #bfdbfe;
}

.input-row {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.input-row textarea {
  flex: 1;
  border: 1.5px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.925rem;
  font-family: inherit;
  resize: vertical;
  min-height: 48px;
  outline: none;
  transition: border-color 0.2s;
}
.input-row textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.cmd-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 12px;
  background: var(--accent-amber-light);
  border-radius: 6px;
  font-size: 0.85rem;
  color: #92400e;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #fcd34d;
  border-top-color: #b45309;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- BỐ CỤC CHÍNH (SPLIT VIEW) --- */
.main-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  padding: 0 24px 24px 24px;
  overflow: hidden;
}

/* --- CỘT TRÁI: LỊCH THÁNG --- */
.calendar-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  height: fit-content;
}

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

.calendar-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.nav-btn:hover {
  background: #e2e8f0;
}

.calendar-month-text {
  font-weight: 700;
  font-size: 0.975rem;
  min-width: 130px;
  text-align: center;
}

.btn-today {
  background: transparent;
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text-muted);
}
.btn-today:hover {
  background: var(--bg-secondary);
  color: var(--text-main);
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.calendar-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
  user-select: none;
  border: 1px solid transparent;
}
.calendar-cell:hover:not(.empty) {
  background: var(--bg-secondary);
}
.calendar-cell.empty {
  cursor: default;
}
.calendar-cell.has-events {
  background: #eff6ff;
  font-weight: 700;
  color: var(--primary);
  border-color: #bfdbfe;
}
.calendar-cell.has-events::after {
  content: '';
  position: absolute;
  bottom: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--primary);
}
.calendar-cell.today {
  border: 1.5px solid var(--accent-amber);
  background: var(--accent-amber-light);
  color: #b45309;
  font-weight: 700;
}
.calendar-cell.selected {
  background: var(--primary) !important;
  color: #ffffff !important;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}
.calendar-cell.selected::after {
  background: #ffffff;
}

.calendar-legend {
  display: flex;
  justify-content: space-around;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
  font-size: 0.75rem;
  color: var(--text-muted);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.dot-today { background: var(--accent-amber); }
.dot-event { background: var(--primary); }
.dot-selected { background: var(--primary); outline: 2px solid #93c5fd; }

.calendar-actions {
  margin-top: 14px;
}

/* --- CỘT PHẢI: DANH SÁCH GHI CHÚ --- */
.notes-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: calc(100vh - 180px);
}

.notes-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.search-wrap {
  flex: 1;
}
.search-wrap input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.875rem;
  outline: none;
}
.search-wrap input:focus {
  border-color: var(--primary);
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.filter-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.tab-btn {
  background: transparent;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.825rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}
.tab-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-main);
}
.tab-btn.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
}

.filter-status-banner {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.btn-clear-filter {
  background: transparent;
  border: none;
  color: #dc2626;
  font-size: 0.8rem;
  cursor: pointer;
  font-weight: 600;
}

/* Danh sách cuộn */
.notes-list {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* THẺ GHI CHÚ (NOTE CARD) */
.note-card {
  border: 1.5px solid var(--border-color);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
  transition: all 0.2s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.note-card:hover {
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

/* ĐỔI MÀU SỰ KIỆN GẦN ĐẾN / SẮP TỚI */
.note-card.upcoming-event {
  border: 2px solid var(--accent-amber) !important;
  background: linear-gradient(to right, #fffdfa, #ffffff);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.15);
}
.note-card.upcoming-event .upcoming-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-amber);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
}

/* Trạng thái đã xong */
.note-card.status-done {
  opacity: 0.65;
  background: #f8fafc;
}
.note-card.status-done .note-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.note-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.note-title {
  font-size: 0.975rem;
  font-weight: 700;
  color: var(--text-main);
}

.card-actions {
  display: flex;
  gap: 6px;
}

.action-icon-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: all 0.15s;
}
.action-icon-btn:hover {
  background: #e2e8f0;
  color: var(--text-main);
}
.action-icon-btn.delete-btn:hover {
  background: var(--danger-light);
  color: var(--danger);
  border-color: #fca5a5;
}

.note-content {
  font-size: 0.875rem;
  color: #334155;
  white-space: pre-wrap;
  word-break: break-word;
}

/* BADGES THÔNG TIN */
.card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.725rem;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 500;
}

.badge-time {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.badge-condition-work {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid #bfdbfe;
}

.badge-condition-off {
  background: var(--accent-purple-light);
  color: var(--accent-purple);
  border: 1px solid #ddd6fe;
}

.badge-condition-all {
  background: var(--accent-green-light);
  color: var(--accent-green);
  border: 1px solid #a7f3d0;
}

.badge-repeat {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.badge-compressed {
  background: #e0e7ff;
  color: #4338ca;
  border: 1px solid #c7d2fe;
}

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
  font-size: 0.9rem;
}

/* --- BUTTONS CHUNG --- */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover {
  background: #e2e8f0;
}

.full-width {
  width: 100%;
}

/* --- MODALS --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-dialog {
  background: #ffffff;
  border-radius: var(--radius);
  width: 100%;
  max-width: 580px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow: hidden;
}

.modal-dialog.modal-lg {
  max-width: 820px;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  color: var(--text-light);
  cursor: pointer;
}
.modal-close:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
}

/* DRAFT REVIEW ITEMS */
.draft-items-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.draft-card {
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.draft-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.draft-index-badge {
  background: #3b82f6;
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
}

.btn-delete-draft {
  background: transparent;
  border: none;
  color: var(--danger);
  font-size: 0.8rem;
  cursor: pointer;
}

.draft-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.draft-field-full {
  grid-column: span 2;
}

.draft-card label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  display: block;
  margin-bottom: 2px;
}

.draft-card input, .draft-card select, .draft-card textarea {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
  background: #ffffff;
}

.add-draft-btn {
  width: 100%;
  border-style: dashed;
}

/* FORM GRID */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

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

.form-group.full-col {
  grid-column: span 2;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #334155;
}

.form-group input, .form-group select, .form-group textarea {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.875rem;
  font-family: inherit;
}

.required {
  color: var(--danger);
}

.days-checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  background: var(--bg-secondary);
  padding: 8px 12px;
  border-radius: 6px;
}
.days-checkbox-group label {
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* NÉN TRÙNG TIÊU ĐỀ */
.duplicate-group-card {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-secondary);
}
.duplicate-group-info h4 {
  font-size: 0.9rem;
  font-weight: 700;
}
.duplicate-group-info span {
  font-size: 0.775rem;
  color: var(--text-muted);
}

/* TIỆN ÍCH */
.hidden {
  display: none !important;
}

/* RESPONSIVE */
@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
  .notes-panel {
    height: auto;
    min-height: 500px;
  }
}
