:root{
    --bg:#07111f;
    --panel:#0d1b2d;
    --panel2:#102238;
    --line:#203a58;
    --text:#eef5ff;
    --muted:#93a8c1;
    --blue:#2b82ff;
    --blue2:#1267dd;
    --green:#37d39a;
    --red:#ff6b7a;
}

*{
    box-sizing:border-box;
}

html,
body{
    margin:0;
    width:100%;
    max-width:100%;
    min-height:100%;
    overflow-x:hidden;
}

body{
    font-family:Inter,Segoe UI,Arial,sans-serif;
    background:var(--bg);
    color:var(--text);
}

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

.app-shell{
    min-height:100vh;
    display:flex;
    width:100%;
    max-width:100%;
}

.sidebar{
    width:250px;
    background:#091625;
    border-right:1px solid var(--line);
    padding:22px 16px;
    display:flex;
    flex-direction:column;
    position:fixed;
    inset:0 auto 0 0;
    z-index:20;
}

.brand{
    display:flex;
    gap:12px;
    align-items:center;
    padding:4px 8px 24px;
    min-width:0;
}

.admin-brand-logo{
    width:50px;
    height:50px;
    object-fit:contain;
    display:block;
    flex:0 0 auto;
}

.brand-copy{
    min-width:0;
}

.brand strong{
    display:block;
    font-size:15px;
}

.brand span{
    display:block;
    color:var(--muted);
    font-size:11px;
    margin-top:2px;
}

nav{
    display:grid;
    gap:8px;
}

nav a{
    padding:12px 14px;
    border-radius:10px;
    color:#c6d5e7;
}

nav a:hover,
nav a.active{
    background:#132946;
    color:#fff;
}

.sidebar-user{
    margin-top:auto;
    border-top:1px solid var(--line);
    padding:16px 8px 0;
}

.sidebar-user small{
    display:block;
    color:var(--muted);
    margin-bottom:5px;
}

.content{
    margin-left:250px;
    width:calc(100% - 250px);
    min-width:0;
    padding:30px;
}

.login-content{
    margin:0;
    width:100%;
    min-height:100vh;
    display:grid;
    place-items:center;
    padding:30px;
}

.login-card{
    width:min(430px,100%);
    background:var(--panel);
    border:1px solid var(--line);
    border-radius:18px;
    padding:30px;
    box-shadow:0 18px 60px rgba(0,0,0,.25);
}

.login-card h1{
    margin:0 0 6px;
}

.login-card p{
    color:var(--muted);
    margin:0 0 24px;
}

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

.topbar>div{
    min-width:0;
}

.topbar h1{
    margin:0;
    font-size:30px;
}

.topbar p{
    margin:5px 0 0;
    color:var(--muted);
}

.btn{
    border:0;
    border-radius:10px;
    background:var(--blue);
    color:#fff;
    padding:11px 16px;
    min-height:42px;
    font-weight:700;
    cursor:pointer;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    text-align:center;
}

.btn:hover{
    background:var(--blue2);
}

.btn.secondary{
    background:#162a41;
}

.btn.danger{
    background:#6f2532;
}

.grid{
    display:grid;
    grid-template-columns:repeat(4,minmax(0,1fr));
    gap:16px;
}

.card{
    min-width:0;
    background:var(--panel);
    border:1px solid var(--line);
    border-radius:16px;
    padding:20px;
}

.metric .value{
    font-size:30px;
    font-weight:800;
}

.metric .label{
    color:var(--muted);
    margin-top:5px;
}

.table-card{
    margin-top:20px;
    padding:0;
    overflow:hidden;
}

table{
    width:100%;
    border-collapse:collapse;
    table-layout:auto;
}

th,
td{
    text-align:left;
    padding:14px 16px;
    border-bottom:1px solid #19314b;
    vertical-align:middle;
}

th{
    color:#9eb2c9;
    font-size:13px;
    text-transform:uppercase;
    letter-spacing:.04em;
    background:#0b1929;
}

td{
    overflow-wrap:anywhere;
}

.badge{
    display:inline-flex;
    padding:5px 9px;
    border-radius:999px;
    font-size:12px;
    font-weight:700;
    white-space:nowrap;
}

.badge.green{
    background:#123d32;
    color:#65e0b2;
}

.badge.red{
    background:#4b1f29;
    color:#ff94a0;
}

.badge.blue{
    background:#123354;
    color:#85bfff;
}

.badge.amber{
    background:#49391a;
    color:#ffd477;
}

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

label{
    display:block;
    color:#b8c8da;
    font-size:13px;
    margin-bottom:6px;
}

input,
select,
textarea{
    width:100%;
    max-width:100%;
    min-width:0;
    background:#071524;
    color:#fff;
    border:1px solid #28445f;
    border-radius:10px;
    padding:12px 13px;
    outline:none;
    font:inherit;
}

input:focus,
select:focus,
textarea:focus{
    border-color:#438dff;
    box-shadow:0 0 0 3px rgba(67,141,255,.12);
}

textarea{
    min-height:100px;
    resize:vertical;
}

.field{
    min-width:0;
    margin-bottom:15px;
}

.actions{
    display:flex;
    gap:8px;
    flex-wrap:wrap;
}

.flash{
    padding:13px 16px;
    border-radius:10px;
    margin-bottom:18px;
    border:1px solid;
}

.flash.success{
    background:#0f3329;
    border-color:#245d4d;
    color:#79e8bd;
}

.flash.error{
    background:#3e1c24;
    border-color:#6b2d3c;
    color:#ff9baa;
}

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

.code{
    font-family:ui-monospace,SFMono-Regular,Consolas,monospace;
    font-weight:700;
    overflow-wrap:anywhere;
    word-break:break-word;
}

.section-title{
    margin:28px 0 12px;
}

@media(max-width:1000px){
    .grid{
        grid-template-columns:1fr 1fr;
    }

    .content{
        padding:24px;
    }
}

/* ==========================================================
   REAL PHONE LAYOUT
   No desktop-width sidebar.
   No table running off the right side.
   ========================================================== */
@media(max-width:760px){

    html,
    body{
        width:100%;
        max-width:100%;
        overflow-x:hidden;
    }

    .app-shell{
        display:block;
        width:100%;
        max-width:100%;
        min-height:100vh;
    }

    .sidebar{
        position:relative;
        inset:auto;
        width:100%;
        max-width:100%;
        height:auto;
        padding:9px 10px 10px;
        border-right:0;
        border-bottom:1px solid var(--line);
        display:block;
        overflow:hidden;
    }

    .brand{
        min-height:48px;
        padding:0 4px 8px;
        gap:9px;
    }

    .admin-brand-logo{
        width:40px;
        height:40px;
    }

    .brand strong{
        font-size:13px;
    }

    .brand span{
        font-size:10px;
    }

    /*
     * The menu is a grid, not one long horizontal line.
     * This fixes the menu disappearing off the right side.
     */
    .sidebar nav{
        display:grid;
        grid-template-columns:repeat(3,minmax(0,1fr));
        gap:6px;
        width:100%;
        overflow:visible;
    }

    .sidebar nav a{
        min-width:0;
        width:100%;
        padding:9px 5px;
        font-size:11px;
        line-height:1.15;
        text-align:center;
        white-space:normal;
        overflow-wrap:anywhere;
        display:flex;
        align-items:center;
        justify-content:center;
        min-height:38px;
    }

    .sidebar-user{
        display:none;
    }

    .content{
        margin:0;
        width:100%;
        max-width:100%;
        min-width:0;
        padding:16px 10px 26px;
        overflow:hidden;
    }

    .login-content{
        padding:16px 10px;
    }

    .login-card{
        width:100%;
        max-width:430px;
        padding:22px 17px;
    }

    .topbar{
        width:100%;
        max-width:100%;
        flex-direction:column;
        align-items:stretch;
        gap:11px;
        margin-bottom:17px;
    }

    .topbar h1{
        font-size:25px;
    }

    .topbar p{
        font-size:13px;
        line-height:1.45;
    }

    .topbar>a.btn,
    .topbar>.btn{
        width:100%;
    }

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

    .card{
        width:100%;
        max-width:100%;
        min-width:0;
        padding:14px;
        border-radius:13px;
    }

    .metric{
        display:flex;
        align-items:center;
        justify-content:space-between;
        gap:12px;
        min-height:64px;
    }

    .metric .value{
        font-size:27px;
    }

    .metric .label{
        margin:0;
        text-align:right;
        font-size:13px;
    }

    form .row,
    .form .row{
        grid-template-columns:1fr;
        gap:0;
    }

    .actions{
        display:grid;
        grid-template-columns:1fr;
    }

    .actions>*,
    .actions .btn,
    .actions form,
    .actions form .btn{
        width:100%;
    }

    input,
    select,
    textarea{
        font-size:16px;
    }

    .btn{
        min-height:44px;
        padding:10px 12px;
        font-size:12px;
    }

    /*
     * Search bars: do not squeeze the input and button off screen.
     */
    .card form[style*="display:flex"]{
        display:grid!important;
        grid-template-columns:1fr!important;
        gap:9px!important;
        width:100%;
    }

    .card form[style*="display:flex"] .btn{
        width:100%;
    }

    /*
     * MOBILE TABLES -> CARDS.
     * We deliberately remove the desktop header and give each value a
     * page-specific label below.
     */
    .table-card{
        width:100%;
        max-width:100%;
        margin-top:14px;
        padding:10px;
        overflow:visible;
        background:transparent;
        border:0;
    }

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

    .table-card thead{
        display:none;
    }

    .table-card tbody{
        display:grid;
        gap:11px;
    }

    .table-card tr{
        background:var(--panel);
        border:1px solid var(--line);
        border-radius:13px;
        padding:10px 12px;
        overflow:hidden;
    }

    .table-card td{
        position:relative;
        border:0;
        border-bottom:1px solid #1b334d;
        padding:8px 0 8px 43%;
        min-height:35px;
        font-size:12px;
        line-height:1.4;
        overflow-wrap:anywhere;
        word-break:break-word;
        white-space:normal;
    }

    .table-card td:last-child{
        border-bottom:0;
    }

    .table-card td::before{
        position:absolute;
        left:0;
        top:8px;
        width:39%;
        color:#89a3c0;
        font-size:10px;
        font-weight:800;
        line-height:1.35;
        text-transform:uppercase;
        letter-spacing:.035em;
        overflow-wrap:anywhere;
    }

    .table-card td .btn{
        width:100%;
        margin-top:2px;
    }

    /* Dashboard recent licences */
    .admin-page-dashboard .table-card td:nth-child(1)::before{content:"Licence"}
    .admin-page-dashboard .table-card td:nth-child(2)::before{content:"Customer"}
    .admin-page-dashboard .table-card td:nth-child(3)::before{content:"Source"}
    .admin-page-dashboard .table-card td:nth-child(4)::before{content:"Status"}
    .admin-page-dashboard .table-card td:nth-child(5)::before{content:"Expires"}

    /* Licences page */
    .admin-page-licenses .table-card td:nth-child(1)::before{content:"Licence"}
    .admin-page-licenses .table-card td:nth-child(2)::before{content:"Customer"}
    .admin-page-licenses .table-card td:nth-child(3)::before{content:"Source"}
    .admin-page-licenses .table-card td:nth-child(4)::before{content:"Status"}
    .admin-page-licenses .table-card td:nth-child(5)::before{content:"Device"}
    .admin-page-licenses .table-card td:nth-child(6)::before{content:"Expires"}
    .admin-page-licenses .table-card td:nth-child(7)::before{content:"Manage"}

    /* Trials & devices */
    .admin-page-trials .table-card td:nth-child(1)::before{content:"Device"}
    .admin-page-trials .table-card td:nth-child(2)::before{content:"Installation ID"}
    .admin-page-trials .table-card td:nth-child(3)::before{content:"Started"}
    .admin-page-trials .table-card td:nth-child(4)::before{content:"Expires"}
    .admin-page-trials .table-card td:nth-child(5)::before{content:"Status"}
    .admin-page-trials .table-card td:nth-child(6)::before{content:"Last seen"}
    .admin-page-trials .table-card td:nth-child(7)::before{content:"Actions"}

    /* Dealers */
    .admin-page-dealers .table-card td:nth-child(1)::before{content:"Dealer"}
    .admin-page-dealers .table-card td:nth-child(2)::before{content:"Code"}
    .admin-page-dealers .table-card td:nth-child(3)::before{content:"Discount"}
    .admin-page-dealers .table-card td:nth-child(4)::before{content:"Commission"}
    .admin-page-dealers .table-card td:nth-child(5)::before{content:"Allocation"}
    .admin-page-dealers .table-card td:nth-child(6)::before{content:"Licences"}
    .admin-page-dealers .table-card td:nth-child(7)::before{content:"Due"}
    .admin-page-dealers .table-card td:nth-child(8)::before{content:"Status"}
    .admin-page-dealers .table-card td:nth-child(9)::before{content:"Manage"}

    /* General payments */
    .admin-page-payments .table-card td:nth-child(1)::before{content:"Date"}
    .admin-page-payments .table-card td:nth-child(2)::before{content:"Provider"}
    .admin-page-payments .table-card td:nth-child(3)::before{content:"Transaction"}
    .admin-page-payments .table-card td:nth-child(4)::before{content:"Licence"}
    .admin-page-payments .table-card td:nth-child(5)::before{content:"Amount"}
    .admin-page-payments .table-card td:nth-child(6)::before{content:"Status"}
    .admin-page-payments .table-card td:nth-child(7)::before{content:"Expires"}

    /* Audit can still be long: make it card-based as well. */
    .admin-page-audit .table-card td{
        padding-left:0;
    }

    .admin-page-audit .table-card td::before{
        display:none;
    }

    /*
     * Existing Mollie page already has its own mobile card layout.
     * Do not convert it twice.
     */
    .admin-page-mollie .mollie-table-wrap{
        display:none!important;
    }

    .admin-page-mollie .mollie-cards{
        display:grid!important;
    }
}

@media(max-width:430px){

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

    .sidebar nav a{
        font-size:11px;
        min-height:37px;
    }

    .content{
        padding:14px 8px 24px;
    }

    .topbar h1{
        font-size:23px;
    }

    .table-card{
        padding:7px 0;
    }

    .table-card td{
        padding-left:40%;
    }

    .table-card td::before{
        width:36%;
    }
}
