/* Pikkolo CMS - App Styles
 * Modern design system with DaisyUI base
 */

/* Tailwind v4: restore cursor-pointer on interactive elements */
button, [role="button"], a, select, summary,
[type="button"], [type="submit"], [type="reset"] {
  cursor: pointer;
}

/* ============================================
   CSS Variables / Design Tokens
   ============================================ */
:root {
  --sidebar-width: fit-content;
  --pikkolo-width: 400px;

  /* Custom shadow - teal glow accent */
  --shadow-glow: 0 0 20px rgba(13, 148, 136, 0.15);

  /* Transitions */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

/* Alpine cloak - hide elements until Alpine initializes */
[x-cloak] {
  display: none !important;
}

/* Balanced headings prevent orphaned words */
h1, h2, h3 {
  text-wrap: balance;
}

/* Auto-size textareas based on content (Chrome 123+, Firefox 131+, Safari 18.4+) */
.textarea {
  field-sizing: content;
  min-height: 2.5rem;
}

/* Container queries: grids respond to available space, not viewport */
#main-content {
  container-type: inline-size;
}

/* Rendering performance: skip layout for off-screen rows */
.table-modern tbody tr {
  content-visibility: auto;
  contain-intrinsic-size: auto 56px;
}

/* ============================================
   Glass Surface System
   ============================================ */

.surface-glass {
  background: color-mix(in oklch, var(--color-base-200) 60%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid color-mix(in oklch, var(--color-base-content) 6%, transparent);
  border-radius: var(--radius-box);
}

.surface-glass-strong {
  background: color-mix(in oklch, var(--color-base-200) 80%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid color-mix(in oklch, var(--color-base-content) 8%, transparent);
  border-radius: var(--radius-box);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.25), 0 4px 6px -2px rgba(0, 0, 0, 0.12);
}

.surface-elevated {
  background: var(--color-base-100);
  border: 1px solid color-mix(in oklch, var(--color-base-content) 6%, transparent);
  border-radius: var(--radius-box);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -1px rgba(0, 0, 0, 0.1);
}

/* ============================================
   Pre-Alpine Flash Prevention
   ============================================ */

/* Theme toggle: show correct icon before Alpine sets checkbox state.
   DaisyUI swap shows swap-off (moon) when unchecked, swap-on (sun) when checked.
   In dark mode the checkbox should be checked. Before Alpine runs x-init,
   CSS overrides the swap icon visibility to match the current theme.
   The .no-alpine class (set by blocking script, removed on alpine:init) ensures
   this override is temporary and doesn't interfere with the swap animation. */
html.no-alpine[data-theme="nordic"] #theme-toggle > .swap-on {
  opacity: 1;
}
html.no-alpine[data-theme="nordic"] #theme-toggle > .swap-off {
  opacity: 0;
}

/* Pikkolo panel: hidden by default via x-cloak.
   Override x-cloak when the blocking script's data attribute says open. */
html[data-pikkolo-open="true"] #pikkolo-panel[x-cloak] {
  display: flex !important;
}

/* View transitions disabled — instant page swaps */

/* ============================================
   Disabled Button State (htmx hx-disabled-elt)
   ============================================ */

button[disabled],
a[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ============================================
   Page Transitions (htmx boost)
   ============================================ */

/* Progress indicator at top of page */
.htmx-progress-indicator {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: var(--color-primary);
  z-index: 9999;
  transition: width 0.3s ease;
  pointer-events: none;
}

body.htmx-request .htmx-progress-indicator {
  width: 70%;
  animation: progress-pulse 1s ease-in-out infinite;
}

@keyframes progress-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* ============================================
   Sidebar
   ============================================ */

/* Initial state for sidebar before Alpine loads */
:root[data-sidebar-collapsed="true"] .sidebar-collapsible {
  width: 5rem;
}
:root[data-sidebar-collapsed="false"] .sidebar-collapsible {
  width: fit-content;
}

/* Hide text elements in collapsed sidebar before Alpine loads */
:root[data-sidebar-collapsed="true"] .sidebar-collapsible .sidebar-text {
  display: none;
}

/* Sidebar nav link text - explicit color for dark bg contrast */
.sidebar-collapsible .menu a {
  color: color-mix(in oklch, var(--color-base-content) 80%, transparent);
}
.sidebar-collapsible .menu a:hover {
  color: color-mix(in oklch, var(--color-base-content) 95%, transparent);
}

/* Sidebar tooltip fix - MUST allow overflow for tooltips */
.sidebar-collapsible {
  overflow: visible !important;
}
.sidebar-collapsible .menu {
  overflow: visible !important;
}
.sidebar-collapsible .menu li {
  overflow: visible !important;
}
.sidebar-collapsible .tooltip::before,
.sidebar-collapsible .tooltip::after {
  z-index: 9999 !important;
  white-space: nowrap;
}
/* Ensure drawer-side doesn't clip tooltips */
.drawer-side {
  overflow: visible !important;
}
.drawer-side > * {
  overflow: visible !important;
}

/* ============================================
   Pikkolo Chat Panel
   ============================================ */

.pikkolo-panel {
  width: var(--pikkolo-width, 400px);
  min-width: 320px;
  max-width: 80vw;
  box-shadow: -4px 0 6px -1px rgb(0 0 0 / 0.1);
  border-top: 2px solid;
  border-image: linear-gradient(to right, var(--color-primary), color-mix(in oklch, var(--color-primary) 30%, transparent)) 1;
}

/* Content shifts when pikkolo is open */
:root[data-pikkolo-open="true"] .drawer-content {
  margin-right: var(--pikkolo-width, 400px);
  transition: margin-right 0.2s ease;
}
:root[data-pikkolo-open="false"] .drawer-content {
  margin-right: 0;
  transition: margin-right 0.2s ease;
}

/* Resize handle on left edge */
.pikkolo-resize-handle {
  position: absolute;
  left: -4px;
  top: 0;
  bottom: 0;
  width: 12px;
  cursor: ew-resize;
  background: transparent;
  z-index: 60;
  transition: background-color 0.15s ease;
}
.pikkolo-resize-handle::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 0;
  bottom: 0;
  width: 4px;
  background: rgba(0, 0, 0, 0.05);
  transition: background-color 0.15s ease;
}
.pikkolo-resize-handle:hover::after {
  background: rgba(13, 148, 136, 0.4);
}
.pikkolo-resize-handle:active::after,
.pikkolo-resize-handle.resizing::after {
  background: rgba(13, 148, 136, 0.6);
}

/* Comic-style thought bubble (classic cloud shape) */
.pikkolo-thought-bubble {
  --bubble-border: color-mix(in oklch, var(--color-base-content) 30%, transparent);
  position: relative;
  background: var(--color-base-100);
  padding: 0.75rem 1rem;
  margin-bottom: 8px;
  margin-left: 24px;
  border-radius: 50%;
  min-width: 60px;
  /* Cloud shape using box-shadow bumps */
  box-shadow:
    0 0 0 2px var(--bubble-border),
    -12px -8px 0 -2px var(--color-base-100),
    -12px -8px 0 0 var(--bubble-border),
    12px -8px 0 -2px var(--color-base-100),
    12px -8px 0 0 var(--bubble-border),
    0px -12px 0 -2px var(--color-base-100),
    0px -12px 0 0 var(--bubble-border),
    -16px 0px 0 -4px var(--color-base-100),
    -16px 0px 0 -2px var(--bubble-border),
    16px 0px 0 -4px var(--color-base-100),
    16px 0px 0 -2px var(--bubble-border),
    -10px 8px 0 -2px var(--color-base-100),
    -10px 8px 0 0 var(--bubble-border),
    10px 8px 0 -2px var(--color-base-100),
    10px 8px 0 0 var(--bubble-border);
}

/* Trailing thought circles */
.pikkolo-thought-bubble::before {
  content: '';
  position: absolute;
  bottom: -10px;
  left: -8px;
  width: 12px;
  height: 12px;
  background: var(--color-base-100);
  border: 2px solid var(--bubble-border);
  border-radius: 50%;
}

.pikkolo-thought-bubble::after {
  content: '';
  position: absolute;
  bottom: -16px;
  left: -18px;
  width: 9px;
  height: 9px;
  background: var(--color-base-100);
  border: 2px solid var(--bubble-border);
  border-radius: 50%;
  box-shadow:
    -8px -4px 0 -2px var(--color-base-100),
    -8px -4px 0 0 var(--bubble-border);
}

/* Chat textarea auto-resize */
.pikkolo-panel textarea.textarea {
  overflow-y: auto;
  transition: height 0.1s ease;
}

/* Animation for thinking state */
@keyframes thought-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.01); }
}

.pikkolo-thought-bubble.thinking {
  animation: thought-pulse 2s ease-in-out infinite;
}

/* Dot floating animation */
@keyframes thought-dot-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

.pikkolo-thought-bubble.thinking::after {
  animation: thought-dot-float 1.2s ease-in-out infinite;
}

/* ============================================
   Modern Cards
   ============================================ */

.card-modern {
  background: color-mix(in oklch, var(--color-base-200) 60%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: var(--radius-box);
  border: 1px solid color-mix(in oklch, var(--color-base-content) 6%, transparent);
  transition: all 0.2s ease;
}

.card-modern:hover {
  border-color: color-mix(in oklch, var(--color-primary) 20%, transparent);
  box-shadow: 0 0 20px color-mix(in oklch, var(--color-primary) 5%, transparent);
}

.card-modern-interactive {
  background: color-mix(in oklch, var(--color-base-200) 60%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: var(--radius-box);
  border: 1px solid color-mix(in oklch, var(--color-base-content) 6%, transparent);
  transition: all 0.2s ease;
  cursor: pointer;
}

.card-modern-interactive:hover {
  border-color: color-mix(in oklch, var(--color-primary) 25%, transparent);
  box-shadow: 0 0 20px color-mix(in oklch, var(--color-primary) 8%, transparent);
  transform: translateY(-1px) scale(1.005);
}

.card-modern-interactive:active {
  transform: translateY(0) scale(0.98);
  transition-duration: 100ms;
}

/* ============================================
   Buttons - Use DaisyUI btn classes
   ============================================ */

/* All buttons now use DaisyUI btn classes (btn, btn-primary, btn-ghost, etc.) */

/* Button micro-interaction: press effect */
.btn:not([disabled]):active {
  transform: scale(0.97);
  transition-duration: 100ms;
}

/* Teal focus rings */
*:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ============================================
   DaisyUI v5 Width Overrides
   ============================================ */

/* DaisyUI v5 sets width: clamp(48px, 320px, 100%) on .select and .input.
   Override when Tailwind size utilities are used. */
select.select.w-auto,
.select.w-auto {
  width: auto !important;
}

input.input.w-full,
.input.w-full {
  width: 100% !important;
}

/* ============================================
   Scrollbar Utilities
   ============================================ */

/* Hide scrollbar utility */
.scrollbar-none {
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.scrollbar-none::-webkit-scrollbar {
  display: none;
}

/* ============================================
   Modern Tables
   ============================================ */

.table-modern {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.table-modern thead tr {
  background: color-mix(in oklch, var(--color-base-200) 50%, transparent);
}

.table-modern th {
  padding: 0.5rem 0.5rem;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: color-mix(in oklch, var(--color-base-content) 50%, transparent);
  text-align: left;
  border-bottom: 1px solid color-mix(in oklch, var(--color-base-300) 50%, transparent);
}

.table-modern td {
  padding: 0.625rem 0.5rem;
  border-bottom: 1px solid color-mix(in oklch, var(--color-base-300) 30%, transparent);
  vertical-align: middle;
}

@media (min-width: 640px) {
  .table-modern th {
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
  }
  .table-modern td {
    padding: 0.875rem 1rem;
  }
}

.table-modern tbody tr {
  transition: background 0.15s ease;
}

.table-modern tbody tr:hover {
  background: color-mix(in oklch, var(--color-base-content) 4%, transparent);
}

.table-modern tbody tr:last-child td {
  border-bottom: none;
}

/* ============================================
   Empty States
   ============================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
}

.empty-state-icon {
  width: 4rem;
  height: 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-base-200);
  color: color-mix(in oklch, var(--color-base-content) 30%, transparent);
  border-radius: 1.5rem;
  margin-bottom: 1rem;
}

.empty-state-title {
  font-weight: 600;
  color: color-mix(in oklch, var(--color-base-content) 70%, transparent);
  margin-bottom: 0.25rem;
}

.empty-state-description {
  font-size: 0.875rem;
  color: color-mix(in oklch, var(--color-base-content) 50%, transparent);
  margin-bottom: 1.5rem;
  max-width: 20rem;
}

/* Skeleton loading: uses DaisyUI v5 built-in .skeleton class */

/* ============================================
   htmx Request Indicators
   ============================================ */

.htmx-indicator {
  display: none;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline;
}
.htmx-request .btn {
  pointer-events: none;
}

/* ============================================
   Utilities
   ============================================ */

/* Pikkolo connection status animations */
.animate-blink {
  animation: blink 2s ease-in-out infinite;
}
.animate-pulse-fast {
  animation: pulse-fast 0.8s ease-in-out infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.15; }
}
@keyframes pulse-fast {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.75); }
}

/* ============================================
   Pikkolo Panel - Mobile Responsive
   ============================================ */

@media (max-width: 768px) {
  .pikkolo-panel {
    width: 100vw !important;
    min-width: unset;
    max-width: 100vw;
    border-left: none;
    box-shadow: 0 -2px 10px rgb(0 0 0 / 0.15);
  }

  /* Don't shift content on mobile - panel overlays */
  :root[data-pikkolo-open="true"] .drawer-content {
    margin-right: 0;
  }

  /* Hide resize handle on mobile (no room to resize) */
  .pikkolo-resize-handle {
    display: none;
  }

  /* Taller input area for touch */
  .pikkolo-panel input[type="text"],
  .pikkolo-panel textarea {
    font-size: 16px; /* Prevents iOS zoom on focus */
    min-height: 44px; /* Touch-friendly target size */
  }

  /* Larger touch targets for buttons */
  .pikkolo-panel .btn-sm {
    min-height: 40px;
    min-width: 40px;
  }

  /* Full-width toggle button positioning */
  #pikkolo-toggle {
    bottom: 1rem;
    right: 1rem;
  }

  /* Ensure minimum 44px touch targets on mobile */
  .btn-sm,
  .btn-xs {
    min-height: 44px;
    min-width: 44px;
  }

}

/* Tablet: slightly smaller panel */
@media (min-width: 769px) and (max-width: 1024px) {
  .pikkolo-panel {
    max-width: 50vw;
  }
}

/* ============================================
   Autosave Pulse Animation
   ============================================ */

@keyframes save-pulse {
  0% { opacity: 1; }
  50% { opacity: 0.6; }
  100% { opacity: 1; }
}

.save-pulse {
  animation: save-pulse 0.6s ease-in-out;
}

/* ============================================
   Dark Mode Contrast Fixes
   ============================================ */

/* Badge colors handled by DaisyUI v5 theme (input.css nordic theme) */

/* Ensure text-base-content/50 meets WCAG AA in dark mode */
[data-theme="nordic"] .text-base-content\/50 {
  color: color-mix(in oklch, var(--color-base-content) 60%, transparent);
}


/* ============================================
   Drag-and-Drop Placeholder (future reordering)
   ============================================ */

/* Visual indicator for items that will support drag-and-drop reordering */
.draggable-item {
  cursor: grab;
}

.draggable-item:active {
  cursor: grabbing;
}

/* ============================================
   Sticky Filter Bar
   ============================================ */

.filter-bar-sticky {
  position: sticky;
  top: 0;
  z-index: 10;
  transition: box-shadow 0.15s ease;
}

.filter-bar-sticky.is-stuck {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

/* ============================================
   Mobile Bottom Tab Bar
   ============================================ */

/* Add bottom padding on mobile to avoid content behind dock */
@media (max-width: 1023px) {
  #main-content {
    padding-bottom: 4.5rem !important;
  }

  /* Larger touch targets on mobile */
  .menu a, .menu button {
    min-height: 2.75rem;
  }

  /* Table row actions: always visible on touch devices (no hover) */
  .table-modern .group .opacity-0 {
    opacity: 1;
  }
}

@media print {
  .drawer-side,
  .navbar,
  .toast,
  .fixed,
  .pikkolo-panel,
  .dock,
  .htmx-progress-indicator {
    display: none !important;
  }
  .drawer-content {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}
