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

/* ─── Design Tokens ─────────────────────────────────────────── */
:root {
    --bg-body:          #f1f5f9;
    --bg-card:          #ffffff;
    --bg-sidebar:       #ffffff;
    --border:           #e2e8f0;
    --border-input:     #cbd5e1;
    --primary:          #2563eb;
    --primary-hover:    #1d4ed8;
    --primary-subtle:   #eff6ff;
    --text-1:           #0f172a;
    --text-2:           #475569;
    --text-3:           #94a3b8;
    --success-bg:       #f0fdf4;
    --success-border:   #86efac;
    --success-text:     #15803d;
    --error-bg:         #fef2f2;
    --error-border:     #fca5a5;
    --error-text:       #b91c1c;
    --info-bg:          #eff6ff;
    --info-border:      #93c5fd;
    --info-text:        #1e40af;
    --topbar-h:         52px;
    --sidebar-w:        300px;
}

/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg-body);
    color: var(--text-1);
    font-size: 14px;
    line-height: 1.5;
}

/* ─── Topbar ─────────────────────────────────────────────────── */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr auto;
    align-items: center;
    padding: 0 1.25rem;
    gap: 1rem;
    z-index: 100;
}

.topbar-left { display: flex; align-items: center; padding-right: 1rem; border-right: 1px solid var(--border); }

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-1);
    letter-spacing: -0.02em;
}
.logo svg { color: var(--primary); }

.topbar-center {
    display: flex;
    align-items: center;
    padding: 0 1rem;
}

.topbar-filename {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.security-badge {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--success-text);
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    padding: 0.3rem 0.65rem;
    border-radius: 100px;
    white-space: nowrap;
}

.btn-sign {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0.5rem 1.1rem;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
    white-space: nowrap;
}
.btn-sign:hover:not(:disabled) { background: var(--primary-hover); }
.btn-sign:active:not(:disabled) { transform: scale(0.97); }
.btn-sign:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── App Shell ──────────────────────────────────────────────── */
.app-shell {
    display: flex;
    height: 100%;
    padding-top: var(--topbar-h);
}

/* ─── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
    padding: 1.5rem 1.25rem;
    gap: 1.5rem;
}

/* Sidebar scrollbar */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ─── Step Blocks ────────────────────────────────────────────── */
.step-block {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.1rem;
}

.step-num {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-size: 0.72rem;
    font-weight: 700;
    flex-shrink: 0;
}

.step-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-2);
}

/* ─── Dropzone ───────────────────────────────────────────────── */
.dropzone {
    border: 1.5px dashed var(--border-input);
    border-radius: 8px;
    padding: 1.25rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
}
.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary);
    background: var(--primary-subtle);
}
.dropzone-icon {
    width: 28px;
    height: 28px;
    color: var(--text-3);
    transition: color 0.15s;
}
.dropzone:hover .dropzone-icon { color: var(--primary); }
.dropzone p {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-2);
}
.dropzone-link { color: var(--primary); }
.dropzone-hint { font-size: 0.72rem; color: var(--text-3); }

/* ─── File Chip ──────────────────────────────────────────────── */
.file-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--primary-subtle);
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    padding: 0.45rem 0.65rem;
    animation: fadeIn 0.2s ease-out;
}
.file-chip-name {
    flex: 1;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chip-remove {
    background: transparent;
    border: none;
    color: #93c5fd;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.1rem 0.15rem;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}
.chip-remove:hover { color: #ef4444; background: #fee2e2; }

/* ─── Form Elements ──────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-2);
    letter-spacing: 0.01em;
}
.input-field {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border-input);
    border-radius: 6px;
    padding: 0.5rem 0.7rem;
    color: var(--text-1);
    font-family: inherit;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
}
.input-field:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
select.input-field { cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; padding-right: 2.25rem; }

/* ─── Key Details ────────────────────────────────────────────── */
.key-details {
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    border-radius: 6px;
    padding: 0.65rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    animation: fadeIn 0.25s ease-out;
}
.key-details-ok {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--success-text);
    margin-bottom: 0.2rem;
}
.key-details-row {
    font-size: 0.76rem;
    color: var(--success-text);
    opacity: 0.85;
    line-height: 1.4;
}
.key-serial {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.7rem;
    word-break: break-all;
}

/* ─── Stamp Settings ─────────────────────────────────────────── */
.stamp-settings-block {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    animation: fadeIn 0.2s ease-out;
}
.settings-divider {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-3);
    padding: 0.25rem 0;
    border-top: 1px solid var(--border);
}
.checkbox-row {
    display: flex;
    gap: 1.25rem;
}
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    font-weight: 400;
    color: var(--text-1);
    cursor: pointer;
    text-transform: none;
    letter-spacing: 0;
}
.checkbox-label input[type="checkbox"] {
    accent-color: var(--primary);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.slider-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.slider-label-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-2);
}
.slider-value { font-variant-numeric: tabular-nums; }
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 5px;
    background: var(--border);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 0 0 1px var(--border-input);
    transition: transform 0.1s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }

/* ─── Status Messages ────────────────────────────────────────── */
.status-msg {
    padding: 0.65rem 0.85rem;
    border-radius: 6px;
    font-size: 0.82rem;
    line-height: 1.4;
    animation: fadeIn 0.2s ease-out;
}
.status-info    { background: var(--info-bg);    border: 1px solid var(--info-border);    color: var(--info-text); }
.status-success { background: var(--success-bg); border: 1px solid var(--success-border); color: var(--success-text); }
.status-error   { background: var(--error-bg);   border: 1px solid var(--error-border);   color: var(--error-text); }

/* ─── Viewer ─────────────────────────────────────────────────── */
.viewer {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-body);
}

/* Viewer Toolbar */
.viewer-toolbar {
    height: 44px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    gap: 1rem;
    flex-shrink: 0;
}
.viewer-toolbar-left, .viewer-toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 160px;
}
.viewer-toolbar-right { justify-content: flex-end; }
.viewer-hint {
    font-size: 0.8rem;
    color: var(--text-3);
}
.stamp-hint {
    font-size: 0.78rem;
    color: var(--primary);
    font-weight: 500;
}

/* Page Controls */
.page-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.page-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 0.3rem;
    cursor: pointer;
    color: var(--text-2);
    transition: background 0.15s, border-color 0.15s;
}
.page-btn:hover { background: var(--primary-subtle); border-color: #93c5fd; color: var(--primary); }
.page-info {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-2);
    min-width: 52px;
    text-align: center;
}

/* Viewer Canvas Area */
.viewer-canvas-area {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2.5rem;
    background: #e2e8f0;
}

/* Placeholder */
.viewer-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin: auto;
    text-align: center;
    user-select: none;
}
.viewer-placeholder p {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-2);
}
.viewer-placeholder span {
    font-size: 0.82rem;
    color: var(--text-3);
}

/* PDF Page */
#pdf-render-wrap {
    position: relative;
    box-shadow: 0 4px 24px rgba(15, 23, 42, 0.15);
    background: white;
    line-height: 0;
    flex-shrink: 0;
}
#pdf-canvas { display: block; }

/* ─── Draggable Stamp ────────────────────────────────────────── */
.stamp-box {
    position: absolute;
    width: 260px;
    height: 80px;
    border: 1.5px solid var(--primary);
    background: rgba(255, 255, 255, 0.97);
    cursor: move;
    border-radius: 3px;
    /* Block layout from top — matches PDF rendering direction */
    display: block;
    overflow: hidden;
    padding: 5px 6px;
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.12);
    user-select: none;
    z-index: 20;
}
.stamp-box-title {
    font-weight: 700;
    text-transform: uppercase;
    color: #1e293b;
    white-space: nowrap;
    letter-spacing: 0.04em;
    display: block;
    line-height: 1;
    /* font-size set by JS */
}
.stamp-box-text {
    color: #475569;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    line-height: 1;
    /* font-size and margin-bottom set by JS */
}
.stamp-box-text.bold { font-weight: 600; }

/* ─── Utilities ──────────────────────────────────────────────── */
.hidden { display: none !important; }

.loader {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.4);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

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