/* ==========================================================================
   KayelAuto POS - shared design layer
   Loaded last in <head> so its :root tokens override each page's inline theme.
   Dark "utility" theme for a data-dense POS: one interactive accent (blue),
   green / red / amber reserved for semantic state only.
   ========================================================================== */

:root {
    /* Surfaces (off-black, never pure #000) */
    --dark-bg: #15171c;
    --darker-bg: #0f1115;
    --card-bg: #1b1e24;
    --card-bg-2: #21252d;
    --border-color: #2b313b;
    --border-strong: #3a424f;

    /* Text (off-white, never pure #fff) */
    --text-primary: #e6e8ec;
    --text-secondary: #98a1ae;
    --text-muted: #6b7280;

    /* Single interactive accent + semantic state colors */
    --accent-blue: #6ea8fe;
    --accent-primary: #6ea8fe;
    --accent-green: #4ade80;
    --accent-red: #f87171;
    --accent-yellow: #fbbf24;
    /* purple retired in favour of the single interactive accent */
    --accent-purple: #6ea8fe;

    /* Shape + depth */
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    --ring: 0 0 0 3px rgba(110, 168, 254, .35);

    /* Type */
    --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-sans);
    background-color: var(--dark-bg);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

a { color: var(--accent-blue); }

::selection { background: rgba(110, 168, 254, .3); }

/* Accessible focus ring for keyboard users only */
:focus-visible {
    outline: none;
    box-shadow: var(--ring);
    border-radius: var(--radius-sm);
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--darker-bg); }
::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 999px;
    border: 2px solid var(--darker-bg);
}
::-webkit-scrollbar-thumb:hover { background: #4a5464; }

/* --------------------------------------------------------------------------
   Forms - dark, AA contrast, consistent radius
   -------------------------------------------------------------------------- */
input, select, textarea,
.form-control, .form-select {
    background-color: var(--darker-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    min-height: 42px;
}

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

input:focus, select:focus, textarea:focus,
.form-control:focus, .form-select:focus {
    background-color: var(--darker-bg);
    border-color: var(--accent-blue);
    box-shadow: var(--ring);
    color: var(--text-primary);
    outline: none;
}

.form-label { color: var(--text-secondary); font-weight: 500; }

/* Native date pickers on dark */
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(.8); }

/* --------------------------------------------------------------------------
   Buttons - shared press/focus behaviour (colors come from each page)
   -------------------------------------------------------------------------- */
.btn, .btn-pay, .btn-print, .btn-quotation, .btn-cancel, .btn-logout {
    border-radius: var(--radius-sm);
    font-weight: 600;
    transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}

.btn:active, .btn-pay:active, .btn-print:active, .btn-quotation:active,
.btn-cancel:active, .btn-logout:active { transform: translateY(1px) scale(.99); }

.btn:focus-visible, .btn-pay:focus-visible, .btn-print:focus-visible,
.btn-quotation:focus-visible, .btn-cancel:focus-visible, .btn-logout:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

.btn:hover, .btn-pay:hover, .btn-print:hover, .btn-quotation:hover,
.btn-cancel:hover, .btn-logout:hover { filter: brightness(1.06); opacity: 1; }

/* --------------------------------------------------------------------------
   Cards & surfaces
   -------------------------------------------------------------------------- */
.card, .main-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.card-header, .card-footer {
    background-color: var(--card-bg-2);
    border-color: var(--border-color);
}

/* --------------------------------------------------------------------------
   Tables - dark by default; reports get Bootstrap dark theme too
   -------------------------------------------------------------------------- */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-primary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.table > :not(caption) > * > * { border-bottom-color: var(--border-color); }

.table th {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    background-color: var(--darker-bg);
}

.table tbody tr { transition: background-color .12s ease; }
.table tbody tr:hover { background-color: rgba(255, 255, 255, .03); }

.table-responsive { -webkit-overflow-scrolling: touch; }

/* Status tints that survive dark mode (stock report) */
.low-stock { background-color: rgba(251, 191, 36, .14) !important; }
.out-of-stock { background-color: rgba(248, 113, 113, .16) !important; }

/* --------------------------------------------------------------------------
   Dashboard POS specifics
   -------------------------------------------------------------------------- */

/* Price / qty inputs used to render black-on-dark (invisible). Fix contrast. */
.editable-cell {
    color: var(--text-primary);
    background-color: var(--darker-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    min-height: 38px;
}

.editable-cell:focus { border-color: var(--accent-blue); box-shadow: var(--ring); }

/* Search suggestions were light-on-dark. Re-theme. */
.suggestions {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.suggestion-item { border-bottom: 1px solid var(--border-color); color: var(--text-primary); }
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background-color: var(--darker-bg); }
.suggestion-item .price { color: var(--text-secondary); }
.suggestion-item .stock { color: var(--accent-green); }
.suggestion-item .out-of-stock { color: var(--accent-red); }

/* On phones the cart becomes a card list and moves below the search/actions. */
@media (max-width: 767px) {
    .content-wrapper > .main-card { order: 2; }
    .content-wrapper > .d-flex.flex-column { order: 1; }

    .main-card .table thead { display: none; }
    .main-card .table,
    .main-card .table tbody,
    .main-card .table tr,
    .main-card .table td { display: block; width: 100%; }

    .main-card .table tr {
        background: var(--darker-bg);
        border: 1px solid var(--border-color);
        border-radius: var(--radius);
        margin-bottom: .75rem;
        padding: .5rem .85rem;
    }

    .main-card .table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        padding: .4rem 0;
        border: none;
    }

    .main-card .table td::before {
        color: var(--text-secondary);
        font-size: .78rem;
        text-transform: uppercase;
        letter-spacing: .04em;
    }

    .main-card .table td:nth-child(1) {
        font-weight: 600;
        font-size: 1.05rem;
        padding-bottom: .5rem;
        margin-bottom: .25rem;
        border-bottom: 1px solid var(--border-color);
    }
    .main-card .table td:nth-child(1)::before { content: none; }
    .main-card .table td:nth-child(2)::before { content: "Price"; }
    .main-card .table td:nth-child(3)::before { content: "Qty"; }
    .main-card .table td:nth-child(4)::before { content: "Total"; }
    .main-card .table td:nth-child(5)::before { content: none; }
    .main-card .table td:nth-child(5) { justify-content: flex-end; }
}

/* Wide tables inside custom containers should scroll on small screens. */
.product-table-container, .history-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Payment method toggle on the POS */
.payment-method {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .3rem;
    padding: .25rem;
    margin-bottom: .5rem;
    background: var(--darker-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.pay-method {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 600;
    padding: .6rem;
    min-height: 42px;
    border-radius: 6px;
    cursor: pointer;
}

.pay-method.active { background: var(--accent-blue); color: #0b1220; }
.pay-method:focus-visible { outline: none; box-shadow: var(--ring); }
.btn-pay.credit-mode { background-color: var(--accent-yellow); }

/* --------------------------------------------------------------------------
   Bootstrap dark-theme touch-ups (reports)
   -------------------------------------------------------------------------- */
[data-bs-theme="dark"] .card { background-color: var(--card-bg); border-color: var(--border-color); }
[data-bs-theme="dark"] .table { --bs-table-bg: transparent; }
[data-bs-theme="dark"] .summary-card { box-shadow: var(--shadow-sm); }
[data-bs-theme="dark"] .mobile-nav-btn { color: var(--text-primary) !important; }

/* Report pages hardcode light surfaces in their own mobile CSS; re-theme. */
.mobile-action-menu { background: var(--card-bg) !important; box-shadow: 0 -2px 10px rgba(0, 0, 0, .5) !important; }
.mobile-back-btn { background: var(--card-bg) !important; color: var(--text-primary); border: 1px solid var(--border-color); }
.mobile-nav-panel { background-color: var(--darker-bg) !important; border-top-color: var(--border-color) !important; }
.mobile-card { background: var(--card-bg) !important; box-shadow: var(--shadow-sm) !important; }
.mobile-card-label { color: var(--text-secondary) !important; }
.filter-toggle { background: var(--darker-bg) !important; border-color: var(--border-color) !important; color: var(--text-primary); }

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