/* ===== CSS Variables - Light Theme (Notion/Linear Style) ===== */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --success-color: #16a34a;
    --success-hover: #15803d;
    --danger-color: #dc2626;
    --warning-color: #ea580c;

    --bg-color: #ffffff;
    --bg-secondary: #fafafa;
    --bg-tertiary: #f5f5f5;
    --surface-color: #ffffff;
    --surface-hover: #fafafa;

    --text-primary: #171717;
    --text-secondary: #525252;
    --text-muted: #a3a3a3;

    --border-color: #e5e5e5;
    --border-focus: #2563eb;

    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;

    --transition-fast: 0.12s ease;
    --transition-normal: 0.18s ease;

    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background: var(--bg-secondary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ===== App Container ===== */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    max-width: 100vw;
    overflow: hidden;
}

/* ===== Header ===== */
.header {
    padding: 0.75rem 1rem;
    text-align: center;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.logo-image {
    height: 28px;
    width: 28px;
    display: block;
    object-fit: contain;
}



/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0.75rem;
    overflow: hidden;
    background: var(--bg-secondary);
}

/* ===== Upload Section ===== */
.upload-section {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.upload-box {
    width: 100%;
    max-width: 320px;
    padding: 2rem 1.5rem;
    text-align: center;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--surface-color);
    cursor: pointer;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.upload-box:hover,
.upload-box.dragover {
    border-color: var(--primary-color);
    background: var(--bg-tertiary);
}

.upload-icon {
    width: 36px;
    height: 36px;
    margin: 0 auto 0.75rem;
    color: var(--text-muted);
}

.upload-icon svg {
    width: 100%;
    height: 100%;
}

.upload-text {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
}

.upload-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ===== Editor Section ===== */
.editor-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 0;
}

.editor-section.hidden {
    display: none;
}

.canvas-container {
    position: relative;
    flex: 1;
    min-height: 0;
    height: 100%;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#main-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.signatures-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* ===== Signature Item on Canvas ===== */
.signature-item {
    position: absolute;
    cursor: move;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
}

.signature-item img {
    display: block;
    max-width: 150px;
    height: auto;
    pointer-events: none;
}

.signature-item.selected {
    outline: 1.5px solid var(--primary-color);
    outline-offset: 2px;
}

.signature-item .resize-handle {
    position: absolute;
    bottom: -5px;
    right: -5px;
    width: 14px;
    height: 14px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: nwse-resize;
    display: none;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 8px;
}

.signature-item.selected .resize-handle {
    display: flex;
}

.signature-item .delete-handle {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 16px;
    height: 16px;
    background: var(--danger-color);
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 10px;
    font-weight: 500;
}

.signature-item.selected .delete-handle {
    display: flex;
}



/* ===== Toolbar ===== */
.toolbar {
    display: flex;
    justify-content: center;
    gap: 1.25rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-wrap: nowrap;
}

/* ===== Page Footer ===== */
.page-footer {
    padding: 0.6rem 1rem 0.75rem;
    background: var(--bg-secondary);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    color: var(--text-muted);
    font-size: 0.75rem;
    text-align: center;
    line-height: 1.4;
}

.page-footer a {
    color: inherit;
    text-decoration: none;
    font-weight: inherit;
}

.page-footer a:visited,
.page-footer a:hover,
.page-footer a:active {
    color: inherit;
    text-decoration: none;
}

.tool-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1.1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    min-height: 40px;
    min-width: 108px;
    white-space: nowrap;
}

.tool-btn svg {
    width: 18px;
    height: 18px;
}

.tool-btn:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: var(--text-muted);
}

.tool-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tool-btn.primary {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.tool-btn.primary:hover:not(:disabled) {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.tool-btn.success {
    background: var(--success-color);
    border-color: var(--success-color);
    color: white;
}

.tool-btn.success:hover:not(:disabled) {
    background: var(--success-hover);
    border-color: var(--success-hover);
}

/* ===== Signature Panel ===== */
.signature-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    visibility: hidden;
    opacity: 0;
    transition: visibility 0s linear var(--transition-normal), opacity var(--transition-normal);
}

.signature-panel.active {
    visibility: visible;
    opacity: 1;
    transition: visibility 0s linear 0s, opacity var(--transition-normal);
}

.panel-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.25);
}

.panel-content {
    position: relative;
    width: 100%;
    max-height: 80vh;
    background: var(--bg-color);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 1rem;
    transform: translateY(100%);
    transition: transform var(--transition-normal);
    border-top: 1px solid var(--border-color);
}

.signature-panel.active .panel-content {
    transform: translateY(0);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.panel-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.panel-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.panel-close:hover {
    background: var(--surface-hover);
}

.panel-close svg {
    width: 16px;
    height: 16px;
}

.panel-canvas-wrapper {
    position: relative;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    touch-action: none;
}

#signature-canvas {
    display: block;
    width: 100%;
    height: 160px;
    cursor: crosshair;
}

.signature-guide {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.875rem;
    color: var(--text-muted);
    pointer-events: none;
    transition: opacity var(--transition-fast);
}

.signature-guide.hidden {
    opacity: 0;
}

.panel-tools {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

.pen-options,
.pen-colors {
    display: flex;
    gap: 0.4rem;
}

.pen-size {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.pen-size:hover {
    border-color: var(--text-muted);
}

.pen-size.active {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.08);
}

.pen-dot {
    border-radius: 50%;
    background: var(--text-primary);
}

.pen-dot.small {
    width: 5px;
    height: 5px;
}

.pen-dot.medium {
    width: 8px;
    height: 8px;
}

.pen-dot.large {
    width: 12px;
    height: 12px;
}

.pen-color {
    width: 24px;
    height: 24px;
    background: var(--color);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.pen-color:hover {
    transform: scale(1.08);
}

.pen-color.active {
    border-color: var(--text-primary);
}

.panel-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.6rem 1rem;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

.btn svg {
    width: 16px;
    height: 16px;
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
}

.btn-primary {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

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

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    padding: 0.6rem 1rem;
    background: var(--text-primary);
    color: white;
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    z-index: 2000;
}

.toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--danger-color);
}

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

/* ===== Responsive ===== */
@media (min-width: 768px) {
    html {
        font-size: 17px;
    }

    .main-content {
        padding: 1rem;
    }

    .canvas-container {
        min-height: 320px;
    }

    #signature-canvas {
        height: 200px;
    }

    .toolbar {
        gap: 2.25rem;
    }

    .tool-btn {
        padding: 0.7rem 1.35rem;
        min-height: 44px;
        min-width: 120px;
    }
}

@media (min-width: 1024px) {
    .app-container {
        max-width: 720px;
        margin: 0 auto;
        border-left: 1px solid var(--border-color);
        border-right: 1px solid var(--border-color);
    }

    .panel-content {
        max-width: 480px;
        margin: 0 auto;
        border-radius: var(--radius-lg);
        margin-bottom: 1.5rem;
        border: 1px solid var(--border-color);
    }

    .signature-panel {
        align-items: center;
    }
}