/* ============================================================
   BUTTONS
============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 22px;
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.18s ease;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--bg); }
body.theme-dark .btn-primary { color: #0b0b0b; }
.btn-primary:not(:disabled):hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-ghost {
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border);
}
.btn-ghost:not(:disabled):hover {
  background: var(--bg2);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-danger { background: var(--status-failed); color: #fff; }
.btn-danger:not(:disabled):hover { filter: brightness(1.08); transform: translateY(-1px); }

.btn-sm { padding: 7px 14px; font-size: 0.82rem; }
.btn-full { width: 100%; }

/* ============================================================
   CARDS
============================================================ */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  overflow: hidden;
}

.form-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.form-card-header-left { display: flex; align-items: center; gap: 12px; }
.form-card-icon { font-size: 1.2rem; }
.form-card-title { font-weight: 700; font-size: 1rem; color: var(--text); }
.form-card-subtitle { font-size: 0.8rem; color: var(--text3); margin-top: 2px; }
.form-card-body { padding: 24px; }

.meta-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}
.meta-card h3 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.1rem;
  color: var(--text);
  margin-bottom: 20px;
}
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.content-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
}
.content-card h3 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.3rem;
  color: var(--text);
  margin-bottom: 24px;
}

/* ============================================================
   TASK ENTRY (report sections)
============================================================ */
.task-entry {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 14px;
  transition: all 0.2s;
}
.task-entry:hover { border-color: var(--border-strong); }
.task-entry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.task-num {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text3);
  background: var(--bg2);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.btn-remove-task {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text3);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  transition: all 0.15s;
}
.btn-remove-task:hover {
  border-color: #e53e3e;
  color: #e53e3e;
  background: rgba(229,62,62,0.05);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.add-task-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1.5px dashed var(--border-strong);
  color: var(--text2);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  transition: all 0.18s;
  width: 100%;
  justify-content: center;
  margin-top: 4px;
}
.add-task-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--bg2); }

/* ---- AI "Polish" button (per textarea) ---- */
.rf-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.ai-polish-btn {
  /* Hidden until the server confirms an AI key is configured. */
  display: none;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 3px 11px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  transition: all 0.15s;
  white-space: nowrap;
}
.ai-enabled .ai-polish-btn { display: inline-flex; }
.ai-polish-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg2);
}
.ai-polish-btn:disabled { opacity: 0.7; cursor: default; }
.ai-polish-btn.is-undo { border-color: var(--accent); color: var(--accent); }
.spinner-sm { width: 12px; height: 12px; border-width: 2px; }

/* ============================================================
   REPORT TYPE SELECTOR
============================================================ */
.report-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.report-type-card { position: relative; cursor: pointer; }
.report-type-card input[type="checkbox"] { position: absolute; opacity: 0; width: 0; height: 0; }
.report-type-label {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.18s ease;
  user-select: none;
  height: 100%;
}
.report-type-label:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.report-type-card input:checked + .report-type-label {
  border-color: var(--check-active);
  background: var(--bg2);
  box-shadow: var(--shadow-sm);
}
.report-type-icon { font-size: 1.5rem; line-height: 1; }
.report-type-name { font-size: 0.88rem; font-weight: 700; color: var(--text); }
.report-type-desc { font-size: 0.78rem; color: var(--text3); line-height: 1.4; }
.check-indicator {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1.5px solid var(--border-strong);
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  flex-shrink: 0;
  transition: all 0.15s;
}
.report-type-card input:checked + .report-type-label .check-indicator {
  background: var(--check-active);
  border-color: var(--check-active);
}
.check-indicator::after {
  content: '';
  width: 10px;
  height: 6px;
  border-left: 2px solid white;
  border-bottom: 2px solid white;
  transform: rotate(-45deg) translateY(-1px);
  opacity: 0;
  transition: opacity 0.15s;
}
body.theme-dark .check-indicator::after { border-color: #0b0b0b; }
.report-type-card input:checked + .report-type-label .check-indicator::after { opacity: 1; }

/* ============================================================
   TOGGLE SWITCH
============================================================ */
.toggle-switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border-strong);
  border-radius: 24px;
  transition: 0.25s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  left: 4px;
  top: 4px;
  transition: 0.25s;
  box-shadow: var(--shadow-sm);
}
input:checked + .toggle-slider { background: var(--check-active); }
input:checked + .toggle-slider::before { transform: translateX(20px); }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
}
.setting-label { font-weight: 600; font-size: 0.9rem; color: var(--text); }
.setting-desc { font-size: 0.8rem; color: var(--text3); margin-top: 2px; }

/* ============================================================
   MODALS
============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 24px;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 36px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.modal-box.modal-wide { max-width: 720px; text-align: left; }
.modal-icon { font-size: 3rem; margin-bottom: 16px; }
.modal-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.5rem;
  color: var(--text);
  margin-bottom: 8px;
}
.modal-sub {
  font-size: 0.88rem;
  color: var(--text3);
  line-height: 1.6;
  margin-bottom: 28px;
}
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.modal-box.modal-wide .modal-actions { justify-content: flex-end; }
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h3 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.4rem;
  color: var(--text);
}
.modal-close-x {
  background: transparent;
  border: none;
  color: var(--text3);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
.modal-close-x:hover { color: var(--text); }
.modal-body-scroll { max-height: 70vh; overflow-y: auto; }

/* ============================================================
   AVATAR
============================================================ */
.avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  overflow: hidden;
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
body.theme-dark .avatar { color: #0b0b0b; }
.avatar-sm { width: 34px; height: 34px; font-size: 0.85rem; }
.avatar-lg { width: 120px; height: 120px; font-size: 2.4rem; }

/* ============================================================
   BADGES
============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border: 1px solid transparent;
}
.badge-admin { background: rgba(124,58,237,0.12); color: var(--badge-admin); border-color: rgba(124,58,237,0.25); }
.badge-user  { background: rgba(37,99,235,0.12);  color: var(--badge-user);  border-color: rgba(37,99,235,0.25); }
.badge-submitted { background: rgba(22,163,74,0.12);  color: var(--status-submitted); border-color: rgba(22,163,74,0.25); }
.badge-draft     { background: rgba(202,138,4,0.12);  color: var(--status-draft);     border-color: rgba(202,138,4,0.25); }
.badge-failed    { background: rgba(220,38,38,0.12);  color: var(--status-failed);    border-color: rgba(220,38,38,0.25); }
.badge-active    { background: rgba(22,163,74,0.12);  color: var(--status-submitted); border-color: rgba(22,163,74,0.25); }
.badge-inactive  { background: var(--bg2);            color: var(--text3);            border-color: var(--border); }
.badge-neutral   { background: var(--bg2);            color: var(--text2);            border-color: var(--border); }

/* ============================================================
   METRIC CARD
============================================================ */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.metric-card {
  background: var(--card-metric-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}
.metric-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
  background: var(--bg2);
}
.metric-body { display: flex; flex-direction: column; }
.metric-value {
  font-family: 'DM Serif Display', serif;
  font-size: 2rem;
  line-height: 1.1;
  color: var(--text);
}
.metric-label { font-size: 0.82rem; color: var(--text3); margin-top: 4px; }

/* ============================================================
   DATA TABLE
============================================================ */
.data-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  overflow-x: auto;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface2);
  text-align: left;
  padding: 13px 16px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: default;
}
.data-table thead th.sortable { cursor: pointer; user-select: none; }
.data-table thead th.sortable:hover { color: var(--text); }
.data-table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text2);
  vertical-align: middle;
}
.data-table tbody tr:nth-child(even) { background: var(--surface2); }
.data-table tbody tr:hover { background: var(--bg2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.table-actions { display: flex; gap: 6px; }
.table-empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--text3);
}
.table-empty .empty-icon { font-size: 2.5rem; margin-bottom: 10px; opacity: 0.5; }

/* ============================================================
   MULTI-SELECT DROPDOWN
============================================================ */
.multiselect { position: relative; }
.ms-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.ms-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--tag-bg);
  color: var(--tag-text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  font-size: 0.82rem;
}
.ms-chip button {
  background: transparent;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0 2px;
}
.ms-chip button:hover { color: var(--status-failed); }
.ms-trigger {
  width: 100%;
  text-align: left;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  color: var(--text2);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ms-trigger:hover { border-color: var(--border-strong); }
.ms-trigger .ms-caret { transition: transform 0.2s; color: var(--text3); }
.multiselect.open .ms-trigger .ms-caret { transform: rotate(180deg); }
.ms-panel {
  position: absolute;
  z-index: 200;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 10px;
  max-height: 320px;
  overflow-y: auto;
}
.ms-search { margin-bottom: 8px; }
.ms-group-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text3);
  padding: 8px 8px 4px;
}
.ms-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.ms-option:hover { background: var(--bg2); }
.ms-option input { width: auto; }
.ms-option .ms-opt-main { font-size: 0.88rem; color: var(--text); }
.ms-option .ms-opt-sub { font-size: 0.76rem; color: var(--text3); }
.ms-empty { padding: 16px 8px; color: var(--text3); font-size: 0.85rem; text-align: center; }

/* ============================================================
   TOAST SYSTEM
============================================================ */
#toastHost {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 14px 18px;
  font-size: 0.88rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideDown 0.22s ease;
}
.toast.toast-success { border-left-color: var(--status-submitted); }
.toast.toast-error   { border-left-color: var(--status-failed); }
.toast.toast-info    { border-left-color: var(--badge-user); }
.toast .toast-icon { font-size: 1.1rem; }

/* ============================================================
   BAR CHART (SVG)
============================================================ */
.chart-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
}
.chart-panel h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 18px;
}
.bar-row { margin-bottom: 14px; }
.bar-row:last-child { margin-bottom: 0; }
.bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text2);
  margin-bottom: 5px;
}
.bar-label .bar-count { font-weight: 700; color: var(--text); }
.bar-track {
  height: 10px;
  background: var(--chart-bar-empty);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--chart-bar);
  border-radius: 999px;
  width: 0;
  transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
.bar-row.empty .bar-label { color: var(--text3); }

/* ============================================================
   ACTIVITY FEED
============================================================ */
.activity-feed { display: flex; flex-direction: column; }
.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 7px;
  flex-shrink: 0;
}
.activity-text { font-size: 0.85rem; color: var(--text2); line-height: 1.5; }
.activity-text strong { color: var(--text); }
.activity-time { font-size: 0.76rem; color: var(--text3); margin-top: 2px; }

/* ============================================================
   TABS
============================================================ */
.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  overflow-x: auto;
}
.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text3);
  padding: 12px 18px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text2); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }

/* ============================================================
   NOTE CARDS
============================================================ */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  min-height: 140px;
}
.note-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.note-card h4 { font-size: 0.95rem; color: var(--text); margin-bottom: 8px; }
.note-card .note-preview {
  font-size: 0.83rem;
  color: var(--text2);
  line-height: 1.5;
  flex: 1;
  white-space: pre-wrap;
  overflow: hidden;
}
.note-card .note-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.note-card .note-date { font-size: 0.74rem; color: var(--text3); }
.note-card-actions { display: flex; gap: 6px; }
.note-editor textarea { min-height: 240px; resize: vertical; }

/* ============================================================
   FILTER BAR
============================================================ */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 20px;
}
.filter-bar label { margin-bottom: 4px; }

/* ============================================================
   SUBMIT BAR
============================================================ */
.submit-bar {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 24px;
}

/* ============================================================
   DRAFT BANNER
============================================================ */
.draft-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(202,138,4,0.10);
  border: 1px solid rgba(202,138,4,0.3);
  color: var(--text);
  border-radius: var(--radius);
  padding: 12px 18px;
  margin-bottom: 18px;
  font-size: 0.88rem;
}
.draft-banner .draft-actions { display: flex; gap: 8px; flex-shrink: 0; }
