/* ==========================================================================
   A.M GORI — Reusable UI components (progressive enhancement)
   Does not rename existing IDs/classes required by JS.
   ========================================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

body {
    font-family: var(--font-sans, Inter, ui-sans-serif, system-ui, sans-serif);
    color: var(--text-primary);
    background: var(--background-app);
    -webkit-font-smoothing: antialiased;
}

:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 100000;
    padding: 12px 16px;
    background: var(--brand-primary);
    color: #fff;
    border-radius: 0 0 var(--radius-sm) 0;
    text-decoration: none;
    font-weight: 600;
}
.skip-link:focus {
    left: 0;
}

/* --------------------------------------------------------------------------
   App splash (startup only)
   -------------------------------------------------------------------------- */
.app-splash {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #002f1b 0%, #00552f 55%, #00381e 100%);
    color: #fff;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}
.app-splash.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.app-splash__inner {
    text-align: center;
    padding: 24px;
}
.app-splash__mark {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    display: block;
    object-fit: contain;
    border-radius: 18px;
    background: #fff;
    padding: 6px;
    box-shadow: var(--shadow-md);
}
.app-splash__brand {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}
.app-splash__sub {
    margin: 4px 0 0;
    font-size: 0.9rem;
    opacity: 0.85;
}
.app-splash__tag {
    margin: 10px 0 0;
    font-size: 0.8rem;
    opacity: 0.7;
}
.app-splash__loader {
    width: 36px;
    height: 36px;
    margin: 22px auto 0;
    border: 3px solid rgba(255,255,255,0.25);
    border-top-color: var(--brand-secondary);
    border-radius: 50%;
    animation: appSplashSpin 0.8s linear infinite;
}
@keyframes appSplashSpin {
    to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
    .app-splash__loader { animation: none; border-top-color: #fff; }
}

/* --------------------------------------------------------------------------
   Sticky header polish
   -------------------------------------------------------------------------- */
.header {
    position: sticky;
    top: 0;
    z-index: 900;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-light);
    box-shadow: var(--shadow-xs);
    border-radius: 0 !important;
}

.main-content {
    background: var(--background-app);
}

.dashboard-content {
    max-width: 1600px;
}

/* --------------------------------------------------------------------------
   Page header pattern
   -------------------------------------------------------------------------- */
.page-header,
.reports-header,
.dashboard-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px 16px;
    margin-bottom: 20px;
}
.page-header h1,
.page-header h2,
.dashboard-header h1,
.reports-title {
    margin: 0;
    color: var(--text-primary);
    font-weight: 700;
    letter-spacing: -0.01em;
}
.page-header p,
.page-description {
    margin: 4px 0 0;
    color: var(--text-secondary);
    font-size: 0.925rem;
}

/* --------------------------------------------------------------------------
   Cards / stats
   -------------------------------------------------------------------------- */
.card,
.stat-card,
.gf-summary-card,
.reports-card,
.ecc-card {
    background: var(--surface-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}
.card:hover,
.stat-card:hover {
    box-shadow: var(--shadow-sm);
}

.stat-card {
    padding: 16px 18px;
}
.stat-card .value,
.stat-card-content .value {
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn-primary,
button.btn-primary,
a.btn-primary {
    background: var(--brand-primary) !important;
    color: var(--text-inverse) !important;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-weight: 600;
    transition: background var(--transition-fast), box-shadow var(--transition-fast);
}
.btn-primary:hover { background: var(--brand-primary-hover) !important; }
.btn-primary:active { background: var(--brand-primary-active) !important; }

.btn-secondary,
button.btn-secondary,
a.btn-secondary {
    background: var(--brand-secondary) !important;
    color: var(--text-inverse) !important;
    border-radius: var(--radius-sm);
    font-weight: 600;
}
.btn-secondary:hover { background: var(--brand-secondary-hover) !important; }

.btn-soft,
.btn-light {
    background: var(--brand-primary-soft) !important;
    color: var(--brand-primary) !important;
    border: 1px solid var(--border-default) !important;
    border-radius: var(--radius-sm);
}

.btn-danger,
button.btn-danger {
    background: var(--danger) !important;
    color: #fff !important;
    border-radius: var(--radius-sm);
}

.btn-link {
    background: transparent;
    border: none;
    color: var(--brand-primary);
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
}

button:disabled,
.btn-primary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none !important;
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
label {
    color: var(--text-secondary);
    font-weight: 500;
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
input[type="tel"],
select,
textarea {
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--surface-primary);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
input:focus,
select:focus,
textarea:focus {
    border-color: var(--brand-secondary);
    box-shadow: var(--focus-ring);
    outline: none;
}
input:disabled,
select:disabled,
textarea:disabled {
    background: var(--background-subtle);
    color: var(--text-muted);
}
.is-invalid,
input.error,
.form-error input {
    border-color: var(--danger) !important;
}
.field-hint,
.help-text {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-muted);
}
.field-error {
    color: var(--danger);
    font-size: 12px;
    margin-top: 4px;
}

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table-scroll,
.table-responsive,
.card > .table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--surface-primary);
    position: relative;
}
.table-scroll::after {
    content: "";
    pointer-events: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(90deg, transparent, rgba(245, 248, 246, 0.9));
    opacity: 0.9;
}
.dashboard-content .card {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table.data-table,
.card table,
.dashboard-content table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

/* Dense operational tables: allow controlled horizontal scroll on small screens */
@media (max-width: 768px) {
    .dashboard-content table,
    .card table.data-table {
        min-width: 640px;
    }
}
.dashboard-content table thead th,
.card table thead th,
table.data-table thead th {
    background: var(--table-header-bg);
    color: var(--text-primary);
    font-weight: 600;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-default);
    white-space: nowrap;
}
.dashboard-content table tbody td,
.card table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
    vertical-align: middle;
}
.dashboard-content table tbody tr:hover {
    background: var(--surface-secondary);
}
.num,
.money,
td.amount,
th.amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Badges / chips / alerts
   -------------------------------------------------------------------------- */
.badge,
.status-chip,
.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
}
.badge-success,
.pill--ok { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }

.alert,
.login-flash {
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    border: 1px solid var(--border-default);
}
.alert-success { background: var(--success-soft); border-color: #b7e4c7; color: #14532d; }
.alert-warning { background: var(--warning-soft); border-color: #f0d59a; color: #7a4d00; }
.alert-danger { background: var(--danger-soft); border-color: #f5c2c0; color: #7f1d1d; }
.alert-info { background: var(--info-soft); border-color: #b6d4f0; color: #1e3a5f; }

/* --------------------------------------------------------------------------
   Skeleton loaders (async only)
   -------------------------------------------------------------------------- */
.skeleton {
    position: relative;
    overflow: hidden;
    background: var(--background-subtle);
    border-radius: var(--radius-sm);
    color: transparent !important;
    pointer-events: none;
    user-select: none;
}
.skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.55), transparent);
    transform: translateX(-100%);
    animation: skeletonShimmer 1.4s ease-in-out infinite;
}
.skeleton-line { height: 12px; margin: 8px 0; }
.skeleton-card { height: 96px; border-radius: var(--radius-md); }
.skeleton-chart { height: 220px; border-radius: var(--radius-md); }
.skeleton-row { height: 40px; margin-bottom: 8px; }

@keyframes skeletonShimmer {
    100% { transform: translateX(100%); }
}
@media (prefers-reduced-motion: reduce) {
    .skeleton::after { animation: none; display: none; }
}

/* SPA loader upgrade (class names preserved) */
.spa-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 220px;
    padding: 32px;
}
.spa-loader-inner {
    text-align: center;
    color: var(--text-secondary);
}
.spa-loader-spinner {
    width: 36px;
    height: 36px;
    margin: 0 auto 12px;
    border: 3px solid var(--border-default);
    border-top-color: var(--brand-primary);
    border-radius: 50%;
    animation: appSplashSpin 0.75s linear infinite;
}
.spa-loader-text {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    background: var(--surface-primary);
    border: 1px dashed var(--border-default);
    border-radius: var(--radius-md);
}

/* --------------------------------------------------------------------------
   PWA install banner
   -------------------------------------------------------------------------- */
.pwa-install {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 16px;
    z-index: 9500;
    max-width: 420px;
    margin: 0 auto;
    background: var(--surface-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 16px 18px;
    display: none;
}
.pwa-install.is-visible { display: block; }
.pwa-install__title {
    margin: 0 0 4px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}
.pwa-install__desc {
    margin: 0 0 14px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}
.pwa-install__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.pwa-install__actions .btn-primary,
.pwa-install__actions .btn-soft {
    flex: 1;
    min-width: 120px;
    text-align: center;
    cursor: pointer;
}
.pwa-install__ios {
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-muted);
    display: none;
}
.pwa-install__ios.is-visible { display: block; }

/* --------------------------------------------------------------------------
   Modals (visual only — IDs/events unchanged)
   -------------------------------------------------------------------------- */
.modal-overlay,
#modalRoot .modal-backdrop {
    backdrop-filter: blur(2px);
}
.modal,
.modal-dialog,
#modalRoot .modal {
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-lg);
}

/* --------------------------------------------------------------------------
   Offline page helpers
   -------------------------------------------------------------------------- */
.offline-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(160deg, #002f1b, #00552f 60%, #00381e);
}
.offline-card {
    width: min(440px, 100%);
    background: #fff;
    border-radius: var(--radius-xl);
    padding: 32px 28px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}
.offline-card img {
    width: 72px;
    height: 72px;
    object-fit: contain;
    margin: 0 auto 14px;
    display: block;
    border-radius: 16px;
    background: #fff;
}
.offline-card h1 {
    margin: 0 0 8px;
    color: var(--brand-primary);
    font-size: 1.35rem;
}
.offline-card p {
    margin: 0 0 8px;
    color: var(--text-secondary);
    font-size: 0.925rem;
}
.offline-card .btn-retry {
    margin-top: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-pill);
    background: var(--brand-primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

/* --------------------------------------------------------------------------
   Responsive helpers
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .header {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
    .pos-button span { display: none; }
    .user-name { display: none; }
    .pwa-install { left: 12px; right: 12px; bottom: 12px; }
}

@media (max-width: 430px) {
    .language-selector { display: none; }
    .stat-card { padding: 12px; }
}

/* Print safety */
@media print {
    .app-splash,
    .pwa-install,
    .skip-link,
    .spa-loader,
    .sidebar,
    .sidebar-toggle,
    .sidebar-backdrop,
    .header,
    .toast,
    #toastRoot,
    .no-print {
        display: none !important;
    }
    .main-content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }
    body {
        background: #fff !important;
        color: #000 !important;
    }
}
