/**
 * Design system layer. Loaded LAST so it wins over the page stylesheets.
 *
 * One set of rules for every surface (cards, popups, modals, sheets, toasts):
 *   - 3 radii, 3 shadows, 1 easing curve, 2 durations
 *   - one entrance animation for overlays, one for toasts
 *   - hover = lift, active = press, drag = tilt
 * Pages keep their layout; this only normalizes how things look and move.
 */

/* ==================== Tokens ==================== */
:root {
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    --shadow-rest: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow-raised: 0 12px 28px -12px rgba(15, 23, 42, 0.28), 0 4px 10px -4px rgba(15, 23, 42, 0.12);
    --shadow-overlay: 0 24px 60px -16px rgba(15, 23, 42, 0.45);
    /* legacy aliases used by older rules */
    --shadow-sm: var(--shadow-rest);
    --shadow-card: var(--shadow-rest);
    --shadow-md: var(--shadow-raised);
    --shadow-lg: var(--shadow-overlay);

    --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
    --dur-in: 150ms;
    --dur-out: 260ms;
    --transition-fast: var(--dur-in) var(--ease);
    --transition-normal: var(--dur-in) var(--ease);
    --transition-slow: var(--dur-out) var(--ease);
    --t-base: color var(--dur-in) var(--ease), background-color var(--dur-in) var(--ease),
              border-color var(--dur-in) var(--ease), box-shadow var(--dur-in) var(--ease),
              transform var(--dur-in) var(--ease), opacity var(--dur-in) var(--ease);

    /* readable secondary text (was #9ca3af on light, #64748b on dark) */
    --text-muted: #6b7280;
}

.dark {
    --shadow-rest: 0 1px 2px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-raised: 0 16px 32px -14px rgba(0, 0, 0, 0.6), 0 4px 10px -4px rgba(0, 0, 0, 0.3);
    --shadow-overlay: 0 24px 60px -16px rgba(0, 0, 0, 0.7);
    --text-muted: #94a3b8;
}

body { font-size: 15px; }

/* Tailwind's gray-400/500 on dark backgrounds is what makes meta text hard to read */
.dark .text-gray-400 { color: #a3b1c6 !important; }
.dark .text-gray-500 { color: #94a3b8 !important; }
.text-gray-400 { color: #6b7280; }

/* ==================== Motion primitives ==================== */
@keyframes ds-surface-in {
    from { opacity: 0; transform: translateY(10px) scale(0.985); }
    to   { opacity: 1; transform: none; }
}
@keyframes ds-sheet-in {
    from { transform: translateY(100%); }
    to   { transform: none; }
}
@keyframes ds-backdrop-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes ds-toast-in {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to   { opacity: 1; transform: none; }
}
@keyframes ds-shimmer {
    0%   { background-position: 100% 0; }
    100% { background-position: 0 0; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ==================== Cards: one family ==================== */
.card,
.kanban-card,
.issue-card,
.issue-card-grid,
.issue-card-list,
.issue-card-compact,
.issue-card-kanban,
.issue-card-fancy,
.chart-card,
.chart-card-wide,
.invite-card,
.stat-card {
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-rest) !important;
    border: 1px solid var(--border-color);
    transition: var(--t-base);
}

a.issue-card:hover,
.issue-card-compact:hover,
.issue-card-grid:hover,
.issue-card-list:hover,
.issue-card-fancy:hover,
.kanban-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-raised) !important;
    border-color: var(--border-color-light);
}
.kanban-card:active,
.issue-card-compact:active { transform: translateY(0) scale(0.995); }
.kanban-card.dragging {
    transform: rotate(1.5deg) scale(1.02);
    box-shadow: var(--shadow-raised) !important;
    opacity: 0.92;
}

/* the priority bar on grid cards: thin and rounded, no second status stripe */
.compact-priority-bar { width: 3px !important; border-radius: var(--radius-full); margin: 10px 0 10px 8px; opacity: 0.95; }
.issue-card-fancy { border-left: 1px solid var(--border-color) !important; }

/* card title line wraps like text, not like a flex row */
.compact-category { display: block !important; line-height: 1.4; }
.compact-category > * { display: inline; vertical-align: baseline; }

/* chips and pills share one shape */
.drawer-chip, .filter-chip, .issue-campaign-badge, .detail-badge, .quick-stat,
.status-badge, .priority-badge, .badge { border-radius: var(--radius-full) !important; }

/* ==================== Overlays: one surface, one motion ==================== */
.issue-detail-modal,
.status-modal,
.modal-content,
.notif__panel,
.mention-menu,
.leaflet-popup-content-wrapper {
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-overlay) !important;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
}

.issue-detail-modal,
.status-modal,
.modal-content,
.notif__panel {
    animation: ds-surface-in var(--dur-out) var(--ease) both !important;
    transform-origin: top center;
}

.bottom-sheet,
.filter-sheet-content,
.filter-drawer,
.mobile-filter-drawer {
    border-radius: var(--radius-xl) var(--radius-xl) 0 0 !important;
    box-shadow: var(--shadow-overlay) !important;
}
/* These sheets hide themselves with translateY(100%) and a .show class, so the
   entrance animation may only run while .show is present; a fill-mode animation on
   the base class would pin them on screen. */
.bottom-sheet.show,
.filter-sheet-content.show,
.filter-drawer.show,
.mobile-filter-drawer.show {
    animation: ds-sheet-in var(--dur-out) var(--ease) both;
}

/* Backdrops toggled with display (x-show) get the fade; backdrops toggled with an
   opacity .show class already transition on their own and only get the blur. */
.status-modal-overlay,
.modal-overlay,
.lightbox,
.fixed.inset-0.bg-black\/50,
.fixed.inset-0.bg-black\/60,
.fixed.inset-0.bg-black\/70,
.fixed.inset-0.bg-black\/80 {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: ds-backdrop-in var(--dur-in) var(--ease) both;
}
.bottom-sheet-overlay.show,
.filter-drawer-overlay.show,
.filter-sheet-overlay.show,
.mobile-filter-overlay.show {
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

/* Modals become bottom sheets on phones */
@media (max-width: 640px) {
    .issue-detail-modal,
    .status-modal,
    .modal-content {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 88vh;
        overflow-y: auto;
        margin: 0 !important;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0 !important;
        animation: ds-sheet-in var(--dur-out) var(--ease) both !important;
    }
}

/* Leaflet popups look like our cards, not Leaflet's default */
.leaflet-popup-content-wrapper { padding: 0; overflow: hidden; color: var(--text-primary); }
.leaflet-popup-content { margin: 0; }
.leaflet-popup-tip { background: var(--bg-card); border: 1px solid var(--border-color); box-shadow: none; }
/* Leaflet positions .leaflet-popup with its own transform, so only the inner surface may animate */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { animation: ds-surface-in var(--dur-out) var(--ease) both; }
.leaflet-popup-close-button { color: var(--text-muted) !important; transition: var(--t-base); }
.leaflet-popup-close-button:hover { color: var(--text-primary) !important; }
.leaflet-container a.leaflet-popup-close-button { top: 6px; right: 8px; }

/* ==================== Toasts ==================== */
.toast {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-overlay);
    animation: ds-toast-in var(--dur-out) var(--ease) both;
    font-weight: 500;
    backdrop-filter: blur(6px);
}

/* ==================== Buttons and inputs ==================== */
.btn-primary, .btn-secondary, .btn-danger, button.btn, .btn {
    border-radius: var(--radius-md);
    transition: var(--t-base);
}
.btn-primary:hover, .btn-danger:hover { transform: translateY(-1px); box-shadow: var(--shadow-raised); }
.btn-primary:active, .btn-danger:active, .btn-secondary:active { transform: translateY(0) scale(0.98); box-shadow: none; }

.input-field, input.input-field, select.input-field, textarea.input-field {
    border-radius: var(--radius-md);
    transition: var(--t-base);
}
.input-field:focus { box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.25); }

/* ==================== Skeleton and empty states ==================== */
.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-card-hover) 37%, var(--bg-tertiary) 63%);
    background-size: 400% 100%;
    animation: ds-shimmer 1.4s var(--ease) infinite;
    border-radius: var(--radius-md);
}
.empty-state { color: var(--text-muted); font-size: 0.95rem; text-align: center; padding: 2.5rem 1rem; }
.empty-state i { font-size: 1.75rem; opacity: 0.6; display: block; margin-bottom: 0.5rem; }

/* ==================== Card header: chips never collide ==================== */
.compact-header { gap: 0.5rem; }
.compact-header > .flex { min-width: 0; flex-wrap: nowrap; }
.compact-header .issue-campaign-badge { display: block !important; max-width: 110px; }
.compact-header .rounded-full { white-space: nowrap; flex-shrink: 0; }

/* Leaflet popup header leaves room for the close button */
.issue-popup-header { padding-right: 48px !important; }
.popup-title, .leaflet-popup-content .popup-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ==================== Phone nav overflow menu ==================== */
.nav-overflow-menu {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-overlay);
    animation: ds-surface-in var(--dur-in) var(--ease) both;
}
.nav-overflow-item {
    display: flex; align-items: center; gap: 0.6rem;
    width: 100%; padding: 0.6rem 0.9rem; font-size: 0.9rem; text-align: left;
    color: var(--text-primary); transition: var(--t-base);
}
.nav-overflow-item:hover { background: var(--bg-card-hover); }
.nav-phone-only { display: none; }
@media (max-width: 639px) { .nav-phone-only { display: block; } }

/* Phone nav: main.css forces 44px items with !important, which cannot fit 8 items in
   360-390px. Same weight, smaller: 36px targets, 18px icons, 2px gaps. */
@media (max-width: 639px) {
    .main-nav a, .main-nav button { min-width: 36px !important; padding: 0.3rem !important; }
    .main-nav i.fas, .main-nav i.far, .main-nav i.fab { font-size: 1.1rem !important; }
    .main-nav .gap-2, .main-nav .gap-4 { gap: 0.125rem !important; }
    .main-nav .w-10.h-10 { width: 2.25rem; height: 2.25rem; }
    .main-nav .h-6.w-px { display: none; }
    .main-nav .notif__btn { width: 2.25rem; height: 2.25rem; }
}

/* ==================== Skeleton cards (while lists load) ==================== */
.skeleton-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    padding: 1rem;
    display: flex; flex-direction: column; gap: 0.6rem;
}
.skeleton-line { height: 0.8rem; }
.skeleton-line.w-60 { width: 60%; } .skeleton-line.w-40 { width: 40%; } .skeleton-line.w-80 { width: 80%; }
.skeleton-line.tall { height: 1.1rem; }
.skeleton-thumb { height: 7rem; }
.skeleton-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
