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

:root {
    --bg: #ffffff;
    --bg-sidebar: #f7f7f5;
    --bg-hover: #ebebea;
    --bg-selected: #e8e7e5;
    --text: #37352f;
    --text-muted: #9b9a97;
    --border: #e8e7e5;
    --accent: #2383e2;
    --danger: #eb5757;
    --radius: 4px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    height: 100vh;
    overflow: hidden;
}

/* Login page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-sidebar);
}

.login-card {
    text-align: center;
    padding: 48px 40px;
    background: var(--bg);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
    max-width: 360px;
    width: 100%;
}

.login-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.login-subtitle {
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 15px;
}

.login-hint {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 16px;
}

.login-steps {
    text-align: left;
    margin: 24px 0 16px;
}

.login-step {
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--text);
}

.login-step code {
    background: var(--bg-sidebar);
    padding: 2px 6px;
    border-radius: var(--radius);
    font-size: 13px;
}

.login-form {
    margin-top: 16px;
}

.login-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 16px;
    letter-spacing: 4px;
    text-align: center;
    outline: none;
    font-family: monospace;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.login-input::placeholder {
    letter-spacing: 2px;
    color: var(--text-muted);
}

.login-input:focus {
    border-color: var(--accent);
}

.login-btn {
    width: 100%;
    padding: 10px 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
}

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

.login-error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 12px;
}

/* Main layout */
.app-layout {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 12px 8px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand {
    font-weight: 700;
    font-size: 15px;
}

.sidebar-actions {
    display: flex;
    gap: 4px;
}

.btn-icon {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: var(--radius);
    font-size: 18px;
    line-height: 1;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text);
}

/* Tree */
.sidebar-tree {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.tree-item {
    display: flex;
    align-items: center;
    height: 30px;
    padding-right: 8px;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
}

.tree-item:hover {
    background: var(--bg-hover);
}

.tree-item.selected {
    background: var(--bg-selected);
}

.tree-toggle {
    width: 18px;
    height: 18px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
}

.tree-spacer {
    width: 18px;
    flex-shrink: 0;
}

.tree-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-action {
    width: 20px;
    height: 20px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-muted);
    border-radius: var(--radius);
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tree-item:hover .tree-action {
    display: flex;
}

.tree-action:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.tree-action-delete:hover {
    color: var(--danger);
}

.tree-empty {
    color: var(--text-muted);
    font-size: 13px;
    padding: 16px;
    text-align: center;
}

.sidebar-footer {
    padding: 8px 12px;
    border-top: 1px solid var(--border);
}

.logout-link {
    color: var(--text-muted);
    font-size: 13px;
    text-decoration: none;
}

.logout-link:hover {
    color: var(--text);
}

/* Editor area */
.editor-area {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.editor-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.editor-header {
    display: flex;
    align-items: center;
    padding: 8px 24px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.editor-title {
    flex: 1;
    border: none;
    outline: none;
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    background: none;
}

.editor-title::placeholder {
    color: var(--text-muted);
}

.editor-status {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.editor-container #editor {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.editor-container .toastui-editor-defaultUI {
    border: none;
}

.editor-container .toastui-editor-md-container,
.editor-container .toastui-editor-ww-container {
    flex: 1;
}

.editor-container .toastui-editor-md-preview {
    background: var(--bg);
}

.editor-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 15px;
}
