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

@keyframes admin-low-stock-blink {
    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgb(220 38 38 / 0.55);
    }
    50% {
        opacity: 0.88;
        box-shadow: 0 0 24px 6px rgb(220 38 38 / 0.45);
    }
}

.admin-low-stock-alert {
    animation: admin-low-stock-blink 1.1s ease-in-out infinite;
}

@layer components {
    .admin-card {
        @apply relative overflow-hidden rounded-2xl border border-slate-200/90 bg-white p-6 shadow-sm transition-all duration-300 hover:shadow-xl hover:shadow-slate-200/40 dark:border-slate-800 dark:bg-slate-900 dark:hover:shadow-none dark:hover:border-slate-700;
        animation: card-in 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
    }

    .admin-card-glass {
        @apply relative overflow-hidden rounded-2xl border border-white/20 bg-white/70 p-6 backdrop-blur-md shadow-lg dark:border-slate-800/50 dark:bg-slate-900/80;
    }

    .admin-card-title {
        @apply mb-4 text-xs font-black uppercase tracking-[0.2em] text-slate-400 dark:text-slate-500;
    }

    .admin-stat-value {
        @apply text-3xl font-black tracking-tighter text-slate-900 dark:text-white;
    }

    .admin-label {
        @apply block text-xs font-bold uppercase tracking-wider text-slate-500 dark:text-slate-400 mb-1.5;
    }

    .admin-input {
        @apply mt-1 block w-full rounded-xl border-slate-200 bg-white px-4 py-2.5 text-sm text-slate-900 shadow-sm transition focus:border-amber-500 focus:ring-amber-500 dark:border-slate-800 dark:bg-slate-950/60 dark:text-slate-100;
    }

    .admin-btn-primary {
        @apply inline-flex items-center justify-center gap-2 rounded-xl bg-slate-950 px-5 py-2.5 text-sm font-bold text-white shadow-lg transition hover:bg-slate-800 active:scale-[0.98] dark:bg-amber-500 dark:text-slate-950 dark:hover:bg-amber-400;
    }

    .admin-btn-secondary {
        @apply inline-flex items-center justify-center gap-2 rounded-xl border border-slate-200 bg-white px-4 py-2 text-sm font-bold text-slate-700 transition hover:bg-slate-50 hover:border-slate-300 dark:border-slate-800 dark:bg-slate-900 dark:text-slate-200 dark:hover:bg-slate-800 dark:hover:border-slate-700;
    }

    .admin-table-shell {
        @apply overflow-hidden rounded-2xl border border-slate-200/90 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900;
        animation: card-in 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
    }

    .admin-table-shell table {
        @apply min-w-full text-sm text-slate-800 dark:text-slate-200;
    }

    .admin-table-shell thead {
        @apply border-b border-slate-100 bg-slate-50/50 dark:border-slate-800 dark:bg-slate-800/50;
    }

    .admin-table-shell tbody tr {
        @apply border-b border-slate-50 transition-colors duration-150 dark:border-slate-800/50;
        animation: admin-row-in 0.4s ease backwards;
    }

    .admin-table-shell tbody tr:hover {
        @apply bg-slate-50/50 dark:bg-slate-800/30;
    }

    .admin-th-sortable {
        @apply select-none whitespace-nowrap transition-colors hover:bg-slate-100/80 dark:hover:bg-slate-700/50;
    }

    .admin-th-sortable .sort-ind {
        @apply ml-1 inline-block text-xs font-normal text-slate-400 opacity-60 dark:text-slate-500;
    }

    .admin-th-sortable.sort-active .sort-ind {
        @apply text-amber-600 opacity-100 dark:text-amber-400;
    }

    .admin-muted {
        @apply text-slate-400 dark:text-slate-500;
    }

    .admin-link-action {
        @apply text-sm font-medium text-indigo-600 hover:underline dark:text-indigo-400;
    }

    .admin-link-danger {
        @apply text-sm font-medium text-red-600 hover:underline dark:text-red-400;
    }

    /*
     | Attendance monthly calendar: grid + cell colors live here so Tailwind/Vite never purges them
     | (they are not reliably detected inside <script> strings in Blade).
     */
    .attendance-month-grid {
        display: grid;
        grid-template-columns: repeat(7, minmax(0, 1fr));
        gap: 0.125rem;
        width: 100%;
        max-width: 100%;
    }

    @media (min-width: 640px) {
        .attendance-month-grid {
            gap: 0.2rem;
        }
    }

    .attendance-month-dow {
        @apply min-w-0 py-0.5 text-center text-[9px] font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400 sm:text-[10px];
    }

    /* Short fixed row height — wide columns stay slim (no square aspect-ratio). */
    .attendance-month-grid .attendance-cal-cell {
        @apply flex h-6 min-h-0 min-w-0 items-center justify-center rounded text-[10px] font-semibold tabular-nums leading-none sm:h-7 sm:text-[11px];
    }

    .attendance-month-grid .attendance-cal-cell--pad {
        @apply h-6 min-h-0 min-w-0 rounded sm:h-7;
    }

    .attendance-cal-cell--clickable {
        @apply cursor-pointer transition-shadow duration-150;
    }

    .attendance-cal-cell--clickable:hover {
        box-shadow: inset 0 0 0 2px rgb(45 212 191 / 0.65);
    }

    .dark .attendance-cal-cell--clickable:hover {
        box-shadow: inset 0 0 0 2px rgb(94 234 212 / 0.5);
    }

    .attendance-cal-cell--static {
        @apply cursor-default opacity-95;
    }

    .attendance-cal-cell--selected {
        box-shadow:
            0 0 0 2px rgb(255 255 255),
            0 0 0 4px rgb(13 148 136);
    }

    .dark .attendance-cal-cell--selected {
        box-shadow:
            0 0 0 2px rgb(15 23 42),
            0 0 0 4px rgb(45 212 191);
    }

    .attendance-cell-present {
        background-color: #00695c;
        color: #fff;
    }

    .attendance-cell-absent {
        background-color: #ef5350;
        color: #fff;
    }

    .attendance-cell-late {
        background-color: #ffa000;
        color: #fff;
    }

    .attendance-cell-half {
        background-color: #4285f4;
        color: #fff;
    }

    .attendance-cell-leave {
        background-color: #ab47bc;
        color: #fff;
    }

    .attendance-cell-holiday {
        @apply bg-slate-400 text-white;
    }

    .attendance-cell-unknown {
        @apply bg-slate-500 text-white;
    }

    .attendance-cell-weekend {
        @apply bg-slate-200/90 text-slate-600 dark:bg-slate-700/90 dark:text-slate-200;
    }

    .attendance-cell-future {
        @apply bg-slate-100 text-slate-400 dark:bg-slate-800/80 dark:text-slate-500;
    }

    .attendance-month-grid .attendance-cal-cell.attendance-cal-cell--future-day {
        @apply cursor-not-allowed opacity-50;
        pointer-events: none;
    }

    .attendance-cell-empty {
        @apply bg-white text-slate-500 ring-1 ring-inset ring-slate-200/90 dark:bg-slate-900/40 dark:text-slate-400 dark:ring-slate-600/80;
    }

    .attendance-badge {
        @apply inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold;
    }

    .attendance-badge-present {
        background-color: #00695c;
        color: #fff;
    }

    .attendance-badge-absent {
        background-color: #ef5350;
        color: #fff;
    }

    .attendance-badge-late {
        background-color: #ffa000;
        color: #fff;
    }

    .attendance-badge-half {
        background-color: #4285f4;
        color: #fff;
    }

    .attendance-badge-leave {
        background-color: #ab47bc;
        color: #fff;
    }

    .attendance-badge-holiday {
        @apply bg-slate-400 text-white;
    }

    .attendance-badge-unknown {
        @apply bg-slate-500 text-white;
    }

    .attendance-summary-grid {
        display: grid;
        gap: 0.5rem;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    @media (min-width: 640px) {
        .attendance-summary-grid {
            grid-template-columns: repeat(3, minmax(0, 1fr));
        }
    }

    @media (min-width: 1024px) {
        .attendance-summary-grid {
            grid-template-columns: repeat(5, minmax(0, 1fr));
        }
    }

    /* POS custom order form (orders/create partial) */
    .order-pos-create {
        @apply max-w-full min-w-0 space-y-6 text-slate-800 dark:text-slate-100;
    }

    .order-pos-card {
        @apply rounded-xl border border-slate-200/90 bg-white p-4 shadow-sm dark:border-slate-800 dark:bg-slate-900 sm:p-5;
    }

    .order-pos-card-hero {
        @apply border-violet-200/90 bg-gradient-to-br from-violet-50 via-white to-amber-50/40 dark:border-violet-800/70 dark:from-violet-950/45 dark:via-slate-900 dark:to-slate-900;
    }

    .order-pos-totals-bar {
        @apply flex flex-col gap-3 rounded-xl border border-sky-200/80 bg-gradient-to-r from-sky-50 to-white p-4 dark:border-sky-900/60 dark:from-sky-950/30 dark:to-slate-900 sm:flex-row sm:items-center sm:justify-between;
    }

    .order-pos-footer {
        @apply mt-4 flex flex-col-reverse gap-2 border-t border-slate-200 bg-slate-50/90 p-3 dark:border-slate-700 dark:bg-slate-800/50 sm:flex-row sm:justify-end sm:gap-3 sm:p-4;
    }

    .order-pos-btn-success {
        @apply inline-flex w-full items-center justify-center rounded-lg bg-emerald-600 px-5 py-2.5 text-sm font-semibold text-white shadow-sm transition hover:bg-emerald-500 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-emerald-500 dark:hover:bg-emerald-400 sm:w-auto;
    }

    .order-pos-table-wrap {
        @apply mt-4 overflow-x-auto rounded-xl border border-slate-300 dark:border-slate-700;
    }

    .order-pos-table {
        @apply w-full min-w-[320px] border-collapse text-left text-sm;
    }

    .order-pos-table thead {
        @apply border-b border-slate-300 bg-slate-50 dark:border-slate-700 dark:bg-slate-800/80;
    }

    .order-pos-table th {
        @apply px-3 py-3 text-xs font-semibold uppercase tracking-wide text-slate-700 dark:text-slate-300 sm:px-4;
    }

    .order-pos-table td {
        @apply border-b border-slate-100 px-3 py-3 dark:border-slate-800 sm:px-4;
    }

    .order-pos-qty-input {
        @apply admin-input mx-auto !mt-0 text-center;
        width: 5rem;
    }

    /* Restaurant POS Card Animations */
    .pos-product-card {
        @apply relative transition-all duration-200;
    }

    .pos-product-card:hover {
        @apply -translate-y-1;
    }

    .pos-product-card span {
        @apply transition-colors duration-200;
    }
}

.dark .pos-product-card {
    --pos-card-bg: rgb(30 41 59); /* Matches slate-800 */
}

@keyframes admin-row-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes card-in {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.animate-float {
    animation: float 3s ease-in-out infinite;
}

/*
 * Select2 draws its own UI; classes on <select> do not style the visible field.
 * These rules mirror .admin-input (rounded-xl, border, padding, shadow, focus ring).
 */
.order-pos-create .select2-container.order-create-s2 {
    width: 100% !important;
    z-index: 30 !important;
}
.order-pos-create .select2-dropdown.order-create-s2 {
    z-index: 35 !important;
}

.select2-container {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
}

.select2-container--default .select2-selection--single {
    height: auto !important;
    min-height: 2.75rem !important;
    padding: 0 !important;
    border-radius: 0.75rem !important;
    border: 1px solid rgb(203 213 225) !important; /* slate-300 */
    background-color: #fff !important;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05) !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease !important;
}

.dark .select2-container--default .select2-selection--single {
    border-color: rgb(30 41 55) !important;
    background-color: rgb(2 6 23 / 0.6) !important;
    box-shadow: none !important;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    padding: 0.625rem 2.25rem 0.625rem 1rem !important;
    font-size: 0.875rem !important;
    line-height: 1.25rem !important;
    color: rgb(15 23 42) !important;
}

.dark .select2-container--default .select2-selection--single .select2-selection__rendered {
    color: rgb(241 245 249) !important;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: rgb(100 116 139) !important;
}

.dark .select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: rgb(148 163 184) !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 2.75rem !important;
    top: 0 !important;
    right: 0.5rem !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: rgb(100 116 139) transparent transparent transparent !important;
}

.dark .select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: rgb(148 163 184) transparent transparent transparent !important;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
    border-color: rgb(245 158 11) !important;
    outline: none !important;
    box-shadow: 0 0 0 1px rgb(245 158 11 / 0.35) !important;
}

.select2-dropdown {
    border-radius: 0.75rem !important;
    border: 1px solid rgb(203 213 225) !important; /* slate-300 */
    background-color: #fff !important;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.06) !important;
    overflow: hidden;
}

.dark .select2-dropdown {
    border-color: rgb(51 65 85) !important;
    background-color: rgb(30 41 59) !important;
    color: rgb(241 245 249) !important;
}

.select2-container--default .select2-results__option--selectable {
    font-size: 0.875rem !important;
    color: rgb(15 23 42) !important;
}

.dark .select2-container--default .select2-results__option--selectable {
    color: rgb(241 245 249) !important;
    background-color: rgb(30 41 59) !important;
}

.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    background-color: rgb(254 243 199) !important;
    color: rgb(15 23 42) !important;
}

.dark .select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    background-color: rgb(245 158 11 / 0.4) !important;
    color: rgb(254 252 232) !important;
}

.select2-container--default .select2-results__option--selected,
.select2-container--default .select2-results__option[aria-selected="true"] {
    background-color: rgb(241 245 249) !important;
    color: rgb(15 23 42) !important;
}

.dark .select2-container--default .select2-results__option--selected,
.dark .select2-container--default .select2-results__option[aria-selected="true"] {
    background-color: rgb(51 65 85) !important;
    color: rgb(248 250 252) !important;
}

.select2-search--dropdown {
    padding: 0.5rem !important;
    border-bottom: 1px solid rgb(203 213 225) !important; /* slate-300 */
}

.dark .select2-search--dropdown {
    border-bottom-color: rgb(51 65 85) !important;
}

.select2-search--dropdown .select2-search__field {
    border-radius: 0.5rem !important;
    border: 1px solid rgb(203 213 225) !important; /* slate-300 */
    background-color: #fff !important;
    padding: 0.5rem 0.75rem !important;
    font-size: 0.875rem !important;
    color: rgb(15 23 42) !important;
}

.dark .select2-search--dropdown .select2-search__field {
    border-color: rgb(71 85 105) !important;
    background-color: rgb(15 23 42 / 0.95) !important;
    color: rgb(241 245 249) !important;
}

@media (max-width: 639px) {
    .order-pos-create .order-create-top-grid > *,
    .order-pos-create .order-create-charges-grid > * {
        grid-column: 1 / -1 !important;
    }
}
