/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

@tailwind base;
@tailwind components;
@tailwind utilities;

/* Custom styles */
@layer base {
  :root {
    --primary: #3D9970;
    --text: #333333;
    --light-bg: #F7F7F7;
    --border: #E0E0E0;
  }

  /* Prevent horizontal scroll on mobile */
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }
}

/* Common components */
@layer components {
  /* Drag handle - smooth opacity transitions */
  .drag-handle {
    transition: opacity 0.15s ease-out;
  }

  /* Collapsible sections - smooth grid-based animation */
  .collapsible-content {
    display: grid;
    grid-template-rows: 1fr;
    overflow: hidden;
    transition: grid-template-rows 0.2s ease-out;
  }

  .collapsible-content.collapsed {
    grid-template-rows: 0fr;
  }

  .collapsible-content > * {
    overflow: hidden;
  }

  /* Hide number input spinners */
  input[type="number"]::-webkit-outer-spin-button,
  input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }

  input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
  }

  /* Seamless editing - make form fields look like text */
  .field-as-text {
    border: none;
    background: transparent;
    padding: 2px 4px;
    margin: -2px -4px;
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
    outline: none;
    cursor: text;
    width: auto;
    min-width: 60px;
    border-radius: 4px;
  }

  /* Instant feedback on interaction */
  .field-as-text:active {
    background: rgba(0, 0, 0, 0.04);
  }

  /* Focused state - subtle indication */
  .field-as-text:focus {
    background: rgba(0, 0, 0, 0.02);
    border: none;
    outline: none;
  }

  /* Description field (textarea) */
  .description-field {
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.4;
    field-sizing: content; /* Auto-resize without JS reflows */
  }

  /* Amount field */
  .amount-field {
    font-size: 1rem;
    font-weight: 600;
    text-align: right;
    width: 100px;
  }

  .amount-field.mode-expense {
    color: rgb(220, 38, 38);
  }

  .amount-field.mode-income {
    color: rgb(16, 185, 129);
  }

  /* Actions panel - slides in/out */
  .actions-panel {
    overflow: hidden;
    transition: max-height 0.2s ease-out;
  }

  .actions-panel.visible {
    max-height: 120px;
  }

  /* Saving state */
  .saving .field-as-text:focus {
    animation: pulse-saving 1s ease-in-out infinite;
  }

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

  /* Success flash */
  @keyframes flash-success {
    0%, 100% { background-color: transparent; }
    50% { background-color: rgba(16, 185, 129, 0.15); }
  }

  .save-success {
    animation: flash-success 0.6s ease;
  }

  /* Error state */
  .field-error {
    border-color: rgb(239, 68, 68) !important;
    background: rgba(239, 68, 68, 0.05) !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
  }

  /* Mobile: Numeric input */
  @media (max-width: 768px) {
    /* Prevent iOS zoom on focus - font-size must be >= 16px */
    .description-field {
      font-size: 1rem; /* 16px - prevents iOS auto-zoom */
    }

    .amount-field {
      font-size: 1.125rem; /* 18px */
    }

    .field-as-text:focus {
      padding: 8px 12px;
      margin: -10px -14px;
    }
  }

  /* Chat message animations */
  .chat-message {
    animation: slideInMessage 0.2s ease-out;
  }

  @keyframes slideInMessage {
    from {
      opacity: 0;
      transform: translateY(10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* View transitions for groups */
  ::view-transition-old(group-*),
  ::view-transition-new(group-*) {
    animation-duration: 0.15s;
  }

  /* Formula Editor */
  .formula-editor {
    min-height: 1.5em;
    min-width: 150px;
    width: fit-content;
    max-width: 400px;
    padding: 8px 12px;
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
    outline: none;
    cursor: text;
    border-radius: 6px;
    white-space: nowrap;
    background: white;
    border: 1px solid #d1d5db;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    text-align: left;
    caret-color: currentColor;
  }

  .formula-editor:focus {
    background: white;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    caret-color: #1d4ed8;
  }

  /* Formula chips - visual pills for item references */
  .formula-chip {
    display: inline-block;
    background: #e0f2fe;
    color: #0369a1;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.875em;
    font-weight: 500;
    margin: 0 1px;
    user-select: none;
    cursor: default;
    vertical-align: baseline;
    border: 1px solid #bae6fd;
  }

  .formula-chip.selected {
    background: #fecaca;
    color: #b91c1c;
    border-color: #fca5a5;
  }

  /* Formula dropdown - autocomplete suggestions */
  .formula-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    margin-top: 4px;
    opacity: 1;
    transition: opacity 0.1s ease-out;
  }

  .formula-dropdown.hidden {
    opacity: 0;
    pointer-events: none;
  }

  .formula-dropdown-item {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .formula-dropdown-item:hover,
  .formula-dropdown-item.selected {
    background: #f3f4f6;
  }

  .formula-dropdown-item.selected {
    background: #e0f2fe;
  }

}
