/**
 * BlackOasis ERP — Premium Design System
 * UI-only layer. Loads after main.css; extends tokens & components app-wide.
 */

:root {
    /* Brand palette */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #eff6ff;
    --secondary: #64748b;
    --secondary-hover: #475569;
    --secondary-soft: #f1f5f9;

    /* Semantic */
    --success: #059669;
    --success-soft: #ecfdf5;
    --warning: #d97706;
    --warning-soft: #fffbeb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --info: #2563eb;
    --info-soft: #eff6ff;

    /* Neutrals */
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    /* Surfaces */
    --sidebar-bg: #0b1220;
    --sidebar-hover: #151f32;
    --sidebar-active: #2563eb;
    --content-bg: #f4f6f9;
    --card-bg: #ffffff;
    --surface-elevated: #ffffff;

    /* Typography */
    --font-sans: 'Inter', 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: ui-monospace, 'Cascadia Code', 'Segoe UI Mono', monospace;
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-base: 0.875rem;
    --text-md: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;

    /* Spacing scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;

    /* Radius */
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 14px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12);
    --shadow-focus: 0 0 0 3px rgba(37, 99, 235, 0.22);

    /* Motion */
    --ease-out: cubic-bezier(0.4, 0, 0.2, 1);
    --duration-fast: 120ms;
    --duration-normal: 200ms;

    --accent-gradient: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
    --text-primary: var(--gray-900);
    --text-secondary: var(--gray-500);
    --text-muted: var(--gray-500);
    --border: var(--gray-200);
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ——— Base typography ——— */
body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    letter-spacing: -0.011em;
    background: var(--content-bg);
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

.page-header h1 {
    font-size: var(--text-2xl);
    font-weight: 700;
}

.page-header p {
    font-size: var(--text-sm);
    line-height: 1.6;
}

/* ——— Breadcrumbs ——— */
.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.breadcrumbs a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-out);
}

.breadcrumbs a:hover {
    color: var(--primary);
}

.breadcrumbs-sep {
    opacity: 0.45;
    user-select: none;
}

.breadcrumbs-current {
    color: var(--text-primary);
    font-weight: 600;
}

/* ——— Buttons ——— */
.btn {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: var(--text-sm);
    line-height: 1.2;
    border-radius: var(--radius-sm);
    padding: 10px 18px;
    gap: 8px;
    transition:
        background var(--duration-fast) var(--ease-out),
        border-color var(--duration-fast) var(--ease-out),
        box-shadow var(--duration-fast) var(--ease-out),
        transform var(--duration-fast) var(--ease-out),
        opacity var(--duration-fast) var(--ease-out);
    box-shadow: var(--shadow-xs);
}

.btn:hover {
    opacity: 1;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0);
}

.btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.btn:disabled,
.btn.is-disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
}

.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
    border: 1px solid transparent;
}

.btn-primary:hover {
    filter: brightness(1.05);
}

.btn-secondary {
    background: var(--gray-100);
    color: var(--gray-800);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--gray-200);
    border-color: var(--gray-300);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--gray-300);
}

.btn-outline:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
}

.btn-success {
    background: var(--success);
    color: #fff;
    border: 1px solid transparent;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    border: 1px solid transparent;
}

.btn-sm {
    padding: 7px 14px;
    font-size: var(--text-xs);
    border-radius: var(--radius-sm);
}

.btn-lg {
    padding: 12px 22px;
    font-size: var(--text-md);
}

.btn.is-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn.is-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    margin: auto;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: ds-spin 0.65s linear infinite;
}

.btn-secondary.is-loading::after,
.btn-outline.is-loading::after {
    border-color: rgba(37, 99, 235, 0.2);
    border-top-color: var(--primary);
}

@keyframes ds-spin {
    to { transform: rotate(360deg); }
}

/* ——— Forms ——— */
.form-group label {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: var(--space-2);
}

.form-group label .required,
.form-label-required::after {
    content: " *";
    color: var(--danger);
}

.form-help {
    display: block;
    margin-top: var(--space-1);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    line-height: 1.5;
}

.form-group input,
.form-group select,
.form-group textarea,
.filter-row input,
.filter-row select,
.sidebar-search-input {
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.form-group input:hover,
.form-group select:hover,
.form-group textarea:hover {
    border-color: var(--gray-300);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.filter-row input:focus,
.filter-row select:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-focus);
}

.form-group input::placeholder,
.filter-row input::placeholder {
    color: var(--gray-400);
}

.form-group input:invalid:not(:placeholder-shown),
.form-group.is-error input {
    border-color: var(--danger);
}

.form-error {
    font-size: var(--text-xs);
    color: var(--danger);
    margin-top: var(--space-1);
}

/* Checkbox / radio polish */
input[type="checkbox"],
input[type="radio"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
}

/* ——— Cards ——— */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    border: 1px solid rgba(226, 232, 240, 0.9);
    box-shadow: var(--shadow);
    padding: var(--space-6);
    transition: box-shadow var(--duration-normal) var(--ease-out);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-title {
    font-size: var(--text-md);
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--gray-100);
}

.kpi-card,
.dash-kpi {
    border-radius: var(--radius-lg);
    transition: transform var(--duration-fast), box-shadow var(--duration-fast);
}

.kpi-card:hover,
.dash-kpi-link:hover {
    transform: translateY(-2px);
}

/* ——— Tables ——— */
.data-table {
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.table-scroll .data-table,
.history-table-wrap .data-table {
    border: none;
}

.data-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

.data-table th {
    background: var(--gray-800);
    color: #f8fafc;
    padding: 11px 16px;
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.data-table td {
    padding: 11px 16px;
    font-size: var(--text-sm);
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

.data-table tbody tr:nth-child(even) td {
    background: var(--gray-50);
}

.data-table tbody tr:hover td {
    background: var(--primary-soft);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.action-links a {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    margin-right: 4px;
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
    transition: background var(--duration-fast);
}

.action-links a:hover {
    background: var(--primary-soft);
    text-decoration: none;
}

/* ——— Badges & status ——— */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
}

.badge-success, .badge-active { background: var(--success-soft); color: #047857; border-color: #a7f3d0; }
.badge-warning, .badge-pending { background: var(--warning-soft); color: #b45309; border-color: #fde68a; }
.badge-danger, .badge-cancelled { background: var(--danger-soft); color: #b91c1c; border-color: #fecaca; }
.badge-info { background: var(--info-soft); color: #1d4ed8; border-color: #bfdbfe; }
.badge-neutral, .badge-inactive { background: var(--gray-100); color: var(--gray-600); border-color: var(--gray-200); }
.badge-completed, .badge-paid { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge-unpaid { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.badge-returned { background: #ffedd5; color: #c2410c; border-color: #fed7aa; }

/* ——— Filters ——— */
.filter-bar {
    gap: var(--space-2);
    padding: var(--space-3);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
}

.filter-btn {
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: var(--text-xs);
    padding: 8px 16px;
    transition: all var(--duration-fast) var(--ease-out);
}

.filter-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-soft);
}

.filter-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.filter-row {
    padding: var(--space-4);
    background: linear-gradient(180deg, #fff 0%, var(--gray-50) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
}

/* ——— Alerts & toasts ——— */
.alert {
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-weight: 500;
    line-height: 1.5;
}

.alert-success { background: var(--success-soft); color: #065f46; border-color: #a7f3d0; }
.alert-warning { background: var(--warning-soft); color: #92400e; border-color: #fde68a; }
.alert-danger { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }
.alert-info { background: var(--info-soft); color: #1e40af; border-color: #bfdbfe; }

.toast-stack {
    position: fixed;
    top: calc(var(--topbar-h, 56px) + 12px);
    right: 16px;
    z-index: 9000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(420px, calc(100vw - 32px));
    pointer-events: none;
}

.toast-stack .alert {
    pointer-events: auto;
    margin: 0;
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.35s var(--ease-out);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.toast-close {
    background: transparent;
    border: none;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.6;
    padding: 0 4px;
    color: inherit;
}

.toast-close:hover { opacity: 1; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ——— Empty states ——— */
.empty-state,
.dash-empty,
.analytics-empty,
.report-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-10) var(--space-6);
    background: linear-gradient(180deg, #fff 0%, var(--gray-50) 100%);
    border: 1px dashed var(--gray-300);
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    gap: var(--space-3);
}

.empty-state-icon {
    font-size: 2.5rem;
    opacity: 0.35;
    line-height: 1;
}

.empty-state-title {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text-primary);
}

.empty-state-desc {
    font-size: var(--text-sm);
    max-width: 360px;
    line-height: 1.6;
}

/* ——— Skeleton loading ——— */
.skeleton {
    background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.2s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-title { height: 24px; width: 60%; margin-bottom: 12px; }
.skeleton-kpi { height: 72px; border-radius: var(--radius-lg); }

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ——— Navigation ——— */
.sidebar {
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, #0a101c 100%);
}

.sidebar-menu a {
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: all var(--duration-fast) var(--ease-out);
}

.sidebar-menu a.active {
    background: rgba(37, 99, 235, 0.18);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--primary);
}

.sidebar-search-input {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    padding: 10px 14px 10px 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.006a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
}

.sidebar-search-input:focus {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(96, 165, 250, 0.5);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

.nav-group-header {
    border-radius: var(--radius-sm);
    margin: 0 8px;
}

.main-content {
    background: var(--content-bg);
}

/* ——— Quick actions ——— */
.quick-action {
    border-radius: var(--radius);
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--card-bg);
    box-shadow: var(--shadow-xs);
}

.quick-action:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
}

/* ——— Dashboard premium ——— */
.dash-section-period {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
}

.dash-kpi {
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
    transition: transform var(--duration-fast), box-shadow var(--duration-fast);
}

.dash-kpi-val {
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.03em;
}

.ai-health-card,
.ai-summary-card,
.ai-score-card,
.ai-rec-card {
    border-radius: var(--radius-lg);
}

.ai-health-ring {
    font-variant-numeric: tabular-nums;
}

/* ——— Pagination ——— */
.pagination a,
.pagination span {
    border-radius: var(--radius-sm);
    font-weight: 600;
    transition: all var(--duration-fast);
}

.pagination a:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* ——— Modals ——— */
.premium-modal-panel {
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
}

.premium-modal-header h3 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ——— Notify panel ——— */
.notify-panel {
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.notify-bell-btn {
    font-weight: 600;
    transition: all var(--duration-fast);
}

.notify-bell-btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

/* ——— Progress ——— */
.progress-bar {
    height: 6px;
    background: var(--gray-200);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: var(--radius-full);
    transition: width var(--duration-normal) var(--ease-out);
}

/* ——— Mobile bottom nav ——— */
@media (max-width: 1024px) {
    .mobile-bottom-nav {
        border-top: 1px solid var(--border);
        box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.08);
    }

    .bottom-nav-item.active {
        color: var(--primary);
    }

    .toast-stack {
        top: calc(var(--topbar-h) + env(safe-area-inset-top, 0) + 8px);
        right: 12px;
        left: 12px;
        max-width: none;
    }
}

@media print {
    .toast-stack,
    .breadcrumbs,
    .sidebar,
    .mobile-topbar,
    .mobile-bottom-nav,
    .app-topbar {
        display: none !important;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .card {
        box-shadow: none !important;
        break-inside: avoid;
    }
}

/* ——— Search page ——— */
.search-hero-card {
    margin-bottom: var(--space-6);
}

.search-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.search-input-wrap {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.search-input {
    flex: 1 1 280px;
    min-width: 0;
    padding: 12px 16px;
    font-size: var(--text-md);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-sans);
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-focus);
}

/* ——— Keyboard focus ——— */
.user-is-tabbing :focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.user-is-tabbing .btn:focus-visible {
    outline-offset: 3px;
}

.notify-panel-loading::after {
    content: "";
    display: block;
    width: 28px;
    height: 28px;
    margin: 12px auto 0;
    border: 2px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: ds-spin 0.65s linear infinite;
}
