/**
 * Global custom styles for the Filament v5 admin panel.
 * Stack: Laravel 13 · Filament v5.4 · Tailwind CSS v4
 * Injected via AdminPanelProvider renderHook('panels::head.end').
 *
 * Sections:
 *   1. SVG Icon Constraints
 *   2. Transaction Page Layouts (Purchase, Sale, Layaway, Quotation, Stock)
 *   3. Form Inputs — Filament-consistent styling
 *   4. Tables — Purchase/Sale item tables
 *   5. Summary Cards
 *   6. Action Buttons
 *   7. Dark Mode Overrides
 */

/* ══════════════════════════════════════════════════════════════════════════
   1. SVG Icon Constraints — Global
   Prevents SVG icons from overflowing their containers across all pages.
   ══════════════════════════════════════════════════════════════════════════ */

/* All SVGs inside Filament containers — prevent flex expansion */
.fi-section svg,
.fi-modal svg,
.fi-ta-cell svg,
.fi-page svg:not(.fi-sidebar-item-icon):not(.fi-topbar-item-icon):not(.fi-logo-icon) {
    flex-shrink: 0;
}

/* Inline icons inside buttons and links — excludes decorative card icons */
button svg,
a svg {
    flex-shrink: 0;
    max-width: 1.25rem;
    max-height: 1.25rem;
}

/* Section heading icons */
.fi-section-header svg {
    max-width: 1.25rem;
    max-height: 1.25rem;
}

/* Fix section header icon vertical alignment */
.fi-section-header {
    align-items: center !important;
}

/* Remove top margin from section header icons that breaks centering */
.fi-section-header > .fi-icon.fi-size-lg,
.fi-section-header > .fi-icon.fi-size-md {
    margin-top: 0 !important;
}

/* Summary card decorative icons — allow full size (opacity-10 background icons) */
.fi-section .opacity-10 svg,
.fi-section .text-4xl svg,
.stat-icon svg {
    max-width: none !important;
    max-height: none !important;
}

/* Empty state illustrations — allow their specified Tailwind sizes */
.fi-section .text-center > svg,
.fi-page .text-center > svg,
.fi-section .text-center > .fi-icon-wrapper,
.fi-page .text-center > .fi-icon-wrapper {
    max-width: none;
    max-height: none;
}

/* Filament icon component wrappers — respect class sizes */
.fi-icon-wrapper svg {
    width: inherit;
    height: inherit;
}

/* Absolute-positioned overlay icons (search input) */
.relative > svg.pointer-events-none {
    flex-shrink: 0;
    max-width: 1.25rem;
    max-height: 1.25rem;
}

/* Shortcuts tooltip icons */
.shortcuts-tooltip svg {
    max-width: 0.875rem;
    max-height: 0.875rem;
}

/* ══════════════════════════════════════════════════════════════════════════
   2. Transaction Page Layouts
   Generic 2/3 + 1/3 (or 3/4 + 1/4) grid for all transaction pages.
   Use .transaction-layout on the container, .transaction-main on the left,
   .transaction-sidebar on the right.
   ══════════════════════════════════════════════════════════════════════════ */

.transaction-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 1024px) {
    /* Default: 2fr + 1fr ≈ 66% + 33% */
    .transaction-layout {
        grid-template-columns: 2fr 1fr;
    }
    /* Wide variant: 3fr + 1fr ≈ 75% + 25% (for purchase/sale with more table columns) */
    .transaction-layout--wide {
        grid-template-columns: 3fr 1fr;
    }
}

/* Sticky sidebar on lg screens */
@media (min-width: 1024px) {
    .transaction-sidebar {
        position: sticky;
        top: 1rem;
        align-self: start;
    }
}

/* Legacy class alias (used in create-purchase) */
.purchase-layout { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
@media (min-width: 1024px) {
    .purchase-layout { grid-template-columns: 3fr 1fr; }
}
.purchase-sidebar { }
@media (min-width: 1024px) {
    .purchase-sidebar { position: sticky; top: 1rem; align-self: start; }
}

/* ══════════════════════════════════════════════════════════════════════════
   3. Form Inputs — Consistent styling for custom blade pages
   Matches Filament v5's native input appearance.
   ══════════════════════════════════════════════════════════════════════════ */

.fi-custom-input {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
    border: 1px solid rgb(209 213 219); /* gray-300 */
    border-radius: 0.5rem;
    background-color: white;
    color: rgb(17 24 39); /* gray-900 */
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    outline: none;
}

.fi-custom-input:focus {
    border-color: rgb(59 130 246); /* blue-500 / primary */
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.fi-custom-input::placeholder {
    color: rgb(156 163 175); /* gray-400 */
}

/* Compact variant for table inline inputs */
.fi-custom-input--compact {
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
    border-radius: 0.375rem;
}

/* Select variant */
select.fi-custom-input {
    padding-right: 2rem;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    appearance: none;
}

/* Textarea variant */
textarea.fi-custom-input {
    resize: vertical;
    min-height: 4rem;
}

/* Label styling */
.fi-custom-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
    color: rgb(75 85 99); /* gray-600 */
}

.fi-custom-label .required {
    color: rgb(239 68 68); /* red-500 */
}

/* Error messages */
.fi-custom-error {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: rgb(220 38 38); /* red-600 */
}

/* ══════════════════════════════════════════════════════════════════════════
   4. Tables — Filament v5 native-style tables for custom pages
   ══════════════════════════════════════════════════════════════════════════ */

/* Wrapper: mimics Filament's fi-ta container */
.fi-ta-wrapper {
    overflow: hidden;
    border-radius: 0.75rem; /* rounded-xl */
    background: white;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); /* shadow-sm */
    outline: 1px solid rgba(0, 0, 0, 0.05); /* ring-1 ring-gray-950/5 */
}

.transaction-table {
    border-collapse: collapse;
    width: 100%;
}

.transaction-table th {
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    padding: 0.75rem 1rem;
    color: rgb(3 7 18); /* gray-950 */
    background: rgb(249 250 251); /* gray-50 */
    border-bottom: 1px solid rgb(229 231 235); /* gray-200 */
    text-align: start;
}

.transaction-table td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    font-size: 0.875rem;
    color: rgb(3 7 18); /* gray-950 */
}

.transaction-table tbody tr {
    transition: background-color 0.1s ease;
    border-bottom: 1px solid rgb(229 231 235); /* gray-200 */
}

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

.transaction-table tbody tr:hover {
    background: rgb(249 250 251); /* gray-50 */
}

/* Badges and pills inside tables */
.transaction-table .inline-flex,
.transaction-table .inline-block {
    white-space: nowrap;
}

/* Sortable header cells */
.transaction-table th[wire\\:click] {
    cursor: pointer;
    user-select: none;
}

.transaction-table th[wire\\:click]:hover {
    background: rgb(243 244 246); /* gray-100 */
}

/* Delete button inside table */
.transaction-table .btn-delete svg {
    max-width: 1rem;
    max-height: 1rem;
}

/* Inline table inputs */
.transaction-table td input[type="number"],
.transaction-table td input[type="date"] {
    font-size: 0.8125rem;
    padding: 0.25rem 0.5rem;
}

/* Filament-style pagination wrapper */
.fi-ta-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-top: 1px solid rgb(229 231 235); /* gray-200 */
}

.fi-ta-pagination .fi-pagination-items {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.fi-ta-pagination .fi-pagination-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.5rem;
    transition: background-color 0.15s ease, color 0.15s ease;
    cursor: pointer;
    border: none;
    background: transparent;
    color: rgb(107 114 128); /* gray-500 */
}

.fi-ta-pagination .fi-pagination-item:hover {
    background: rgb(243 244 246); /* gray-100 */
    color: rgb(17 24 39); /* gray-900 */
}

.fi-ta-pagination .fi-pagination-item--active {
    background: rgb(59 130 246); /* primary-600 */
    color: white;
    font-weight: 600;
}

.fi-ta-pagination .fi-pagination-item--active:hover {
    background: rgb(37 99 235); /* primary-700 */
    color: white;
}

.fi-ta-pagination .fi-pagination-item--disabled {
    color: rgb(209 213 219); /* gray-300 */
    cursor: not-allowed;
}

.fi-ta-pagination .fi-pagination-item--disabled:hover {
    background: transparent;
    color: rgb(209 213 219);
}

.fi-ta-pagination .fi-per-page select {
    padding: 0.375rem 2rem 0.375rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid rgb(209 213 219);
    border-radius: 0.5rem;
    background: white;
    color: rgb(17 24 39);
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.25em 1.25em;
}

.fi-ta-pagination .fi-pagination-info {
    font-size: 0.875rem;
    color: rgb(107 114 128); /* gray-500 */
}

/* Legacy alias */
.purchase-items-table th { font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
.purchase-items-table td input[type="number"],
.purchase-items-table td input[type="date"] { font-size: 0.8125rem; padding: 0.25rem 0.5rem; }
.purchase-items-table .btn-delete svg { max-width: 1rem; max-height: 1rem; }

/* ══════════════════════════════════════════════════════════════════════════
   5. Summary Cards
   ══════════════════════════════════════════════════════════════════════════ */

.summary-total {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(59, 130, 246, 0.15));
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgb(243 244 246); /* gray-100 */
}

.summary-row:last-child {
    border-bottom: none;
}

/* ══════════════════════════════════════════════════════════════════════════
   5b. Report Pages — Stat cards & layout
   ══════════════════════════════════════════════════════════════════════════ */

/* Lightweight stat card — replaces <x-filament::section> for KPI metrics */
.report-stat-card {
    position: relative;
    overflow: hidden;
    padding: 1.25rem 1.5rem;
    border-radius: 0.75rem;
    border: 1px solid rgb(229 231 235); /* gray-200 */
    background: white;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.report-stat-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    transform: translateY(-1px);
}

.report-stat-card .stat-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: rgb(107 114 128); /* gray-500 */
    margin-bottom: 0.5rem;
}

.report-stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    color: rgb(17 24 39); /* gray-900 */
}

.report-stat-card .stat-hint {
    font-size: 0.75rem;
    color: rgb(156 163 175); /* gray-400 */
    margin-top: 0.25rem;
}

.report-stat-card .stat-icon {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.08;
}

.report-stat-card .stat-icon svg {
    width: 3.5rem;
    height: 3.5rem;
    max-width: none;
    max-height: none;
}

/* Colored accent borders for stat cards */
.report-stat-card--blue    { border-left: 3px solid rgb(59 130 246);  }
.report-stat-card--green   { border-left: 3px solid rgb(22 163 74);  }
.report-stat-card--red     { border-left: 3px solid rgb(220 38 38);  }
.report-stat-card--orange  { border-left: 3px solid rgb(234 88 12);  }
.report-stat-card--purple  { border-left: 3px solid rgb(147 51 234); }
.report-stat-card--yellow  { border-left: 3px solid rgb(202 138 4);  }

/* Dark mode — stat cards */
.dark .report-stat-card {
    background: rgb(31 41 55); /* gray-800 */
    border-color: rgb(55 65 81); /* gray-700 */
}

.dark .report-stat-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.dark .report-stat-card .stat-label {
    color: rgb(156 163 175); /* gray-400 */
}

.dark .report-stat-card .stat-value {
    color: rgb(243 244 246); /* gray-100 */
}

.dark .report-stat-card .stat-hint {
    color: rgb(107 114 128); /* gray-500 */
}

.dark .report-stat-card--blue    { border-left-color: rgb(96 165 250);  }
.dark .report-stat-card--green   { border-left-color: rgb(74 222 128);  }
.dark .report-stat-card--red     { border-left-color: rgb(248 113 113); }
.dark .report-stat-card--orange  { border-left-color: rgb(251 146 60);  }
.dark .report-stat-card--purple  { border-left-color: rgb(192 132 252); }
.dark .report-stat-card--yellow  { border-left-color: rgb(250 204 21);  }

/* Stats grid — consistent gap */
.report-stats-grid {
    display: grid;
    gap: 1.25rem;
    grid-template-columns: repeat(1, 1fr);
}

@media (min-width: 640px) {
    .report-stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
    .report-stats-grid { grid-template-columns: repeat(3, 1fr); }
    .report-stats-grid--4 { grid-template-columns: repeat(4, 1fr); }
    .report-stats-grid[style*="--cols:2"] { grid-template-columns: repeat(2, 1fr); }
}

/* ══════════════════════════════════════════════════════════════════════════
   6. Action Buttons
   ══════════════════════════════════════════════════════════════════════════ */

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: white;
    background: rgb(22 163 74); /* green-600 */
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.15s ease;
    white-space: nowrap;
}

.btn-primary:hover {
    background: rgb(21 128 61); /* green-700 */
}

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

.btn-primary svg {
    max-width: 1.25rem;
    max-height: 1.25rem;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: rgb(55 65 81); /* gray-700 */
    background: transparent;
    border: 1px solid rgb(209 213 219); /* gray-300 */
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color 0.15s ease;
    white-space: nowrap;
}

.btn-secondary:hover {
    background: rgb(249 250 251); /* gray-50 */
}

.btn-secondary svg {
    max-width: 1rem;
    max-height: 1rem;
}

.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    color: rgb(239 68 68); /* red-500 */
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.btn-danger:hover {
    background: rgb(254 242 242); /* red-50 */
}

.btn-danger svg {
    max-width: 1rem;
    max-height: 1rem;
}

/*
 * Create Purchase sidebar: Filament <x-filament::button> often renders w-full.
 * Keeps Save + Clear on one row inside the narrow column.
 */
.purchase-sidebar .purchase-action-buttons {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.purchase-sidebar .purchase-action-buttons .purchase-action-btn {
    width: auto !important;
    max-width: none;
    flex: 0 0 auto;
}

/* ══════════════════════════════════════════════════════════════════════════
   7. Dark Mode — Complete overrides for custom pages
   ══════════════════════════════════════════════════════════════════════════ */

/* Inputs */
.dark .fi-custom-input {
    background-color: rgb(31 41 55); /* gray-800 */
    border-color: rgb(75 85 99); /* gray-600 */
    color: rgb(243 244 246); /* gray-100 */
}

.dark .fi-custom-input:focus {
    border-color: rgb(96 165 250); /* blue-400 */
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.25);
}

.dark .fi-custom-input::placeholder {
    color: rgb(107 114 128); /* gray-500 */
}

/* Labels */
.dark .fi-custom-label {
    color: rgb(156 163 175); /* gray-400 */
}

/* Table wrapper */
.dark .fi-ta-wrapper {
    background: rgb(17 24 39); /* gray-900 */
    outline-color: rgba(255, 255, 255, 0.1); /* ring-white/10 */
}

/* Tables */
.dark .transaction-table th {
    color: white;
    background: rgba(255, 255, 255, 0.05); /* white/5 */
    border-color: rgba(255, 255, 255, 0.05);
}

.dark .transaction-table th[wire\:click]:hover {
    background: rgba(255, 255, 255, 0.1); /* white/10 */
}

.dark .transaction-table td {
    color: white;
}

.dark .transaction-table tbody tr {
    border-color: rgba(255, 255, 255, 0.05);
}

.dark .transaction-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.05); /* white/5 */
}

/* Pagination dark mode */
.dark .fi-ta-pagination {
    border-color: rgba(255, 255, 255, 0.05);
}

.dark .fi-ta-pagination .fi-pagination-item {
    color: rgb(156 163 175); /* gray-400 */
}

.dark .fi-ta-pagination .fi-pagination-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.dark .fi-ta-pagination .fi-pagination-item--active {
    background: rgb(59 130 246);
    color: white;
}

.dark .fi-ta-pagination .fi-pagination-item--disabled {
    color: rgb(75 85 99); /* gray-600 */
}

.dark .fi-ta-pagination .fi-per-page select {
    background-color: rgb(31 41 55);
    border-color: rgb(75 85 99);
    color: rgb(243 244 246);
}

.dark .fi-ta-pagination .fi-pagination-info {
    color: rgb(156 163 175);
}

/* Summary */
.dark .summary-total {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(59, 130, 246, 0.25));
}

.dark .summary-row {
    border-color: rgb(55 65 81); /* gray-700 */
}

/* Buttons */
.dark .btn-secondary {
    color: rgb(209 213 219); /* gray-300 */
    border-color: rgb(75 85 99); /* gray-600 */
}

.dark .btn-secondary:hover {
    background: rgb(55 65 81); /* gray-700 */
}

.dark .btn-danger:hover {
    background: rgba(127, 29, 29, 0.2); /* red-900/20 */
}

/* Generic text helpers (fallbacks for Tailwind v3 classes in dark mode) */
.dark .text-gray-700 { color: rgb(209 213 219); }
.dark .text-gray-900 { color: rgb(243 244 246); }
.dark .text-gray-600 { color: rgb(156 163 175); }
.dark .text-gray-500 { color: rgb(107 114 128); }
.dark .bg-gray-50 { background-color: rgb(31 41 55); }
.dark .bg-white { background-color: rgb(17 24 39); }
.dark .border-gray-200 { border-color: rgb(55 65 81); }
.dark .border-gray-100 { border-color: rgb(55 65 81); }
.dark .border-gray-300 { border-color: rgb(75 85 99); }

/* Legacy inline input overrides (for pages not yet using .fi-custom-input) */
.dark input[type="text"],
.dark input[type="number"],
.dark input[type="date"],
.dark input[type="month"],
.dark input[type="tel"],
.dark select,
.dark textarea {
    background-color: rgb(31 41 55);
    border-color: rgb(75 85 99);
    color: rgb(243 244 246);
}

/* Colored backgrounds in dark mode */
.dark .bg-blue-50 { background-color: rgba(30, 58, 138, 0.2); }
.dark .bg-green-50 { background-color: rgba(20, 83, 45, 0.2); }
.dark .bg-orange-50 { background-color: rgba(124, 45, 18, 0.2); }
.dark .bg-red-50 { background-color: rgba(127, 29, 29, 0.2); }

/* Search results in dark mode */
.dark .hover\:bg-blue-50:hover { background-color: rgba(30, 58, 138, 0.2) !important; }

/* Gradient summary background in dark mode */
.dark .bg-gradient-to-b.from-blue-50.to-blue-100 {
    background: linear-gradient(to bottom, rgba(30, 58, 138, 0.15), rgba(30, 58, 138, 0.25));
}
