/* ====================================
   WEBNOTE V2 — Premium Design System
   ==================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ---------- Design Tokens ---------- */
:root {
    /* Colors */
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.25);
    --accent: #818cf8;
    --accent-soft: rgba(129, 140, 248, 0.12);

    /* Surfaces */
    --bg-base: #f0f2f5;
    --bg-elevated: #ffffff;
    --bg-subtle: #f8f9fb;
    --bg-glass: rgba(255, 255, 255, 0.72);

    /* Text */
    --text-1: #111827;
    --text-2: #4b5563;
    --text-3: #9ca3af;
    --text-on-primary: #ffffff;

    /* Borders */
    --border: rgba(0, 0, 0, 0.08);
    --border-hover: rgba(99, 102, 241, 0.35);

    /* Semantic */
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.1);

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
    --shadow-glow: 0 0 24px rgba(99, 102, 241, 0.15);

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Timing */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 400ms;

    /* Line numbers */
    --ln-bg: #f3f4f6;
    --ln-text: #c4c9d4;
    --ln-width: 56px;
}

/* ---------- Dark Mode ---------- */
body.dark-mode {
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-glow: rgba(129, 140, 248, 0.2);
    --accent: #a5b4fc;
    --accent-soft: rgba(165, 180, 252, 0.1);

    --bg-base: #0c0f1a;
    --bg-elevated: #151929;
    --bg-subtle: #1a1f33;
    --bg-glass: rgba(21, 25, 41, 0.8);

    --text-1: #f1f5f9;
    --text-2: #94a3b8;
    --text-3: #64748b;

    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(129, 140, 248, 0.4);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 32px rgba(129, 140, 248, 0.12);

    --ln-bg: #111525;
    --ln-text: #3b4264;
}

/* ---------- Reset ---------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ---------- Base ---------- */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-base);
    color: var(--text-1);
    height: 100vh;
    overflow: hidden;
    transition: background var(--duration-slow) var(--ease-out),
                color var(--duration-slow) var(--ease-out);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(99, 102, 241, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(129, 140, 248, 0.06) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
    animation: bgShift 20s ease-in-out infinite alternate;
}

@keyframes bgShift {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* ---------- App Layout ---------- */
.app-container,
.view-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
    z-index: 1;
}

/* ====================================
   HEADER
   ==================================== */
.header {
    height: 64px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
    position: relative;
    transition: background var(--duration-slow) var(--ease-out),
                border-color var(--duration-slow) var(--ease-out);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-link {
    text-decoration: none;
    display: flex;
    align-items: center;
}

.logo-img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    transition: transform var(--duration-normal) var(--ease-spring);
}

.logo-link:hover .logo-img {
    transform: scale(1.1) rotate(-3deg);
}

.logo-fallback {
    display: flex;
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    border-radius: var(--radius-sm);
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    box-shadow: var(--shadow-sm), 0 0 20px var(--primary-glow);
    transition: transform var(--duration-normal) var(--ease-spring);
}

.logo-link:hover .logo-fallback {
    transform: scale(1.1) rotate(-3deg);
}

.title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-1);
    letter-spacing: -0.02em;
    margin: 0;
}

.note-id {
    color: var(--text-2);
    font-weight: 500;
    font-size: 15px;
    margin-left: 6px;
    outline: none;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    transition: all var(--duration-normal) var(--ease-out);
    min-width: 40px;
    max-width: 300px;
}

.note-id[contenteditable="true"]:hover {
    border-color: var(--border);
    background: var(--bg-subtle);
}

.note-id[contenteditable="true"]:focus {
    border-color: var(--primary);
    background: var(--bg-card);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.note-id:empty::before {
    content: attr(data-placeholder);
    color: var(--text-3);
    font-style: italic;
}

.protocol-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    margin-left: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.protocol-badge.https {
    color: var(--success);
    background: var(--success-bg);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.protocol-badge.http {
    color: var(--warning);
    background: var(--warning-bg);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.button-group {
    display: flex;
    gap: 6px;
}

/* ====================================
   BUTTONS
   ==================================== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--duration-normal) var(--ease-out);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-1);
    position: relative;
    overflow: hidden;
    white-space: nowrap;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--primary-glow), transparent);
    opacity: 0;
    transition: opacity var(--duration-normal) var(--ease-out);
}

.btn:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-sm), 0 0 16px var(--primary-glow);
    transform: translateY(-1px);
}

.btn:hover::after {
    opacity: 1;
}

.btn:active {
    transform: translateY(0) scale(0.98);
    box-shadow: var(--shadow-xs);
}

.btn .icon {
    position: relative;
    z-index: 1;
    font-size: 15px;
}

.btn span {
    position: relative;
    z-index: 1;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    color: var(--text-on-primary);
    border: none;
    box-shadow: var(--shadow-sm), 0 0 20px var(--primary-glow);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-hover), #6d28d9);
    box-shadow: var(--shadow-md), 0 0 28px var(--primary-glow);
}

.btn-icon {
    padding: 8px;
    width: 40px;
    height: 40px;
    justify-content: center;
}

/* ====================================
   STATUS MESSAGE
   ==================================== */
.status-message {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    margin-right: 8px;
    transition: all var(--duration-normal) var(--ease-out);
}

.status-message.saved {
    color: var(--success);
    background: var(--success-bg);
}

.status-message.saving {
    color: var(--warning);
    background: var(--warning-bg);
    animation: pulse-soft 1.5s ease-in-out infinite;
}

.status-message.error {
    color: var(--error);
    background: var(--error-bg);
}

@keyframes pulse-soft {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ====================================
   MAIN CONTENT — EDITOR
   ==================================== */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    background: var(--bg-elevated);
    min-height: 0;
    transition: background var(--duration-slow) var(--ease-out);
}

.code-panel {
    height: 100%;
    overflow: hidden;
    background: var(--ln-bg);
    border-right: 1px solid var(--border);
    user-select: none;
    flex-shrink: 0;
    transition: background var(--duration-slow) var(--ease-out);
}

.line-numbers {
    padding: 20px 14px;
    text-align: right;
    color: var(--ln-text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.7;
    min-width: var(--ln-width);
    white-space: pre;
    will-change: transform;
    transition: color var(--duration-slow) var(--ease-out);
}

.editor-section {
    flex: 1;
    position: relative;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}

.editor {
    display: block;
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    padding: 20px 20px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.7;
    background: transparent;
    color: var(--text-1);
    resize: none;
    overflow-y: auto;
    overflow-x: auto;
    white-space: pre;
    tab-size: 4;
    caret-color: var(--primary);
    transition: color var(--duration-slow) var(--ease-out);
    word-wrap: normal;
}

.editor::placeholder {
    color: var(--text-3);
    font-style: italic;
}

.viewer {
    margin: 0;
    display: block;
    overflow: auto;
}

/* ====================================
   STATUS BAR (Footer)
   ==================================== */
.status-bar {
    height: 34px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-3);
    transition: all var(--duration-slow) var(--ease-out);
}

.status-left,
.status-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* ====================================
   NOTIFICATION TOAST
   ==================================== */
.notification {
    position: fixed;
    top: 80px;
    right: 24px;
    padding: 12px 20px;
    background: var(--bg-elevated);
    color: var(--text-1);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--success);
    transform: translateX(120%) scale(0.95);
    transition: transform var(--duration-slow) var(--ease-spring),
                opacity var(--duration-slow) var(--ease-out);
    z-index: 99999;
    font-size: 13px;
    font-weight: 500;
    opacity: 0;
    visibility: hidden;
    backdrop-filter: blur(12px);
}

.notification.show {
    transform: translateX(0) scale(1);
    opacity: 1;
    visibility: visible;
}

/* ====================================
   HISTORY MODAL
   ==================================== */
.history-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}

.history-modal.show {
    display: flex;
}

.history-box {
    width: min(760px, 100%);
    max-height: 80vh;
    overflow: hidden;
    background: var(--bg-elevated);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), 0 0 60px rgba(99, 102, 241, 0.08);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    animation: modalSlideUp var(--duration-slow) var(--ease-spring);
}

@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}

.history-header h3 {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.history-header-actions,
.history-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.history-list {
    padding: 16px;
    overflow: auto;
    max-height: calc(80vh - 78px);
}

.history-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
    background: var(--bg-subtle);
    transition: all var(--duration-normal) var(--ease-out);
}

.history-item:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.history-item.current,
.history-item.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.history-top,
.history-meta {
    margin-bottom: 8px;
}

.history-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.history-label {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: var(--accent-soft);
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.history-time {
    font-size: 12px;
    color: var(--text-3);
}

.history-link,
.history-preview {
    font-size: 13px;
    word-break: break-all;
    margin-bottom: 12px;
    line-height: 1.6;
    color: var(--text-2);
    text-decoration: none;
    display: block;
    transition: color var(--duration-fast) var(--ease-out);
}

a.history-preview:hover {
    color: var(--primary);
    text-decoration: underline;
}

.history-note-name {
    font-size: 12px;
    color: var(--text-3);
    margin-bottom: 4px;
}

.history-title-input {
    width: 100%;
    margin: 8px 0 10px 0;
    border: 1px solid var(--border);
    outline: none;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-family: inherit;
    font-size: 13px;
    background: var(--bg-elevated);
    color: var(--text-1);
    transition: all var(--duration-normal) var(--ease-out);
}

.history-title-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.history-empty {
    text-align: center;
    padding: 32px 12px;
    color: var(--text-3);
    font-size: 14px;
}

.history-password {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.history-password-input {
    flex: 1;
    border: 1px solid var(--border);
    outline: none;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-family: inherit;
    font-size: 13px;
    background: var(--bg-elevated);
    color: var(--text-1);
    transition: all var(--duration-normal) var(--ease-out);
}

.history-password-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ====================================
   PASSWORD OVERLAY
   ==================================== */
.password-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99998;
    padding: 20px;
}

.password-box {
    background: var(--bg-elevated);
    border-radius: var(--radius-xl);
    padding: 48px 40px;
    text-align: center;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow-lg), 0 0 60px rgba(99, 102, 241, 0.1);
    border: 1px solid var(--border);
    animation: modalSlideUp var(--duration-slow) var(--ease-spring);
}

.password-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.password-box h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.password-box p {
    font-size: 14px;
    color: var(--text-3);
    margin-bottom: 24px;
}

.password-field {
    width: 100%;
    padding: 14px 18px;
    font-family: inherit;
    font-size: 15px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    outline: none;
    background: var(--bg-subtle);
    color: var(--text-1);
    text-align: center;
    letter-spacing: 0.1em;
    transition: all var(--duration-normal) var(--ease-out);
}

.password-field:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

.password-error {
    color: var(--error);
    font-size: 13px;
    font-weight: 500;
    min-height: 20px;
    margin: 12px 0;
}

.password-submit {
    width: 100%;
    justify-content: center;
    padding: 14px;
    font-size: 15px;
}

.password-modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}

.password-modal-actions .btn {
    flex: 1;
    justify-content: center;
    padding: 14px;
    font-size: 15px;
}

.password-cancel {
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    color: var(--text-2);
}

.password-cancel:hover {
    background: var(--border);
    color: var(--text-1);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    border: none;
}

.btn-danger:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* ====================================
   SCROLLBAR
   ==================================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
    border: 2px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-3);
    background-clip: content-box;
}

/* ====================================
   LOADING SCREEN (index.html)
   ==================================== */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 24px;
}

.loading-logo {
    width: 72px;
    height: 72px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: logoPulse 2s ease-in-out infinite;
    overflow: hidden;
}

.loading-logo-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
}

@keyframes logoPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: var(--shadow-md), 0 0 40px var(--primary-glow);
    }
    50% {
        transform: scale(1.05);
        box-shadow: var(--shadow-lg), 0 0 60px var(--primary-glow);
    }
}

.loading-text h1 {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--text-1), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.loading-text p {
    margin-top: 8px;
    font-size: 14px;
    color: var(--text-3);
}

.loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ====================================
   RESPONSIVE
   ==================================== */
@media (max-width: 768px) {
    .header {
        padding: 0 14px;
        height: 56px;
    }

    .header-right .btn span:not(.icon) {
        display: none;
    }

    .btn {
        padding: 8px 10px;
    }

    .status-message span:not(.status-icon) {
        display: none;
    }

    .status-message {
        margin-right: 4px;
        padding: 6px 8px;
    }

    .title {
        font-size: 16px;
    }

    .editor {
        padding: 16px;
        font-size: 13px;
    }

    .line-numbers {
        padding: 16px 10px;
        font-size: 13px;
        min-width: 44px;
    }
}

@media (max-width: 480px) {
    .note-id,
    .protocol-badge {
        display: none;
    }

    .button-group {
        gap: 4px;
    }
}
