/**
 * ============================================================================
 * EBAY PET SHOP — GLOBAL STYLESHEET & DESIGN TOKENS
 * ============================================================================
 * Architecture Phase 1 & 2: Design Tokens & Reusable UI Components
 * Guidelines: AGENTS.md v2.0.1, UI_AUDIT.md, UI_REDESIGN_PLAN.md
 * Visual Direction: Linear & Replit inspired — Clean, Modern, Minimal, Light Mode.
 * ============================================================================
 */

/* ----------------------------------------------------------------------------
 * 1. DESIGN TOKENS (CSS Custom Properties)
 * ---------------------------------------------------------------------------- */
:root {
    /* --- Surface & Background Tokens (Light Mode Only) --- */
    --bg-app: #FBF9F5;              /* Canvas dasar aplikasi (Warm off-white toko) */
    --bg-surface: #FFFFFF;          /* Surface kartu, kontainer, tabel, modal */
    --bg-surface-elevated: #F9F8F6; /* Header tabel, input hover, dropdown surface */
    --bg-surface-muted: #F3EFEA;    /* Tag neutral background, active sidebar */

    /* --- Border Tokens --- */
    --border-subtle: #EAE5DE;       /* Garis divider tipis (1px) */
    --border-default: #DDD6CE;      /* Border default kartu, kontainer, tabel */
    --border-strong: #B8AEA2;       /* Border field input normal */
    --border-focus: #854D0E;        /* Focus ring input (Amber-800) */

    /* --- Typography & Text Tokens --- */
    --text-primary: #1C1917;        /* stone-900: Header, teks utama, angka harga */
    --text-secondary: #57534E;      /* stone-600: Label form, subteks deskripsi */
    --text-muted: #8C857B;          /* stone-400: Placeholder, timestamp, hint */
    --text-inverse: #FFFFFF;        /* Teks di atas background brand/gelap */

    /* --- Brand & Action Tokens (Ebay Pet Shop Warm Accent Core) --- */
    --brand-primary: #854D0E;       /* Amber-800: Tombol primer, aksen aktif, icon */
    --brand-hover: #713F12;         /* Amber-900: State hover tombol primer */
    --brand-active: #58310E;        /* Amber-950: State active/pressed */
    --brand-surface: #FEF3C7;       /* Amber-100: Highlight, badge aktif */

    /* --- Secondary Action Tokens --- */
    --action-secondary-bg: #F5F3EF;
    --action-secondary-text: #44403C;
    --action-secondary-hover: #E7E3DC;

    /* --- Functional Status Tokens --- */
    --status-danger-bg: #FEF2F2;    /* Red-50 */
    --status-danger-text: #B91C1C;  /* Red-700: Teks error, tombol hapus */
    --status-danger-border: #FECACA;/* Red-200 */
    --status-danger-hover: #991B1B; /* Red-800 */

    --status-success-bg: #F0FDF4;   /* Emerald-50 */
    --status-success-text: #15803D; /* Emerald-700: Tombol export, total amount */
    --status-success-border: #BBF7D0;/* Emerald-200 */

    --status-warning-bg: #FFFBEB;   /* Amber-50 */
    --status-warning-text: #B45309; /* Amber-700: Alert stok kritis */
    --status-warning-border: #FDE68A;/* Amber-200 */

    /* --- Typography Scale --- */
    --font-family-base: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --text-xs: 0.75rem;             /* 12px */
    --text-sm: 0.875rem;            /* 14px */
    --text-base: 1rem;              /* 16px */
    --text-lg: 1.125rem;            /* 18px */
    --text-xl: 1.25rem;             /* 20px */
    --text-2xl: 1.5rem;             /* 24px */
    --text-3xl: 1.875rem;           /* 30px */

    /* --- Spacing Scale --- */
    --space-1: 0.25rem;             /* 4px */
    --space-2: 0.5rem;              /* 8px */
    --space-3: 0.75rem;             /* 12px */
    --space-4: 1rem;                /* 16px */
    --space-5: 1.25rem;             /* 20px */
    --space-6: 1.5rem;              /* 24px */
    --space-8: 2rem;                /* 32px */

    /* --- Border Radius Scale --- */
    --radius-sm: 4px;               /* Badge kecil, tombol counter POS */
    --radius-md: 6px;               /* Input field, tombol aksi tabel, pills */
    --radius-lg: 8px;               /* Tombol primer, kartu, modal dialog */
    --radius-xl: 12px;              /* Kontainer besar */
    --radius-full: 9999px;          /* Bulat sempurna */

    /* --- Subtle Shadows (Minimal Elevation ala Linear) --- */
    --shadow-none: none;
    --shadow-subtle: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
    --shadow-modal: 0 8px 30px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-toast: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);

    /* --- Transitions --- */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);

    /* --- Z-Index Layers --- */
    --z-base: 0;
    --z-sticky: 10;
    --z-overlay: 20;
    --z-sidebar: 30;
    --z-modal-backdrop: 40;
    --z-modal: 50;
    --z-toast: 60;
}

/* ----------------------------------------------------------------------------
 * 2. GLOBAL BASE STYLES (Non-destructive to Tailwind classes)
 * ---------------------------------------------------------------------------- */
html {
    font-family: var(--font-family-base);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-family-base);
    color: var(--text-primary);
}

/* Aksesibilitas: Focus Ring yang konsisten dan rapi */
*:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 1px;
}

/* Text Selection styling khas brand */
::selection {
    background-color: var(--brand-surface);
    color: var(--brand-primary);
}

/* Scrollbar Minimalis & Rapi (Webkit-based & Firefox) */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-default) transparent;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: var(--border-default);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--border-strong);
}

/* ----------------------------------------------------------------------------
 * 3. REUSABLE UI COMPONENTS (Fase 2 Specification)
 * ---------------------------------------------------------------------------- */

/* === A. BUTTON SYSTEM === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-family-base);
    font-weight: 500;
    font-size: var(--text-sm);
    line-height: 1.25rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast), transform var(--transition-fast);
    cursor: pointer;
    user-select: none;
    text-decoration: none;
    border: 1px solid transparent;
    gap: 0.375rem;
    outline: none;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--border-focus);
}

.btn:disabled,
.btn[disabled] {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
}

/* Variant: Primary */
.btn-primary {
    background-color: var(--brand-primary);
    color: var(--text-inverse);
    border-color: var(--brand-primary);
}
.btn-primary:hover {
    background-color: var(--brand-hover);
    border-color: var(--brand-hover);
    color: var(--text-inverse);
}
.btn-primary:active {
    background-color: var(--brand-active);
    border-color: var(--brand-active);
}

/* Variant: Secondary */
.btn-secondary {
    background-color: var(--action-secondary-bg);
    color: var(--action-secondary-text);
    border-color: var(--border-default);
}
.btn-secondary:hover {
    background-color: var(--action-secondary-hover);
    border-color: var(--border-strong);
    color: var(--text-primary);
}
.btn-secondary:active {
    background-color: #DDD6CE;
}

/* Variant: Outline */
.btn-outline {
    background-color: transparent;
    color: var(--text-primary);
    border-color: var(--border-default);
}
.btn-outline:hover {
    background-color: var(--bg-surface-elevated);
    border-color: var(--border-strong);
    color: var(--text-primary);
}
.btn-outline:active {
    background-color: var(--bg-surface-muted);
}

/* Variant: Primary Outline (Transparent style with brand accent) */
.btn-outline-primary {
    background-color: transparent;
    color: var(--brand-primary);
    border-color: var(--brand-primary);
}
.btn-outline-primary:hover {
    background-color: var(--brand-surface);
    color: var(--brand-hover);
    border-color: var(--brand-hover);
}
.btn-outline-primary:active {
    background-color: #FDE68A;
    color: var(--brand-active);
}

/* Variant: Danger */
.btn-danger {
    background-color: var(--status-danger-text);
    color: var(--text-inverse);
    border-color: var(--status-danger-text);
}
.btn-danger:hover {
    background-color: var(--status-danger-hover);
    border-color: var(--status-danger-hover);
    color: var(--text-inverse);
}
.btn-danger:active {
    background-color: #7F1D1D;
}

/* Variant: Table Action Compact Buttons */
.btn-action-edit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xs);
    font-weight: 500;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-md);
    background-color: #EFF6FF; /* Blue-50 */
    color: #1D4ED8;            /* Blue-700 */
    border: 1px solid #BFDBFE; /* Blue-200 */
    transition: all var(--transition-fast);
    cursor: pointer;
    min-height: 28px;
    outline: none;
}
.btn-action-edit:hover {
    background-color: #DBEAFE; /* Blue-100 */
    color: #1E40AF;
    border-color: #93C5FD;
}
.btn-action-edit:active {
    background-color: #BFDBFE;
}
.btn-action-edit:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 4px #3B82F6;
}

.btn-action-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xs);
    font-weight: 500;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-md);
    background-color: var(--status-danger-bg);
    color: var(--status-danger-text);
    border: 1px solid var(--status-danger-border);
    transition: all var(--transition-fast);
    cursor: pointer;
    min-height: 28px;
    outline: none;
}
.btn-action-delete:hover {
    background-color: #FEE2E2;
    color: var(--status-danger-hover);
    border-color: #FCA5A5;
}
.btn-action-delete:active {
    background-color: #FECACA;
}
.btn-action-delete:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--status-danger-text);
}

/* Variant: Export Button */
.btn-export {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    background-color: var(--status-success-bg);
    color: var(--status-success-text);
    border: 1px solid var(--status-success-border);
    transition: all var(--transition-fast);
    cursor: pointer;
    gap: 0.375rem;
    outline: none;
}
.btn-export:hover {
    background-color: #DCFCE7;
    color: #166534;
    border-color: #86EFAC;
}
.btn-export:active {
    background-color: #BBF7D0;
}
.btn-export:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--status-success-text);
}

/* === B. FORM CONTROLS === */
.input-text,
.select-input,
.textarea-input {
    width: 100%;
    font-family: var(--font-family-base);
    font-size: var(--text-sm);
    color: var(--text-primary);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 0.5rem 0.75rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
}

.input-text:focus,
.select-input:focus,
.textarea-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 1px var(--border-focus);
}

.input-text::placeholder,
.textarea-input::placeholder {
    color: var(--text-muted);
}

.input-text:disabled,
.input-text[readonly],
.select-input:disabled {
    background-color: var(--bg-surface-elevated);
    color: var(--text-secondary);
    cursor: not-allowed;
}

/* Search Input wrapper & input */
.search-input-field {
    width: 100%;
    font-size: var(--text-sm);
    padding: 0.5rem 2.5rem 0.5rem 2.25rem;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.search-input-field:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 1px var(--border-focus);
}

.search-clear-btn {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    line-height: 1;
    transition: color var(--transition-fast);
}
.search-clear-btn:hover {
    color: var(--text-primary);
}

/* === C. DATA TABLE === */
.table-responsive-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    background-color: var(--bg-surface);
}

.data-table-standard {
    width: 100%;
    font-size: var(--text-sm);
    text-align: left;
    color: var(--text-secondary);
    border-collapse: collapse;
}

.data-table-standard thead {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    background-color: var(--bg-surface-elevated);
    border-bottom: 1px solid var(--border-default);
}

.data-table-standard th {
    padding: 0.75rem 1rem;
    white-space: nowrap;
}

.data-table-standard tbody tr {
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    transition: background-color var(--transition-fast);
}

.data-table-standard tbody tr:hover {
    background-color: var(--bg-surface-elevated);
}

.data-table-standard td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
}

/* Empty State Table Cell */
.table-empty-cell {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
    font-size: var(--text-sm);
}

/* === D. BADGES & STATUS === */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    font-size: var(--text-xs);
    font-weight: 500;
    border-radius: var(--radius-full);
    line-height: 1rem;
    gap: 0.25rem;
}

.badge-brand {
    background-color: var(--brand-surface);
    color: var(--brand-primary);
    border: 1px solid #FDE68A;
}

.badge-danger {
    background-color: var(--status-danger-bg);
    color: var(--status-danger-text);
    border: 1px solid var(--status-danger-border);
}

.badge-success {
    background-color: var(--status-success-bg);
    color: var(--status-success-text);
    border: 1px solid var(--status-success-border);
}

.badge-neutral {
    background-color: var(--bg-surface-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-default);
}

/* === E. FLOATING TOAST NOTIFICATION CONTAINER & CARDS === */
#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
    max-width: calc(100vw - 2rem);
    width: 360px;
}

.toast-card {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-toast);
    font-size: var(--text-sm);
    color: var(--text-primary);
    animation: toast-slide-in 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast-card.toast-hide {
    opacity: 0;
    transform: translateY(-8px) scale(0.96);
}

.toast-card.toast-success {
    border-left: 4px solid var(--status-success-text);
}

.toast-card.toast-error {
    border-left: 4px solid var(--status-danger-text);
}

.toast-card.toast-warning {
    border-left: 4px solid var(--status-warning-text);
}

.toast-card.toast-info {
    border-left: 4px solid var(--brand-primary);
}

.toast-close-btn {
    margin-left: auto;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast);
}
.toast-close-btn:hover {
    color: var(--text-primary);
}

@keyframes toast-slide-in {
    from {
        opacity: 0;
        transform: translateY(-12px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* === F. APPLICATION SHELL & NAVIGATION (Phase 3 Specification - Light Mode) === */
.app-shell-sidebar {
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-default);
    transition: width var(--transition-normal), transform var(--transition-normal);
}

.app-shell-sidebar .nav-link {
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    text-decoration: none;
    border-left: 2px solid transparent;
}

.app-shell-sidebar .nav-link:hover {
    background-color: var(--bg-surface-elevated);
    color: var(--text-primary);
}

.app-shell-sidebar .nav-link.nav-active {
    background-color: var(--brand-surface);
    color: var(--brand-primary);
    border-left: 2px solid var(--brand-primary);
    font-weight: 600;
}

.app-shell-topbar {
    height: 3.5rem; /* 56px */
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
}

/* --- Admin Top Navbar Specific Styles --- */
.admin-top-navbar {
    height: 4rem; /* 64px */
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-default);
    position: sticky;
    top: 0;
    z-index: 40;
    width: 100%;
}

.admin-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background-color var(--transition-fast), color var(--transition-fast);
    white-space: nowrap;
    border: none;
    outline: none;
    background-color: transparent;
}

.admin-nav-link:hover {
    color: var(--text-primary);
    background-color: #F3EFEA;
    border: none;
    outline: none;
}

.admin-nav-link.nav-active {
    background-color: var(--brand-surface);
    color: var(--brand-primary);
    border: none;
    outline: none;
    font-weight: 700;
}

.admin-nav-link.nav-active:hover {
    background-color: var(--brand-surface);
    color: var(--brand-primary);
    border: none;
    outline: none;
}

.admin-nav-link.nav-active ion-icon {
    color: var(--brand-primary);
}

.admin-nav-link:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--border-focus);
}

/* Mobile Nav Link in Drawer */
.admin-mobile-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    min-height: 44px;
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background-color var(--transition-fast), color var(--transition-fast);
    border: none;
    outline: none;
    background-color: transparent;
}

.admin-mobile-nav-link:hover {
    color: var(--text-primary);
    background-color: #F3EFEA;
    border: none;
    outline: none;
}

.admin-mobile-nav-link.nav-active {
    background-color: var(--brand-surface);
    color: var(--brand-primary);
    border: none;
    outline: none;
    font-weight: 700;
}

.admin-mobile-nav-link.nav-active:hover {
    background-color: var(--brand-surface);
    color: var(--brand-primary);
    border: none;
    outline: none;
}

.admin-mobile-nav-link.nav-active ion-icon {
    color: var(--brand-primary);
}

.admin-mobile-nav-link:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--border-focus);
}

.app-shell-content-container {
    background-color: var(--bg-app);
    min-height: 100%;
}

/* Reusable Form Page Layout Container (Account, Product Form, etc.) */
.form-page-container {
    width: 100%;
    max-width: 56rem; /* 896px = max-w-4xl */
    margin-left: auto;
    margin-right: auto;
}

/* ----------------------------------------------------------------------------
 * 15. POS MOBILE RESPONSIVE BOTTOM SHEET CART & SCANNER OVERLAY
 * ---------------------------------------------------------------------------- */
@media (max-width: 1023px) {
    /* Ruang padding bawah pada katalog agar kartu produk terakhir tidak tertutup bottom sheet */
    #cashier-view {
        padding-bottom: calc(6rem + env(safe-area-inset-bottom, 0px)) !important;
    }

    #cashier-cart-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 40;
        width: 100%;
        max-width: 100vw;
        border-top-left-radius: 1rem;
        border-top-right-radius: 1rem;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        box-shadow: 0 -10px 25px -5px rgba(0, 0, 0, 0.15), 0 -4px 6px -2px rgba(0, 0, 0, 0.05);
        background-color: var(--bg-surface);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* Kondisi Collapsed (Default Mobile) */
    #cashier-cart-panel.cart-sheet-collapsed #cart-expandable-body {
        display: none !important;
    }

    #cashier-cart-panel.cart-sheet-collapsed #cart-chevron-icon {
        transform: rotate(0deg);
    }

    /* Kondisi Expanded (Ketika Kasir Membuka Keranjang) */
    #cashier-cart-panel.cart-sheet-expanded {
        max-height: min(85dvh, 85vh);
        overscroll-behavior-y: contain;
    }

    #cashier-cart-panel.cart-sheet-expanded #cart-expandable-body {
        display: flex !important;
        overscroll-behavior-y: contain;
    }

    #cashier-cart-panel.cart-sheet-expanded #cart-items-list {
        overscroll-behavior-y: contain;
        -webkit-overflow-scrolling: touch;
    }

    #cashier-cart-panel.cart-sheet-expanded #cart-chevron-icon {
        transform: rotate(180deg);
    }
}
