/* ================================================================
   NEXCLIQ — BASE STYLESHEET v2
   Design tokens, resets, layout primitives, shared components.
   Mobile-first: phones get the original compact layout.
   Desktop (≥1024px): sidebar nav + wide content area.
   ================================================================ */

/* -------------------- DESIGN TOKENS -------------------- */
:root {
    --bg:                  #0B0B0B;
    --card:                #111111;
    --line:                #222222;
    --accent:              #FF5500;
    --accent-hover:        #e04a00;
    --accent-green-bg:     #0D382B;
    --accent-green-border: #14533F;
    --text:                #ffffff;
    --text-muted:          #555555;
    --success:             #10B981;
    --danger:              #EF4444;
    --font-sans:           'Inter', 'Segoe UI', sans-serif;
    --radius-sm:           10px;
    --radius-md:           14px;
    --radius-lg:           18px;
    --radius-xl:           20px;
    --transition:          0.25s ease;
    --max-width:           420px;
    --shadow-card:         0 10px 30px rgba(0, 0, 0, 0.5);
    --shadow-accent:       0 4px 15px rgba(255, 85, 0, 0.25);

    /* Desktop layout */
    --sidebar-width:       240px;
    --content-max-width:   820px;
}

body.light-mode {
    --bg:                  #F2F2F2;
    --card:                #FFFFFF;
    --line:                #E1E1E1;
    --accent-green-bg:     #E4F3EC;
    --accent-green-border: #14533F;
    --text:                #111111;
    --text-muted:          #7A7A7A;
    --success:             #0D9467;
    --danger:              #DC2626;
}

/* -------------------- RESET & BASE -------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 300;
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--transition), color var(--transition);
}

img {
    max-width: 100%;
    display: block;
}

button {
    font-family: inherit;
    cursor: pointer;
}

input, select, textarea {
    font-family: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

/* -------------------- UTILITIES -------------------- */
.hidden {
    display: none !important;
}

.center-text {
    text-align: center;
}

.amount-green {
    color: var(--success);
    font-weight: bold;
}

.amount-red {
    color: var(--danger);
    font-weight: bold;
}

/* -------------------- TYPOGRAPHY -------------------- */
.page-title {
    font-size: 20px;
    font-weight: 300;
    letter-spacing: 0.5px;
    margin: 15px 0 5px;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 25px;
    font-weight: 300;
}

.section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin-bottom: 15px;
    padding-bottom: 5px;
    border-bottom: 0.5px solid var(--line);
}

/* ================================================================
   MOBILE LAYOUT  (< 1024px)
   Original phone-style: centered card, bottom nav
   ================================================================ */
@media (max-width: 1023px) {
    body {
        display: flex;
        justify-content: center;
        align-items: flex-start;
        padding: 20px;
        padding-bottom: 90px;
    }

    body.auth-body {
        align-items: center;
        min-height: 100vh;
    }

    /* Tablet: slight gradient */
    @media (min-width: 600px) {
        body {
            background: radial-gradient(circle at 50% -10%, #1c1c1c 0%, var(--bg) 55%);
            align-items: center;
        }
        body.light-mode {
            background: radial-gradient(circle at 50% -10%, #ffffff 0%, var(--bg) 55%);
        }
    }

    #app-frame {
        width: 100%;
        max-width: var(--max-width);
        box-sizing: border-box;
    }

    .page-layout {
        width: 100%;
        max-width: var(--max-width);
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        animation: fadeIn 0.35s ease-out;
    }

    .page-layout.align-top {
        align-self: flex-start;
        margin: 30px 0;
    }

    /* Bottom nav — mobile style */
    .bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 800;
        display: flex;
        justify-content: space-around;
        align-items: center;
        background-color: var(--card);
        border-top: 0.5px solid var(--line);
        padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        transition: transform 0.3s ease;
    }

    .bottom-nav.hide-nav {
        transform: translateY(100%);
    }

    /* On tablet, centre the nav under the content */
    @media (min-width: 600px) {
        .bottom-nav {
            left: 50%;
            right: auto;
            width: 100%;
            max-width: var(--max-width);
            transform: translateX(-50%);
            border-left: 0.5px solid var(--line);
            border-right: 0.5px solid var(--line);
            border-radius: 20px 20px 0 0;
        }

        .bottom-nav.hide-nav {
            transform: translate(-50%, 100%);
        }
    }

    /* Hide desktop sidebar on mobile */
    .desktop-sidebar { display: none !important; }
}

/* ================================================================
   DESKTOP LAYOUT  (≥ 1024px)
   Two-column: left sidebar + scrollable right content
   ================================================================ */
@media (min-width: 1024px) {

    body {
        display: grid;
        grid-template-columns: var(--sidebar-width) 1fr;
        grid-template-rows: 1fr;
        min-height: 100vh;
        padding: 0;
        background: radial-gradient(circle at 20% 50%, #161616 0%, var(--bg) 60%);
    }

    body.light-mode {
        background: radial-gradient(circle at 20% 50%, #e8e8e8 0%, var(--bg) 60%);
    }

    /* ---- Sidebar ---- */
    .desktop-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: var(--sidebar-width);
        height: 100vh;
        background-color: var(--card);
        border-right: 0.5px solid var(--line);
        display: flex;
        flex-direction: column;
        padding: 28px 20px 24px;
        z-index: 900;
        overflow-y: auto;
    }

    .sidebar-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        margin-bottom: 36px;
        padding-bottom: 20px;
        border-bottom: 0.5px solid var(--line);
    }

    .sidebar-brand-icon {
        height: 30px;
        width: 30px;
        border-radius: 8px;
        object-fit: cover;
    }

    .sidebar-brand-logo {
        height: 22px;
        width: 90px;
        object-fit: contain;
        object-position: left center;
    }

    .sidebar-brand-logo-light { display: none; }
    body.light-mode .sidebar-brand-logo-dark  { display: none; }
    body.light-mode .sidebar-brand-logo-light { display: block; }

    .sidebar-nav {
        display: flex;
        flex-direction: column;
        gap: 4px;
        flex: 1;
    }

    .sidebar-nav-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 11px 14px;
        border-radius: var(--radius-md);
        background: transparent;
        border: none;
        color: var(--text-muted);
        font-size: 13px;
        font-weight: 400;
        cursor: pointer;
        text-align: left;
        transition: background-color var(--transition), color var(--transition);
        width: 100%;
        font-family: inherit;
    }

    .sidebar-nav-item svg {
        width: 18px;
        height: 18px;
        fill: none;
        stroke: currentColor;
        stroke-width: 2;
        flex-shrink: 0;
    }

    .sidebar-nav-item:hover {
        background-color: rgba(255, 255, 255, 0.04);
        color: var(--text);
    }

    .sidebar-nav-item.active {
        background-color: rgba(255, 85, 0, 0.1);
        color: var(--accent);
        font-weight: 600;
    }

    .sidebar-nav-separator {
        height: 0.5px;
        background: var(--line);
        margin: 12px 0;
    }

    .sidebar-nav-section-label {
        font-size: 9px;
        text-transform: uppercase;
        letter-spacing: 1.5px;
        color: var(--text-muted);
        padding: 0 14px;
        margin: 8px 0 4px;
        opacity: 0.6;
    }

    .sidebar-footer {
        margin-top: auto;
        padding-top: 16px;
        border-top: 0.5px solid var(--line);
    }

    .sidebar-user-info {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 14px;
        border-radius: var(--radius-md);
        cursor: default;
    }

    .sidebar-user-avatar {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background-color: var(--accent);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 13px;
        font-weight: bold;
        flex-shrink: 0;
        color: #fff;
    }

    .sidebar-user-name {
        font-size: 13px;
        font-weight: 600;
        color: var(--text);
    }

    .sidebar-user-status {
        font-size: 10px;
        color: var(--success);
    }

    /* ---- Main content area ---- */
    #app-frame,
    .page-layout {
        grid-column: 2;
        margin-left: var(--sidebar-width);
        width: calc(100vw - var(--sidebar-width));
        max-width: none;
        box-sizing: border-box;
        min-height: 100vh;
    }

    /* Content wrapper gives padding + max-width centering */
    .desktop-content {
        max-width: var(--content-max-width);
        width: 100%;
    }

    /* Page top bar: hide mobile topbar on desktop — sidebar replaces it */
    .top-bar {
        display: none;
    }

    /* Desktop page header injected via JS instead */
    .desktop-page-header {
        margin-bottom: 32px;
        padding-bottom: 20px;
        border-bottom: 0.5px solid var(--line);
    }

    .desktop-page-header .page-title {
        font-size: 26px;
        margin: 0 0 6px;
    }

    .desktop-page-header .page-subtitle {
        margin-bottom: 0;
    }

    /* Cards side-by-side on desktop where applicable */
    .desktop-grid-2 {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }

    .desktop-grid-3 {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 16px;
    }

    /* Bottom nav hidden on desktop */
    .bottom-nav {
        display: none !important;
    }

    /* Auth stays centred, ignore sidebar */
    body.auth-body {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 40px;
        background: radial-gradient(circle at 50% 10%, #1c1c1c 0%, var(--bg) 55%);
    }

    body.auth-body.light-mode {
        background: radial-gradient(circle at 50% 10%, #ffffff 0%, var(--bg) 55%);
    }

    body.auth-body .desktop-sidebar { display: none !important; }
    body.auth-body #app-frame {
        margin-left: 0;
        width: auto;
    }

    /* Page layout align-top has some top margin */
    .page-layout.align-top {
        margin-top: 0;
    }

    /* Wider form on desktop */
    .card {
        max-width: 600px;
    }

    /* Explanation box full width */
    .explanation-box {
        max-width: 600px;
    }
}

/* ---- Shared large-screen card tweak ---- */
@media (min-width: 1280px) {
    :root {
        --content-max-width: 900px;
    }
}

/* -------------------- ANIMATION -------------------- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* -------------------- TOP BAR (mobile only) -------------------- */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding: 0 5px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-icon {
    height: 26px;
    width: 26px;
    border-radius: 6px;
    object-fit: cover;
    display: block;
}

.brand-logo {
    height: 26px;
    width: 100px;
    object-fit: contain;
    object-position: left center;
    display: block;
}

.brand-logo-light { display: none; }
body.light-mode .brand-logo-dark { display: none; }
body.light-mode .brand-logo-light { display: block; }

/* -------------------- ICON BUTTON -------------------- */
.icon-btn {
    background: transparent;
    border: none;
    color: var(--text);
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 14px;
    transition: color var(--transition);
}

.icon-btn:hover {
    color: var(--accent);
}

.icon-btn svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

/* -------------------- BACK BUTTON -------------------- */
.back-btn {
    border: 1px solid var(--accent-green-border) !important;
    background-color: var(--accent-green-bg) !important;
    color: var(--text) !important;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    transition: background-color var(--transition);
}

.back-btn:hover {
    background-color: var(--accent-green-border) !important;
}

/* -------------------- CARD -------------------- */
.card {
    background-color: var(--card);
    border: 0.5px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 22px;
    margin-bottom: 20px;
}

body.light-mode .card {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

/* -------------------- FORM ELEMENTS -------------------- */
.form-group {
    margin-bottom: 15px;
    text-align: left;
}

.field-label {
    display: block;
    margin-bottom: 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.input {
    width: 100%;
    background: transparent;
    border: 0.5px solid var(--line);
    color: var(--text);
    font-size: 13px;
    padding: 12px 15px;
    border-radius: var(--radius-md);
    transition: border-color var(--transition);
    font-weight: 300;
    appearance: none;
}

.input:focus {
    outline: none;
    border-color: var(--accent);
}

select.input {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23555555' stroke-width='2'><polyline points='6 9 12 15 18 9'></polyline></svg>");
    background-repeat: no-repeat;
    background-position: right 15px center;
    padding-right: 35px;
}

select.input option {
    background-color: var(--card);
    color: var(--text);
}

.phone-container {
    display: flex;
    border: 0.5px solid var(--line);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color var(--transition);
}

.phone-container:focus-within {
    border-color: var(--accent);
}

.phone-prefix {
    background: transparent;
    color: var(--accent);
    font-size: 13px;
    padding: 12px 0 12px 15px;
    border-right: 0.5px solid var(--line);
    display: flex;
    align-items: center;
    font-weight: bold;
    white-space: nowrap;
}

.phone-container .input {
    border: none;
    padding-left: 10px;
    border-radius: 0;
}

.phone-container .input:focus {
    border: none;
}

/* -------------------- BUTTONS -------------------- */
.btn-primary {
    width: 100%;
    background-color: var(--accent);
    border: 0.5px solid var(--accent);
    color: #ffffff;
    padding: 14px;
    border-radius: var(--radius-md);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: bold;
    transition: opacity var(--transition), box-shadow var(--transition);
}

.btn-primary:hover {
    opacity: 0.9;
    box-shadow: var(--shadow-accent);
}

.btn-secondary {
    width: 67%;
    padding: 14px;
    border-radius: var(--radius-md);
    background: var(--card);
    border: 0.5px solid var(--line);
    color: var(--text);
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: border-color var(--transition), color var(--transition);
}

.btn-secondary:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-secondary svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

.btn-danger {
    border-color: var(--danger) !important;
    color: var(--danger) !important;
}

/* -------------------- INFO ROWS -------------------- */
.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 0.5px solid var(--line);
    font-size: 13px;
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--text-muted);
    font-weight: 300;
}

.info-value {
    font-weight: bold;
}

/* -------------------- TOGGLE SWITCH -------------------- */
.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 0.5px solid var(--line);
}

.toggle-row:last-child {
    border-bottom: none;
}

.toggle-label {
    font-size: 13px;
    font-weight: 300;
}

.switch {
    position: relative;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: var(--line);
    transition: background-color var(--transition);
    border-radius: 24px;
}

.slider::before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: transform var(--transition);
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent);
}

input:checked + .slider::before {
    transform: translateX(18px);
}

/* -------------------- AVATAR -------------------- */
.avatar-circle {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background-color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: bold;
    margin: 0 auto 15px;
}

/* -------------------- EXPLANATION BOX -------------------- */
.explanation-box {
    border: 0.5px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 300;
    line-height: 1.5;
    margin-bottom: 20px;
}

/* -------------------- WARNING BOX -------------------- */
.confirm-warning {
    border: 1px solid var(--accent);
    background-color: rgba(255, 85, 0, 0.08);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    font-size: 12px;
    color: var(--accent);
    font-weight: 600;
    line-height: 1.5;
}

/* -------------------- HISTORY TABLE -------------------- */
.history-box {
    border: 0.5px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 20px;
    background-color: var(--card);
    margin-bottom: 20px;
}

.history-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.table-scroll {
    max-height: 250px;
    overflow-y: auto;
    margin-top: 15px;
    padding-right: 5px;
}

.table-scroll::-webkit-scrollbar {
    width: 4px;
}

.table-scroll::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 10px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    text-align: left;
}

td {
    padding: 12px 0;
    border-bottom: 0.5px solid var(--line);
    color: var(--text-muted);
}

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

/* -------------------- LINK BOX -------------------- */
.link-box {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 0.5px solid var(--line);
    border-radius: var(--radius-md);
    padding: 12px 15px;
    font-size: 12px;
    color: var(--text-muted);
    word-break: break-all;
}

/* -------------------- QR PLACEHOLDER -------------------- */
.qr-placeholder {
    width: 160px;
    height: 160px;
    margin: 0 auto 20px;
    background: repeating-linear-gradient(
        45deg,
        #1a1a1a,
        #1a1a1a 6px,
        #0b0b0b 6px,
        #0b0b0b 12px
    );
    border-radius: var(--radius-md);
    border: 0.5px solid var(--line);
}

/* -------------------- BOTTOM NAV (mobile only) -------------------- */
.bottom-nav-item {
    background: transparent;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 10px;
    flex: 1;
    transition: color var(--transition);
}

.bottom-nav-item svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}

.bottom-nav-item.active {
    color: var(--accent);
}

/* -------------------- FOOTER -------------------- */
.footer {
    font-size: 9px;
    opacity: 0.2;
    letter-spacing: 1px;
    margin-top: 30px;
    text-align: center;
}

/* -------------------- TOAST NOTIFICATION -------------------- */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--accent-green-border);
    color: #ffffff;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.5);
    opacity: 0;
    z-index: 9999;
    white-space: nowrap;
    transition: opacity 0.4s ease;
}

.toast.show {
    opacity: 1;
}

/* -------------------- PRINT -------------------- */
@media print {
    body { background: #fff !important; }
    body * { visibility: hidden; }
    #facture-printable,
    #facture-printable * { visibility: visible; }
    #facture-printable {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        color: #000 !important;
    }
    #facture-printable .card {
        background: #fff !important;
        border: 1px solid #ccc !important;
    }
    .no-print { display: none !important; }
}