/* ================================================
   COMMONPLACE BOOK - DENSE & PROFESSIONAL THEME
   Version 3.2 - Improved Dark Mode
   ================================================ */

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2c3e50; /* Sober Dark Blue */
    --secondary-color: #5a6268; /* Neutral Dark Gray */
    --accent-color: #c0392b; /* Muted Red */
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --bg-color: #f5f5f5;
    --card-bg: #ffffff;
    --text-color: #333333;
    --text-light: #666666;
    --border-color: #e0e0e0; /* Lighter border */
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-lg: 0 3px 5px rgba(0,0,0,0.1);
    --prelude-bg: #f8f9fa;
    --prelude-border: #e9ecef;
    --prelude-text: #4a5f7a;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.95rem; /* Denser font */
    line-height: 1.5; /* Tighter line height */
    color: var(--text-color);
    background-color: var(--bg-color);
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header Styles */
header {
    background-color: var(--primary-color);
    color: white;
    padding: 1rem 2rem; /* Reduced padding */
    margin: 0 -20px;
    box-shadow: var(--shadow);
}

header h1 {
    font-size: 1.75rem; /* Reduced size */
    margin-bottom: 0.25rem;
}

nav {
    display: flex;
    gap: 0.75rem; /* Reduced gap */
    flex-wrap: wrap;
}

nav a {
    color: white;
    text-decoration: none;
    padding: 0.35rem 0.75rem; /* Reduced padding */
    border-radius: 3px;
    transition: background-color 0.3s;
}

nav a:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Search Bar */
.search-bar {
    background: white;
    padding: 0.75rem; /* Reduced padding */
    margin: 0.75rem 0; /* Reduced margin */
    border-radius: 4px;
    box-shadow: var(--shadow);
}

.search-bar form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.search-bar input[type="text"] {
    flex: 1;
    padding: 0.6rem; /* Reduced padding */
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 0.95rem;
}

.search-bar button {
    padding: 0.6rem 1.25rem; /* Reduced padding */
    background-color: var(--secondary-color); /* Muted color */
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.search-bar button:hover {
    background-color: #4a5056;
}

.clear-search {
    color: var(--text-light);
    text-decoration: none;
    padding: 0.6rem 1rem;
}

/* Content Layout */
.content {
    display: flex;
    gap: 1.5rem; /* Reduced gap */
    margin-top: 1.5rem; /* Reduced margin */
    flex: 1;
}

/* Sidebar */
.topics-sidebar {
    width: 260px; /* Slightly narrower */
    background: white;
    padding: 1rem; /* Reduced padding */
    border-radius: 4px;
    box-shadow: var(--shadow);
    height: fit-content;
    position: sticky;
    top: 1rem;
}

.topics-sidebar h2 {
    margin-bottom: 0.75rem;
    color: var(--primary-color);
    font-size: 1.1rem;
}

.topics-list {
    list-style: none;
}

.topics-list li {
    margin-bottom: 0.25rem;
}

.topics-list a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem; /* Reduced padding */
    color: var(--text-color);
    text-decoration: none;
    border-radius: 3px;
    transition: background-color 0.3s;
}

.topics-list a:hover {
    background-color: var(--bg-color);
}

.topics-list a.active {
    background-color: var(--primary-color); /* Primary color for active */
    color: white;
}

.quote-count {
    font-size: 0.85rem;
    opacity: 0.7;
}

/* Main Content */
.quotes-section {
    flex: 1;
    background: white;
    padding: 1.5rem; /* Reduced padding */
    border-radius: 4px;
    box-shadow: var(--shadow);
}

.quotes-section h2 {
    margin-bottom: 0.75rem;
    color: var(--primary-color);
}

.topic-description {
    color: var(--text-light);
    margin-bottom: 1.5rem; /* Reduced margin */
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

/* Quote Cards - DENSE VERSION */
.quote-card {
    background: var(--card-bg);
    padding: 1.25rem; /* Reduced padding */
    margin-bottom: 1.5rem; /* Reduced margin */
    border-radius: 4px; /* Sharper edges */
    border-left: 3px solid var(--primary-color); /* Thinner, primary color */
    box-shadow: var(--shadow);
    /* Removed hover state for a static, professional look */
}

/* Prelude (Context) - Simpler */
.quote-card .prelude {
    font-style: italic;
    color: var(--prelude-text);
    margin-bottom: 1rem; /* Reduced margin */
    padding: 0.75rem 1rem; /* Reduced padding */
    background: var(--prelude-bg);
    border-radius: 4px;
    border: 1px solid var(--prelude-border);
    line-height: 1.6;
    font-size: 0.9rem;
    position: relative;
    font-family: Georgia, 'Times New Roman', serif;
}

/* Simpler "Context" label */
.quote-card .prelude:before {
    content: "Context";
    display: block;
    font-size: 0.7rem;
    font-weight: 500; /* Not bold */
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-light); /* Muted color */
    margin-bottom: 0.35rem;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-style: normal;
}

/* Quote Text - Denser */
.quote-card blockquote {
    font-size: 1.15rem; /* Reduced size */
    line-height: 1.7; /* Tighter line height */
    margin-bottom: 1rem;
    color: var(--text-color);
    font-weight: 500;
    position: relative;
    padding-left: 1.5rem; /* Reduced indent */
    font-family: Georgia, 'Times New Roman', serif;
}

/* Subtler quote mark */
.quote-card blockquote:before {
    content: """;
    position: absolute;
    left: 0;
    top: -0.2rem;
    font-size: 2.5rem; /* Reduced size */
    color: var(--text-light); /* Muted color */
    opacity: 0.15;
    font-family: Georgia, serif;
    line-height: 1;
}

.quote-card cite {
    display: block;
    margin-bottom: 0.25rem;
    color: var(--text-light);
    font-style: italic;
    font-size: 0.95rem;
}

.source {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 0.25rem;
}

.quote-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.topic-tag {
    background-color: var(--primary-color);
    color: white;
    padding: 0.25rem 0.6rem; /* Reduced padding */
    border-radius: 10px;
    font-size: 0.8rem;
}

.date {
    color: var(--text-light);
}

/* Forms */
.form-group {
    margin-bottom: 1rem; /* Reduced margin */
}

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 500;
    color: var(--text-color);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem 0.75rem; /* Reduced padding */
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 0.95rem;
    font-family: inherit;
}

.form-group textarea[name="quote_prelude"],
.form-group textarea#quote_prelude {
    font-style: italic;
    font-family: Georgia, 'Times New Roman', serif;
    color: var(--prelude-text);
    background: var(--prelude-bg);
}

.form-group textarea {
    resize: vertical;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* Buttons */
.btn, button[type="submit"] {
    padding: 0.6rem 1.25rem; /* Reduced padding */
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.9rem; /* Reduced size */
    transition: background-color 0.3s;
    display: inline-block;
    text-decoration: none;
    text-align: center;
}

.btn-primary {
    background-color: var(--primary-color); /* Primary color */
    color: white;
}

.btn-primary:hover {
    background-color: #1e2b37;
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #4a5056;
}

.btn-danger {
    background-color: var(--accent-color);
    color: white;
}

.btn-danger:hover {
    background-color: #a53125;
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    margin: 0 0.25rem;
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem; /* Reduced padding */
    margin-bottom: 1rem;
    border-radius: 3px;
}

.alert-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-warning {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.alert-error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Login Page */
.login-container {
    max-width: 400px;
    margin: 3rem auto; /* Reduced margin */
}

.login-card {
    background: white;
    padding: 1.5rem; /* Reduced padding */
    border-radius: 4px; /* Sharper */
    box-shadow: var(--shadow-lg);
}

.login-card h2 {
    margin-bottom: 1.5rem;
    color: var(--primary-color);
    text-align: center;
}

/* Admin Dashboard */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem; /* Reduced gap */
}

.admin-card {
    background: white;
    padding: 1.25rem; /* Reduced padding */
    border-radius: 4px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.3s;
}

.admin-card:hover {
    box-shadow: var(--shadow-lg);
}

.admin-card h3 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.admin-card p {
    color: var(--text-light);
    margin-bottom: 1rem;
}

/* Statistics */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem; /* Reduced gap */
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-color);
    padding: 0.75rem 1rem; /* Reduced padding */
    border-radius: 3px;
    text-align: center;
}

.stat-label {
    font-weight: 500;
}

.stat-value {
    color: var(--primary-color); /* Primary color */
    font-weight: bold;
}

/* Tables */
.topics-table {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th {
    background-color: var(--bg-color);
    padding: 0.6rem 0.75rem; /* Reduced padding */
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

table tr:hover {
    background-color: var(--bg-color);
}

/* Edit Page */
.edit-container {
    max-width: 900px;
    margin: 1.5rem auto;
}

.topic-selector {
    background: white;
    padding: 1rem;
    border-radius: 4px;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.topic-selector select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 0.95rem;
}

.edit-section {
    background: white;
    padding: 1.25rem;
    border-radius: 4px;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

.quotes-editor {
    background: white;
    padding: 1.25rem;
    border-radius: 4px;
    box-shadow: var(--shadow);
}

.quote-edit-card {
    background: var(--bg-color);
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.quote-edit-card .prelude {
    font-style: italic;
    color: var(--prelude-text);
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--prelude-bg);
    border-radius: 4px;
    border: 1px solid var(--prelude-border);
    line-height: 1.6;
    font-size: 0.9rem;
    font-family: Georgia, 'Times New Roman', serif;
}

.quote-edit-card.editing {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-lg);
}

.quote-actions {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.move-select {
    padding: 0.4rem;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 0.85rem;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

/* Footer */
footer {
    margin-top: auto;
    padding: 1.5rem 0; /* Reduced padding */
    text-align: center;
    color: var(--text-light);
    border-top: 1px solid var(--border-color);
}

/* Messages */
.no-results,
.no-quotes,
.welcome {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-light);
    font-style: italic;
}

/* Data Management */
.data-actions {
    display: grid;
    gap: 1rem;
}

/* Mobile Responsive Design (Adjusted for Density) */
@media (max-width: 768px) {
    .container {
        padding: 0 10px;
    }
    
    header {
        padding: 1rem 1rem;
        margin: 0 -10px;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
    
    nav {
        gap: 0.5rem;
    }
    
    nav a {
        padding: 0.5rem 1rem;
    }
    
    .search-bar {
        padding: 0.75rem;
        margin: 0.75rem 0;
    }
    
    .content {
        gap: 1rem;
        margin-top: 1rem;
    }
    
    .topics-sidebar {
        width: 100%;
        position: static;
        padding: 1rem;
    }
    
    .quotes-section {
        padding: 1rem;
    }
    
    .quote-card {
        padding: 1rem; /* Denser mobile card */
        margin-bottom: 1rem;
        border-radius: 4px;
        border-left-width: 3px;
    }
    
    .quote-card .prelude {
        margin-bottom: 1rem;
        padding: 0.75rem; /* Denser mobile prelude */
        font-size: 0.85rem;
        line-height: 1.5;
    }
    
    .quote-card .prelude:before {
        font-size: 0.7rem;
        margin-bottom: 0.3rem;
    }
    
    .quote-card blockquote {
        font-size: 1.05rem; /* Denser mobile quote */
        line-height: 1.6;
        padding-left: 1.25rem;
        margin-bottom: 0.75rem;
    }
    
    .quote-card blockquote:before {
        font-size: 2rem;
        left: -0.1rem;
        top: -0.1rem;
    }
    
    .quote-card cite {
        font-size: 0.9rem;
    }
    
    .quote-meta {
        gap: 0.5rem;
        padding-top: 0.5rem;
    }
    
    .topic-tag {
        font-size: 0.75rem;
    }
    
    .date {
        font-size: 0.8rem;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .btn, button[type="submit"] {
        padding: 0.75rem 1rem; /* Denser mobile button */
        font-size: 0.95rem;
        width: 100%;
    }
    
    .btn-small {
        padding: 0.5rem 0.8rem;
        font-size: 0.85rem;
        width: auto;
    }
    
    .admin-grid {
        gap: 1rem;
    }
    
    table {
        font-size: 0.85rem;
    }
    
    table th,
    table td {
        padding: 0.4rem;
    }
    
    .quote-edit-card {
        padding: 0.75rem;
    }
    
    .quote-actions {
        gap: 0.75rem;
    }
    
    footer {
        padding: 1.25rem 1rem;
    }
}

/* Small phone optimization */
@media (max-width: 375px) {
    header h1 {
        font-size: 1.25rem;
    }
    
    .quote-card blockquote {
        font-size: 1rem;
    }
}

/* Tablet optimization */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: 0 30px;
    }
    
    .topics-sidebar {
        width: 240px;
    }
    
    .quote-card {
        padding: 1rem;
    }
}

/* Print Styles */
@media print {
    header, footer, nav, .search-bar, .topics-sidebar, .quote-actions, .btn, button {
        display: none;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.4;
        background: #fff;
    }
    
    .content {
        display: block;
    }
    
    .quote-card {
        page-break-inside: avoid;
        border: 1px solid #ddd;
        margin-bottom: 1.5rem;
        box-shadow: none;
    }
    
    .quote-card .prelude {
        background: #f5f5f5;
        border: 1px solid #ddd;
    }
}

/* Accessibility & Focus Styles */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--primary-color); /* Use primary color */
    outline-offset: 1px;
    box-shadow: 0 0 0 2px rgba(44, 62, 80, 0.2);
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .quote-card .prelude {
        border: 2px solid var(--primary-color);
    }
    
    .quote-card blockquote {
        font-weight: 600;
    }
}

/* ================================================
   IMPROVED DARK MODE - Easier on the eyes
   ================================================ */
@media (prefers-color-scheme: dark) {
    :root {
        /* Main backgrounds - using warmer, softer grays instead of harsh black */
        --bg-color: #2d3436;           /* Warm dark gray instead of #1a1a1a */
        --card-bg: #3d4447;            /* Slightly lighter warm gray instead of #2a2a2a */
        
        /* Text colors - using cream/off-white instead of bright white */
        --text-color: #e8e6e3;         /* Warm off-white/cream instead of #e0e0e0 */
        --text-light: #a8a5a0;         /* Warmer light gray instead of #b0b0b0 */
        
        /* Borders and accents */
        --border-color: #4a5154;       /* Softer border color instead of #444 */
        
        /* Prelude/context specific colors */
        --prelude-bg: #353b3e;         /* Warmer dark background instead of #222 */
        --prelude-border: #4a5154;     /* Consistent with border color instead of #333 */
        --prelude-text: #b8c7d9;       /* Softer blue-gray instead of #a8c3e0 */
        
        /* Primary and accent colors - slightly muted for dark mode */
        --primary-color: #4a6fa5;      /* Softer blue for dark mode */
        --accent-color: #d35847;       /* Softer red for dark mode */
        
        /* Shadows - lighter for dark mode */
        --shadow: 0 1px 3px rgba(0,0,0,0.2);
        --shadow-lg: 0 3px 5px rgba(0,0,0,0.3);
    }
    
    /* Additional dark mode specific adjustments */
    
    /* Search bar in dark mode */
    .search-bar {
        background: var(--card-bg);
    }
    
    .search-bar input[type="text"] {
        background: var(--bg-color);
        color: var(--text-color);
        border-color: var(--border-color);
    }
    
    .search-bar input[type="text"]::placeholder {
        color: var(--text-light);
        opacity: 0.7;
    }
    
    /* Topics sidebar in dark mode */
    .topics-sidebar {
        background: var(--card-bg);
    }
    
    .topics-sidebar h2 {
        color: var(--text-color);
    }
    
    .topics-list a:hover {
        background-color: var(--bg-color);
    }
    
    .topics-list a.active {
        background-color: var(--primary-color);
    }
    
    /* Quotes section in dark mode */
    .quotes-section {
        background: var(--card-bg);
    }
    
    .quotes-section h2 {
        color: var(--text-color);
    }
    
    /* Forms in dark mode */
    .form-group input[type="text"],
    .form-group input[type="password"],
    .form-group input[type="file"],
    .form-group select,
    .form-group textarea {
        background: var(--bg-color);
        color: var(--text-color);
        border-color: var(--border-color);
    }
    
    .form-group input::placeholder,
    .form-group textarea::placeholder {
        color: var(--text-light);
        opacity: 0.7;
    }
    
    /* Buttons in dark mode - softer hover states */
    .btn-primary:hover {
        background-color: #5c7fb8;
    }
    
    .btn-secondary:hover {
        background-color: #6a7278;
    }
    
    .btn-danger:hover {
        background-color: #e06656;
    }
    
    /* Header adjustments for dark mode */
    header {
        background-color: #2c3335;  /* Slightly darker than main bg */
    }
    
    /* Quote cards - subtle adjustments */
    .quote-card {
        border-left-color: var(--primary-color);
    }
    
    .quote-card blockquote:before {
        opacity: 0.1;  /* Even more subtle in dark mode */
    }
    
    /* Topic tags in dark mode */
    .topic-tag {
        background-color: var(--primary-color);
        opacity: 0.9;
    }
    
    /* Tables in dark mode */
    table th {
        background-color: var(--bg-color);
    }
    
    table tr:hover {
        background-color: var(--bg-color);
    }
    
    /* Admin cards in dark mode */
    .admin-card {
        background: var(--card-bg);
    }
    
    .admin-card h3 {
        color: var(--text-color);
    }
    
    /* Login card in dark mode */
    .login-card {
        background: var(--card-bg);
    }
    
    .login-card h2 {
        color: var(--text-color);
    }
    
    /* Edit sections in dark mode */
    .topic-selector,
    .edit-section,
    .quotes-editor {
        background: var(--card-bg);
    }
    
    .topic-selector select {
        background: var(--bg-color);
        color: var(--text-color);
    }
    
    .quote-edit-card {
        background: var(--bg-color);
    }
    
    .move-select {
        background: var(--bg-color);
        color: var(--text-color);
    }
    
    /* Stat cards in dark mode */
    .stat-card {
        background: var(--bg-color);
    }
    
    .stat-value {
        color: var(--primary-color);
    }
    
    /* Alerts in dark mode - adjusted for better visibility */
    .alert-success {
        background-color: #2d4a34;
        color: #a8d5b0;
        border-color: #3a5f42;
    }
    
    .alert-warning {
        background-color: #4a3f2d;
        color: #e5c890;
        border-color: #5f5139;
    }
    
    .alert-error {
        background-color: #4a2d31;
        color: #e5a0a8;
        border-color: #5f3940;
    }
    
    .alert-info {
        background-color: #2d3f4a;
        color: #a0c8e5;
        border-color: #39515f;
    }
}

/* Loading & Disabled States */
.btn:disabled,
button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Utility Classes */
.text-center {
    text-align: center;
}
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* End of Stylesheet */