/* ==========================================
   DGserve PDF Editor
   Version : 1.0
==========================================*/

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/*==========================
    RESET
==========================*/

*{
    margin:0;
    padding:0;
    box-sizing:border-box;
}

[hidden]{
    display:none !important;
}

html{
    scroll-behavior:smooth;
}

body{
    font-family:'Inter',system-ui,-apple-system,sans-serif;
    background:#fafbfc;
    color:#111827;
    -webkit-font-smoothing:antialiased;
}

button, input{
    font-family:inherit;
}

/*==========================
    VARIABLES
==========================*/

:root{
    --primary:#2563eb;
    --primary-hover:#1e40af;
    --white:#ffffff;
    --text:#111827;
    --gray:#6b7280;
    --border:#e5e7eb;
    --bg:#fafbfc;
    --radius:16px;
    --shadow:0 10px 30px rgba(15,23,42,.06);

    --stage-bg:#2b2f38;
    --stage-bg-dark:#20232b;
    --rail-bg:#1c1f26;
    --rail-text:#c7cad1;
    --danger:#ef4444;
    --highlight:#ffd54a;
}

/*==========================
    HEADER
==========================*/

header{
    display:flex;
    justify-content:space-between;
    align-items:center;
    background:rgba(255,255,255,.95);
    border-bottom:1px solid var(--border);
    padding:14px 30px;
    position:sticky;
    top:0;
    z-index:999;
}

.brand{
    display:flex;
    align-items:center;
    gap:10px;
    text-decoration:none;
    color:#222;
    font-weight:600;
    font-size:15px;
    transition:.3s;
}

.brand:hover{ opacity:.8; }

.brand img{
    width:32px;
    height:32px;
    object-fit:contain;
}

.logo{
    font-size:20px;
    font-weight:800;
    color:var(--primary);
}

.headerActions{
    display:flex;
    gap:10px;
}

/*==========================
    BUTTONS (shared)
==========================*/

.primaryBtn{
    display:inline-flex;
    align-items:center;
    gap:8px;
    background:linear-gradient(135deg,#2563eb,#3b82f6);
    color:#fff;
    border:none;
    padding:11px 20px;
    font-size:14px;
    font-weight:700;
    border-radius:10px;
    cursor:pointer;
    transition:.25s;
    box-shadow:0 8px 20px rgba(37,99,235,.25);
}

.primaryBtn:hover{
    transform:translateY(-1px);
    box-shadow:0 12px 25px rgba(37,99,235,.35);
}

.primaryBtn:disabled{
    opacity:.5;
    cursor:not-allowed;
    transform:none;
}

.ghostBtn{
    display:inline-flex;
    align-items:center;
    gap:8px;
    background:#fff;
    color:var(--text);
    border:1px solid var(--border);
    padding:10px 18px;
    font-size:14px;
    font-weight:600;
    border-radius:10px;
    cursor:pointer;
    transition:.2s;
}

.ghostBtn:hover{
    border-color:var(--primary);
    color:var(--primary);
}

/*==========================
    UPLOAD SCREEN
==========================*/

.container{
    max-width:900px;
    margin:auto;
    padding:55px 20px;
}

.container h1{
    text-align:center;
    font-size:38px;
    font-weight:800;
    letter-spacing:-1px;
    margin-bottom:12px;
}

.subtitle{
    text-align:center;
    color:var(--gray);
    max-width:640px;
    margin:0 auto 40px;
    line-height:1.7;
}

#dropArea{
    background:var(--white);
    border:2px dashed #60a5fa;
    border-radius:22px;
    padding:50px 20px;
    text-align:center;
    box-shadow:var(--shadow);
    transition:.25s;
    cursor:pointer;
}

#dropArea:hover{
    transform:translateY(-3px);
    border-color:var(--primary);
}

#dropArea.dragOver{
    background:#eef5ff;
    border-color:var(--primary);
}

#dropArea i{
    font-size:46px;
    color:var(--primary);
    margin-bottom:14px;
}

#dropArea h2{
    margin-bottom:6px;
    font-size:1.4rem;
}

#dropArea p{
    color:var(--gray);
    margin-bottom:10px;
}

.browseBtn{
    display:inline-block;
    padding:12px 26px;
    background:linear-gradient(135deg,#2563eb,#3b82f6);
    color:#fff;
    border-radius:10px;
    font-weight:700;
    cursor:pointer;
    transition:.25s;
}

.browseBtn:hover{
    transform:translateY(-1px);
}

#dropArea small{
    display:block;
    margin-top:12px;
    color:var(--gray);
    font-size:.85rem;
}

.featureStrip{
    display:grid;
    grid-template-columns:repeat(4,1fr);
    gap:16px;
    margin-top:36px;
}

.featureStrip div{
    background:#fff;
    border:1px solid var(--border);
    border-radius:14px;
    padding:18px 10px;
    text-align:center;
    color:var(--gray);
    font-size:13px;
    font-weight:600;
}

.featureStrip i{
    display:block;
    font-size:20px;
    color:var(--primary);
    margin-bottom:8px;
}

/*==========================
    EDITOR SHELL
==========================*/

#editorScreen{
    display:flex;
    flex-direction:column;
    height:calc(100vh - 65px);
}

/*==========================
    TOOLBAR
==========================*/

.toolbar{
    display:flex;
    align-items:center;
    gap:10px;
    padding:10px 20px;
    background:#fff;
    border-bottom:1px solid var(--border);
    flex-wrap:wrap;
}

.toolGroup{
    display:flex;
    align-items:center;
    gap:6px;
}

.toolDivider{
    width:1px;
    height:28px;
    background:var(--border);
    margin:0 4px;
}

.toolBtn{
    display:flex;
    flex-direction:column;
    align-items:center;
    gap:3px;
    background:transparent;
    border:1px solid transparent;
    border-radius:10px;
    padding:7px 12px;
    cursor:pointer;
    color:var(--gray);
    font-size:11px;
    font-weight:600;
    transition:.15s;
}

.toolBtn i{
    font-size:16px;
}

.toolBtn:hover{
    background:#f1f5f9;
    color:var(--text);
}

.toolBtn:active{
    transform:scale(.93);
}

.toolBtn.active{
    background:#eaf1ff;
    border-color:#bfd7ff;
    color:var(--primary);
}

.toolBtn.danger:hover{
    background:#fef2f2;
    color:var(--danger);
}

.contextControls{
    display:flex;
    align-items:center;
    gap:16px;
}

.colorLabel, .sizeLabel, .fontLabel, .fontSizeLabel{
    display:flex;
    flex-direction:column;
    gap:4px;
    font-size:11px;
    font-weight:600;
    color:var(--gray);
}

.fontLabel select{
    height:28px;
    border:1px solid var(--border);
    border-radius:6px;
    padding:0 6px;
    font-size:12px;
    cursor:pointer;
    background:#fff;
    max-width:150px;
}

.fontSizeLabel input[type="number"]{
    width:56px;
    height:28px;
    border:1px solid var(--border);
    border-radius:6px;
    padding:0 6px;
    font-size:12px;
}

.styleToggles{
    display:flex;
    align-self:flex-end;
    gap:4px;
}

.styleToggleBtn{
    width:28px;
    height:28px;
    border:1px solid var(--border);
    border-radius:6px;
    background:#fff;
    color:var(--text);
    cursor:pointer;
    font-size:13px;
    transition:.15s;
}

.styleToggleBtn:hover{
    border-color:var(--primary);
}

.styleToggleBtn.active{
    background:#eaf1ff;
    border-color:var(--primary);
    color:var(--primary);
}

.colorLabel input[type="color"]{
    width:34px;
    height:28px;
    border:1px solid var(--border);
    border-radius:6px;
    padding:0;
    cursor:pointer;
    background:none;
}

.sizeLabel input[type="range"]{
    width:110px;
}

/*==========================
    WORKSPACE
==========================*/

.workspace{
    flex:1;
    display:flex;
    overflow:hidden;
}

/*==========================
    THUMBNAIL RAIL
==========================*/

.thumbRail{
    width:170px;
    flex-shrink:0;
    background:var(--rail-bg);
    padding:16px 12px;
    overflow-y:auto;
    display:flex;
    flex-direction:column;
    gap:14px;
}

.thumb-item{
    position:relative;
    border-radius:10px;
    overflow:hidden;
    cursor:grab;
    border:2px solid transparent;
    background:#111;
    transition:transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.thumb-item:hover{
    transform:translateY(-2px);
    box-shadow:0 6px 16px rgba(0,0,0,.35);
}

.thumb-item:active{ cursor:grabbing; }

.thumb-item.active{
    border-color:var(--primary);
    box-shadow:0 0 0 3px rgba(37,99,235,.25);
}

.thumb-item img{
    display:block;
    width:100%;
    height:auto;
    background:#fff;
}

.thumb-item .thumbLabel{
    position:absolute;
    bottom:6px;
    left:6px;
    background:rgba(0,0,0,.6);
    color:#fff;
    font-size:10px;
    padding:2px 6px;
    border-radius:5px;
    font-weight:600;
}

.thumb-item .thumbActions{
    position:absolute;
    top:6px;
    right:6px;
    display:flex;
    gap:4px;
    opacity:0;
    transition:.15s;
}

.thumb-item:hover .thumbActions{
    opacity:1;
}

.thumbActions button{
    width:22px;
    height:22px;
    border:none;
    border-radius:6px;
    background:rgba(0,0,0,.65);
    color:#fff;
    font-size:10px;
    cursor:pointer;
}

.thumbActions button:hover{
    background:var(--primary);
}

.thumbActions button.danger:hover{
    background:var(--danger);
}

.thumb-item.dragging{
    opacity:.5;
}

/*==========================
    CANVAS STAGE
==========================*/

.canvasStage{
    flex:1;
    background-color: var(--stage-bg-dark);
    background-image:
        radial-gradient(rgba(255,255,255,.06) 1px, transparent 1px),
        radial-gradient(circle at 50% 0%, var(--stage-bg) 0%, var(--stage-bg-dark) 100%);
    background-size: 24px 24px, 100% 100%;
    background-position: 0 0, 0 0;
    overflow:auto;
    display:flex;
    align-items:flex-start;
    justify-content:center;
    padding:36px;
    position:relative;
}

.pageWrap{
    background:#fff;
    box-shadow:0 20px 50px rgba(0,0,0,.45);
    line-height:0;
    transform-origin: top center;
    transition: transform .15s ease;
}

.pageWrap canvas{
    display:block;
}

/*==========================
    MODAL (Signature)
==========================*/

.modalOverlay{
    position:fixed;
    inset:0;
    background:rgba(15,23,42,.55);
    display:flex;
    align-items:center;
    justify-content:center;
    z-index:2000;
    padding:20px;
}

.modalCard{
    background:#fff;
    border-radius:18px;
    padding:26px;
    max-width:560px;
    width:100%;
    box-shadow:0 25px 60px rgba(0,0,0,.35);
}

.modalCard h3{
    font-size:19px;
    margin-bottom:6px;
}

.modalHint{
    color:var(--gray);
    font-size:13px;
    margin-bottom:16px;
}

.sigCanvasWrap{
    background:#fff;
    border:2px dashed var(--border);
    border-radius:12px;
    overflow:hidden;
    display:flex;
    justify-content:center;
    position:relative;
}

.sigCanvasWrap::after{
    content:"";
    position:absolute;
    left:34px;
    right:34px;
    bottom:44px;
    border-bottom:2px dashed #cbd5e1;
    pointer-events:none;
}

#sigCanvas{
    touch-action:none;
    cursor:crosshair;
}

.modalActions{
    display:flex;
    justify-content:flex-end;
    gap:10px;
    margin-top:18px;
}

/*==========================
    LOADING OVERLAY
==========================*/

.loadingOverlay{
    position:fixed;
    inset:0;
    background:rgba(15,23,42,.75);
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    gap:16px;
    z-index:3000;
    color:#fff;
    font-weight:600;
}

.spinner{
    width:44px;
    height:44px;
    border:4px solid rgba(255,255,255,.25);
    border-top-color:#fff;
    border-radius:50%;
    animation:spin .8s linear infinite;
}

@keyframes spin{
    to{ transform:rotate(360deg); }
}

/*==========================
    FOOTER
==========================*/

footer{
    text-align:center;
    padding:18px;
    color:var(--gray);
    font-size:13px;
    background:#fff;
    border-top:1px solid var(--border);
}

footer a{
    color:var(--primary);
    text-decoration:none;
    font-weight:600;
}

/*==========================
    FLOATING CONTROLS (zoom + page nav)
==========================*/

.floatingControls{
    position:fixed;
    bottom:22px;
    left:50%;
    transform:translateX(-50%);
    display:flex;
    gap:10px;
    z-index:150;
}

.pill{
    display:flex;
    align-items:center;
    gap:8px;
    background:rgba(28,31,38,.88);
    backdrop-filter:blur(10px);
    -webkit-backdrop-filter:blur(10px);
    color:#fff;
    padding:6px 8px;
    border-radius:999px;
    box-shadow:0 10px 25px rgba(0,0,0,.35);
    font-size:12px;
    font-weight:700;
}

.pill button{
    width:26px;
    height:26px;
    flex-shrink:0;
    border:none;
    border-radius:50%;
    background:rgba(255,255,255,.1);
    color:#fff;
    cursor:pointer;
    display:flex;
    align-items:center;
    justify-content:center;
    font-size:11px;
    transition:.15s ease;
}

.pill button:hover:not(:disabled){
    background:var(--primary);
}

.pill button:disabled{
    opacity:.3;
    cursor:not-allowed;
}

.pill span{
    min-width:38px;
    text-align:center;
    color:#e5e7eb;
}

#zoomResetBtn{
    width:auto;
    padding:0 12px;
    border-radius:14px;
    font-size:11px;
    font-weight:600;
}

/*==========================
    ACCESSIBILITY: FOCUS STATES
==========================*/

button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible{
    outline:2px solid var(--primary);
    outline-offset:2px;
}

/*==========================
    MOTION
==========================*/

#uploadScreen{
    animation:fadeInUp .45s ease;
}

#editorScreen:not([hidden]){
    animation:fadeIn .3s ease;
}

@keyframes fadeIn{
    from{ opacity:0; }
    to{ opacity:1; }
}

@keyframes fadeInUp{
    from{ opacity:0; transform:translateY(10px); }
    to{ opacity:1; transform:translateY(0); }
}

@media (prefers-reduced-motion: reduce){
    #uploadScreen,
    #editorScreen,
    .thumb-item,
    .toolBtn,
    .pageWrap,
    #dropArea{
        animation:none !important;
        transition:none !important;
    }
}

@media(max-width:900px){

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

    .thumbRail{
        width:110px;
    }

    .toolBtn span{
        display:none;
    }

    .sizeLabel input[type="range"]{
        width:80px;
    }
}

@media(max-width:600px){

    header{
        padding:12px 16px;
    }

    .logo{
        display:none;
    }

    .container h1{
        font-size:28px;
    }

    .thumbRail{
        width:88px;
        padding:10px 8px;
    }

    .canvasStage{
        padding:16px;
    }

    .floatingControls{
        bottom:14px;
        gap:6px;
    }

    .pill{
        padding:5px 6px;
        font-size:11px;
    }

    .pill button{
        width:22px;
        height:22px;
    }

    #zoomResetBtn{
        display:none;
    }
}
