/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: auto;
    font-family: 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background-color: beige;
}

body {
    margin: 0;
    padding: 0;
    color: #373737;
}

/* Header styles */
.app-header {
    background-color: #c1c8b0;
    color: #373737;
    padding: 8px 16px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.app-title {
    font-size: 1.5rem;
    font-weight: 500;
    margin: 0;
    min-width: 180px;
    color: #373737;
}

.search-section {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 400px;
}

.search-field {
    padding: 6px 12px;
    border: 1px solid #373737;
    border-radius: 4px;
    background-color: white;
    color: #373737;
    font-size: 0.95rem;
    min-width: 200px;
}

.search-field.category-field {
    min-width: 150px;
}

.search-field:focus {
    outline: none;
    border-color: #111111;
    box-shadow: 0 0 0 2px rgba(17, 17, 17, 0.1);
}

.book-count {
    min-width: 100px;
    text-align: right;
    font-weight: 500;
    color: #373737;
}

/* Main container layout */
.main-container {
    display: flex;
    margin-top: 64px;
    padding: 8px;
    gap: 8px;
    min-height: calc(100vh - 72px);
}

/* Sidebar styles */
.sidebar {
    width: 360px;
    flex-shrink: 0;
}

.sidebar-card {
    background-color: rgba(17, 17, 17, 0.85);
    color: #c1c8b0;
    padding: 12px;
    border-radius: 4px;
    max-height: calc(100vh - 88px);
    overflow-y: auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.sidebar-title {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 12px;
    color: #c1c8b0;
}

/* Scrollbar styling for sidebar */
.sidebar-card::-webkit-scrollbar {
    width: 8px;
}

.sidebar-card::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

.sidebar-card::-webkit-scrollbar-thumb {
    background: #c1c8b0;
    border-radius: 4px;
}

.sidebar-card::-webkit-scrollbar-thumb:hover {
    background: #d1d8c0;
}

/* Form styles */
.form-group {
    margin-bottom: 12px;
}

.form-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.form-row .form-input {
    flex: 1;
}

.form-row .btn {
    flex-shrink: 0;
}

.form-field {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.form-field .form-label {
    margin-bottom: 4px;
}

.form-field .form-input {
    width: 100%;
}

.form-label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.9rem;
    color: #c1c8b0;
}

.form-input, .form-textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #c1c8b0;
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 0.1);
    color: #c1c8b0;
    font-size: 0.95rem;
    font-family: inherit;
}

.form-input:focus, .form-textarea:focus {
    outline: none;
    border-color: #d1d8c0;
    background-color: rgba(255, 255, 255, 0.15);
}

.form-input::placeholder {
    color: rgba(193, 200, 176, 0.5);
}

.form-textarea {
    resize: vertical;
    font-family: 'Courier New', monospace;
}

/* Libris results */
.libris-results-section {
    margin-bottom: 12px;
}

.results-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: #c1c8b0;
}

.libris-results {
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid #c1c8b0;
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.2);
}

.libris-result-item {
    padding: 8px 12px;
    cursor: pointer;
    color: #c1c8b0;
    font-size: 0.9rem;
    border-left: 3px solid transparent;
    background-color: rgba(255, 255, 255, 0.05);
    transition: all 0.2s;
}

.libris-result-item:hover {
    background-color: rgba(193, 200, 176, 0.2);
}

.libris-result-item.selected {
    background-color: rgba(193, 200, 176, 0.4);
    border-left-color: #c1c8b0;
    font-weight: 600;
}

/* Button styles */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
}

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

.btn-primary {
    background-color: #5c6b77;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: #4a5864;
}

.btn-secondary {
    background-color: #8b9a87;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #7a8976;
}

.btn-success {
    background-color: #6b9b6f;
    color: white;
}

.btn-success:hover:not(:disabled) {
    background-color: #5a8a5e;
}

.btn-danger {
    background-color: #c75450;
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background-color: #b6433f;
}

.btn-full {
    width: 100%;
    margin-top: 4px;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
    text-decoration: none;
    display: inline-block;
    transition: transform 0.2s;
}

.btn-icon:hover {
    transform: scale(1.2);
}

.btn-edit {
    filter: grayscale(0);
}

.btn-delete {
    filter: grayscale(0);
}

/* Main content area */
.main-content {
    flex: 1;
    min-width: 0;
}

.content-card {
    background-color: rgba(193, 200, 176, 0.3);
    padding: 12px;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.table-actions {
    margin-bottom: 12px;
    display: flex;
    justify-content: flex-end;
}

/* Table styles */
.table-container {
    overflow-x: auto;
    margin-bottom: 16px;
}

.books-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 2px;
}

.books-table thead th {
    background-color: #c1c8b0;
    color: #111111;
    font-weight: bold;
    padding: 10px 8px;
    text-align: left;
    border: 1px solid #111111;
    position: sticky;
    top: 0;
    z-index: 10;
}

.books-table tbody td {
    background-color: #c1c8b0;
    color: #373737;
    padding: 8px;
    border: 1px solid #111111;
    white-space: normal;
    word-wrap: break-word;
}

.books-table tbody tr:hover td {
    background-color: #d1d8c0;
}

.actions-cell {
    text-align: center;
    white-space: nowrap;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.page-info {
    font-weight: 500;
    color: #373737;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-overlay p {
    color: white;
    font-size: 1.2rem;
    margin-top: 16px;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Notification system */
.notification-container {
    position: fixed;
    top: 80px;
    right: 16px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notification {
    padding: 12px 20px;
    border-radius: 4px;
    color: white;
    font-size: 0.95rem;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateX(400px);
    transition: all 0.3s ease-out;
    min-width: 250px;
}

.notification.show {
    opacity: 1;
    transform: translateX(0);
}

.notification-success {
    background-color: #6b9b6f;
}

.notification-error {
    background-color: #c75450;
}

.notification-warning {
    background-color: #d4a373;
}

.notification-info {
    background-color: #5c6b77;
}

/* Dialog overlay */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
}

.dialog {
    background-color: white;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    min-width: 400px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
}

.dialog-small {
    min-width: 300px;
}

.dialog-large {
    min-width: 600px;
}

.dialog-title {
    font-size: 1.4rem;
    font-weight: 500;
    margin-bottom: 16px;
    color: #373737;
}

.dialog-content {
    margin-bottom: 20px;
}

.dialog-text {
    color: #373737;
    margin-bottom: 16px;
}

.dialog-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Dialog form fields */
.dialog .form-group {
    margin-bottom: 16px;
}

.dialog .form-label {
    color: #373737;
}

.dialog .form-input,
.dialog .form-textarea {
    background-color: white;
    color: #373737;
    border: 1px solid #c1c8b0;
}

.dialog .form-input:focus,
.dialog .form-textarea:focus {
    border-color: #8b9a87;
    background-color: white;
}

/* Book cover preview */
.title-with-cover {
    position: relative;
    display: inline-block;
}

.cover-preview {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 12px;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
}

.title-with-cover:hover .cover-preview {
    opacity: 1;
}

.cover-preview img {
    display: block;
    max-width: 200px;
    max-height: 300px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    border: 2px solid #c1c8b0;
    background-color: white;
}

.cover-preview img[src*="id="] {
    /* Hide broken images gracefully */
    display: none;
}

/* Book details dialog */
.book-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.details-row {
    display: flex;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 8px;
}

.details-row:last-child {
    border-bottom: none;
}

.details-label {
    font-weight: 600;
    color: #5c6b77;
    min-width: 120px;
    flex-shrink: 0;
}

.details-value {
    color: #373737;
    flex: 1;
    word-break: break-word;
}

.details-subject {
    line-height: 1.5;
}

.btn-view {
    filter: grayscale(0);
}

/* Tree view styles */
.tree-container {
    display: flex;
    gap: 16px;
    min-height: calc(100vh - 150px);
}

.category-tree {
    width: 300px;
    flex-shrink: 0;
    overflow-y: auto;
    border-right: 1px solid #c1c8b0;
    padding-right: 16px;
    max-height: calc(100vh - 150px);
}

.tree-books-panel {
    flex: 1;
    overflow-y: auto;
    max-height: calc(100vh - 150px);
}

.tree-books-panel h3 {
    margin: 0 0 16px 0;
    color: #373737;
    font-size: 1.1rem;
}

.tree-node {
    margin-left: 0;
}

.tree-node-children {
    margin-left: 20px;
    display: none;
}

.tree-node-children.expanded {
    display: block;
}

.tree-node-header {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 4px;
    gap: 8px;
}

.tree-node-header:hover {
    background-color: rgba(193, 200, 176, 0.4);
}

.tree-node-header.selected {
    background-color: #c1c8b0;
    font-weight: bold;
}

.tree-toggle {
    width: 16px;
    font-size: 12px;
    color: #5c6b77;
    font-family: monospace;
}

.tree-label {
    flex: 1;
    color: #373737;
}

.tree-count {
    color: #5c6b77;
    font-size: 0.85rem;
}

.tree-books-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tree-book-item {
    background-color: #f5f5f0;
    padding: 12px;
    border-radius: 4px;
    border: 1px solid #c1c8b0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.tree-book-info {
    flex: 1;
}

.tree-book-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: #373737;
}

.tree-book-author {
    color: #5c6b77;
    font-size: 0.9rem;
}

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

/* Responsive design */
@media (max-width: 1024px) {
    .main-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
    }

    .sidebar-card {
        max-height: none;
    }

    .search-section {
        min-width: 300px;
    }
}

@media (max-width: 768px) {
    .tree-container {
        flex-direction: column;
    }

    .category-tree {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #c1c8b0;
        max-height: 40vh;
        padding-right: 0;
        padding-bottom: 16px;
        margin-bottom: 16px;
    }

    .tree-books-panel {
        max-height: 50vh;
    }

    .app-header {
        padding: 6px 12px;
    }

    .header-content {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
    }

    .app-title {
        font-size: 1.1rem;
        min-width: auto;
        flex: 0 0 auto;
    }

    .search-section {
        flex-wrap: wrap;
        min-width: unset;
        gap: 4px;
        order: 3;
        flex-basis: 100%;
    }

    .search-section .search-field {
        flex: 1;
        min-width: 100px;
        padding: 4px 8px;
        font-size: 0.85rem;
    }

    .search-section .btn {
        padding: 4px 10px;
        font-size: 0.85rem;
    }

    .table-actions {
        display: none;
    }

    .book-count {
        order: 1;
        min-width: auto;
        font-size: 0.85rem;
    }

    .main-container {
        margin-top: 90px;
    }

    .sidebar-card {
        padding: 10px;
    }

    .form-input {
        padding: 6px;
        font-size: 0.9rem;
    }

    .dialog {
        min-width: 90vw;
    }

    .table-container {
        overflow-x: scroll;
    }

    .books-table {
        font-size: 0.85rem;
    }

    .books-table thead th,
    .books-table tbody td {
        padding: 6px 4px;
    }
}
