/* ============================================================
   Kasali ERP - Custom styles
   Tailwind CSS handles most styling. This file provides:
   - Print styles
   - Custom scrollbar for dark mode
   - Theme transition utilities
   - Minor overrides
   ============================================================ */

/* ---- Theme transitions ---- */
html {
    transition: background-color 0.2s ease, color 0.2s ease;
}

html.dark body {
    color-scheme: dark;
}

/* ---- Custom scrollbar (dark mode) ---- */
.dark ::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.dark ::-webkit-scrollbar-track {
    background: #1f2937; /* gray-800 */
}

.dark ::-webkit-scrollbar-thumb {
    background: #4b5563; /* gray-600 */
    border-radius: 4px;
}

.dark ::-webkit-scrollbar-thumb:hover {
    background: #6b7280; /* gray-500 */
}

/* Light mode scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f3f4f6; /* gray-100 */
}

::-webkit-scrollbar-thumb {
    background: #d1d5db; /* gray-300 */
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #9ca3af; /* gray-400 */
}

/* ---- Form focus ring consistency ---- */
input:focus,
select:focus,
textarea:focus {
    outline: none;
}

/* ============================================================
   Tom Select — Kasali ERP přizpůsobení
   ============================================================ */

/* Light mode — shodné s Tailwind inputy (px-3 py-2 rounded-lg border-gray-300) */
.ts-wrapper .ts-control {
    border: 1px solid #d1d5db;       /* border-gray-300 */
    border-radius: 0.5rem;           /* rounded-lg */
    padding: 0.5rem 2rem 0.5rem 0.75rem; /* py-2 px-3 + prostor pro šipku vpravo */
    min-height: 38px;
    font-size: 0.875rem;             /* text-sm */
    line-height: 1.25rem;            /* 20px — shodné s inputy */
    background-color: #ffffff;
    color: #111827;                  /* text-gray-900 */
    box-shadow: none;
    box-sizing: border-box;
}

.ts-wrapper .ts-control:focus,
.ts-wrapper.focus .ts-control {
    border-color: #3b82f6;           /* focus:border-primary-500 */
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3); /* focus:ring-2 ring-primary-500 */
}

.ts-wrapper .ts-control > input {
    color: #111827;
    font-size: 0.875rem;
    line-height: 1.25rem;
    padding: 0 !important;
    margin: 0 !important;
}

.ts-wrapper .ts-control > input::placeholder {
    color: #9ca3af;                  /* text-gray-400 */
}

/* Plná šířka wrapperu */
.ts-wrapper {
    width: 100%;
}

.ts-wrapper.single .ts-control::after {
    /* Šipka dropdownu — jemnější, shodná s nativním select */
    border-color: #9ca3af transparent transparent;
}

.ts-dropdown {
    border-radius: 0.5rem;
    border-color: #d1d5db;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    font-size: 0.875rem;
    z-index: 9999;
}

.ts-dropdown .option {
    padding: 0.5rem 0.75rem;
}

.ts-dropdown .active {
    background-color: #eff6ff;
    color: #1d4ed8;
}

.ts-dropdown .dropdown-input-wrap {
    padding: 0.5rem;
    border-bottom: 1px solid #e5e7eb;
}

.ts-dropdown .dropdown-input {
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    padding: 0.375rem 0.5rem;
    font-size: 0.875rem;
}

.ts-dropdown .no-results {
    padding: 0.75rem;
    text-align: center;
    color: #6b7280;
    font-size: 0.875rem;
}

/* Dark mode — shodné s Tailwind dark:border-gray-600 dark:bg-gray-700 dark:text-white */
.dark .ts-wrapper .ts-control {
    background-color: #374151;       /* dark:bg-gray-700 */
    border-color: #4b5563;           /* dark:border-gray-600 */
    color: #ffffff;                  /* dark:text-white — shodné s inputy */
}

.dark .ts-wrapper .ts-control:focus,
.dark .ts-wrapper.focus .ts-control {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.dark .ts-wrapper .ts-control > input {
    color: #f9fafb;
}

.dark .ts-wrapper .ts-control > input::placeholder {
    color: #6b7280;
}

.dark .ts-wrapper.single .ts-control::after {
    border-color: #6b7280 transparent transparent;
}

.dark .ts-dropdown {
    background-color: #1f2937;
    border-color: #4b5563;
}

.dark .ts-dropdown .option {
    color: #d1d5db;
}

.dark .ts-dropdown .option:hover,
.dark .ts-dropdown .active {
    background-color: #374151;
    color: #93c5fd;
}

.dark .ts-dropdown .dropdown-input-wrap {
    border-bottom-color: #4b5563;
}

.dark .ts-dropdown .dropdown-input {
    background-color: #374151;
    border-color: #4b5563;
    color: #f9fafb;
}

.dark .ts-dropdown .no-results {
    color: #6b7280;
}

/* Odstranit původní select border (Tom Select skryje originál) */
.ts-wrapper + select[hidden] {
    display: none !important;
}

/* ============================================================
   Flatpickr — Calendar/clock icon wrapper
   ============================================================ */

/* Wrapper for date/time inputs with icon */
.flatpickr-wrapper {
    position: relative;
    width: 100%;
}

/* Calendar/clock icon positioned inside the input */
.flatpickr-icon {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: #9ca3af; /* gray-400 */
    display: flex;
    align-items: center;
}

.dark .flatpickr-icon {
    color: #6b7280; /* gray-500 */
}

/* Ensure the input has right padding for the icon */
.flatpickr-wrapper .flatpickr-input,
.flatpickr-wrapper input.flatpickr-input.active {
    padding-right: 2.5rem !important;
}

/* altInput: viditelný vstup pro uživatele */
.flatpickr-wrapper input.form-control[readonly],
.flatpickr-wrapper input.flatpickr-alt-input {
    padding-right: 2.5rem !important;
    cursor: pointer !important;
}

/* ============================================================
   Flatpickr — Kasali ERP přizpůsobení
   ============================================================ */

/* Light mode */
.flatpickr-input {
    cursor: pointer !important;
}

/* Dark mode */
.dark .flatpickr-calendar {
    background: #1f2937;
    border-color: #4b5563;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
}

.dark .flatpickr-months .flatpickr-month,
.dark .flatpickr-current-month .flatpickr-monthDropdown-months {
    background: #1f2937;
    color: #f9fafb;
}

.dark .flatpickr-current-month input.cur-year {
    color: #f9fafb;
}

.dark .flatpickr-weekdays {
    background: #1f2937;
}

.dark span.flatpickr-weekday {
    background: #1f2937;
    color: #9ca3af;
}

.dark .flatpickr-day {
    color: #d1d5db;
    border-color: transparent;
}

.dark .flatpickr-day:hover {
    background: #374151;
    border-color: #4b5563;
}

.dark .flatpickr-day.selected {
    background: #2563eb;
    border-color: #2563eb;
    color: #ffffff;
}

.dark .flatpickr-day.today {
    border-color: #3b82f6;
}

.dark .flatpickr-day.today:hover {
    background: #3b82f6;
    color: #ffffff;
}

.dark .flatpickr-day.prevMonthDay,
.dark .flatpickr-day.nextMonthDay {
    color: #4b5563;
}

.dark .flatpickr-months .flatpickr-prev-month,
.dark .flatpickr-months .flatpickr-next-month {
    fill: #9ca3af;
}

.dark .flatpickr-months .flatpickr-prev-month:hover,
.dark .flatpickr-months .flatpickr-next-month:hover {
    fill: #f9fafb;
}

.dark .flatpickr-time input,
.dark .flatpickr-time .flatpickr-am-pm {
    background: #1f2937;
    color: #f9fafb;
    border-color: #4b5563;
}

.dark .flatpickr-time .flatpickr-time-separator {
    color: #9ca3af;
}

.dark .numInputWrapper:hover {
    background: #374151;
}

/* ============================================================
   Turbo progress bar — stylized loading indicator
   ============================================================ */

.turbo-progress-bar {
    height: 3px;
    background-color: #3b82f6; /* primary-500 */
    z-index: 9999;
}

.dark .turbo-progress-bar {
    background-color: #60a5fa; /* primary-400 */
}

/* ---- Table hover row (dark variant not in Tailwind by default) ---- */
.dark .hover\:bg-gray-750:hover {
    background-color: rgba(55, 65, 81, 0.5);
}

/* ============================================================
   Docs content — prose styling for rendered Markdown
   ============================================================ */

.docs-content {
    line-height: 1.75;
    color: #374151; /* gray-700 */
}

.dark .docs-content {
    color: #d1d5db; /* gray-300 */
}

.docs-content h1 {
    font-size: 1.875rem;
    font-weight: 800;
    margin-top: 0;
    margin-bottom: 1rem;
    color: #111827;
    line-height: 1.2;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 0.75rem;
}

.dark .docs-content h1 {
    color: #f9fafb;
    border-bottom-color: #374151;
}

.docs-content h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    color: #1f2937;
    line-height: 1.3;
    border-bottom: 1px solid #f3f4f6;
    padding-bottom: 0.5rem;
}

.dark .docs-content h2 {
    color: #e5e7eb;
    border-bottom-color: #1f2937;
}

.docs-content h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    color: #374151;
}

.dark .docs-content h3 {
    color: #d1d5db;
}

.docs-content h4 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
    color: #4b5563;
}

.dark .docs-content h4 {
    color: #9ca3af;
}

.docs-content p {
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
}

.docs-content a {
    color: #2563eb;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.dark .docs-content a {
    color: #60a5fa;
}

.docs-content a:hover {
    color: #1d4ed8;
}

.dark .docs-content a:hover {
    color: #93c5fd;
}

.docs-content strong {
    font-weight: 600;
    color: #111827;
}

.dark .docs-content strong {
    color: #f9fafb;
}

.docs-content ul {
    list-style-type: disc;
    padding-left: 1.5rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.docs-content ol {
    list-style-type: decimal;
    padding-left: 1.5rem;
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

.docs-content li {
    margin-top: 0.25rem;
    margin-bottom: 0.25rem;
}

.docs-content li > ul,
.docs-content li > ol {
    margin-top: 0.25rem;
    margin-bottom: 0.25rem;
}

.docs-content blockquote {
    border-left: 4px solid #3b82f6;
    padding: 0.75rem 1rem;
    margin: 1rem 0;
    background-color: #eff6ff;
    border-radius: 0 0.5rem 0.5rem 0;
    color: #1e40af;
}

.dark .docs-content blockquote {
    background-color: rgba(59, 130, 246, 0.1);
    border-left-color: #3b82f6;
    color: #93c5fd;
}

/* Pozor blocks — amber/yellow styling */
.docs-content blockquote:has(strong:first-child) {
    border-left-color: #3b82f6;
}

.docs-content code {
    background-color: #f3f4f6;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
    color: #dc2626;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.dark .docs-content code {
    background-color: #1f2937;
    color: #f87171;
}

.docs-content pre {
    background-color: #1f2937;
    color: #e5e7eb;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin: 1rem 0;
    font-size: 0.875rem;
    line-height: 1.5;
}

.docs-content pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: inherit;
}

.dark .docs-content pre {
    background-color: #111827;
    border: 1px solid #374151;
}

.docs-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.875rem;
}

.docs-content table th {
    background-color: #f9fafb;
    border: 1px solid #e5e7eb;
    padding: 0.5rem 0.75rem;
    text-align: left;
    font-weight: 600;
    color: #374151;
}

.dark .docs-content table th {
    background-color: #1f2937;
    border-color: #374151;
    color: #d1d5db;
}

.docs-content table td {
    border: 1px solid #e5e7eb;
    padding: 0.5rem 0.75rem;
    color: #4b5563;
}

.dark .docs-content table td {
    border-color: #374151;
    color: #9ca3af;
}

.docs-content table tr:hover td {
    background-color: #f9fafb;
}

.dark .docs-content table tr:hover td {
    background-color: rgba(55, 65, 81, 0.5);
}

.docs-content hr {
    border: 0;
    border-top: 1px solid #e5e7eb;
    margin: 2rem 0;
}

.dark .docs-content hr {
    border-top-color: #374151;
}

/* ============================================================
   Form field info tooltips
   ============================================================ */

.field-info {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin-left: 0.25rem;
    padding: 0.25rem;
    cursor: help;
}

.field-info .info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.125rem;
    height: 1.125rem;
    border-radius: 9999px;
    background-color: #e5e7eb; /* gray-200 */
    color: #6b7280; /* gray-500 */
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
    transition: background-color 0.15s, color 0.15s;
}

.field-info:hover .info-icon {
    background-color: #3b82f6; /* primary-500 */
    color: #ffffff;
}

.dark .field-info .info-icon {
    background-color: #4b5563; /* gray-600 */
    color: #9ca3af; /* gray-400 */
}

.dark .field-info:hover .info-icon {
    background-color: #3b82f6;
    color: #ffffff;
}

.field-info .info-tooltip {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 0.75rem;
    background-color: #1f2937; /* gray-800 */
    color: #f9fafb; /* gray-50 */
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.4;
    border-radius: 0.5rem;
    white-space: normal;
    width: max-content;
    max-width: 280px;
    z-index: 50;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    pointer-events: none;
}

.field-info .info-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #1f2937;
}

.dark .field-info .info-tooltip {
    background-color: #374151; /* gray-700 */
    color: #e5e7eb;
}

.dark .field-info .info-tooltip::after {
    border-top-color: #374151;
}

.field-info:hover .info-tooltip {
    display: block;
}

/* ============================================================
   Responsive — column visibility + filter collapse
   ============================================================ */

/* Mobilní filtr toggle — na sm+ zobrazit obsah, skrýt summary */
@media (min-width: 640px) {
    details.filter-details > summary { display: none; }
    details.filter-details > div { display: block !important; }
}
summary.filter-toggle { list-style: none; cursor: pointer; }
summary.filter-toggle::-webkit-details-marker { display: none; }
summary.filter-toggle::marker { display: none; content: ''; }

/* Chevron rotace při otevření */
details.filter-details[open] > summary .filter-chevron {
    transform: rotate(180deg);
}

/* ---- Print styles ---- */
@media print {
    /* Responzivně skryté sloupce — v tisku zobrazit */
    .hidden.md\:table-cell,
    .hidden.lg\:table-cell {
        display: table-cell !important;
    }
    .hidden.sm\:table-cell {
        display: table-cell !important;
    }
    .hidden.md\:block,
    .hidden.lg\:block {
        display: block !important;
    }

    /* Mobilní subtitle skrýt v tisku (data je ve vlastním sloupci) */
    .mobile-subtitle {
        display: none !important;
    }
    /* Hide notification bell */
    .notification-bell {
        display: none !important;
    }

    /* Hide navigation and interactive controls */
    aside,
    header,
    [data-controller="sidebar"],
    [data-action*="sidebar"],
    [data-action*="theme"],
    [data-controller="date-preset"],
    [data-controller="interactive-table"] [data-interactive-table-target="search"],
    [data-controller="interactive-table"] [data-interactive-table-target="pageSize"],
    [data-controller="interactive-table"] [data-interactive-table-target="info"],
    [data-controller="global-search"],
    #toast-container,
    .no-print {
        display: none !important;
    }

    /* Hide pagination, sort indicators, filter button and modal in print */
    [data-interactive-table-target="pagination"],
    [data-interactive-table-target="filterButton"],
    .table-filter-modal,
    .sort-indicator {
        display: none !important;
    }

    /* Show ALL table rows (override interactive-table JS hiding) */
    [data-interactive-table-target="body"] tr {
        display: table-row !important;
    }

    /* Hide filter form submit buttons */
    form button[type="submit"],
    form .date-preset-buttons {
        display: none !important;
    }

    /* Show print header (hidden on screen) */
    .print-header {
        display: block !important;
        margin-bottom: 12px;
    }

    /* Reset background and text for print */
    body,
    .dark body {
        background-color: #ffffff !important;
        color: #000000 !important;
    }

    /* Dark mode text reset */
    .dark .text-white,
    .dark .text-gray-100,
    .dark .text-gray-200,
    .dark .text-gray-300 {
        color: #000000 !important;
    }

    .dark .bg-gray-800,
    .dark .bg-gray-900,
    .dark .bg-gray-900\/50 {
        background-color: #ffffff !important;
    }

    .dark .border-gray-700,
    .dark .border-gray-600 {
        border-color: #d1d5db !important;
    }

    /* Full width for main content */
    main {
        padding: 0 !important;
        margin: 0 !important;
    }

    .flex {
        display: block !important;
    }

    /* Restore table layout */
    table {
        display: table !important;
    }

    thead {
        display: table-header-group !important;
    }

    tbody {
        display: table-row-group !important;
    }

    tfoot {
        display: table-footer-group !important;
    }

    tr {
        display: table-row !important;
    }

    td, th {
        display: table-cell !important;
    }

    /* Ensure tables print nicely */
    table {
        width: 100% !important;
        border-collapse: collapse !important;
    }

    th, td {
        border: 1px solid #d1d5db !important;
        padding: 4px 8px !important;
        font-size: 11px !important;
    }

    /* Remove shadows and rounded corners for print */
    .shadow-sm,
    .shadow-lg,
    .shadow-xl {
        box-shadow: none !important;
    }

    .rounded-xl,
    .rounded-2xl,
    .rounded-lg {
        border-radius: 0 !important;
    }

    /* Chart canvas — keep on same page */
    canvas {
        page-break-inside: avoid;
        max-height: 300px !important;
    }

    /* Page breaks */
    .page-break-before {
        page-break-before: always;
    }

    .page-break-after {
        page-break-after: always;
    }

    .no-break {
        page-break-inside: avoid;
    }
}

/* Print header — visible only in print */
.print-header {
    display: none;
}
