/* Canticle Design System
 * Design Direction: Restrained Sophistication (aligned with Starlight docs)
 * - Pure neutral gray palette for professional feel
 * - Teal accent (#2d7a9e light / #4a9bc4 dark) used sparingly for meaning
 * - Proper WCAG AA contrast ratios
 * - Dark mode as rebalanced palette, not just inverted
 * - 4px grid system for consistent spacing
 */

/* ============================================
   CSS Custom Properties
   ============================================ */
:root {
    /* Timing */
    --transition-fast: 150ms;
    --transition-base: 200ms;
    --transition-slow: 300ms;
    --ease-out: cubic-bezier(0.25, 1, 0.5, 1);

    /* Borders - subtle and refined */
    --border-subtle: rgba(0, 0, 0, 0.05);
    --border-default: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.12);

    /* Scrollbar */
    --scrollbar-thumb: rgba(0, 0, 0, 0.12);
    --scrollbar-thumb-hover: rgba(0, 0, 0, 0.2);

    /* Design System Colors - Light Mode (aligned with Starlight docs) */
    --color-brand: #2d7a9e;
    --color-brand-hover: #246280;
    --color-brand-muted: rgba(45, 122, 158, 0.08);
    --color-surface-bg: #f4f4f5;
    --color-surface-card: #ffffff;
    --color-surface-elevated: #ffffff;
    --color-surface-border: #e4e4e7;
    --color-text-primary: #18181b;
    --color-text-secondary: #52525b;
    --color-text-muted: #71717a;
    --color-text-faint: #a1a1aa;

    /* Focus ring - visible but not jarring */
    --focus-ring: 0 0 0 2px #fff, 0 0 0 4px var(--color-brand);
    --focus-ring-inset: inset 0 0 0 2px var(--color-brand);
}

.dark {
    /* Design System Colors - Dark Mode (rebalanced, not inverted) */
    --color-brand: #4a9bc4;
    --color-brand-hover: #66bdd5;
    --color-brand-muted: rgba(74, 155, 196, 0.12);
    --color-surface-bg: #18181b;
    --color-surface-card: #27272a;
    --color-surface-elevated: #3f3f46;
    --color-surface-border: #3f3f46;
    --color-text-primary: #fafafa;
    --color-text-secondary: #a1a1aa;
    --color-text-muted: #71717a;
    --color-text-faint: #52525b;
    --focus-ring: 0 0 0 2px #18181b, 0 0 0 4px var(--color-brand);

    /* Borders - Dark Mode */
    --border-subtle: rgba(255, 255, 255, 0.05);
    --border-default: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.12);

    /* Scrollbar - Dark Mode */
    --scrollbar-thumb: rgba(255, 255, 255, 0.12);
    --scrollbar-thumb-hover: rgba(255, 255, 255, 0.2);
}

/* ============================================
   Base Styles
   ============================================ */

/* Typography refinements - system fonts for performance */
html {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-feature-settings: "cv02", "cv03", "cv04", "cv11";
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Tabular numbers for data displays */
.tabular-nums {
    font-variant-numeric: tabular-nums;
}

/* Custom scrollbar - subtle and unobtrusive */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* Smooth scrolling for supported elements */
@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

/* ============================================
   Card System
   ============================================ */

/* Base card - clean, subtle elevation */
.card {
    background: var(--color-surface-card);
    border: 1px solid var(--color-surface-border);
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* Compact card variant */
.card-compact {
    padding: 16px;
}

/* Card with hover interaction */
.card-interactive {
    transition:
        box-shadow var(--transition-base) var(--ease-out),
        border-color var(--transition-base) var(--ease-out),
        transform var(--transition-base) var(--ease-out);
    cursor: pointer;
}

.card-interactive:hover {
    border-color: var(--color-surface-border);
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.06),
        0 2px 4px -2px rgba(0, 0, 0, 0.04);
}

.card-interactive:active {
    transform: scale(0.995);
}

/* Card section - no padding, for sections with internal structure */
.card-section {
    background: var(--color-surface-card);
    border: 1px solid var(--color-surface-border);
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    overflow: hidden;
}

/* Elevated card - for modals, dropdowns, popovers */
.card-elevated {
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-surface-border);
    border-radius: 12px;
    padding: 24px;
    box-shadow:
        0 10px 15px -3px rgba(0, 0, 0, 0.08),
        0 4px 6px -4px rgba(0, 0, 0, 0.04);
}

.dark .card-elevated {
    box-shadow:
        0 10px 15px -3px rgba(0, 0, 0, 0.3),
        0 4px 6px -4px rgba(0, 0, 0, 0.2);
}

/* ============================================
   Button System
   ============================================ */

/* Base button - consistent sizing and feel */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.25;
    border-radius: 6px;
    transition: all var(--transition-fast) var(--ease-out);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

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

/* Small button variant */
.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    gap: 4px;
}

/* Large button variant */
.btn-lg {
    padding: 12px 20px;
    font-size: 14px;
    gap: 8px;
}

/* Primary button - brand teal, used sparingly for main CTAs */
.btn-primary {
    background: var(--color-brand);
    color: #ffffff;
    border: 1px solid transparent;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-brand-hover);
}

.btn-primary:active:not(:disabled) {
    background: #1e5a73;
}

/* Secondary button - most common, neutral */
.btn-secondary {
    background: var(--color-surface-card);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-surface-border);
}

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

.btn-secondary:active:not(:disabled) {
    background: var(--color-surface-border);
}

/* Ghost button - minimal, text-like */
.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
    border: 1px solid transparent;
}

.btn-ghost:hover:not(:disabled) {
    background: var(--color-brand-muted);
    color: var(--color-text-secondary);
}

.btn-ghost:active:not(:disabled) {
    background: rgba(0, 0, 0, 0.06);
}

.dark .btn-ghost:active:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
}

/* Danger button - red for destructive actions */
.btn-danger {
    background: transparent;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.btn-danger:hover:not(:disabled) {
    background: #fef2f2;
    border-color: #fca5a5;
}

.btn-danger:active:not(:disabled) {
    background: #fee2e2;
}

.dark .btn-danger {
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.25);
}

.dark .btn-danger:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.4);
}

.dark .btn-danger:active:not(:disabled) {
    background: rgba(239, 68, 68, 0.15);
}

/* Gold accent button - for special/premium actions */
.btn-gold {
    background: linear-gradient(180deg, #f7e09a 0%, #d4a843 100%);
    color: #654720;
    border: 1px solid rgba(212, 168, 67, 0.3);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.btn-gold:hover:not(:disabled) {
    background: linear-gradient(180deg, #fbefc3 0%, #e5c65c 100%);
}

.btn-gold:active:not(:disabled) {
    background: linear-gradient(180deg, #e5c65c 0%, #b8892d 100%);
}

/* ============================================
   Form Controls
   ============================================ */

/* Input base */
.input {
    display: block;
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.5;
    color: #292524;
    background: #ffffff;
    border: 0.5px solid var(--border-default);
    border-radius: 6px;
    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast);
}

.dark .input {
    color: #e4e4e7;
    background: #3f3f46;
    border-color: #52525b;
}

.input:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-brand) 10%, transparent);
}

.input::placeholder {
    color: #a8a29e;
}

.dark .input::placeholder {
    color: #71717a;
}

/* Select trigger (custom) */
.select-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    color: #44403c;
    background: #ffffff;
    border: 0.5px solid var(--border-default);
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
}

.dark .select-trigger {
    color: #e4e4e7;
    background: #3f3f46;
    border-color: #52525b;
}

.select-trigger:hover {
    border-color: var(--border-strong);
    background: #fafaf9;
}

.dark .select-trigger:hover {
    background: #52525b;
}

/* Select wrapper with custom icon */
.select-wrapper {
    position: relative;
    display: inline-block;
}

.select-wrapper .select-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: #78716c;
    font-size: 14px;
}

/* Form select - native select with hidden arrow */
.form-select {
    display: block;
    width: 100%;
    padding: 8px 32px 8px 12px;
    font-size: 14px;
    line-height: 1.5;
    color: #292524;
    background: #ffffff;
    border: 0.5px solid var(--border-default);
    border-radius: 6px;
    cursor: pointer;
    /* Hide native dropdown arrow */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast);
}

.dark .form-select {
    color: #e4e4e7;
    background: #3f3f46;
    border-color: #52525b;
}

.form-select:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-brand) 10%, transparent);
}

/* Form input */
.form-input {
    display: block;
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.5;
    color: #292524;
    background: #ffffff;
    border: 0.5px solid var(--border-default);
    border-radius: 6px;
    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast);
}

.dark .form-input {
    color: #e4e4e7;
    background: #3f3f46;
    border-color: #52525b;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-brand);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-brand) 10%, transparent);
}

.form-input::placeholder {
    color: #a8a29e;
}

.dark .form-input::placeholder {
    color: #71717a;
}

/* ============================================
   Navigation & Sidebar
   ============================================ */

/* Sidebar container - structural fallback */
aside {
    display: flex;
    flex-direction: column;
}

aside > div {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Navigation container */
aside nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Sidebar nav link - clear hierarchy with subtle interaction */
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-muted);
    border-radius: 6px;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.nav-link:hover {
    background: var(--color-brand-muted);
    color: var(--color-text-secondary);
}

.nav-link.active {
    background: var(--color-brand-muted);
    color: var(--color-brand);
}

/* Nav link icons */
.nav-link .ph,
.nav-link .ph-duotone {
    font-size: 18px;
    opacity: 0.75;
    flex-shrink: 0;
}

.nav-link:hover .ph,
.nav-link:hover .ph-duotone {
    opacity: 0.9;
}

.nav-link.active .ph,
.nav-link.active .ph-duotone {
    opacity: 1;
}

/* Sidebar section divider */
.nav-divider {
    height: 1px;
    background: var(--color-surface-border);
    margin: 12px 0;
}

/* ============================================
   Status Badges
   ============================================ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 4px;
    text-transform: capitalize;
    letter-spacing: 0.01em;
}

/* Neutral/draft - gray */
.badge-draft,
.badge-secondary {
    background: #f4f4f5;
    color: #52525b;
}

/* Warning/pending - amber */
.badge-pending,
.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

/* Success/approved - emerald */
.badge-approved,
.badge-success {
    background: #d1fae5;
    color: #065f46;
}

/* Error/rejected - red */
.badge-error {
    background: #fee2e2;
    color: #991b1b;
}

/* Info - brand teal */
.badge-info {
    background: rgba(45, 122, 158, 0.12);
    color: #1e5a73;
}

/* Badge dark mode variants - muted backgrounds with lighter text */
.dark .badge-draft,
.dark .badge-secondary {
    background: rgba(161, 161, 170, 0.12);
    color: #a1a1aa;
}

.dark .badge-pending,
.dark .badge-warning {
    background: rgba(251, 191, 36, 0.12);
    color: #fbbf24;
}

.dark .badge-approved,
.dark .badge-success {
    background: rgba(52, 211, 153, 0.12);
    color: #34d399;
}

.dark .badge-error {
    background: rgba(248, 113, 113, 0.12);
    color: #f87171;
}

.dark .badge-info {
    background: rgba(74, 155, 196, 0.12);
    color: #4a9bc4;
}

/* ============================================
   Liturgical Season Colors (Semantic Only)
   ============================================ */

.season-advent {
    background: #7c3aed;
    color: #ffffff;
}
.season-christmas {
    background: #fafaf9;
    color: #292524;
    border: 1px solid #e7e5e4;
}
.season-epiphany {
    background: #ffffff;
    color: #292524;
    border: 1px solid #e7e5e4;
}
.season-lent {
    background: #7c3aed;
    color: #ffffff;
}
.season-easter {
    background: #fafaf9;
    color: #292524;
    border: 1px solid #e7e5e4;
}
.season-pentecost {
    background: #dc2626;
    color: #ffffff;
}
.season-ordinary {
    background: #059669;
    color: #ffffff;
}

/* Season dot indicator (compact) */
.season-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.season-dot-advent { background: #7c3aed; }
.season-dot-christmas { background: #d4a843; }
.season-dot-epiphany { background: #d4a843; }
.season-dot-lent { background: #7c3aed; }
.season-dot-easter { background: #d4a843; }
.season-dot-pentecost { background: #dc2626; }
.season-dot-ordinary { background: #059669; }

/* ============================================
   HTMX States
   ============================================ */

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-indicator {
    display: none;
}

.htmx-added {
    animation: fadeIn var(--transition-slow) var(--ease-out);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   Loading States
   ============================================ */

.spinner,
.loading-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-surface-border);
    border-top-color: var(--color-brand);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.skeleton {
    background: linear-gradient(90deg, #f5f5f4 25%, #e7e5e4 50%, #f5f5f4 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

.dark .skeleton {
    background: linear-gradient(90deg, #3f3f46 25%, #52525b 50%, #3f3f46 75%);
    background-size: 200% 100%;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================
   Service Slot Timeline
   ============================================ */

.service-slot {
    position: relative;
    padding-left: 28px;
}

.service-slot::before {
    content: '';
    position: absolute;
    left: 9px;
    top: 0;
    bottom: 0;
    width: 1.5px;
    background: var(--color-surface-border);
}

.service-slot:last-child::before {
    bottom: 50%;
}

.service-slot::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #d6d3d1;
    border: 2px solid var(--color-surface-card);
    box-shadow: 0 0 0 1px var(--color-surface-border);
}

.dark .service-slot::after {
    background: #52525b;
}

.service-slot.filled::after {
    background: var(--color-brand);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--color-brand) 40%, white);
}

.service-slot.suggested::after {
    background: #7c3aed;
    box-shadow: 0 0 0 1px #ddd6fe;
    animation: pulse-ring 2s infinite;
}

.service-slot.instrumental::after {
    background: #d4a843;
    box-shadow: 0 0 0 1px #fbefc3;
}

@keyframes pulse-ring {
    0%, 100% {
        box-shadow: 0 0 0 1px #ddd6fe, 0 0 0 3px rgba(124, 58, 237, 0);
    }
    50% {
        box-shadow: 0 0 0 1px #ddd6fe, 0 0 0 6px rgba(124, 58, 237, 0.15);
    }
}

/* ============================================
   Drag and Drop
   ============================================ */

.draggable {
    cursor: grab;
}

.draggable:active {
    cursor: grabbing;
}

.drop-zone {
    transition:
        background-color var(--transition-fast),
        border-color var(--transition-fast);
}

.drop-zone.drag-over {
    background: color-mix(in srgb, var(--color-brand) 4%, transparent);
    border-color: var(--color-brand);
}

/* ============================================
   Focus Styles (Accessibility)
   ============================================ */

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .no-print {
        display: none !important;
    }

    .print-only {
        display: block !important;
    }

    body {
        font-size: 11pt;
        color: #000;
        background: #fff;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}

/* ============================================
   Utility Classes
   ============================================ */

/* Text hierarchy - semantic classes */
.text-primary { color: var(--color-text-primary); }
.text-secondary { color: var(--color-text-secondary); }
.text-muted { color: var(--color-text-muted); }
.text-faint { color: var(--color-text-faint); }
.text-brand { color: var(--color-brand); }

/* Dividers */
.divider {
    height: 1px;
    background: var(--border-subtle);
}

.divider-strong {
    height: 1px;
    background: var(--border-default);
}

/* Icon containers - for decorative icons in cards */
.icon-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: var(--color-brand-muted);
    flex-shrink: 0;
}

.icon-container-brand {
    background: var(--color-brand-muted);
    color: var(--color-brand);
}

.icon-container-gold {
    background: rgba(212, 168, 67, 0.12);
    color: #966c24;
}

.dark .icon-container-gold {
    background: rgba(212, 168, 67, 0.15);
    color: #f7e09a;
}

.icon-container-success {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
}

.dark .icon-container-success {
    background: rgba(52, 211, 153, 0.12);
    color: #34d399;
}

.icon-container-error {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

.dark .icon-container-error {
    background: rgba(248, 113, 113, 0.12);
    color: #f87171;
}

/* Truncation utilities */
.truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.truncate-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Interactive hover utilities */
.hover-lift {
    transition: transform var(--transition-fast) var(--ease-out);
}

.hover-lift:hover {
    transform: translateY(-1px);
}

/* Visibility utilities */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}
