/* Main CSS for Book Template */

/* CSS Variables */
:root {
    /* Colors */
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    
    /* Text Colors */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    
    /* Background Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    
    /* Border Colors */
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    /* Layout */
    --header-height: 64px;
    --sidebar-width: 280px;
    --content-max-width: 900px;
    
    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
    --font-mono: "Monaco", "Menlo", "Ubuntu Mono", "Consolas", "source-code-pro", monospace;
    
    /* Transitions */
    --transition: all 0.2s ease;
}

/* Dark Theme */
[data-theme="dark"] {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #94a3b8;
    
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    
    --border-color: #334155;
    --border-hover: #475569;
    
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.3);
}

/* Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.75;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    margin-top: 2rem;
    margin-bottom: 1rem;
    font-weight: 600;
    line-height: 1.25;
    color: var(--text-primary);
}

h1 { font-size: 2.25rem; }
h2 { font-size: 1.875rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1.125rem; }
h6 { font-size: 1rem; }

p {
    margin-top: 0;
    margin-bottom: 1rem;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Layout */
.book-layout {
    display: flex;
    min-height: 100vh;
}

/* Header */
.book-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

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

.header-title {
    text-decoration: none;
    color: var(--text-primary);
}

.header-title h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

/* Sidebar */
.book-sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    z-index: 900;
    transform: translateX(0);
    transition: transform 0.3s ease;
}

.sidebar-content {
    padding: 1.5rem;
}

.book-info {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.book-title {
    font-size: 1.125rem;
    margin: 0 0 0.5rem 0;
}

.book-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin: 0;
}

/* Table of Contents */
.toc-title {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin: 1.5rem 0 0.75rem 0;
}

.toc-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin: 1.5rem 0 0.5rem 0;
}

.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-item {
    margin: 0;
}

.toc-link {
    display: block;
    padding: 0.5rem 0.75rem;
    color: var(--text-secondary);
    border-radius: 6px;
    transition: var(--transition);
}

.toc-link:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    text-decoration: none;
}

.toc-link.active {
    background: var(--bg-tertiary);
    color: var(--primary-color);
    font-weight: 500;
}

.toc-chapter .toc-link {
    font-weight: 500;
}

.chapter-number, .section-number {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-right: 0.5rem;
}

.toc-sections {
    list-style: none;
    padding: 0;
    margin: 0 0 0 1rem;
}

.toc-section .toc-link {
    font-size: 0.875rem;
    padding: 0.375rem 0.75rem;
}

/* Main Content */
.book-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
}

.book-content {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: 2rem 3rem;
}

.page-content {
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 2rem;
    box-shadow: var(--shadow-sm);
}

/* Search */
.search-container {
    position: relative;
    max-width: 400px;
    width: 100%;
}

.search-input {
    width: 100%;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--text-primary);
    transition: var(--transition);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 0.5rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: var(--shadow-lg);
    max-height: 400px;
    overflow-y: auto;
    display: none;
}

.search-results.active {
    display: block;
}

/* Buttons */
.sidebar-toggle,
.theme-toggle {
    padding: 0.5rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: var(--transition);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle:hover,
.theme-toggle:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.theme-icon {
    display: none;
}

[data-theme="light"] .theme-icon-light {
    display: block;
}

[data-theme="dark"] .theme-icon-dark {
    display: block;
}

.github-link {
    display: flex;
    align-items: center;
    color: var(--text-secondary);
    transition: var(--transition);
}

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

/* Edit Link */
.edit-page {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.edit-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.edit-link:hover {
    color: var(--primary-color);
}

/* Mobile Styles */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 850;
}

/* タブレット・モバイル向けレスポンシブ対応 */
@media (max-width: 768px) {
    .book-sidebar {
        transform: translateX(-100%);
    }
    
    .book-sidebar.active {
        transform: translateX(0);
    }
    
    .book-main {
        margin-left: 0;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    .sidebar-toggle {
        display: block;
    }
    
    .book-content {
        padding: 1rem 0.5rem;
    }
    
    .page-content {
        padding: 1rem;
        margin: 0;
        border-radius: 0;
    }
    
    .header-center {
        display: none;
    }
    
    /* モバイル画面サイズ調整 */
    .book-layout {
        width: 100vw;
        overflow-x: hidden;
    }
    
    .book-header {
        padding: 0 0.5rem;
    }
    
    .header-title h1 {
        font-size: 1rem;
    }
    
    /* テキストサイズ調整 */
    body {
        font-size: 0.9rem;
        line-height: 1.6;
    }
    
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.125rem; }
    h5 { font-size: 1rem; }
    h6 { font-size: 0.9rem; }
}

/* デスクトップ・大画面向け */
@media (min-width: 769px) {
    .sidebar-toggle {
        display: none;
    }
    
    .book-sidebar {
        transform: translateX(0);
    }
    
    .book-main {
        margin-left: var(--sidebar-width);
    }
}


/* Print Styles */
@media print {
    .book-header,
    .book-sidebar,
    .edit-page,
    .page-navigation {
        display: none;
    }
    
    .book-main {
        margin: 0;
    }
    
    .book-content {
        max-width: 100%;
        padding: 0;
    }
    
    .page-content {
        box-shadow: none;
        padding: 0;
    }
}