/**
 * Main Custom Styles
 * Extends Tailwind CSS with custom components
 */

/* Alpine.js cloak */
[x-cloak] {
    display: none !important;
}

/* Form Input Styles */
.form-input,
.form-select,
.form-textarea {
    @apply w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition;
}

.form-input:disabled,
.form-select:disabled {
    @apply bg-gray-100 cursor-not-allowed opacity-60;
}

/* Readonly inputs with custom styling */
input[readonly] {
    cursor: default;
}

input[readonly].bg-blue-50 {
    opacity: 1 !important;
}

.form-input.error {
    @apply border-red-500 focus:ring-red-500 focus:border-red-500;
}

.form-label {
    @apply block text-sm font-medium text-gray-700 mb-1;
}

.form-label.required::after {
    content: " *";
    @apply text-red-500;
}

.form-help {
    @apply text-xs text-gray-500 mt-1;
}

.form-error {
    @apply text-xs text-red-600 mt-1 flex items-center gap-1;
}

.form-error::before {
    content: "⚠";
}

/* Form Group */
.form-group {
    @apply mb-6;
}

/* Checkbox and Radio Styles */
.form-checkbox,
.form-radio {
    @apply w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500;
}

.form-checkbox-label,
.form-radio-label {
    @apply ml-2 text-sm text-gray-700 cursor-pointer select-none;
}

/* Input with Icon */
.input-icon-wrapper {
    @apply relative;
}

.input-icon {
    @apply absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400;
}

.input-with-icon {
    @apply pl-10;
}

/* Range Slider */
input[type="range"] {
    @apply w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer;
}

input[type="range"]::-webkit-slider-thumb {
    @apply appearance-none w-5 h-5 bg-blue-600 rounded-full cursor-pointer;
}

input[type="range"]::-moz-range-thumb {
    @apply w-5 h-5 bg-blue-600 rounded-full cursor-pointer border-0;
}

/* File Upload */
.file-upload {
    @apply w-full px-4 py-3 border-2 border-dashed border-gray-300 rounded-lg hover:border-blue-500 transition cursor-pointer;
}

.file-upload-label {
    @apply flex flex-col items-center justify-center gap-2 text-gray-600;
}

.file-upload input[type="file"] {
    @apply hidden;
}

.file-preview {
    @apply flex items-center gap-3 p-3 bg-gray-50 rounded-lg border border-gray-200;
}

.file-preview-icon {
    @apply text-3xl;
}

.file-preview-info {
    @apply flex-1 min-w-0;
}

.file-preview-name {
    @apply font-medium text-gray-800 truncate;
}

.file-preview-size {
    @apply text-xs text-gray-500;
}

.file-preview-remove {
    @apply text-red-600 hover:text-red-700 cursor-pointer;
}

/* Card Styles */
.card {
    @apply bg-white border border-gray-200 rounded-lg shadow-sm;
}

.card-header {
    @apply px-6 py-4 border-b border-gray-200;
}

.card-body {
    @apply px-6 py-4;
}

.card-title {
    @apply text-lg font-semibold text-gray-800;
}

/* Info Box */
.info-box {
    @apply p-4 rounded-lg border;
}

.info-box.info {
    @apply bg-blue-50 border-blue-200 text-blue-800;
}

.info-box.warning {
    @apply bg-yellow-50 border-yellow-200 text-yellow-800;
}

.info-box.success {
    @apply bg-green-50 border-green-200 text-green-800;
}

.info-box.error {
    @apply bg-red-50 border-red-200 text-red-800;
}

/* Tooltip */
.tooltip-trigger {
    @apply relative inline-flex items-center justify-center w-5 h-5 text-xs text-white bg-gray-400 rounded-full cursor-help;
}

.tooltip-trigger:hover .tooltip-content {
    @apply visible opacity-100;
}

.tooltip-content {
    @apply invisible opacity-0 absolute bottom-full left-1/2 transform -translate-x-1/2 mb-2 px-3 py-2 text-xs text-white bg-gray-800 rounded-lg shadow-lg w-48 text-center transition-all z-10;
}

.tooltip-content::after {
    content: "";
    @apply absolute top-full left-1/2 transform -translate-x-1/2 border-4 border-transparent border-t-gray-800;
}

/* Grid Helpers */
.grid-2 {
    @apply grid grid-cols-1 md:grid-cols-2 gap-4;
}

.grid-3 {
    @apply grid grid-cols-1 md:grid-cols-3 gap-4;
}

.grid-4 {
    @apply grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4;
}

/* Section Header */
.section-header {
    @apply text-2xl font-bold text-gray-800 mb-6 pb-3 border-b-2 border-blue-600;
}

.section-subheader {
    @apply text-lg font-semibold text-gray-700 mb-4 mt-8;
}

/* Badge */
.badge {
    @apply inline-flex items-center px-3 py-1 rounded-full text-xs font-medium;
}

.badge.primary {
    @apply bg-blue-100 text-blue-800;
}

.badge.success {
    @apply bg-green-100 text-green-800;
}

.badge.warning {
    @apply bg-yellow-100 text-yellow-800;
}

.badge.danger {
    @apply bg-red-100 text-red-800;
}

/* Button Variants */
.btn {
    @apply px-6 py-3 rounded-lg font-medium transition cursor-pointer inline-flex items-center justify-center gap-2;
}

.btn.btn-primary {
    @apply bg-blue-600 hover:bg-blue-700 text-white;
}

.btn.btn-secondary {
    @apply bg-gray-200 hover:bg-gray-300 text-gray-800;
}

.btn.btn-success {
    @apply bg-green-600 hover:bg-green-700 text-white;
}

.btn.btn-danger {
    @apply bg-red-600 hover:bg-red-700 text-white;
}

.btn:disabled {
    @apply opacity-50 cursor-not-allowed;
}

/* Divider */
.divider {
    @apply my-8 border-t border-gray-200;
}

/* Loading Spinner */
.spinner {
    @apply inline-block w-6 h-6 border-3 border-blue-600 border-t-transparent rounded-full animate-spin;
}

/* Fade Transitions */
.fade-enter {
    @apply opacity-0;
}

.fade-enter-active {
    @apply transition-opacity duration-300;
}

.fade-enter-to {
    @apply opacity-100;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    min-width: 300px;
    max-width: 400px;
    padding: 16px 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    pointer-events: auto;
    animation: slideInRight 0.3s ease-out;
    border-left: 4px solid;
}

.toast.removing {
    animation: slideOutRight 0.3s ease-out;
}

.toast-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 14px;
}

.toast-content {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    color: #1f2937;
}

.toast-message {
    font-size: 13px;
    color: #6b7280;
    white-space: pre-line;
    line-height: 1.5;
}

.toast-close {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
    color: #9ca3af;
    transition: all 0.2s;
}

.toast-close:hover {
    background: #f3f4f6;
    color: #4b5563;
}

/* Toast Variants */
.toast.success {
    border-left-color: #10b981;
}

.toast.success .toast-icon {
    background: #d1fae5;
    color: #059669;
}

.toast.error {
    border-left-color: #ef4444;
}

.toast.error .toast-icon {
    background: #fee2e2;
    color: #dc2626;
}

.toast.warning {
    border-left-color: #f59e0b;
}

.toast.warning .toast-icon {
    background: #fef3c7;
    color: #d97706;
}

.toast.info {
    border-left-color: #3b82f6;
}

.toast.info .toast-icon {
    background: #dbeafe;
    color: #2563eb;
}

/* Animations */
@keyframes slideInRight {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

/* Responsive Utilities */
@media (max-width: 640px) {
    .container {
        @apply px-4;
    }

    .card-body {
        @apply px-4;
    }

    #toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
    }

    .toast {
        min-width: auto;
        max-width: none;
    }

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

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

/* Animacja pulsowania czerwonej ramki dla instrukcji podpisywania */
@keyframes pulseBorder {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    50% {
        box-shadow: 0 0 0 15px rgba(239, 68, 68, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

.animate-pulse-border {
    animation: pulseBorder 1.5s ease-out infinite;
}
