/* CBOSoft — mobile-first, FR/AR (RTL), thème via --primary (settings) */
:root {
    --primary: #0f766e;
    --primary-dark: color-mix(in srgb, var(--primary) 80%, #000);
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --danger: #dc2626;
    --success: #16a34a;
    --radius: 14px;
    --topbar-h: 56px;
    --bottombar-h: 60px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    padding-top: var(--topbar-h);
    padding-bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
}
body.rtl { direction: rtl; }

/* ---------- Topbar ---------- */
.topbar {
    position: fixed; top: 0; inset-inline: 0; z-index: 50;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 10px;
    background: var(--primary); color: #fff;
    padding: 0 12px;
}
.topbar-burger { background: none; border: 0; color: #fff; font-size: 20px; padding: 8px; cursor: pointer; }
.topbar-title { font-weight: 700; font-size: 16px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-lang { color: #fff; text-decoration: none; font-weight: 700; padding: 6px 8px; border: 1px solid rgba(255,255,255,.4); border-radius: 8px; font-size: 13px; }
.topbar-user { font-size: 13px; display: none; }

/* Cloche notifications */
.topbar-bell { position: relative; background: none; border: 0; color: #fff; font-size: 18px; padding: 6px 8px; cursor: pointer; }
.bell-badge {
    position: absolute; top: 0; inset-inline-end: 0;
    background: #dc2626; color: #fff; font-size: 10px; font-weight: 700;
    min-width: 16px; height: 16px; line-height: 16px; border-radius: 999px; text-align: center; padding: 0 3px;
}
.bell-panel {
    display: none; position: fixed; top: var(--topbar-h); inset-inline-end: 8px; z-index: 60;
    width: min(360px, 94vw); max-height: 70vh; overflow-y: auto;
    background: var(--card); border-radius: var(--radius); box-shadow: 0 10px 36px rgba(15,23,42,.22);
}
.bell-panel.open { display: block; }
.bell-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.bell-item { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.bell-item.unread { background: color-mix(in srgb, var(--primary) 7%, #fff); }
.bell-item small { color: var(--muted); display: block; }

/* Bouton déconnexion bien visible */
.btn-logout {
    background: #fff; color: var(--danger);
    padding: 8px 12px; border-radius: 10px;
    text-decoration: none; font-weight: 700; font-size: 14px;
    display: inline-flex; align-items: center; gap: 6px;
}
.btn-logout-txt { display: none; }

/* ---------- Sidebar / drawer ---------- */
.sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; z-index: 45;
    inset-inline-start: 0;
    width: 250px; background: var(--card);
    border-inline-end: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform .25s;
    overflow-y: auto;
}
body.rtl .sidebar { transform: translateX(100%); }
.sidebar.open, body.rtl .sidebar.open { transform: translateX(0); }
.sidebar ul { list-style: none; margin: 0; padding: 10px; }
.sidebar a {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; border-radius: 10px;
    color: var(--text); text-decoration: none; font-size: 15px; margin-bottom: 2px;
}
.sidebar a i { width: 22px; text-align: center; color: var(--muted); }
.sidebar a.active, .sidebar a:hover { background: color-mix(in srgb, var(--primary) 10%, #fff); color: var(--primary); }
.sidebar a.active i { color: var(--primary); }
.sidebar .soon { color: var(--muted); margin-inline-start: auto; font-style: normal; }
.sidebar-overlay {
    position: fixed; inset: 0; top: var(--topbar-h); z-index: 40;
    background: rgba(0,0,0,.35); display: none;
}
.sidebar-overlay.show { display: block; }

/* ---------- Bottom bar (mobile) ---------- */
.bottombar {
    position: fixed; bottom: 0; inset-inline: 0; z-index: 50;
    height: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--card); border-top: 1px solid var(--border);
    display: flex;
}
.bottombar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; text-decoration: none; color: var(--muted); font-size: 11px;
}
.bottombar a i { font-size: 18px; }
.bottombar a.active { color: var(--primary); }

/* ---------- Contenu ---------- */
.content { padding: 16px; max-width: 1100px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; }

.card {
    background: var(--card); border-radius: var(--radius);
    box-shadow: 0 1px 4px rgba(15, 23, 42, .06);
    padding: 16px; margin-bottom: 16px;
}

/* ---------- Formulaires ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 4px; }
input, select, textarea {
    width: 100%; padding: 12px; font-size: 15px;
    border: 1px solid var(--border); border-radius: 10px;
    background: #fff; color: var(--text); font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, #fff); border-color: var(--primary); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px 18px; border: 0; border-radius: 10px;
    font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-light { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; margin-top: 16px; }

/* ---------- Tables (responsive) ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
tr:hover td { background: color-mix(in srgb, var(--primary) 4%, #fff); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-gray  { background: #e2e8f0; color: #475569; }
.badge-red   { background: #fee2e2; color: #991b1b; }
.badge-blue  { background: #dbeafe; color: #1e40af; }
.badge-purple{ background: #ede9fe; color: #6d28d9; }
.badge-orange{ background: #ffedd5; color: #c2410c; }
.badge-yellow{ background: #fef9c3; color: #a16207; }
.badge-teal  { background: #ccfbf1; color: #0f766e; }

.alert { padding: 12px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.alert-error { background: #fef2f2; color: #b91c1c; }

/* ---------- Dashboard stats ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; }
.stat {
    background: var(--card); border-radius: var(--radius); padding: 14px;
    box-shadow: 0 1px 4px rgba(15,23,42,.06);
}
.stat .stat-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .stat-value { font-size: 22px; font-weight: 800; margin-top: 6px; color: var(--primary); }

/* Cartes colorées (dashboard) */
.stat.grad { color: #fff; border: 0; }
.stat.grad .stat-label { color: rgba(255, 255, 255, .85); }
.stat.grad .stat-value { color: #fff; }
.stat.g-teal   { background: linear-gradient(135deg, #14b8a6, #0f766e); box-shadow: 0 6px 16px rgba(15, 118, 110, .3); }
.stat.g-green  { background: linear-gradient(135deg, #22c55e, #15803d); box-shadow: 0 6px 16px rgba(21, 128, 61, .3); }
.stat.g-violet { background: linear-gradient(135deg, #8b5cf6, #6d28d9); box-shadow: 0 6px 16px rgba(109, 40, 217, .3); }
.stat.g-red    { background: linear-gradient(135deg, #f87171, #dc2626); box-shadow: 0 6px 16px rgba(220, 38, 38, .3); }
.stat.g-blue   { background: linear-gradient(135deg, #60a5fa, #2563eb); box-shadow: 0 6px 16px rgba(37, 99, 235, .3); }

/* ---------- Login ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; padding-top: 16px; padding-bottom: 16px; }
.login-wrap { width: 100%; max-width: 380px; }
.login-brand { text-align: center; margin-bottom: 18px; }
.login-logo { font-size: 42px; }
.login-brand h1 { font-size: 22px; margin: 6px 0; color: var(--primary); }
.login-lang a { color: var(--muted); text-decoration: none; font-weight: 600; margin: 0 6px; padding: 4px 10px; border-radius: 8px; }
.login-lang a.on { background: var(--primary); color: #fff; }

.pin-form { background: var(--card); border-radius: var(--radius); padding: 22px; box-shadow: 0 6px 24px rgba(15,23,42,.08); text-align: center; }
.pin-title { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.pin-dots { display: flex; justify-content: center; gap: 12px; margin-bottom: 18px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border); }
.pin-dots span.full { background: var(--primary); border-color: var(--primary); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-pad button {
    padding: 16px 0; font-size: 20px; font-weight: 700;
    background: var(--bg); border: 0; border-radius: 12px; cursor: pointer; color: var(--text);
}
.pin-pad button:active { background: color-mix(in srgb, var(--primary) 20%, #fff); }
.pad-clear, .pad-back { color: var(--muted) !important; }
.login-alt { display: block; margin-top: 16px; color: var(--primary); font-size: 14px; text-decoration: none; }

.pwd-form { background: var(--card); border-radius: var(--radius); padding: 22px; box-shadow: 0 6px 24px rgba(15,23,42,.08); }
.pwd-links { display: flex; justify-content: space-between; margin-top: 14px; font-size: 14px; }
.pwd-links a { color: var(--primary); text-decoration: none; }

/* ---------- Permissions matrix ---------- */
.perm-grid { display: grid; grid-template-columns: 1fr auto auto auto; gap: 6px 14px; align-items: center; font-size: 14px; }
.perm-grid .perm-head { font-size: 12px; color: var(--muted); font-weight: 700; }

.hide-sm { display: none; }

/* ---------- POS tactile ---------- */
.pos-wrap { display: grid; gap: 14px; }
.pos-grid {
    display: grid; gap: 10px;
    grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
}
.pos-tile {
    position: relative; background: var(--card); border: 0; border-radius: 14px;
    padding: 8px; cursor: pointer; text-align: center;
    box-shadow: 0 1px 4px rgba(15,23,42,.08);
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    min-height: 118px; touch-action: manipulation; font-family: inherit;
    transition: transform .08s;
}
.pos-tile:active { transform: scale(.95); }
.pos-tile img, .pos-tile .tile-ico {
    width: 58px; height: 58px; border-radius: 10px; object-fit: cover;
    font-size: 40px; line-height: 58px; display: block;
}
.pos-tile .tile-name {
    font-size: 12px; font-weight: 600; line-height: 1.2; color: var(--text);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.pos-tile .tile-price { font-size: 13px; font-weight: 800; color: var(--primary); }
.pos-tile .tile-stock {
    position: absolute; top: 6px; inset-inline-end: 6px;
    font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 999px;
    background: #dcfce7; color: #166534;
}
.pos-tile .tile-stock.low { background: #fee2e2; color: #991b1b; }
/* Groupes de tuiles par couleur : dépenses = fond rouge clair, divers = violet clair */
.pos-tile.special-perso,
.pos-tile.special-divers { background: #fee2e2; }
.pos-tile.special-perso .tile-name,
.pos-tile.special-divers .tile-name { color: #991b1b; }
.pos-tile.special-misc   { background: #ede9fe; }
.pos-tile.special-misc .tile-name { color: #6d28d9; }
.pos-tile.special-rep    { background: #ccfbf1; }
.pos-tile.special-rep .tile-name { color: #0f766e; }

/* Design moderne des tuiles : relief doux, survol animé */
.pos-tile { border: 1px solid transparent; transition: transform .08s, box-shadow .15s; }
.pos-tile:hover { box-shadow: 0 6px 18px rgba(15, 23, 42, .14); transform: translateY(-2px); }
.btn-pay { background: linear-gradient(135deg, #22c55e, #15803d); box-shadow: 0 6px 16px rgba(22, 163, 74, .35); }
.pos-tile.add-tile { border: 2px dashed var(--border); background: transparent; box-shadow: none; color: var(--muted); justify-content: center; }

/* Mode édition */
.pos-edit .pos-tile.t-product { animation: wiggle 0.35s infinite; }
@keyframes wiggle { 0%,100% { transform: rotate(-1deg); } 50% { transform: rotate(1deg); } }
.tile-x {
    display: none; position: absolute; top: -7px; inset-inline-start: -7px; z-index: 2;
    width: 24px; height: 24px; border-radius: 50%; border: 0;
    background: var(--danger); color: #fff; font-weight: 700; cursor: pointer;
}
.tile-move { display: none; position: absolute; bottom: 4px; width: 26px; height: 26px; border: 0; border-radius: 8px; background: var(--bg); cursor: pointer; }
.tile-move.mv-l { inset-inline-start: 4px; }
.tile-move.mv-r { inset-inline-end: 4px; }
.pos-edit .tile-x, .pos-edit .tile-move { display: block; }
.pos-tile.dragover { outline: 3px dashed var(--primary); }

/* Panier */
.pos-cart { background: var(--card); border-radius: var(--radius); box-shadow: 0 2px 10px rgba(15,23,42,.09); display: flex; flex-direction: column; }
.pos-cart-lines { flex: 1; overflow-y: auto; padding: 10px 14px; }
.cart-line { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.cart-line .cl-name { flex: 1; font-size: 14px; font-weight: 600; }
.cart-line .cl-name small { color: var(--muted); font-weight: 400; display: block; }
.qty-btn {
    width: 38px; height: 38px; border: 0; border-radius: 10px;
    background: var(--bg); font-size: 18px; font-weight: 800; cursor: pointer; color: var(--text);
    touch-action: manipulation;
}
.qty-btn.del { background: #fee2e2; color: #991b1b; }
.cart-line .cl-qty { min-width: 26px; text-align: center; font-weight: 800; }
.cart-line .cl-total { min-width: 74px; text-align: end; font-weight: 700; }
.pos-cart-foot { padding: 12px 14px; border-top: 2px solid var(--border); }
.pos-total-row { display: flex; justify-content: space-between; align-items: baseline; margin: 6px 0 10px; }
.pos-total { font-size: 38px; font-weight: 900; color: var(--primary); line-height: 1; }
.btn-pay {
    width: 100%; padding: 18px; font-size: 20px; font-weight: 800;
    border: 0; border-radius: 14px; background: var(--success); color: #fff; cursor: pointer;
    touch-action: manipulation;
}
.btn-pay:active { transform: scale(.98); }
.btn-pay:disabled { background: var(--border); color: var(--muted); }

/* Grille modulaire (gridstack) : chaque bloc scrollable, panier pleine hauteur */
#posWrap .grid-stack-item-content { overflow: auto; border-radius: var(--radius); }
#posWrap .pos-cart { position: static; height: 100%; max-height: none; }
#posWrap .pos-cart-lines { display: block; }
.pos-edit .grid-stack-item-content { outline: 2px dashed color-mix(in srgb, var(--primary) 45%, #fff); }

/* Mode plein écran POS : menu latéral replié, tout l'espace exploité */
body.pos-full { padding-inline-start: 0 !important; }
body.pos-full .bottombar { display: none !important; }
body.pos-full .sidebar { transform: translateX(-100%) !important; }
body.pos-full.rtl .sidebar { transform: translateX(100%) !important; }
body.pos-full .sidebar.open { transform: translateX(0) !important; }
body.pos-full .sidebar-overlay { display: block !important; }
body.pos-full .sidebar-overlay:not(.show) { display: none !important; }
body.pos-full .topbar-burger { display: block; }
body.pos-full .content { max-width: none; padding: 12px; }
body.pos-full { padding-bottom: 0; }
@media (min-width: 1200px) {
    body.pos-full .pos-grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
    body.pos-full .pos-wrap { grid-template-columns: 1fr 380px; }
}
@media (max-width: 899px) {
    body.pos-full .pos-cart { bottom: 0; }
}

/* ---------- Desktop ----------
   Menu latéral épinglé (toujours visible), sauf en mode plein écran POS. */
@media (min-width: 900px) {
    body { padding-bottom: 0; padding-inline-start: 250px; }
    body.rtl { padding-inline-start: 250px; }
    .sidebar { transform: none !important; }
    .sidebar-overlay { display: none !important; }
    .bottombar { display: none; }
    .topbar-burger { display: none; }
    .topbar-user { display: inline; }
    .btn-logout-txt { display: inline; }
    .stats { grid-template-columns: repeat(4, 1fr); }
    .content { padding: 24px; }
}
