/* General Styles */
body {
    font-family: sans-serif;
    margin: 0 auto;
    padding: 1em;
    max-width: 1000px;
    line-height: 1.6;
}

/* Paragraph spacing - proper control now that we use <p> tags */
p {
    margin-bottom: 1.2em;
    margin-top: 0;
    line-height: 1.6;
}

/* Universal content spacing */
h1, h2, h3, h4, h5, h6, ul, ol, pre, blockquote {
    margin-bottom: 1em;
}

/* Specific heading adjustments */
h1 { margin-bottom: 0.8em; margin-top: 1.2em; }
h2 { margin-bottom: 0.7em; margin-top: 1em; }
h3 { margin-bottom: 0.6em; margin-top: 0.8em; }

/* Lists */
ul, ol {
    margin-bottom: 1em;
    margin-top: 0.5em;
    padding-left: 2em;
}

li {
    margin-bottom: 0.3em;
}

/* Clear floats before backlinks/related section */
hr {
    clear: both;
}

/* Or more specific - clear before backlinks */
h3 {
    clear: both;
}

/* Tags should clear floats and appear below images */
.tag {
    display: inline-block;
}

/* If tags are at the end of content, ensure they clear floats */
p:has(.tag) {
    clear: both;
}

/* Code blocks */
pre {
    background-color: #f6f8fa;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    padding: 16px;
    overflow-x: auto;
    margin: 1.5em 0;
}

code {
    background-color: #f6f8fa;
    border-radius: 3px;
    padding: 0.2em 0.4em;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}

pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
}

/* Blockquotes */
blockquote {
    border-left: 4px solid #ddd;
    padding-left: 1em;
    margin-left: 0;
    color: #666;
    font-style: italic;
}

/* Navigation */
nav {
    margin-bottom: 1.5em;
    padding-bottom: 0.5em;
    border-bottom: 1px solid #ddd;
}

nav a {
    margin-right: 1em;
    color: #000;
}

nav form {
    display: inline;
}

/* Links */
a {
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.int {
    color: green;
}

.ext {
    color: blue;
}

.tag {
    color: purple;
    font-weight: 500;
}

/* Forms */
textarea {
    width: 100%;
    height: 300px;
    font-family: monospace;
    font-size: 1.2em;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 0.5em;
}

form {
    margin-top: 1em;
}

input[type="text"],
input[type="password"] {
    padding: 0.5em;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1em;
}

button {
    padding: 0.5em 1em;
    background-color: #0066cc;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
}

button:hover {
    background-color: #0052a3;
}

button[type="button"] {
    background-color: #666;
}

button[type="button"]:hover {
    background-color: #555;
}

/* Editor Toolbar */
#toolbar {
    margin-bottom: 0.5em;
}

#toolbar button, #toolbar label {
    margin-right: 0.3em;
    padding: 0.4em 0.8em;
    font-size: 1em;
    cursor: pointer;
    border: 1px solid #888;
    border-radius: 4px;
    background-color: #f0f0f0;
    color: #333;
}

#toolbar button:hover, #toolbar label:hover {
    background-color: #e0e0e0;
}

#toolbar button:active {
    background-color: #ddd;
}

/* Search Results */
mark {
    background: yellow;
    color: black;
    padding: 0 2px;
    border-radius: 3px;
}

.snippet {
    font-size: 0.97em;
    color: #555;
    margin-top: 2px;
    margin-bottom: 8px;
    display: block;
}

/* Error Messages */
.error {
    color: #721c24;
    padding: 10px;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    margin: 10px 0;
}

/* Special Pages */
.tag-link {
    font-weight: bold;
    margin-right: 0.8em;
    display: inline-block;
    padding: 0.2em 0.5em;
    background-color: #f0f0f0;
    border-radius: 3px;
}

.tag-link:hover {
    background-color: #e0e0e0;
}

/* Related pages styling */
.tag-match {
    color: #666;
    font-size: 0.9em;
    margin-left: 0.5em;
}

.tag-match a {
    font-size: 0.95em;
}

/* Backlinks section */
h3 {
    color: #333;
    font-size: 1.1em;
    margin-top: 1.5em;
}

hr {
    margin: 2em 0;
    border: none;
    border-top: 1px solid #ddd;
}

/* Image alignment and sizing classes */
.img-center {
    display: block;
    margin-left: auto;
    margin-right: auto;
    margin-top: 1em;
    margin-bottom: 1em;
}

.img-left {
    float: left;
    margin: 0 1em 1em 0;
}

.img-right {
    float: right;
    margin: 0 0 1em 1em;
}

.img-full {
    width: 100% !important;
    max-width: 100% !important;
    height: auto;
}

.img-small {
    max-width: 300px !important;
    height: auto;
}

.img-medium {
    max-width: 600px !important;
    height: auto;
}

.img-large {
    max-width: 900px !important;
    height: auto;
}

/* Clear floats */
.clear {
    clear: both;
}

/* Prevent images from breaking layout */
img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

/* Tables (if you add them later) */
table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

th, td {
    border: 1px solid #ddd;
    padding: 0.5em;
    text-align: left;
}

th {
    background-color: #f0f0f0;
    font-weight: bold;
}

/* Code block wrapper */
.code-block-wrapper {
    position: relative;
    margin: 1.5em 0;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #e8eaed;
    padding: 0.5em 1em;
    border-radius: 6px 6px 0 0;
    border: 1px solid #d0d7de;
    border-bottom: none;
}

.code-lang {
    font-size: 0.85em;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
}

.code-block-wrapper pre {
    margin: 0;
    border-radius: 0 0 6px 6px;
    border-top: none;
}

.copy-btn {
    padding: 0.3em 0.8em;
    font-size: 0.85em;
    background-color: #fff;
    color: #333;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-btn:hover {
    background-color: #f0f0f0;
    border-color: #999;
}

.copy-btn:active,
.copy-btn.copied {
    background-color: #28a745;
    color: white;
    border-color: #28a745;
}

/* Inline code styling */
code {
    background-color: #f6f8fa;
    border-radius: 3px;
    padding: 0.2em 0.4em;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    color: #d73a49;
    border: 1px solid #e1e4e8;
}

/* Code blocks styling */
pre {
    background-color: #f6f8fa;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    padding: 16px;
    overflow-x: auto;
    margin: 1.5em 0;
}

pre code {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    font-size: 0.95em;
    color: #24292f;
    border: none;
}

/* Pagination styling */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1em;
    margin: 2em 0;
    padding: 1em;
    background-color: #f8f9fa;
    border-radius: 6px;
}

.pagination-link {
    padding: 0.5em 1em;
    background-color: #0066cc;
    color: white;
    border-radius: 4px;
    text-decoration: none;
    font-weight: 500;
    transition: background-color 0.2s;
}

.pagination-link:hover {
    background-color: #0052a3;
    text-decoration: none;
}

.pagination-info {
    color: #666;
    font-weight: 500;
}

/* Revision History Styles */
.revisions-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
}

.revisions-table th,
.revisions-table td {
    border: 1px solid #ddd;
    padding: 0.8em;
    text-align: left;
}

.revisions-table th {
    background-color: #f0f0f0;
    font-weight: bold;
}

.revisions-table tr:hover {
    background-color: #f9f9f9;
}

.revisions-table a {
    color: #0066cc;
    margin-right: 0.5em;
}

/* Diff View Styles */
.diff-container {
    background-color: #f6f8fa;
    border: 1px solid #d0d7de;
    border-radius: 6px;
    padding: 1em;
    margin: 1em 0;
}

.diff-view {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    line-height: 1.5;
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.diff-view div {
    padding: 0.2em 0.5em;
    margin: 0;
}

.diff-added {
    background-color: #e6ffed;
    color: #1a7f37;
    font-weight: 500;
}

.diff-removed {
    background-color: #ffebe9;
    color: #cf222e;
    font-weight: 500;
}

/* Recent Changes Table */
.recent-changes {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
}

.recent-changes th,
.recent-changes td {
    border: 1px solid #ddd;
    padding: 0.8em;
    text-align: left;
}

.recent-changes th {
    background-color: #f0f0f0;
    font-weight: bold;
}

.recent-changes tr:hover {
    background-color: #f9f9f9;
}

.time-ago {
    color: #666;
    font-size: 0.9em;
}

/* Manage Pages Table - NEW */
.manage-pages-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
}

.manage-pages-table th,
.manage-pages-table td {
    border: 1px solid #ddd;
    padding: 0.8em;
    text-align: left;
}

.manage-pages-table th {
    background-color: #f0f0f0;
    font-weight: bold;
}

.manage-pages-table tr:hover {
    background-color: #f9f9f9;
}

.manage-pages-table button[name="delete_page"] {
    background-color: #dc3545;
    color: white;
    border: none;
    padding: 0.4em 0.8em;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
}

.manage-pages-table button[name="delete_page"]:hover {
    background-color: #c82333;
}

/* Responsive Design */
@media (max-width: 600px) {
    body {
        padding: 0.5em;
    }
    
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* Mobile-optimized toolbar */
    #toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 0.4em;
        margin-bottom: 0.8em;
    }
    
    #toolbar button, #toolbar label {
        padding: 0.6em 0.8em;
        font-size: 0.95em;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    }
    
    /* Mobile textarea improvements */
    textarea {
        font-size: 16px !important; /* Prevents zoom on iOS */
        height: 60vh;
        min-height: 300px;
        line-height: 1.5;
        padding: 0.8em;
        -webkit-appearance: none;
        border-radius: 4px;
    }
    
    /* Status indicator on mobile */
    #save-status {
        width: 100%;
        text-align: center;
        margin: 0 !important;
        padding: 0.6em !important;
        font-size: 0.9em !important;
        order: 10;
    }
    
    /* Mobile form buttons */
    button[type="submit"],
    a button {
        padding: 0.8em 1.2em;
        font-size: 1em;
        touch-action: manipulation;
        margin-right: 0.5em;
        margin-top: 0.5em;
    }
    
    /* Keep navigation horizontal but wrap */
    nav {
        display: flex;
        flex-wrap: wrap;
        gap: 0.3em;
        align-items: center;
    }
    
    nav a {
        padding: 0.5em 0.8em;
        display: inline-block;
    }
    
    nav button {
        padding: 0.5em 0.8em;
        font-size: 0.9em;
    }
    
    nav input[type="text"] {
        padding: 0.5em;
        font-size: 16px; /* Prevents zoom on iOS */
        min-width: 150px;
    }
    
    nav form[method="get"] {
        display: flex;
        gap: 0.3em;
    }
    
    nav form[method="post"] {
        display: inline;
    }
    
    .pagination {
        flex-direction: column;
        gap: 0.5em;
    }
    
    .pagination-link {
        width: 100%;
        text-align: center;
    }
    
    .revisions-table,
    .recent-changes,
    .manage-pages-table {
        font-size: 0.9em;
    }
    
    .revisions-table td,
    .recent-changes td,
    .manage-pages-table td {
        padding: 0.5em;
    }
    
    .diff-view {
        font-size: 0.8em;
    }

  /* Disable floats on small screens */
  .img-left, .img-right {
    float: none;
    display: block;
    margin: 1em auto;
  }

  /* Ensure sized classes don't fight mobile */
  .img-small, .img-medium, .img-large {
    max-width: 100% !important;
  }

@media (max-width: 600px) {
  /* Make nav a simple 2-column grid */
  nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4em;
    align-items: stretch;
  }

  /* Links look like touch-friendly buttons */
  nav a {
    margin-right: 0;          /* overrides desktop spacing */
    padding: 0.6em 0.8em;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #f8f9fa;
    text-align: center;
    white-space: nowrap;
  }

  /* Put logout and search on full-width rows */
  nav form[method="post"],
  nav form[method="get"] {
    grid-column: 1 / -1;
    margin: 0;
  }

  /* Make logout button match nav sizing (override big submit padding) */
  nav form[method="post"] button[type="submit"] {
    width: 100%;
    padding: 0.6em 0.8em;
    font-size: 1em;
  }

  /* Search bar: input grows, button stays compact */
  nav form[method="get"] {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.4em;
  }

  nav form[method="get"] input[type="text"] {
    min-width: 0;
  }

  nav form[method="get"] button {
    width: 3.2rem;
    padding: 0.6em 0;
  }
}


}

/* Tablet optimization */
@media (min-width: 601px) and (max-width: 900px) {
    textarea {
        height: 400px;
        font-size: 1.05em;
    }
}
