/**
 * 911Reparame - Custom CSS
 * Extends Tailwind with custom styles and dark mode tokens
 */

/* ============================================
   ROOT VARIABLES & TOKENS
   ============================================ */
:root {
    /* Primary colors */
    --color-primary: 59 130 246;
    --color-primary-hover: 37 99 235;
    --color-primary-light: 219 234 254;
    
    /* Background colors */
    --bg-primary: 255 255 255;
    --bg-secondary: 249 250 251;
    --bg-tertiary: 243 244 246;
    
    /* Text colors */
    --text-primary: 17 24 39;
    --text-secondary: 107 114 128;
    --text-muted: 156 163 175;
    
    /* Border colors */
    --border-color: 229 231 235;
    --border-focus: 59 130 246;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    
    /* Spacing */
    --sidebar-width: 256px;
    --topbar-height: 64px;
    --bottomnav-height: 64px;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
    --transition-slow: 300ms ease;
}

/* Dark mode tokens */
.dark {
    --color-primary: 96 165 250;
    --color-primary-hover: 147 197 253;
    --color-primary-light: 30 58 138;
    
    --bg-primary: 15 23 42;
    --bg-secondary: 30 41 59;
    --bg-tertiary: 51 65 85;
    
    --text-primary: 248 250 252;
    --text-secondary: 148 163 184;
    --text-muted: 100 116 139;
    
    --border-color: 51 65 85;
    --border-focus: 96 165 250;
}

/* ============================================
   BASE STYLES
   ============================================ */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: rgb(var(--bg-secondary));
    color: rgb(var(--text-primary));
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Focus styles */
:focus-visible {
    outline: 2px solid rgb(var(--border-focus));
    outline-offset: 2px;
}

/* Selection */
::selection {
    background-color: rgb(var(--color-primary) / 0.2);
    color: rgb(var(--text-primary));
}

/* ============================================
   LAYOUT
   ============================================ */
.app-container {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Topbar */
.topbar {
    height: var(--topbar-height);
    background-color: rgb(var(--bg-primary));
    border-bottom: 1px solid rgb(var(--border-color));
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1rem;
}

/* Sidebar (Desktop) */
.sidebar {
    width: var(--sidebar-width);
    background-color: rgb(var(--bg-primary));
    border-right: 1px solid rgb(var(--border-color));
    height: 100vh;
    height: 100dvh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-normal);
}

.sidebar-hidden {
    transform: translateX(-100%);
}

/* Bottom Navigation (Mobile/Tablet) */
.bottom-nav {
    height: var(--bottomnav-height);
    background-color: rgb(var(--bg-primary));
    border-top: 1px solid rgb(var(--border-color));
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 0.5rem;
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 1rem;
    color: rgb(var(--text-secondary));
    text-decoration: none;
    font-size: 0.75rem;
    transition: color var(--transition-fast);
    border-radius: 0.5rem;
}

.bottom-nav-item:hover,
.bottom-nav-item.active {
    color: rgb(var(--color-primary));
}

.bottom-nav-item i {
    font-size: 1.25rem;
}

/* Page content area */
.page-content {
    flex: 1;
    padding: 1rem;
    padding-bottom: calc(var(--bottomnav-height) + 1rem + env(safe-area-inset-bottom));
    overflow-x: hidden;
}

/* Desktop adjustments */
@media (min-width: 1024px) {
    .sidebar {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: var(--sidebar-width);
    }
    
    .bottom-nav {
        display: none;
    }
    
    .page-content {
        padding-bottom: 1rem;
    }
}

/* ============================================
   COMPONENTS
   ============================================ */

/* Cards */
.card {
    background-color: rgb(var(--bg-primary));
    border: 1px solid rgb(var(--border-color));
    border-radius: 0.75rem;
    padding: 1rem;
    transition: box-shadow var(--transition-fast);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgb(var(--border-color));
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background-color: rgb(var(--color-primary));
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: rgb(var(--color-primary-hover));
}

.btn-secondary {
    background-color: rgb(var(--bg-tertiary));
    color: rgb(var(--text-primary));
}

.btn-secondary:hover:not(:disabled) {
    background-color: rgb(var(--border-color));
}

.btn-ghost {
    background-color: transparent;
    color: rgb(var(--text-secondary));
}

.btn-ghost:hover:not(:disabled) {
    background-color: rgb(var(--bg-tertiary));
    color: rgb(var(--text-primary));
}

.btn-danger {
    background-color: #ef4444;
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background-color: #dc2626;
}

.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
}

.btn-icon {
    padding: 0.5rem;
    width: 2.5rem;
    height: 2.5rem;
}

/* Form inputs */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: rgb(var(--text-primary));
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
    background-color: rgb(var(--bg-primary));
    border: 1px solid rgb(var(--border-color));
    border-radius: 0.5rem;
    color: rgb(var(--text-primary));
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: rgb(var(--border-focus));
    box-shadow: 0 0 0 3px rgb(var(--color-primary) / 0.15);
    outline: none;
}

.form-input::placeholder {
    color: rgb(var(--text-muted));
}

.form-input-error {
    border-color: #ef4444;
}

.form-error {
    margin-top: 0.25rem;
    font-size: 0.8125rem;
    color: #ef4444;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
}

/* Tables */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table th,
.table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid rgb(var(--border-color));
}

.table th {
    font-weight: 600;
    color: rgb(var(--text-secondary));
    background-color: rgb(var(--bg-secondary));
    position: sticky;
    top: 0;
}

.table tbody tr:hover {
    background-color: rgb(var(--bg-secondary));
}

/* Mobile cards (replace table on small screens) */
@media (max-width: 767px) {
    .table-as-cards {
        display: none;
    }
    
    .cards-list {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
}

@media (min-width: 768px) {
    .cards-list {
        display: none;
    }
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.modal-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    background-color: rgb(var(--bg-primary));
    border-radius: 1rem;
    padding: 1.5rem;
    z-index: 101;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.modal.active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

/* Drawer */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.drawer-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 100%;
    max-width: 480px;
    background-color: rgb(var(--bg-primary));
    z-index: 101;
    transform: translateX(100%);
    transition: transform var(--transition-normal);
    overflow-y: auto;
}

.drawer.active {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid rgb(var(--border-color));
    position: sticky;
    top: 0;
    background-color: rgb(var(--bg-primary));
}

.drawer-content {
    padding: 1rem;
}

/* Bottom Sheet (Mobile) */
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgb(var(--bg-primary));
    border-radius: 1.5rem 1.5rem 0 0;
    z-index: 101;
    max-height: 90vh;
    transform: translateY(100%);
    transition: transform var(--transition-normal);
    overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-sheet.active {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 2.5rem;
    height: 0.25rem;
    background-color: rgb(var(--border-color));
    border-radius: 9999px;
    margin: 0.75rem auto;
}

/* Toast notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

@media (max-width: 767px) {
    .toast-container {
        top: auto;
        bottom: calc(var(--bottomnav-height) + 0.5rem + env(safe-area-inset-bottom));
        right: 0.5rem;
        left: 0.5rem;
    }
}

.toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background-color: rgb(var(--bg-primary));
    border: 1px solid rgb(var(--border-color));
    border-radius: 0.75rem;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast-success {
    border-left: 4px solid #22c55e;
}

.toast-error {
    border-left: 4px solid #ef4444;
}

.toast-warning {
    border-left: 4px solid #f59e0b;
}

.toast-info {
    border-left: 4px solid #3b82f6;
}

/* Skeleton loading */
.skeleton {
    background: linear-gradient(90deg, rgb(var(--bg-tertiary)) 25%, rgb(var(--bg-secondary)) 50%, rgb(var(--bg-tertiary)) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 0.375rem;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1.5rem;
    text-align: center;
}

.empty-state-icon {
    font-size: 3rem;
    color: rgb(var(--text-muted));
    margin-bottom: 1rem;
}

.empty-state-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: rgb(var(--text-primary));
    margin-bottom: 0.5rem;
}

.empty-state-text {
    color: rgb(var(--text-secondary));
    margin-bottom: 1.5rem;
}

/* ============================================
   SPOTLIGHT SEARCH
   ============================================ */
.spotlight-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-fast);
}

.spotlight-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.spotlight {
    position: fixed;
    top: 15%;
    left: 50%;
    transform: translateX(-50%) scale(0.95);
    width: 90%;
    max-width: 600px;
    background-color: rgb(var(--bg-primary));
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    z-index: 201;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    overflow: hidden;
}

.spotlight.active {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) scale(1);
}

.spotlight-input {
    width: 100%;
    padding: 1rem 1.25rem;
    font-size: 1.125rem;
    border: none;
    background: transparent;
    color: rgb(var(--text-primary));
}

.spotlight-input:focus {
    outline: none;
}

.spotlight-results {
    max-height: 400px;
    overflow-y: auto;
    border-top: 1px solid rgb(var(--border-color));
}

.spotlight-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.spotlight-item:hover,
.spotlight-item.active {
    background-color: rgb(var(--bg-secondary));
}

.spotlight-item-icon {
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgb(var(--bg-tertiary));
    border-radius: 0.5rem;
    color: rgb(var(--text-secondary));
}

/* ============================================
   STATUS INDICATORS
   ============================================ */
.online-indicator {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
}

.online-indicator::before {
    content: '';
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background-color: #22c55e;
}

.online-indicator.offline::before {
    background-color: #ef4444;
}

.sync-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    background-color: #fef3c7;
    color: #92400e;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.dark .sync-badge {
    background-color: #78350f;
    color: #fcd34d;
}

/* ============================================
   POS SPECIFIC STYLES
   ============================================ */
.pos-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    height: calc(100vh - var(--topbar-height) - var(--bottomnav-height) - 2rem);
}

@media (min-width: 1024px) {
    .pos-layout {
        grid-template-columns: 1fr 400px;
        height: calc(100vh - var(--topbar-height) - 2rem);
    }
}

.pos-cart {
    background-color: rgb(var(--bg-primary));
    border: 1px solid rgb(var(--border-color));
    border-radius: 0.75rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pos-cart-items {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.pos-cart-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem;
    border-radius: 0.5rem;
    transition: background-color var(--transition-fast);
}

.pos-cart-item:hover {
    background-color: rgb(var(--bg-secondary));
}

.pos-cart-total {
    padding: 1rem;
    border-top: 1px solid rgb(var(--border-color));
    background-color: rgb(var(--bg-secondary));
}

.pos-numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    padding: 1rem;
}

.pos-numpad button {
    padding: 1rem;
    font-size: 1.25rem;
    font-weight: 600;
    background-color: rgb(var(--bg-tertiary));
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.pos-numpad button:hover {
    background-color: rgb(var(--border-color));
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .sidebar,
    .topbar,
    .bottom-nav,
    .no-print {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
    }
    
    .page-content {
        padding: 0 !important;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
}

/* Thermal receipt (80mm) */
@media print and (max-width: 80mm) {
    .receipt {
        width: 80mm;
        font-size: 12px;
    }
    
    .receipt-header {
        text-align: center;
        margin-bottom: 0.5rem;
    }
    
    .receipt-items {
        border-top: 1px dashed black;
        border-bottom: 1px dashed black;
        padding: 0.25rem 0;
    }
    
    .receipt-item {
        display: flex;
        justify-content: space-between;
        margin: 0.25rem 0;
    }
    
    .receipt-total {
        font-weight: bold;
        margin-top: 0.5rem;
    }
}

/* ============================================
   UTILITIES
   ============================================ */
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

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

.scrollbar-thin::-webkit-scrollbar-track {
    background: rgb(var(--bg-secondary));
}

.scrollbar-thin::-webkit-scrollbar-thumb {
    background: rgb(var(--border-color));
    border-radius: 3px;
}

.scrollbar-thin::-webkit-scrollbar-thumb:hover {
    background: rgb(var(--text-muted));
}

/* Hide scrollbar but keep functionality */
.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

/* Fade transition for SPA */
.page-transition {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Loading spinner */
.spinner {
    width: 1.5rem;
    height: 1.5rem;
    border: 2px solid rgb(var(--border-color));
    border-top-color: rgb(var(--color-primary));
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
