@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --theme-bg: #f9f9f9;
    --theme-text: #1c1c1e;
    --theme-accent: #ffffff;
    --toolbar-bg: rgba(255, 255, 255, 0.85); /* Glassmorphism */
    --btn-bg: #0A84FF;
    --btn-hover: #007AFF;
    --btn-color: #ffffff;
    --danger-bg: #FF453A;
    --border-color: rgba(0, 0, 0, 0.08);
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.08);
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --reader-toolbar-height: 72px;
    --app-height: 100vh;
}

body.theme-sepia {
    --theme-bg: #fdf6e3;
    --theme-text: #3c3220;
    --theme-accent: #f0e4cd;
    --toolbar-bg: rgba(245, 235, 215, 0.85);
    --btn-bg: #d4a350;
    --btn-hover: #c29140;
    --border-color: rgba(60, 50, 30, 0.1);
    --shadow-soft: 0 4px 20px rgba(80, 70, 50, 0.08);
    --shadow-hover: 0 8px 30px rgba(80, 70, 50, 0.12);
}

body.theme-oled {
    --theme-bg: #000000;
    --theme-text: #e5e5ea;
    --theme-accent: #1c1c1e;
    --toolbar-bg: rgba(28, 28, 30, 0.85);
    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.5);
    --shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.8);
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    min-height: var(--app-height, 100vh);
    font-family: var(--font-primary);
    background-color: var(--theme-bg);
    color: var(--theme-text);
    transition: background-color 0.4s ease, color 0.4s ease;
}

a {
    color: inherit;
    text-decoration: none;
}

/* Glassmorphism utilities */
.glass {
    background: var(--toolbar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

/* Login */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: var(--app-height, 100vh);
    background: linear-gradient(135deg, var(--theme-bg), var(--theme-accent));
}

.login-form {
    background: var(--theme-accent);
    padding: 40px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 90%;
    max-width: 420px;
    box-shadow: var(--shadow-hover);
    border: 1px solid var(--border-color);
}

.login-form h2 {
    font-weight: 700;
    font-size: 24px;
    text-align: center;
    margin-bottom: 10px;
}

.login-form input {
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 15px;
    background: var(--theme-bg);
    color: var(--theme-text);
    transition: all 0.2s ease;
    font-family: var(--font-primary);
}

.login-form input:focus {
    outline: none;
    border-color: var(--btn-bg);
    box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.2);
}

.error {
    color: var(--danger-bg);
    font-weight: 500;
    font-size: 14px;
    text-align: center;
    background: rgba(255, 69, 58, 0.1);
    padding: 10px;
    border-radius: 6px;
}

/* App Shell */
#app {
    width: 100%;
    height: var(--app-height, 100vh);
    position: relative;
    overflow: hidden;
}

.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.view.active {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Shared Header/Toolbar Utilities */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--toolbar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
}

.app-header h1 {
    font-size: 18px;
    font-weight: 600;
}

.app-header {
    z-index: 10;
}

.bottom-toolbar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 300;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: var(--reader-toolbar-height);
    padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--toolbar-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-color);
    border-bottom: none;
    transition: transform 0.3s ease;
    width: 100%;
    flex-shrink: 0;
}

.toolbar-center {
    display: flex;
    gap: 8px;
    background: var(--theme-bg);
    padding: 4px;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

/* Buttons */
.icon-btn {
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: var(--theme-accent);
    transform: scale(1.05);
}

.icon-btn:active {
    transform: scale(0.95);
}

.btn {
    background: var(--btn-bg);
    color: var(--btn-color);
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.2s ease;
    font-family: var(--font-primary);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

.btn:hover {
    background: var(--btn-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(0, 122, 255, 0.4);
}

.btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.3);
}

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

.btn-danger {
    background: var(--danger-bg);
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(255, 69, 58, 0.3);
}

/* Sidebar */
#sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

#sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 300px;
    height: 100%;
    background: var(--theme-bg);
    border-right: 1px solid var(--border-color);
    z-index: 101;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-hover);
}

#sidebar.active {
    transform: translateX(0);
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--theme-accent);
}

.sidebar-header h3 {
    font-weight: 600;
    margin-bottom: 4px;
}

.role-badge {
    display: inline-block;
    background: var(--theme-text);
    color: var(--theme-bg);
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.menu-list {
    list-style: none;
    overflow-y: auto;
    flex-grow: 1;
    padding: 10px 0;
}

.menu-list li {
    padding: 12px 20px;
    margin: 4px 10px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.menu-list li:hover {
    background: var(--theme-accent);
}

.menu-list li.active,
.menu-list li:active {
    background: var(--btn-bg);
    color: var(--btn-color);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.2);
}

.bottom-menu {
    flex-grow: 0;
    border-top: 1px solid var(--border-color);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.bottom-menu li a {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Library Grid */
.library-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 24px;
    -webkit-overflow-scrolling: touch;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 24px;
}

.book-card {
    background: var(--theme-accent);
    border-radius: 12px;
    padding: 14px;
    text-align: center;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 1px solid var(--border-color);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.book-cover-placeholder {
    width: 100px;
    height: 140px;
    background: linear-gradient(135deg, #666, #444);
    border-radius: 6px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    transition: transform 0.3s ease;
}

.book-card:hover .book-cover-placeholder {
    transform: scale(1.02);
}

.book-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    word-wrap: break-word;
    margin-bottom: 4px;
}

.book-cat {
    font-size: 12px;
    opacity: 0.6;
    font-weight: 500;
}

#reader-view {
    position: relative;
    min-height: 0;
    padding-bottom: calc(var(--reader-toolbar-height) + env(safe-area-inset-bottom, 0px));
}

#reader-container {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    width: 100%;
    position: relative;
}

.disable-select {
    user-select: none;
    -webkit-touch-callout: none;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 200;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--theme-bg);
    width: 90%;
    max-width: 420px;
    border-radius: 16px;
    padding: 24px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid var(--border-color);
}

.modal.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-weight: 600;
    font-size: 18px;
}

.list-group {
    list-style: none;
    overflow-y: auto;
    flex-grow: 1;
}

.list-group li {
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bookmark-info {
    flex-grow: 1;
    cursor: pointer;
}

.bookmark-date {
    font-size: 12px;
    opacity: 0.6;
    display: block;
    margin-top: 4px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .bottom-toolbar {
        padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .icon-btn {
        min-width: 48px; /* Tinta tactila mai buna (iOS HIG) */
        min-height: 48px;
    }
    
    .book-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
}

/* Better support for iOS dynamic viewport */
@supports (-webkit-touch-callout: none) {
    html, body {
        height: -webkit-fill-available;
    }
    #app,
    .login-container {
        height: -webkit-fill-available;
    }
}