/**
 * ERP System - Main Stylesheet
 * Global styles and utilities
 */

/* ========================================
   View Transitions API (cross-document)
   Opt-in for smooth page transitions on same-origin navigation.
   Supported: Chrome 126+, Safari 18.2+. Gracefully ignored elsewhere.
   ======================================== */
@view-transition {
  navigation: auto;
}

::view-transition-old(root) {
  animation: view-transition-fade-out 0.2s ease-out forwards;
}

::view-transition-new(root) {
  animation: view-transition-fade-in 0.2s ease-in forwards;
}

@keyframes view-transition-fade-out {
  to {
    opacity: 0;
  }
}

@keyframes view-transition-fade-in {
  from {
    opacity: 0;
  }
}

/* ========================================
   CSS Variables
   ======================================== */
:root {
    /* Fallback until common.js measures .app-header; overridden live via documentElement.style */
    --header-height: 120px;
}

/* ========================================
   Reset & Base Styles
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
    background: #f8f9fa;
    color: #202124;
    padding: 0;
    margin: 0;
    line-height: 1.5;
    min-height: 100vh;
}

/* Smooth scrolling; scroll-padding matches .content-wrapper / .container top inset under fixed header */
html {
    scroll-behavior: smooth;
}

html:has(.app-header) {
    scroll-padding-top: calc(var(--header-height) + 20px);
}

/* Optimize rendering performance */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   Layout
   ======================================== */
/* Centralized header spacing — only on .content-wrapper (page shell).
   Nested .container (e.g. dashboard) must not repeat the same padding-top or the offset doubles. */
.content-wrapper {
    padding-top: calc(var(--header-height) + 20px) !important;
}

.content-wrapper {
    max-width: 100%;
    margin: 0 auto;
    padding-left: 20px;
    padding-right: 20px;
    padding-bottom: 20px;
    /* padding-top is set above with !important to ensure it's not overridden */
    min-height: calc(100vh - var(--header-height) - 20px);
}

/* Width + horizontal padding; top spacing comes from parent .content-wrapper */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding-left: 20px;
    padding-right: 20px;
    padding-bottom: 20px;
    padding-top: 0;
}

/* ========================================
   Typography
   ======================================== */
h1, h2, h3, h4, h5, h6 {
    font-weight: 500;
    line-height: 1.2;
}

/* ========================================
   Utility Classes
   ======================================== */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-left {
    text-align: left;
}

.no-wrap {
    white-space: nowrap;
}

.hidden {
    display: none !important;
}

/* ========================================
   Badges
   ======================================== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.badge-active,
.badge-paid,
.badge-fulfilled {
    background: #e6f4ea;
    color: #137333;
}

.badge-pending,
.badge-draft,
.badge-unfulfilled {
    background: #fef7e0;
    color: #b06000;
}

.badge-refunded,
.badge-archived {
    background: #fce8e6;
    color: #c5221f;
}

.badge-partial {
    background: #e8f0fe;
    color: #1967d2;
}

.badge-test {
    background: #f3e8fd;
    color: #9334e9;
}

/* ========================================
   Buttons
   ======================================== */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: #1a73e8;
    color: white;
}

.btn-primary:hover {
    background: #1557b0;
}

.btn-secondary {
    background: #f1f3f4;
    color: #202124;
}

.btn-secondary:hover {
    background: #e8eaed;
}

/* ========================================
   Forms
   ======================================== */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid #dadce0;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: all 0.3s;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #1a73e8;
    box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.1);
}

/* ========================================
   Loading States
   ======================================== */
.loading {
    text-align: center;
    padding: 40px;
    color: #5f6368;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #e0e0e0;
    border-top-color: #1a73e8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ========================================
   Empty States
   ======================================== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #5f6368;
}

.empty-state-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 18px;
    color: #202124;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
}

/* ========================================
   Cards
   ======================================== */
.card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    padding: 20px;
    margin-bottom: 20px;
}

/* ========================================
   Tags
   ======================================== */
.tag {
    background: #e8eaed;
    color: #5f6368;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    display: inline-block;
}

/* ========================================
   Images
   ======================================== */
.product-image,
.order-image {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
}

/* Orders page: larger product images */
.orders-table .product-image,
.orders-table .order-image {
    width: 80px;
    height: 80px;
}

/* ========================================
   Tables - Centralized Styles
   ======================================== */
/* Table Container */
.table-container {
    max-height: calc(100vh - 180px);
    overflow-y: auto;
    overflow-x: auto;
}

.table-container table {
    width: 100%;
}

/* Base Table Styles */
table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 11px;
    line-height: 1.3;
    background: white;
}


th {
    text-align: left;
    padding: 6px 8px;
    font-weight: 600;
    color: #5f6368;
    border-bottom: 2px solid #e0e0e0;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    position: relative;
    min-width: 80px;
    line-height: 1.3;
}

th.resizing {
    cursor: col-resize;
}

th:hover {
    background: #e8eaed;
}

/* Resize Handle */
.resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    width: 5px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
    z-index: 1;
}

.resize-handle:hover {
    background: rgba(26, 115, 232, 0.3);
}

.resize-handle.resizing {
    background: rgba(26, 115, 232, 0.5);
}

/* Table Body */
td {
    padding: 6px 8px;
    border-bottom: 1px solid #f0f0f0;
    line-height: 1.3;
}

/* Table Rows */
tr {
    transition: background 0.2s;
}

tr:hover {
    background: #f8f9fa;
}

tr.order-row {
    cursor: pointer;
}

tr.order-row:hover {
    background: #f8f9fa;
}

tr.order-detail-row {
    border-top: 1px solid #f0f0f0;
}

tr.order-detail-row:hover {
    background: #f8f9fa;
}

/* Sticky/Frozen Columns */
.freeze-col {
    position: sticky;
    left: 0;
    background: white;
    z-index: 5;
    box-shadow: 2px 0 4px rgba(0,0,0,0.05);
}

thead .freeze-col {
    z-index: 15;
    background: #f8f9fa;
}

tr:hover .freeze-col {
    background: #f8f9fa;
}

/* Table-specific overrides for permissions table */
.permissions-table {
    overflow-x: auto;
    margin-top: 20px;
}

/* Override all global table styles for permissions table */
.permissions-table table {
    min-width: 100% !important;
    table-layout: auto !important; /* Override fixed layout to respect min-width on columns */
    width: auto !important; /* Allow table to expand based on content */
    border-collapse: collapse;
    font-size: 11px;
    line-height: 1.3;
    background: white;
}

/* Keep header sticky at top for vertical scrolling, but remove horizontal sticky columns */
.permissions-table th {
    position: sticky !important;
    top: 0 !important;
    left: auto !important; /* Remove any left positioning that might cause overlap */
    background: #f8f9fa !important;
    z-index: 1;
    text-align: center;
    padding: 6px 8px !important;
    font-weight: 600;
    color: #5f6368;
    border-bottom: 2px solid #e0e0e0;
    white-space: normal !important; /* Override global white-space: nowrap */
    cursor: default !important;
    user-select: none;
    min-width: auto !important; /* Override global min-width: 80px */
    line-height: 1.3;
    width: auto !important; /* Allow columns to size based on content */
}

/* Remove sticky positioning from ALL columns to allow free horizontal scrolling */
/* First column (Phone) */
.permissions-table th:first-child,
.permissions-table td:first-child {
    position: static !important;
    background: white !important;
    box-shadow: none !important;
    min-width: 150px !important; /* Ensure minimum width for Phone column */
    width: auto !important;
    left: auto !important;
}

.permissions-table th:first-child {
    background: #f8f9fa !important;
    position: sticky !important; /* Only sticky at top, not left */
    top: 0 !important;
    left: auto !important;
}

/* Second column (Name) */
.permissions-table th:nth-child(2),
.permissions-table td:nth-child(2) {
    position: static !important;
    background: white !important;
    box-shadow: none !important;
    min-width: 120px !important; /* Ensure minimum width for Name column */
    width: auto !important;
    left: auto !important;
}

.permissions-table th:nth-child(2) {
    background: #f8f9fa !important;
    position: sticky !important; /* Only sticky at top, not left */
    top: 0 !important;
    left: auto !important;
}

/* Override all other columns to ensure no sticky positioning */
.permissions-table th:nth-child(n+3),
.permissions-table td:nth-child(n+3) {
    position: static !important;
    left: auto !important;
    box-shadow: none !important;
}

.permissions-table td {
    text-align: center;
    padding: 6px 8px;
    border-bottom: 1px solid #f0f0f0;
    line-height: 1.3;
    white-space: normal;
}

.permissions-table input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* ========================================
   Responsive Design
   ======================================== */
@media (max-width: 968px) {
    .content-wrapper {
        padding: 12px;
    }
    
    .badge {
        font-size: 10px;
        padding: 1px 6px;
    }
}

@media (max-width: 640px) {
    body {
        font-size: 14px;
    }
    
    .content-wrapper {
        padding: 8px;
    }
}

/* ========================================
   Watermark - Data Leak Prevention
   ======================================== */
.watermark {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 99999;
    overflow: hidden;
    background: transparent;
}

.watermark-content {
    position: absolute;
    opacity: 0.02;
    font-size: 36px;
    font-weight: bold;
    color: #000;
    transform: rotate(-15deg);
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 400px;
    height: 200px;
}

.watermark-id {
    font-size: 20px;
    font-weight: normal;
    margin-top: 4px;
}

/* Ensure watermark doesn't interfere with printing */
@media print {
    .watermark {
        display: none;
    }
}

