/* ══════════════════════════════════════════════════════════════
   Heros Base — reset + shared components
   ══════════════════════════════════════════════════════════════ */

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
}

img, svg, video, canvas { max-width: 100%; }
img { display: block; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, h4, h5, h6 { margin: 0; line-height: 1.25; font-weight: 600; color: var(--text); }
p { margin: 0; }
code, pre, kbd { font-family: var(--font-mono); }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
::selection { background: var(--accent-soft); }

:focus-visible { outline: 2px solid var(--accent-ring); outline-offset: 2px; border-radius: 6px; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

.serif { font-family: var(--font-serif); font-weight: 400; letter-spacing: -0.01em; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--font-mono); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.hidden { display: none !important; }

/* ── Brand mark ───────────────────────────────────────────── */
.brand-logo {
  width: 28px; height: 28px; border-radius: 8px;
  object-fit: contain; background: none;
  padding: 0; flex-shrink: 0;
}
.brand-word { font-family: var(--font-serif); font-size: 1.3rem; font-weight: 500; letter-spacing: -0.01em; color: var(--text); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn,
.modal-save-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px;
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  background: var(--primary); color: var(--on-primary);
  font-size: var(--fs-sm); font-weight: 550; line-height: 1;
  white-space: nowrap; text-decoration: none;
  transition: background var(--dur) var(--ease), border-color var(--dur), color var(--dur), transform 0.08s, box-shadow var(--dur);
}
.btn:hover,
.modal-save-btn:hover { background: var(--primary-hover); text-decoration: none; }
.btn:active,
.modal-save-btn:active { transform: translateY(1px); }
.btn:disabled,
.modal-save-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-outline,
.btn-secondary {
  background: var(--surface); color: var(--text);
  border-color: var(--border-strong);
}
.btn-outline:hover,
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-strong); }

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

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(0.92); }
.btn-danger-outline { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn-danger-outline:hover { background: var(--danger-soft); }

.btn-sm { height: 32px; padding: 0 12px; font-size: var(--fs-xs); }
.btn-lg { height: 46px; padding: 0 22px; font-size: var(--fs-base); }
.btn-block { width: 100%; }
.btn-square { border-radius: var(--radius-sm); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  border: 0; background: transparent; color: var(--text-muted);
  transition: background var(--dur), color var(--dur);
  flex-shrink: 0; font-size: 0.95rem;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.active { background: var(--active); color: var(--text); }
.icon-btn.sm { width: 30px; height: 30px; font-size: 0.85rem; }

/* ── Form controls ────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field-label, .modal-section-label, .auth-label {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--fs-sm); font-weight: 550; color: var(--text-2);
}
.field-label i, .modal-section-label i { color: var(--text-muted); font-size: 0.85em; }
.field-hint { font-size: var(--fs-xs); color: var(--text-muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.field-hint a { color: var(--link); }

.input, .textarea, .select,
.auth-input, .modal-input, .modal-select, .modal-textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-base);
  transition: border-color var(--dur), box-shadow var(--dur), background var(--dur);
  outline: none;
}
.textarea, .modal-textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder, .auth-input::placeholder, .modal-input::placeholder, .modal-textarea::placeholder { color: var(--text-faint); }
.input:focus, .textarea:focus, .select:focus,
.auth-input:focus, .modal-input:focus, .modal-select:focus, .modal-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.select, .modal-select, select.auth-input {
  appearance: none; -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23868b7f' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  cursor: pointer;
}
input[type="checkbox"] { accent-color: var(--primary); width: 16px; height: 16px; }
input[type="range"] { accent-color: var(--primary); }

/* Toggle switch (JS toggles .on) */
.toggle {
  position: relative; width: 40px; height: 24px; flex-shrink: 0;
  border-radius: var(--radius-full); border: 0;
  background: var(--border-strong);
  transition: background var(--dur) var(--ease);
  padding: 0;
}
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform var(--dur) var(--ease);
}
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(16px); }

.toggle-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: 0; }
.toggle-label { font-size: var(--fs-base); color: var(--text); }
.toggle-sub { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }

/* ── Badges, chips, kbd ───────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: var(--radius-full);
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.01em;
  background: var(--surface-3); color: var(--text-2);
  white-space: nowrap;
}
.badge-accent, .required-badge { background: var(--accent-soft); color: var(--accent); }
.optional-badge { background: var(--surface-3); color: var(--text-muted); }
.required-badge, .optional-badge { display: inline-flex; padding: 1px 8px; border-radius: var(--radius-full); font-size: 0.68rem; font-weight: 600; margin-left: auto; }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-success { background: var(--success-soft); color: var(--success); }

kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 5px;
  border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: 5px; background: var(--surface);
  font-size: 0.68rem; color: var(--text-muted);
}

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--success); flex-shrink: 0; }
.dot.pulse { box-shadow: 0 0 0 0 var(--success-soft); animation: dot-pulse 2s infinite; }
@keyframes dot-pulse { 0% { box-shadow: 0 0 0 0 rgba(61, 119, 65, 0.4); } 70% { box-shadow: 0 0 0 8px rgba(61, 119, 65, 0); } 100% { box-shadow: 0 0 0 0 rgba(61, 119, 65, 0); } }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

/* ── Menus / popovers ─────────────────────────────────────── */
.menu {
  position: absolute; z-index: 60;
  min-width: 220px; padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  opacity: 0; visibility: hidden; transform: translateY(4px) scale(0.98);
  transform-origin: top left;
  transition: opacity 0.14s var(--ease), transform 0.14s var(--ease), visibility 0.14s;
}
.menu.open, .menu.show { opacity: 1; visibility: visible; transform: none; }
.menu-item, .menu-link {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px;
  border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text);
  font-size: var(--fs-sm); text-align: left; text-decoration: none;
  cursor: pointer;
}
.menu-item:hover, .menu-link:hover { background: var(--hover); text-decoration: none; }
.menu-item i, .menu-link i { width: 18px; text-align: center; color: var(--text-muted); font-size: 0.9rem; }
.menu-item.danger, .menu-item.danger i { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }
.menu-label { padding: 8px 10px 4px; font-size: 0.7rem; font-weight: 600; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.06em; }

/* ── Modals ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
  background: var(--overlay);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  opacity: 0; visibility: hidden;
  transition: opacity 0.18s var(--ease), visibility 0.18s;
  overflow-y: auto;
}
.modal-overlay.active, .modal-overlay.open { opacity: 1; visibility: visible; }
.modal-overlay > * { transform: translateY(8px) scale(0.985); transition: transform 0.22s var(--ease); }
.modal-overlay.active > *, .modal-overlay.open > * { transform: none; }

.modal-panel {
  width: 100%; max-width: 480px; max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  margin: auto;
}
.modal-panel.wide { max-width: 720px; }
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 22px 24px 8px;
}
.modal-head h2, .modal-head h3, .modal-title { font-size: var(--fs-lg); font-weight: 600; display: flex; align-items: center; gap: 10px; }
.modal-head p { color: var(--text-muted); font-size: var(--fs-sm); margin-top: 4px; }
.modal-body { padding: 12px 24px 8px; overflow-y: auto; }
.modal-foot, .modal-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 16px 24px 22px;
}
.modal-close {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: transparent; color: var(--text-muted);
  flex-shrink: 0;
}
.modal-close:hover { background: var(--hover); color: var(--text); }
.modal-section { margin-bottom: 18px; }

/* ── Toast ────────────────────────────────────────────────── */
.toast, .custom-notification, .save-toast, .ins-notif {
  position: fixed; left: 50%; bottom: 28px; z-index: 400;
  display: inline-flex; align-items: center; gap: 10px;
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: var(--radius);
  background: var(--olive-900); color: var(--bone-50);
  font-size: var(--fs-sm); font-weight: 500;
  box-shadow: var(--shadow-lg);
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}
:root[data-theme="dark"] .toast,
:root[data-theme="dark"] .custom-notification,
:root[data-theme="dark"] .save-toast,
:root[data-theme="dark"] .ins-notif { background: var(--bone-100); color: var(--olive-900); }
.toast.show, .custom-notification.show, .save-toast.show, .ins-notif.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.custom-notification::before, .ins-notif::before {
  font-family: "Font Awesome 6 Free"; font-weight: 900; content: "\f05a"; opacity: 0.9;
}
.custom-notification.success::before, .ins-notif.success::before { content: "\f058"; color: #8fc58f; }
.custom-notification.error::before, .ins-notif.error::before { content: "\f06a"; color: #f08f7c; }
.custom-notification.warning::before { content: "\f071"; color: #e0b05c; }
:root[data-theme="dark"] .custom-notification.success::before, :root[data-theme="dark"] .ins-notif.success::before { color: var(--leaf-600); }
:root[data-theme="dark"] .custom-notification.error::before, :root[data-theme="dark"] .ins-notif.error::before { color: #b4412f; }
.save-toast.error i { color: #f08f7c; }

/* ── Confirm dialog (built by JS) ─────────────────────────── */
.custom-confirm-overlay {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  opacity: 0; transition: opacity 0.2s var(--ease);
}
.custom-confirm-overlay.show { opacity: 1; }
.custom-confirm {
  width: 100%; max-width: 400px;
  padding: 24px; text-align: left;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  transform: translateY(8px); transition: transform 0.22s var(--ease);
}
.custom-confirm-overlay.show .custom-confirm { transform: none; }
.confirm-icon {
  width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); font-size: 1.1rem;
  margin-bottom: 14px;
}
.confirm-message { font-size: var(--fs-md); color: var(--text); line-height: 1.5; }
.confirm-buttons { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.confirm-btn {
  height: 38px; padding: 0 18px; border-radius: var(--radius-full);
  font-size: var(--fs-sm); font-weight: 550; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
}
.confirm-btn:hover { background: var(--surface-2); }
.confirm-btn.confirm { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.confirm-btn.confirm:hover { background: var(--primary-hover); }

/* ── Tooltips: [data-tip] ─────────────────────────────────── */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; left: 50%; top: calc(100% + 8px);
  transform: translateX(-50%) translateY(-2px);
  padding: 5px 9px; border-radius: 7px;
  background: var(--olive-900); color: var(--bone-50);
  font-size: 0.72rem; font-weight: 500; white-space: nowrap;
  opacity: 0; pointer-events: none; z-index: 90;
  transition: opacity 0.12s, transform 0.12s;
}
[data-tip]:hover::after { opacity: 1; transform: translateX(-50%); transition-delay: 0.35s; }
[data-tip-pos="top"]::after { top: auto; bottom: calc(100% + 8px); }
[data-tip-pos="right"]::after { left: calc(100% + 8px); top: 50%; transform: translateY(-50%); }
[data-tip-pos="right"]:hover::after { transform: translateY(-50%); }
:root[data-theme="dark"] [data-tip]::after { background: var(--bone-100); color: var(--olive-900); }
@media (hover: none) { [data-tip]::after { display: none; } }

/* ── Spinner ──────────────────────────────────────────────── */
.spin { display: inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}
