/* ===========================================
   Components — Buttons, Cards, Inputs, Modals
   =========================================== */

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2); padding: 7px var(--space-4);
  font-family: var(--font-family); font-size: var(--text-sm);
  font-weight: var(--weight-semibold); line-height: 1.4;
  border: 1px solid transparent; border-radius: var(--radius-md);
  cursor: pointer; transition: all var(--transition-fast);
  white-space: nowrap; user-select: none; text-decoration: none; letter-spacing: 0.01em;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--color-primary-600);
  color: #fff;
  border-color: var(--color-primary-700);
}
.btn-primary:hover { background: var(--color-primary-700); }
[data-theme="light"] .btn-primary { background: var(--color-primary-600); border-color: var(--color-primary-700); }

.btn-secondary {
  background: var(--bg-surface-raised); color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--bg-surface-hover); border-color: var(--border-strong); }

.btn-danger {
  background: rgba(239,68,68,0.1); color: var(--color-danger-400);
  border-color: rgba(239,68,68,0.2);
}
.btn-danger:hover { background: var(--color-danger-600); color: #fff; border-color: var(--color-danger-600); }
[data-theme="light"] .btn-danger { background: var(--color-danger-50); color: var(--color-danger-600); border-color: rgba(220,38,38,0.2); }
[data-theme="light"] .btn-danger:hover { background: var(--color-danger-600); color: #fff; }

.btn-ghost {
  background: transparent; color: var(--text-secondary); border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-surface-hover); color: var(--text-primary); }

.btn-success {
  background: rgba(16,185,129,0.1); color: var(--color-success-500);
  border-color: rgba(16,185,129,0.2);
}
.btn-success:hover { background: var(--color-success-600); color: #fff; border-color: var(--color-success-600); }
[data-theme="light"] .btn-success { background: var(--color-success-50); color: var(--color-success-700); }
[data-theme="light"] .btn-success:hover { background: var(--color-success-600); color: #fff; }

.btn-sm { padding: 4px var(--space-3); font-size: var(--text-xs); }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-base); border-radius: var(--radius-lg); }
.btn-icon { padding: 6px; width: 32px; height: 32px; border-radius: var(--radius-md); }
.btn-block { width: 100%; }

/* ── Cards ── */
.card {
  background: var(--bg-surface-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: all var(--transition-fast);
  position: relative; overflow: hidden;
}
.card-clickable { cursor: pointer; }
.card-clickable:hover {
  border-color: var(--border-strong);
  background: var(--bg-surface-raised);
}
.card-icon {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
  border-radius: var(--radius-md);
  background: rgba(59,130,246,0.08);
  color: var(--color-primary-400);
  margin-bottom: var(--space-3);
  border: 1px solid rgba(59,130,246,0.12);
}
[data-theme="light"] .card-icon {
  background: var(--color-primary-50); color: var(--color-primary-600);
  border-color: rgba(37,99,235,0.12);
}
.card-title { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text-primary); margin-bottom: var(--space-1); }
.card-desc { font-size: var(--text-xs); color: var(--text-tertiary); }

/* ── Form Tiles (home page) ── */
.form-tile {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-4); border-radius: var(--radius-lg);
  background: var(--bg-surface-solid); border: 1px solid var(--border-default);
  cursor: pointer; transition: all var(--transition-fast);
  position: relative; overflow: hidden;
}
.form-tile::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--color-primary-500); opacity: 0;
  transition: opacity var(--transition-fast);
}
.form-tile:hover { border-color: var(--border-strong); background: var(--bg-surface-raised); }
.form-tile:hover::before { opacity: 1; }
.form-tile-icon {
  width: 36px; height: 36px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; border-radius: var(--radius-md);
  background: rgba(59,130,246,0.08); color: var(--color-primary-400);
  border: 1px solid rgba(59,130,246,0.1);
}
[data-theme="light"] .form-tile-icon { background: var(--color-primary-50); color: var(--color-primary-600); }
.form-tile-content { flex: 1; min-width: 0; }
.form-tile-title { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text-primary); margin-bottom: 3px; }
.form-tile-meta { font-size: var(--text-xs); color: var(--text-tertiary); }

/* ── Stat Cards ── */
.stat-card {
  background: var(--bg-surface-solid); border: 1px solid var(--border-default);
  border-radius: var(--radius-lg); padding: var(--space-5);
}
.stat-card-value {
  font-size: var(--text-2xl); font-weight: var(--weight-bold);
  color: var(--text-primary); letter-spacing: -0.04em; line-height: 1;
  margin-bottom: var(--space-1);
}
.stat-card-label { font-size: var(--text-xs); color: var(--text-tertiary); font-weight: var(--weight-medium); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card-icon {
  width: 32px; height: 32px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center; font-size: 0.9rem;
  margin-bottom: var(--space-3);
}
.stat-card-icon.blue { background: rgba(59,130,246,0.1); color: var(--color-primary-400); }
.stat-card-icon.green { background: rgba(16,185,129,0.1); color: var(--color-success-400); }
.stat-card-icon.amber { background: rgba(245,158,11,0.1); color: var(--color-warning-500); }
[data-theme="light"] .stat-card-icon.blue  { background: var(--color-primary-50);  color: var(--color-primary-600);  }
[data-theme="light"] .stat-card-icon.green { background: var(--color-success-50);  color: var(--color-success-600);  }
[data-theme="light"] .stat-card-icon.amber { background: var(--color-warning-50);  color: var(--color-warning-600);  }

/* ── Doc Table ── */
.doc-table-wrap { background: var(--bg-surface-solid); border: 1px solid var(--border-default); border-radius: var(--radius-lg); overflow: hidden; }
.doc-table {
  width: 100%; border-collapse: collapse;
}
.doc-table th {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.05em;
  text-align: left; border-bottom: 1px solid var(--border-default);
  background: var(--bg-surface-sunken);
  white-space: nowrap;
}
.doc-table td {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm); color: var(--text-primary);
  border-bottom: 1px solid var(--border-default);
  vertical-align: middle;
}
.doc-table tr:last-child td { border-bottom: none; }
.doc-table tr:hover td { background: var(--bg-surface-hover); }
.doc-table tr { cursor: pointer; transition: background var(--transition-fast); }
.doc-table .doc-icon { font-size: 1.1rem; }
.doc-table .doc-meta { font-size: var(--text-xs); color: var(--text-tertiary); margin-top: 1px; }
.doc-table .doc-date { font-size: var(--text-xs); color: var(--text-tertiary); white-space: nowrap; }
.doc-table .doc-delete-btn {
  opacity: 0; background: transparent; border: none; cursor: pointer;
  color: var(--color-danger-400); font-size: var(--text-sm);
  padding: 4px 6px; border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}
.doc-table tr:hover .doc-delete-btn { opacity: 1; }
.doc-table .doc-delete-btn:hover { background: rgba(239,68,68,0.1); }

/* ── Form Inputs ── */
.input, .select, .textarea {
  width: 100%; padding: 8px var(--space-3);
  font-family: var(--font-family); font-size: var(--text-sm);
  color: var(--input-text); background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
[data-theme="light"] .input:focus, [data-theme="light"] .select:focus, [data-theme="light"] .textarea:focus {
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.input::placeholder, .textarea::placeholder { color: var(--input-placeholder); }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%234A5568' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px;
  cursor: pointer;
}
.textarea { resize: vertical; min-height: 90px; }
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: var(--space-3); }
.form-label {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  color: var(--text-secondary); letter-spacing: 0.02em;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }

/* Fieldsets */
.fieldset {
  border: 1px solid var(--border-default); border-radius: var(--radius-lg);
  padding: var(--space-4); background: var(--bg-surface-solid); margin-bottom: var(--space-3);
}
.fieldset-legend {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  color: var(--color-primary-400); padding: 0 var(--space-2);
  text-transform: uppercase; letter-spacing: 0.05em;
}
[data-theme="light"] .fieldset-legend { color: var(--color-primary-600); }

/* ── Modals ── */
.modal-overlay {
  position: fixed; inset: 0; background: var(--bg-overlay);
  z-index: var(--z-modal-backdrop); display: flex; align-items: center; justify-content: center;
  padding: var(--space-4); animation: fadeIn 200ms ease both;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.modal-overlay.closing { animation: fadeOut 180ms ease forwards; }
.modal {
  background: var(--bg-surface-solid); border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-xl);
  width: 100%; max-width: 560px; max-height: 88vh;
  display: flex; flex-direction: column; z-index: var(--z-modal);
  animation: modalIn 250ms cubic-bezier(0.34, 1.4, 0.64, 1) both; overflow: hidden;
}
.modal-overlay.closing .modal { animation: modalOut 180ms ease forwards; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border-default);
}
.modal-header h3 { font-size: var(--text-base); font-weight: var(--weight-bold); color: var(--text-primary); }
.modal-body { flex: 1; overflow-y: auto; padding: var(--space-5); }
.modal-footer {
  display: flex; justify-content: flex-end; gap: var(--space-2);
  padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border-default);
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.94) translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes modalOut { from { opacity: 1; } to { opacity: 0; transform: scale(0.96); } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ── Drawer ── */
.drawer-overlay {
  position: fixed; inset: 0; background: var(--bg-overlay);
  z-index: var(--z-modal-backdrop); display: flex; justify-content: flex-end;
  animation: fadeIn 200ms ease both; backdrop-filter: blur(6px);
}
.drawer-overlay.closing { animation: fadeOut 250ms ease forwards; }
.drawer {
  background: var(--bg-surface-solid); width: 100%; max-width: 480px; height: 100%;
  box-shadow: -8px 0 40px rgba(0,0,0,0.4); display: flex; flex-direction: column;
  z-index: var(--z-modal); animation: drawerIn 300ms cubic-bezier(0.34,1.2,0.64,1) both;
  border-left: 1px solid var(--border-default);
}
.drawer-overlay.closing .drawer { animation: drawerOut 250ms ease forwards; }
.drawer-header { padding: var(--space-5); border-bottom: 1px solid var(--border-default); display: flex; align-items: center; justify-content: space-between; }
.drawer-header h3 { font-size: var(--text-lg); font-weight: var(--weight-bold); color: var(--text-primary); }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--space-6) var(--space-5); }
.drawer-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border-default); display: flex; justify-content: flex-end; gap: var(--space-2); }
@keyframes drawerIn { from { transform: translateX(100%); } to { transform: none; } }
@keyframes drawerOut { from { transform: none; } to { transform: translateX(100%); } }

/* ── Badge ── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px var(--space-2); font-size: var(--text-xs); font-weight: var(--weight-semibold);
  border-radius: var(--radius-sm); background: rgba(59,130,246,0.1);
  color: var(--color-primary-400); border: 1px solid rgba(59,130,246,0.15);
}
[data-theme="light"] .badge { background: var(--color-primary-50); color: var(--color-primary-700); border-color: rgba(37,99,235,0.15); }
.badge-rh { background: rgba(16,185,129,0.1); color: var(--color-success-400); border-color: rgba(16,185,129,0.15); }
[data-theme="light"] .badge-rh { background: var(--color-success-50); color: var(--color-success-700); }
.badge-hero { background: var(--bg-surface-solid); border: 1px solid var(--border-strong); color: var(--text-secondary); }

/* ── Tabs ── */
.tabs {
  display: flex; gap: 2px;
  background: var(--bg-surface-sunken); padding: 3px;
  border-radius: var(--radius-md); border: 1px solid var(--border-default);
}
.tab-btn {
  flex: 1; padding: 5px var(--space-4); font-family: var(--font-family);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  border: none; cursor: pointer; transition: all var(--transition-fast);
  background: transparent; color: var(--text-secondary); border-radius: var(--radius-sm);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { background: var(--bg-surface-solid); color: var(--color-primary-400); box-shadow: var(--shadow-sm); }
[data-theme="light"] .tab-btn.active { color: var(--color-primary-600); }

/* Tab count badge */
.tab-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 17px; height: 15px; padding: 0 4px;
  background: var(--bg-surface-sunken); color: var(--text-tertiary);
  border-radius: var(--radius-full); font-size: 0.6rem; font-weight: 700;
  margin-left: 4px; border: 1px solid var(--border-default);
  line-height: 1; vertical-align: middle;
}
.tab-btn.active .tab-count {
  background: rgba(59,130,246,0.12); color: var(--color-primary-400);
  border-color: rgba(59,130,246,0.18);
}

/* ── Dropdown ── */
.dropdown-wrapper { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--bg-surface-raised); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); z-index: var(--z-dropdown);
  max-height: 240px; overflow-y: auto;
  animation: slideDown 160ms ease both;
}
.dropdown-item {
  padding: var(--space-2) var(--space-4); font-size: var(--text-sm);
  font-weight: var(--weight-medium); cursor: pointer;
  transition: background var(--transition-fast);
  border-bottom: 1px solid var(--border-default);
  color: var(--text-primary);
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: var(--bg-surface-hover); }
.dropdown-item.selected { background: rgba(59,130,246,0.1); color: var(--color-primary-400); }
[data-theme="light"] .dropdown-item.selected { background: var(--color-primary-50); color: var(--color-primary-700); }
@keyframes slideDown { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ── Toast ── */
.toast {
  position: fixed; bottom: var(--space-6); right: var(--space-6);
  padding: var(--space-3) var(--space-5); background: var(--bg-surface-raised);
  border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl); font-size: var(--text-sm); font-weight: var(--weight-semibold);
  z-index: var(--z-toast); display: flex; align-items: center; gap: var(--space-3);
  animation: slideUp var(--transition-slow) ease-out both;
  color: var(--text-primary);
}
.toast-success { border-left: 3px solid var(--color-success-500); }
.toast-error   { border-left: 3px solid var(--color-danger-500); }
.toast-warning { border-left: 3px solid var(--color-warning-500); }

/* ── Separator ── */
.separator { border: none; border-top: 1px solid var(--border-default); margin: var(--space-4) 0; }

/* ── Empty State ── */
.empty-state {
  text-align: center; padding: var(--space-12) var(--space-6);
  color: var(--text-tertiary); background: var(--bg-surface-sunken);
  border-radius: var(--radius-lg); border: 1px dashed var(--border-strong);
}
.empty-state-icon { font-size: 2rem; margin-bottom: var(--space-3); opacity: 0.4; }
.empty-state-text { font-size: var(--text-sm); font-weight: var(--weight-medium); }

/* ── List Item ── */
.list-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  transition: background var(--transition-fast); cursor: pointer;
  border: 1px solid transparent; margin-bottom: 2px;
}
.list-item:hover { background: var(--bg-surface-hover); border-color: var(--border-default); }
.list-item-icon {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  background: rgba(59,130,246,0.08); color: var(--color-primary-400);
  border-radius: var(--radius-md); font-size: 1rem; flex-shrink: 0;
}
[data-theme="light"] .list-item-icon { background: var(--color-primary-50); color: var(--color-primary-600); }
.list-item-content { flex: 1; min-width: 0; }
.list-item-title { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text-primary); margin-bottom: 1px; }
.list-item-subtitle { font-size: var(--text-xs); color: var(--text-tertiary); }
.list-item-actions { display: flex; gap: var(--space-1); opacity: 0; transition: opacity var(--transition-fast); }
.list-item:hover .list-item-actions { opacity: 1; }

/* ── Recent dates ── */
.recent-date { font-size: var(--text-xs); color: var(--text-tertiary); white-space: nowrap; }
.recent-delete {
  opacity: 0; background: transparent; border: 1px solid transparent;
  color: var(--color-danger-400); cursor: pointer;
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); font-size: var(--text-xs);
  transition: all var(--transition-fast);
}
.recent-delete:hover { background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.2); }
.list-item:hover .recent-delete { opacity: 1; }
.recent-list { display: flex; flex-direction: column; }
.recent-empty {
  text-align: center; padding: var(--space-8);
  color: var(--text-tertiary); font-size: var(--text-sm);
  background: var(--bg-surface-sunken); border-radius: var(--radius-lg);
  border: 1px dashed var(--border-strong);
}
.recent-more-btn {
  margin-top: var(--space-3); font-size: var(--text-xs); color: var(--text-secondary);
  cursor: pointer; padding: var(--space-2) var(--space-4); border-radius: var(--radius-md);
  background: var(--bg-surface-solid); border: 1px solid var(--border-default);
  font-family: var(--font-family); font-weight: var(--weight-semibold);
  transition: all var(--transition-fast); display: inline-block;
}
.recent-more-btn:hover { background: var(--bg-surface-hover); color: var(--text-primary); }

/* ── Profile Selector ── */
.profile-selector {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); background: var(--bg-surface-sunken);
  border: 1px solid var(--border-default); border-radius: var(--radius-md);
  cursor: pointer; transition: all var(--transition-fast); font-size: var(--text-sm); color: var(--text-secondary);
}
.profile-selector:hover { border-color: var(--color-primary-500); background: rgba(59,130,246,0.05); }
[data-theme="light"] .profile-selector:hover { background: var(--color-primary-50); }
.profile-selector-label {
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  color: var(--color-primary-400); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 2px;
}
[data-theme="light"] .profile-selector-label { color: var(--color-primary-600); }
