@import url("https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800;900&family=Outfit:wght@400;500;600;700;800;900&display=swap");

:root {
    color-scheme: light;
    --ink: #111827;
    --muted: #667085;
    --line: #e4e7ec;
    --surface: #ffffff;
    --soft: #f5f7fb;
    --dark: #101828;
    --accent: #16a37b;
    --accent-strong: #087a5d;
    --blue: #2f7cf6;
    --amber: #c96f10;
    --danger: #c2413b;
    --shadow: 0 18px 50px rgba(16, 24, 40, 0.08);
    --font-ar: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
    --font-en: "Outfit", "Segoe UI", Arial, sans-serif;
    font-family: var(--font-ar);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--soft);
    color: var(--ink);
    letter-spacing: 0;
    overflow-x: hidden;
    font-family: var(--font-ar);
}

html[lang="ar"],
html[lang="ar"] body,
html[lang="ar"] body *,
html[dir="rtl"],
html[dir="rtl"] body,
html[dir="rtl"] body * {
    font-family: var(--font-ar) !important;
}

html[lang="en"],
html[lang="en"] body,
html[lang="en"] body *,
html[dir="ltr"],
html[dir="ltr"] body,
html[dir="ltr"] body * {
    font-family: var(--font-en) !important;
}

button,
input,
select,
textarea {
    font: inherit;
}

html[lang="en"] body {
    font-family: var(--font-en);
}

html[lang="ar"] body {
    font-family: var(--font-ar);
}

button {
    cursor: pointer;
}

.hidden {
    display: none !important;
}

.app-shell {
    min-height: 100vh;
}

.login-view {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(320px, 430px);
    gap: 40px;
    align-items: center;
    padding: 48px clamp(20px, 6vw, 90px);
    background:
        linear-gradient(120deg, rgba(16, 24, 40, 0.82), rgba(6, 95, 70, 0.62)),
        url("https://images.unsplash.com/photo-1556742049-0cfed4f6a45d?auto=format&fit=crop&w=1800&q=80") center/cover;
    color: #fff;
}

.login-brand {
    display: flex;
    gap: 22px;
    align-items: flex-start;
    max-width: 620px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 82px;
    aspect-ratio: 1;
    border-radius: 8px;
    background: #fff;
    color: var(--dark);
    font-weight: 900;
    box-shadow: var(--shadow);
    flex: 0 0 auto;
}

.brand-mark.small {
    width: 42px;
    font-size: 0.8rem;
    box-shadow: none;
}

.login-brand h1 {
    margin: 0 0 12px;
    font-size: clamp(2.2rem, 5vw, 4.8rem);
    line-height: 1;
}

.login-brand p {
    margin: 0;
    max-width: 520px;
    color: rgba(255, 255, 255, 0.84);
    font-size: 1.12rem;
    line-height: 1.8;
}

.login-panel,
.edit-panel,
.data-panel,
.cart-panel,
.catalog-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.login-panel {
    padding: 24px;
    color: var(--ink);
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    padding: 11px 12px;
    min-height: 44px;
    outline: none;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(22, 163, 123, 0.14);
}

.primary-action,
.checkout-action,
.ghost-action,
.icon-action,
.payment-method,
.nav-item {
    border: 0;
    border-radius: 8px;
    min-height: 42px;
    transition: transform 0.14s ease, background 0.14s ease, border-color 0.14s ease;
}

.primary-action,
.checkout-action {
    background: var(--accent);
    color: #fff;
    font-weight: 900;
    padding: 12px 18px;
}

.primary-action:hover,
.checkout-action:hover {
    background: var(--accent-strong);
}

.ghost-action,
.icon-action,
.payment-method {
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--line);
    padding: 9px 13px;
    font-weight: 800;
}

.ghost-action:hover,
.icon-action:hover,
.payment-method:hover {
    background: #f8fafc;
}

.danger {
    color: var(--danger);
}

.form-error {
    color: var(--danger);
    min-height: 20px;
    margin: 0;
    font-weight: 800;
}

.language-inline,
.language-switcher {
    display: flex;
    gap: 8px;
}

.language-inline button,
.language-switcher button {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    padding: 8px 10px;
    font-weight: 800;
}

.workspace {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
    background: var(--dark);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 18px;
    min-height: 100vh;
    position: sticky;
    top: 0;
}

.tenant-card {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.tenant-card span {
    display: block;
    color: #98a2b3;
    font-size: 0.84rem;
}

.nav-list {
    display: grid;
    gap: 8px;
}

.nav-item {
    width: 100%;
    display: grid;
    grid-template-columns: 32px 1fr;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: transparent;
    color: #d0d5dd;
    text-align: start;
}

.nav-item.active,
.nav-item:hover {
    background: rgba(255, 255, 255, 0.11);
    color: #fff;
}

.nav-icon {
    display: grid;
    place-items: center;
    width: 32px;
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    font-weight: 900;
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 10px;
}

.sidebar .ghost-action {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.16);
}

.main-area {
    min-width: 0;
    padding: 22px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    margin-bottom: 18px;
}

.topbar h2 {
    margin: 4px 0 0;
    font-size: 1.8rem;
}

.state-pill {
    display: inline-flex;
    align-items: center;
    margin: 0;
    padding: 5px 9px;
    border-radius: 999px;
    background: rgba(22, 163, 123, 0.12);
    color: var(--accent-strong);
    font-size: 0.78rem;
    font-weight: 900;
}

.state-pill.offline {
    background: rgba(194, 65, 59, 0.12);
    color: var(--danger);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-chip {
    text-align: end;
}

.user-chip span,
.user-chip small {
    display: block;
}

.user-chip small {
    color: var(--muted);
}

.page {
    display: none;
}

.page.active {
    display: block;
}

.pos-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(330px, 420px);
    gap: 18px;
    align-items: start;
}

.catalog-panel,
.cart-panel,
.data-panel,
.edit-panel {
    padding: 16px;
}

.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.search-box {
    flex: 1;
    display: grid;
    grid-template-columns: 28px 1fr;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding-inline: 10px;
}

.search-box input {
    border: 0;
    box-shadow: none;
    padding-inline: 0;
}

.category-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 12px;
}

.category-tabs button {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 999px;
    padding: 8px 12px;
    font-weight: 900;
    white-space: nowrap;
}

.category-tabs button.active {
    color: #fff;
    border-color: transparent;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

.product-tile {
    display: grid;
    grid-template-rows: 100px auto;
    min-height: 218px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
    text-align: start;
    padding: 0;
}

.product-tile:hover {
    border-color: rgba(22, 163, 123, 0.6);
    transform: translateY(-1px);
}

.product-tile img,
.product-image-fallback {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #eef2f6;
}

.product-image-fallback {
    display: grid;
    place-items: center;
    color: var(--muted);
    font-weight: 900;
}

.product-info {
    display: grid;
    gap: 5px;
    padding: 10px;
}

.product-info strong {
    line-height: 1.25;
}

.product-info span {
    color: var(--muted);
    font-size: 0.82rem;
}

.product-meta {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
    margin-top: 4px;
}

.price-tag {
    color: var(--accent-strong);
    font-weight: 900;
}

.stock-tag {
    font-size: 0.76rem;
    border-radius: 999px;
    padding: 4px 7px;
    background: #eef2f6;
    color: var(--muted);
    white-space: nowrap;
}

.stock-tag.low {
    background: rgba(201, 111, 16, 0.13);
    color: var(--amber);
}

.cart-panel {
    position: sticky;
    top: 16px;
}

.cart-header,
.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.cart-header h3,
.section-heading h3,
.edit-panel h3,
.data-panel h3 {
    margin: 0;
}

.cart-header span,
.section-heading span {
    color: var(--muted);
    font-weight: 900;
}

.cart-items {
    display: grid;
    gap: 10px;
    min-height: 170px;
    max-height: 38vh;
    overflow: auto;
    padding-inline-end: 4px;
}

.cart-empty {
    display: grid;
    place-items: center;
    min-height: 160px;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 8px;
}

.cart-line {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    display: grid;
    gap: 9px;
}

.cart-line-top,
.cart-line-actions,
.customer-picker,
.payment-row,
.paid-input,
.totals div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.cart-line strong {
    line-height: 1.25;
}

.qty-control {
    display: grid;
    grid-template-columns: 36px 52px 36px;
    align-items: center;
    gap: 4px;
}

.qty-control button {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    min-height: 34px;
    font-weight: 900;
}

.qty-control input {
    min-height: 34px;
    padding: 6px;
    text-align: center;
}

.customer-picker {
    margin: 14px 0;
}

.customer-picker label {
    flex: 1;
}

.totals {
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    padding: 12px 0;
    display: grid;
    gap: 10px;
}

.totals input {
    max-width: 120px;
    min-height: 36px;
    padding: 7px 9px;
    text-align: end;
}

.grand-total {
    font-size: 1.24rem;
}

.grand-total strong {
    color: var(--accent-strong);
}

.payment-row {
    margin: 14px 0;
}

.payment-method {
    flex: 1;
}

.payment-method.active {
    background: var(--dark);
    color: #fff;
    border-color: var(--dark);
}

.paid-input {
    display: grid;
    grid-template-columns: 100px 1fr;
    margin-bottom: 12px;
}

.discount-control {
    align-items: flex-start !important;
}

.discount-fields {
    display: grid;
    grid-template-columns: minmax(126px, auto) minmax(90px, 120px);
    gap: 8px;
    align-items: center;
}

.segmented-control {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.segmented-control button {
    min-height: 36px;
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 6px 9px;
    font-weight: 900;
}

.segmented-control button.active {
    background: var(--dark);
    color: #fff;
}

.checkout-action {
    width: 100%;
    min-height: 54px;
}

.split-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(310px, 380px);
    gap: 18px;
    align-items: start;
}

.edit-panel {
    display: grid;
    gap: 12px;
    position: sticky;
    top: 16px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.check-line {
    display: flex;
    align-items: center;
    gap: 9px;
}

.check-line input {
    width: 18px;
    min-height: 18px;
}

.field-hint {
    margin: -4px 0 0;
    color: var(--muted);
    font-size: 0.8rem;
    line-height: 1.6;
}

.table-list {
    display: grid;
    gap: 8px;
}

.table-row {
    display: grid;
    grid-template-columns: minmax(150px, 1.5fr) repeat(4, minmax(80px, 1fr));
    gap: 12px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    background: #fff;
}

.table-row.header {
    background: #f8fafc;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 900;
}

.table-row strong,
.table-row span {
    min-width: 0;
    overflow-wrap: anywhere;
}

.compact .table-row {
    grid-template-columns: minmax(160px, 1fr) 80px 80px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.metric {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 8px;
}

.metric span {
    color: var(--muted);
    font-weight: 800;
}

.metric strong {
    font-size: 1.7rem;
}

.report-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(300px, 0.9fr);
    gap: 18px;
}

.orders-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 430px);
    gap: 18px;
    align-items: start;
}

.order-details-panel {
    position: sticky;
    top: 16px;
}

.order-details-empty {
    display: grid;
    place-items: center;
    min-height: 180px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    color: var(--muted);
    text-align: center;
}

.order-summary {
    display: grid;
    gap: 10px;
}

.order-summary-row,
.order-item-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 8px;
}

.order-summary-row span,
.order-item-row span {
    color: var(--muted);
}

.order-items {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

.bar-chart {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.bar-line {
    display: grid;
    grid-template-columns: 92px minmax(80px, 1fr) 90px;
    gap: 10px;
    align-items: center;
}

.bar-track {
    height: 12px;
    background: #eef2f6;
    border-radius: 999px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), var(--blue));
}

.receipt-dialog {
    width: min(420px, calc(100% - 24px));
    border: 0;
    border-radius: 8px;
    padding: 0;
}

.receipt-dialog::backdrop {
    background: rgba(16, 24, 40, 0.5);
}

.receipt {
    padding: 22px;
    background: #fff;
    font-family: inherit;
    color: #111;
}

.receipt h3,
.receipt p {
    margin: 0 0 8px;
    text-align: center;
}

.receipt-line {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px dashed #ddd;
    padding: 7px 0;
}

.dialog-actions {
    display: flex;
    gap: 10px;
    padding: 14px;
    background: #f8fafc;
    justify-content: flex-end;
}

[dir="ltr"] .user-chip {
    text-align: start;
}

@media (max-width: 1120px) {
    .workspace {
        grid-template-columns: 86px minmax(0, 1fr);
    }

    .sidebar {
        padding: 12px;
    }

    .tenant-card div:not(.brand-mark),
    .nav-item span:last-child,
    .sidebar-footer .ghost-action span:last-child {
        display: none;
    }

    .nav-item {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    .pos-grid,
    .split-layout,
    .orders-layout,
    .report-grid {
        grid-template-columns: 1fr;
    }

    .cart-panel,
    .edit-panel,
    .order-details-panel {
        position: static;
    }
}

@media (max-width: 760px) {
    .login-view {
        grid-template-columns: 1fr;
        padding: 22px;
    }

    .login-brand {
        display: grid;
    }

    .workspace {
        display: block;
    }

    .sidebar {
        position: static;
        min-height: auto;
        flex-direction: row;
        align-items: center;
        gap: 10px;
        width: 100%;
        max-width: 100vw;
        min-width: 0;
        overflow-x: auto;
        overflow-y: hidden;
    }

    .tenant-card,
    .sidebar-footer {
        margin: 0;
        flex: 0 0 auto;
    }

    .nav-list {
        display: flex;
        flex: 1 0 auto;
        min-width: 0;
    }

    .main-area {
        padding: 14px;
        width: 100%;
        max-width: 100vw;
        overflow: hidden;
    }

    .topbar,
    .topbar-actions {
        align-items: flex-start;
        flex-direction: column;
    }

    .product-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .table-row,
    .compact .table-row {
        grid-template-columns: 1fr;
        gap: 5px;
    }

    .table-row.header {
        display: none;
    }
}

@media (max-width: 460px) {
    .product-grid,
    .metric-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .cart-line-actions,
    .payment-row,
    .paid-input,
    .discount-fields {
        display: grid;
        grid-template-columns: 1fr;
    }
}

@media print {
    body * {
        visibility: hidden;
    }

    #receiptContent,
    #receiptContent * {
        visibility: visible;
    }

    #receiptContent {
        position: absolute;
        inset: 0;
        width: 80mm;
        box-shadow: none;
    }
}
