* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
    --accent-color: #0d6efd;
    --accent-hover: #0b5ed7;
    --success-color: #198754;
    --danger-color: #dc3545;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] {
    --bg-primary: #1e1e1e;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #3d3d3d;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --border-color: #404040;
    --accent-color: #4a9eff;
    --accent-hover: #6bb0ff;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

/* 사이드바 */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 900;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
}

.sidebar.active {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    min-height: 60px;
    flex-shrink: 0;
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-search {
    position: relative;
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.sidebar-search input {
    width: 100%;
    padding: 10px 35px 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
}

.sidebar-search input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.sidebar-search svg {
    position: absolute;
    right: 25px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

.sidebar-controls {
    display: flex;
    gap: 8px;
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    flex-shrink: 0;
}

.sort-select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sort-select:focus {
    outline: none;
    border-color: var(--accent-color);
}

.btn-icon-small {
    padding: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-primary);
}

.btn-icon-small:hover {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
}

.btn-new-memo {
    margin: 12px 15px;
    padding: 12px 16px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-new-memo:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.memo-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 15px 15px;
    min-height: 0;
}

.memo-item {
    padding: 14px 12px;
    margin-bottom: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    word-wrap: break-word;
}

.memo-item:hover {
    background: var(--bg-tertiary);
    transform: translateX(5px);
}

.memo-item.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.memo-item-title {
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.memo-item-preview {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.memo-item.active .memo-item-preview {
    color: rgba(255, 255, 255, 0.8);
}

.memo-item-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.memo-item.active .memo-item-time {
    color: rgba(255, 255, 255, 0.7);
}

.memo-item.favorite {
    border-left: 3px solid #ffc107;
}

.memo-item-actions {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    gap: 4px;
}

.memo-item:hover .memo-item-actions {
    display: flex;
}

.memo-item-btn {
    padding: 4px 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s ease;
}

.memo-item-btn:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.memo-item-btn.delete:hover {
    background: var(--danger-color);
    border-color: var(--danger-color);
}

.memo-item-btn.favorite {
    color: #ffc107;
}

.memo-item-btn.favorite.active {
    background: #ffc107;
    color: white;
    border-color: #ffc107;
}

.empty-memo-list {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.empty-memo-list svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-memo-list p {
    font-size: 14px;
    margin: 0;
}

/* 오버레이 */
.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 899;
}

.overlay.active {
    display: block;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    background: var(--bg-primary);
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    flex-wrap: wrap;
    gap: 10px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--bg-secondary);
}

h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.file-name-input {
    padding: 8px 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    min-width: 150px;
    transition: all 0.2s ease;
}

.file-name-input:focus {
    outline: none;
    border-color: var(--accent-color);
    background: var(--bg-primary);
}

.user-image {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-right: 8px;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    margin-right: 10px;
}

.btn-small {
    padding: 6px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
}

.btn-small:hover {
    background: var(--bg-tertiary);
}

#userProfile {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    background: var(--bg-secondary);
    border-radius: 20px;
    margin-right: 10px;
}

.save-status {
    font-size: 14px;
    color: var(--success-color);
    padding: 4px 12px;
    background: var(--bg-secondary);
    border-radius: 20px;
    font-weight: 500;
}

.save-status.saving {
    color: var(--accent-color);
}

.header-right {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all 0.2s ease;
    font-size: 14px;
}

.btn:hover {
    background: var(--bg-tertiary);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

#langText {
    font-size: 11px;
    font-weight: 600;
}

#favoriteBtn.active #starIcon {
    fill: #ffc107;
    stroke: #ffc107;
}

.editor-container {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transition: all 0.3s ease;
}

.tabs {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 10px;
}

.tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

.tab:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.tab.active {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

.content-area {
    min-height: 500px;
    position: relative;
}

.notepad {
    width: 100%;
    min-height: 500px;
    padding: 30px;
    border: none;
    outline: none;
    font-size: 16px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    line-height: 1.8;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-y: auto;
    transition: all 0.3s ease;
}

.notepad[contenteditable="false"] {
    background: var(--bg-secondary);
    cursor: default;
}

.notepad:empty:before {
    content: attr(data-placeholder);
    color: var(--text-secondary);
    opacity: 0.6;
    white-space: pre-wrap;
}

.notepad img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 10px 0;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.3s ease;
}

.notepad img:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.notepad img.selected {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

.notepad img.size-small {
    max-width: 300px;
}

.notepad img.size-medium {
    max-width: 500px;
}

.notepad img.size-large {
    max-width: 100%;
}

.notepad img.align-left {
    display: block;
    margin-left: 0;
    margin-right: auto;
}

.notepad img.align-center {
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.notepad img.align-right {
    display: block;
    margin-left: auto;
    margin-right: 0;
}

.preview {
    padding: 30px;
    min-height: 500px;
    overflow-y: auto;
    line-height: 1.8;
}

.preview h1,
.preview h2,
.preview h3,
.preview h4,
.preview h5,
.preview h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
}

.preview h1 {
    font-size: 2em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
}

.preview h2 {
    font-size: 1.5em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.3em;
}

.preview p {
    margin-bottom: 16px;
}

.preview code {
    background: var(--bg-secondary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
}

.preview pre {
    background: var(--bg-secondary);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 16px;
}

.preview pre code {
    background: none;
    padding: 0;
}

.preview blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 16px;
    margin: 16px 0;
    color: var(--text-secondary);
}

.preview ul,
.preview ol {
    margin-bottom: 16px;
    padding-left: 32px;
}

.preview li {
    margin-bottom: 8px;
}

.preview a {
    color: var(--accent-color);
    text-decoration: none;
}

.preview a:hover {
    text-decoration: underline;
}

.preview table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 16px;
}

.preview table th,
.preview table td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

.preview table th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.stats {
    display: flex;
    gap: 30px;
    padding: 15px 30px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    font-size: 14px;
    color: var(--text-secondary);
}

.stats strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* 모바일 반응형 디자인 */
@media (max-width: 768px) {
    .sidebar {
        width: 85%;
        max-width: 320px;
    }

    .container {
        padding: 10px;
    }

    header {
        padding: 12px 15px;
        gap: 8px;
    }

    .header-left {
        gap: 8px;
        flex-wrap: nowrap;
        overflow: hidden;
    }

    h1 {
        font-size: 16px;
    }

    .file-name-input {
        min-width: 100px;
        font-size: 13px;
        padding: 6px 12px;
    }

    .save-status {
        font-size: 12px;
        padding: 3px 10px;
    }

    .header-right {
        gap: 6px;
    }

    .btn {
        padding: 6px 10px;
    }

    .btn svg {
        width: 18px;
        height: 18px;
    }

    #langText {
        display: none;
    }

    #userProfile {
        padding: 4px 8px;
    }

    .user-name {
        display: none;
    }

    .user-image {
        width: 28px;
        height: 28px;
    }

    .btn-small {
        padding: 5px 10px;
        font-size: 11px;
    }

    .notepad,
    .preview {
        padding: 15px;
        min-height: 300px;
        font-size: 14px;
    }

    .stats {
        flex-direction: row;
        gap: 15px;
        padding: 10px 15px;
        font-size: 12px;
        overflow-x: auto;
    }

    .tabs {
        padding: 0 5px;
    }

    .tab {
        padding: 10px 15px;
        font-size: 13px;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
    }

    .modal-header {
        padding: 15px 20px;
    }

    .modal-header h2 {
        font-size: 18px;
    }

    .modal-body {
        padding: 20px;
    }

    .ai-actions {
        gap: 8px;
    }

    .ai-action-btn {
        padding: 8px 14px;
        font-size: 13px;
    }

    .chat-messages {
        max-height: 250px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 100%;
        max-width: 100%;
    }

    h1 {
        font-size: 14px;
    }

    .file-name-input {
        min-width: 80px;
        font-size: 12px;
    }

    .save-status {
        display: none;
    }

    .header-right {
        gap: 4px;
    }

    .btn {
        padding: 6px 8px;
    }

    .btn span {
        display: none;
    }

    .stats span {
        font-size: 11px;
    }
}

/* 데스크톱에서 사이드바 활성화 시 */
@media (min-width: 769px) {
    .sidebar.active ~ .container {
        margin-left: 280px;
    }

    .overlay {
        display: none !important;
    }
}

/* 스크롤바 스타일 */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* 애니메이션 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.editor-container {
    animation: fadeIn 0.5s ease;
}

/* 모달 스타일 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 16px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
}

.close-modal {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.close-modal:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-body {
    padding: 25px;
    overflow-y: auto;
    flex: 1;
}

.ai-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.ai-action-btn {
    padding: 10px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.ai-action-btn:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: translateY(-2px);
}

.chat-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.chat-messages {
    max-height: 300px;
    overflow-y: auto;
    padding: 15px;
    background: var(--bg-secondary);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-message {
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 80%;
    word-wrap: break-word;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.chat-message.user {
    background: var(--accent-color);
    color: white;
    align-self: flex-end;
    margin-left: auto;
}

.chat-message.ai {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    align-self: flex-start;
}

.chat-message.loading {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-style: italic;
}

.chat-message.error {
    background: rgba(220, 53, 69, 0.1);
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
    align-self: flex-start;
}

.ai-info {
    padding: 10px 15px;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 15px;
}

.chat-input-container {
    display: flex;
    gap: 10px;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
}

.chat-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

.btn-primary {
    padding: 12px 24px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

/* 이미지 툴바 */
.image-toolbar {
    position: fixed;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 999;
    display: flex;
    gap: 4px;
    align-items: center;
}

.toolbar-btn {
    padding: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    color: var(--text-primary);
}

.toolbar-btn:hover {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
}

.toolbar-btn-danger:hover {
    background: var(--danger-color);
    border-color: var(--danger-color);
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 4px;
}

/* 도움말 모달 */
.help-modal {
    max-width: 600px;
}

.shortcut-section {
    margin-bottom: 24px;
}

.shortcut-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.shortcut-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.shortcut-item:last-child {
    border-bottom: none;
}

kbd {
    display: inline-block;
    padding: 4px 8px;
    font-family: monospace;
    font-size: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    margin: 0 2px;
}
