/* ================================================================
   EasyRetail — Base + Components
   Service-desk / workshop aesthetic. Built on tokens.css.
   Keep legacy classes (.btn1/.btnbrown/.middlediv/.dn) working
   while new components (.btn, .badge, .card, .field, .modal)
   carry forward the modernization.
   ================================================================ */

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

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

body {
    margin: 0;
    padding: 0;
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--line-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--color-primary);
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

a:hover {
    opacity: 0.85;
}

h1, h2, h3, h4 {
    margin: 0;
    font-weight: var(--font-weight-semi);
    line-height: var(--line-tight);
    color: var(--color-text);
}

h2 {
    font-size: var(--text-xl);
    padding-bottom: var(--space-3);
    text-align: center;
}

hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: var(--space-4) 0;
}

/* ---------- Utilities ---------- */
.dn { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
}

.stack {
    display: grid;
    gap: var(--space-3);
}

.row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.muted { color: var(--color-text-muted); }
.subtle { color: var(--color-text-subtle); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }
.right { text-align: right; }
.center { text-align: center; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--color-text-subtle); }


/* ================================================================
   Focus ring — accessibility (replaces outline:none)
   ================================================================ */
:where(a, button, input, textarea, select, [role="button"], [tabindex]):focus {
    outline: none;
}
:where(a, button, input, textarea, select, [role="button"], [tabindex]):focus-visible {
    box-shadow: var(--ring-focus);
    border-radius: var(--radius-sm);
}


/* ================================================================
   Button
   ================================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: 40px;
    padding: 0 var(--space-4);
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: inherit;
    font-size: var(--text-base);
    font-weight: var(--font-weight-semi);
    line-height: 1;
    cursor: pointer;
    user-select: none;
    transition: background var(--duration) var(--ease-standard),
                border-color var(--duration) var(--ease-standard),
                color var(--duration) var(--ease-standard),
                box-shadow var(--duration) var(--ease-standard),
                transform var(--duration-fast) var(--ease-standard);
    text-decoration: none;
    white-space: nowrap;
}

.btn > img, .btn > svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.btn:hover { opacity: 1; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-sm { height: 32px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn-lg { height: 48px; padding: 0 var(--space-5); font-size: var(--text-md); }

.btn-block { width: 100%; }

/* Variants */
.btn-primary {
    background: var(--color-primary);
    color: var(--color-primary-contrast);
    border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }
.btn-primary:active { background: var(--color-primary-active); border-color: var(--color-primary-active); }

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border-strong);
}
.btn-secondary:hover { background: var(--color-surface-alt); border-color: var(--color-text-subtle); }

.btn-ghost {
    background: transparent;
    color: var(--color-text);
    border-color: transparent;
}
.btn-ghost:hover { background: var(--color-surface-sunken); }

.btn-danger {
    background: var(--color-danger);
    color: var(--color-danger-contrast);
    border-color: var(--color-danger);
}
.btn-danger:hover { filter: brightness(0.95); }

.btn-success {
    background: var(--color-success);
    color: var(--color-success-contrast);
    border-color: var(--color-success);
}
.btn-success:hover { filter: brightness(0.95); }

.btn-icon {
    width: 40px;
    padding: 0;
    flex: 0 0 auto;
}
.btn-icon.btn-sm { width: 32px; }


/* ================================================================
   Form fields
   ================================================================ */
.field {
    display: grid;
    gap: var(--space-1);
}

.field-label {
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-muted);
}

.input,
.select,
.textarea {
    display: block;
    width: 100%;
    height: 40px;
    padding: 0 var(--space-3);
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
    color: var(--color-text);
    font: inherit;
    font-size: var(--text-base);
    transition: border-color var(--duration) var(--ease-standard),
                box-shadow var(--duration) var(--ease-standard);
}

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

.textarea {
    height: auto;
    min-height: 80px;
    padding: var(--space-2) var(--space-3);
    line-height: var(--line-normal);
    resize: vertical;
}

.input:focus, .select:focus, .textarea:focus {
    border-color: var(--color-primary);
    box-shadow: var(--ring-focus);
    outline: none;
}

.input[readonly], .input[disabled] {
    background: var(--color-surface-sunken);
    color: var(--color-text-muted);
}

.input-sm { height: 32px; font-size: var(--text-sm); padding: 0 var(--space-2); }

.input-search {
    padding-left: 34px;
    background-image: url(/icons/search.svg);
    background-repeat: no-repeat;
    background-size: 18px 18px;
    background-position: 10px center;
}


/* ================================================================
   Card
   ================================================================ */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
}

.card-header,
.card-body,
.card-footer {
    padding: var(--space-4);
}

.card-header {
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.card-footer {
    border-top: 1px solid var(--color-border);
    background: var(--color-surface-alt);
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}

.card-title {
    font-size: var(--text-md);
    font-weight: var(--font-weight-semi);
}


/* ================================================================
   Badge (status pill)
   ================================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px var(--space-2);
    min-height: 22px;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-semi);
    line-height: 1.2;
    background: var(--color-neutral-soft);
    color: var(--color-neutral);
    white-space: nowrap;
}

.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: currentColor;
    flex: 0 0 auto;
}

.badge-new        { background: var(--status-new-bg);       color: var(--status-new-fg); }
.badge-partial    { background: var(--status-partial-bg);   color: var(--status-partial-fg); }
.badge-ready      { background: var(--status-ready-bg);     color: var(--status-ready-fg); }
.badge-delivered  { background: var(--status-delivered-bg); color: var(--status-delivered-fg); }
.badge-cancelled  { background: var(--status-cancelled-bg); color: var(--status-cancelled-fg); }

.badge-flat::before { display: none; }


/* ================================================================
   Table
   ================================================================ */
.table {
    width: 100%;
    background: var(--color-surface);
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    font-size: var(--text-base);
}

.table th,
.table td {
    padding: var(--space-3) var(--space-3);
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}

.table th {
    font-weight: var(--font-weight-semi);
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    background: var(--color-surface-alt);
    user-select: none;
}

.table tbody tr:hover {
    background: var(--color-surface-alt);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table-clickable tbody tr { cursor: pointer; }

.table-compact th, .table-compact td {
    padding: var(--space-2) var(--space-3);
}


/* ================================================================
   Modal
   ================================================================ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.5);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    animation: mb-in var(--duration) var(--ease-standard);
}

@keyframes mb-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 520px;
    max-height: calc(100vh - var(--space-8));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: m-in var(--duration) var(--ease-standard);
}

@keyframes m-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header,
.modal-body,
.modal-footer {
    padding: var(--space-4);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
    border-bottom: 1px solid var(--color-border);
}

.modal-title {
    font-size: var(--text-lg);
    font-weight: var(--font-weight-semi);
}

.modal-body {
    flex: 1 1 auto;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    gap: var(--space-2);
    justify-content: flex-end;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface-alt);
}

.modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    cursor: pointer;
    color: var(--color-text-muted);
    font-size: 20px;
    line-height: 1;
}
.modal-close:hover { background: var(--color-surface-sunken); color: var(--color-text); }


/* ================================================================
   App shell (header / sidebar / content)
   ================================================================ */
.app-header {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr auto;
    align-items: center;
    gap: var(--space-4);
    height: var(--header-height);
    padding: 0 var(--space-4);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.app-header .brand {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: 100%;
}

.app-header .brand img {
    max-height: 40px;
    max-width: 100%;
    object-fit: contain;
}

.app-header .page-title {
    font-size: var(--text-lg);
    font-weight: var(--font-weight-semi);
    color: var(--color-text);
    margin: 0;
}

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: calc(100vh - var(--header-height));
}

.app-sidebar {
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: var(--space-4) var(--space-2);
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
}

.app-sidebar .nav {
    display: grid;
    gap: 2px;
}

.app-sidebar .nav a {
    display: grid;
    grid-template-columns: 32px 1fr;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    color: var(--color-text);
    font-weight: var(--font-weight-medium);
    font-size: var(--text-base);
    transition: background var(--duration) var(--ease-standard);
    white-space: normal;
    line-height: var(--line-tight);
}

.app-sidebar .nav a:hover {
    background: var(--color-surface-sunken);
    opacity: 1;
}

.app-sidebar .nav a.active {
    background: var(--color-primary-soft);
    color: var(--color-primary);
}

.app-sidebar .nav a img {
    width: 22px;
    height: 22px;
    justify-self: center;
}

.app-main {
    padding: var(--space-6);
    max-width: var(--content-max);
    width: 100%;
    margin: 0 auto;
}


/* ================================================================
   User menu dropdown (header top-right)
   ================================================================ */
.user-menu {
    position: relative;
}

.user-menu-trigger {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-full);
    cursor: pointer;
    background: transparent;
    border: 1px solid transparent;
}
.user-menu-trigger:hover { background: var(--color-surface-sunken); }

.user-menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 200px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: var(--space-1);
    z-index: var(--z-dropdown);
}

.user-menu-panel a {
    display: grid;
    grid-template-columns: 20px 1fr;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    color: var(--color-text);
    font-size: var(--text-base);
}
.user-menu-panel a:hover { background: var(--color-surface-sunken); opacity: 1; }
.user-menu-panel a img { width: 18px; height: 18px; }


/* ================================================================
   Mobile: off-canvas sidebar
   ================================================================ */
.app-burger { display: none; }

@media (max-width: 900px) {
    .app-header {
        grid-template-columns: auto 1fr auto;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .app-sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        width: min(280px, 85vw);
        height: calc(100vh - var(--header-height));
        transform: translateX(-100%);
        transition: transform var(--duration) var(--ease-standard);
        z-index: var(--z-drawer);
        box-shadow: var(--shadow-lg);
    }

    .app-sidebar.is-open { transform: translateX(0); }

    .app-burger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border: none;
        background: transparent;
        cursor: pointer;
        border-radius: var(--radius);
    }
    .app-burger:hover { background: var(--color-surface-sunken); }
    .app-burger img { width: 24px; height: 24px; }

    .app-main { padding: var(--space-4); }
}


/* ================================================================
   Auth shell — used by /signin /join /signup etc.
   Hides sidebar, centers content card.
   ================================================================ */
.app-header--auth {
    grid-template-columns: 1fr !important;
    justify-content: center;
}
.app-header--auth .brand { justify-content: center; }
.app-header--auth .app-burger,
.app-header--auth .page-title,
.app-header--auth .user-menu { display: none; }

body:has(.app-header--auth) .app-shell { grid-template-columns: 1fr; }
body:has(.app-header--auth) .app-sidebar { display: none; }

.auth-card {
    max-width: 380px;
    margin: var(--space-8) auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6) var(--space-5);
    box-shadow: var(--shadow-sm);
}

.auth-card h1 {
    font-size: var(--text-xl);
    text-align: center;
    margin-bottom: var(--space-5);
}

.auth-card .field { margin-bottom: var(--space-4); }

.auth-divider {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin: var(--space-5) 0;
    color: var(--color-text-muted);
    font-size: var(--text-sm);
}
.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--color-border);
}


/* ================================================================
   Backwards compatibility layer — legacy classes used across
   inline <style> blocks in existing pages. Mapped to new tokens
   so old pages keep working until migrated.
   ================================================================ */
.btn1 {
    cursor: pointer;
    display: grid;
    grid-template-columns: 36px 100px;
    align-items: center;
    gap: var(--space-2);
    background-color: var(--color-surface);
    height: 46px;
    padding: 0 var(--space-2);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
    width: 134px;
    transition: background var(--duration) var(--ease-standard),
                border-color var(--duration) var(--ease-standard);
}
.btn1:hover { background: var(--color-surface-alt); border-color: var(--color-text-subtle); opacity: 1; }
.btn1 img { padding: 5px; max-height: 36px; max-width: 36px; margin: 0 auto; }
.btn1 span { color: var(--color-text); font-weight: var(--font-weight-semi); font-size: var(--text-sm); line-height: 1.3; }

.btngreen  { background-color: var(--color-success-soft) !important; }
.btnbrown  { background-color: var(--color-warning-soft) !important; }
.btnblue   { background-color: var(--color-info-soft) !important; }
.btnred    { background-color: var(--color-danger-soft) !important; }
.btngrey   { background-color: var(--color-neutral-soft) !important; }
.btninverse { grid-template-columns: 100px 34px !important; text-align: right !important; }

.icon20 { max-height: 20px !important; max-width: 20px !important; }


/* Step progress — keep but refresh colors */
.StepProgress {
    position: relative;
    padding-left: 45px;
    list-style: none;
}
.StepProgress::before {
    display: inline-block;
    content: '';
    position: absolute;
    top: 0;
    left: 15px;
    width: 10px;
    height: 100%;
    border-left: 2px solid var(--color-border-strong);
}
.StepProgress-item { position: relative; counter-increment: list; }
.StepProgress-item:not(:last-child) { padding-bottom: 20px; }
.StepProgress-item::before {
    display: inline-block;
    content: '';
    position: absolute;
    left: -30px;
    height: 100%;
    width: 10px;
}
.StepProgress-item::after {
    content: '';
    display: inline-block;
    position: absolute;
    top: 0;
    left: -37px;
    width: 12px;
    height: 12px;
    border: 2px solid var(--color-border-strong);
    border-radius: 50%;
    background-color: var(--color-surface);
}
.StepProgress-item.is-done::before { border-left: 2px solid var(--color-success); }
.StepProgress-item.is-done::after {
    content: "\2714";
    font-size: 10px;
    color: var(--color-success-contrast);
    text-align: center;
    border: 2px solid var(--color-success);
    background-color: var(--color-success);
}
.StepProgress-item.current::before { border-left: 2px solid var(--color-primary); }
.StepProgress-item.current::after {
    content: counter(list);
    padding-top: 1px;
    width: 19px;
    height: 18px;
    top: -4px;
    left: -40px;
    font-size: 14px;
    text-align: center;
    color: var(--color-primary);
    border: 2px solid var(--color-primary);
    background-color: var(--color-surface);
}


/* ================================================================
   Action button (appointment / order footer actions)
   Icon on the left, label on the right, full-width card style.
   ================================================================ */
.actionbtn {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-3) var(--space-3) calc(var(--space-5) + 28px);
    background-color: var(--color-surface);
    background-repeat: no-repeat;
    background-position: var(--space-3) center;
    background-size: 20px 20px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    cursor: pointer;
    text-decoration: none;
    font-weight: var(--font-weight-semi);
    min-height: 56px;
    transition: border-color var(--duration) var(--ease-standard),
                background-color var(--duration) var(--ease-standard);
}
.actionbtn:hover {
    border-color: var(--color-primary);
    background-color: var(--color-surface-alt);
    opacity: 1;
}
.actionbtn > span {
    line-height: 1.25;
}
