/* =====================================================================
   BookLib - Design System
   ===================================================================== */

:root {
    --color-bg: #F3EFE7;
    --color-bg-alt: #E9E2D3;
    --color-surface: #FFFFFF;
    --color-surface-alt: #F7F5F0;
    --color-border: #E4E0D6;
    --color-text: #1F2420;
    --color-text-muted: #6B7268;
    --color-text-faint: #9AA097;

    --color-primary: #1F3D34;      /* temno zelena (kot gumb "Search" na Image 1) */
    --color-primary-hover: #16302A;
    --color-accent: #E8703A;        /* topla oranžna (kot ikona "Discover") */
    --color-accent-soft: #FBEAE0;

    --color-success: #2E7D4F;
    --color-success-soft: #E4F3EA;
    --color-warning: #B8862E;
    --color-warning-soft: #FBF1DE;
    --color-danger: #C24B3F;
    --color-danger-soft: #FBEAE7;
    --color-info: #2E6DB8;
    --color-info-soft: #E6F0FB;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;
    --shadow-sm: 0 1px 2px rgba(20, 20, 15, 0.06);
    --shadow-md: 0 6px 20px rgba(20, 20, 15, 0.08);
    --sidebar-width: 248px;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
    --color-bg: #14161A;
    --color-bg-alt: #1B1E23;
    --color-surface: #1E2126;
    --color-surface-alt: #24272D;
    --color-border: #30343B;
    --color-text: #ECEBE7;
    --color-text-muted: #A7ACB3;
    --color-text-faint: #71767D;

    --color-primary: #4F8F7B;
    --color-primary-hover: #62A891;
    --color-accent: #F08A57;
    --color-accent-soft: #3A2A22;

    --color-success: #4CAF7D;
    --color-success-soft: #1C2E24;
    --color-warning: #D8A94E;
    --color-warning-soft: #332A16;
    --color-danger: #E17368;
    --color-danger-soft: #33201D;
    --color-info: #5B9BE0;
    --color-info-soft: #1A2733;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 6px 24px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 0.5em; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0 0 1em; }
ul { margin: 0; padding: 0; list-style: none; }
img { max-width: 100%; display: block; }

/* ---------------- LAYOUT ---------------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 17px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    padding: 0 10px 20px;
}

.sidebar-brand .logo-dot {
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--color-accent);
}

.nav-section-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-faint);
    padding: 16px 10px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
    position: relative;
}

.nav-item:hover { background: var(--color-surface-alt); color: var(--color-text); }
.nav-item.active { background: var(--color-primary); color: #fff; }

.nav-item .badge-count {
    margin-left: auto;
    background: var(--color-accent);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    border-radius: 999px;
    padding: 1px 7px;
}

.sidebar-footer { margin-top: auto; padding-top: 16px; }

.library-switcher {
    margin-top: 12px;
    border-top: 1px solid var(--color-border);
    padding-top: 14px;
}

.library-switcher select {
    width: 100%;
}

.main-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 28px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-search {
    flex: 1;
    max-width: 480px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--color-bg-alt);
    border-radius: 999px;
    padding: 9px 16px;
}

.topbar-search input {
    border: none;
    background: transparent;
    outline: none;
    flex: 1;
    color: var(--color-text);
    font-size: 14px;
}

.topbar-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }

.icon-btn {
    width: 38px; height: 38px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    cursor: pointer;
    color: var(--color-text-muted);
    position: relative;
}
.icon-btn:hover { background: var(--color-surface-alt); color: var(--color-text); }

.icon-btn .dot {
    position: absolute; top: 6px; right: 7px;
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--color-danger);
}

.user-chip {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 12px 6px 6px;
    border-radius: 999px;
    background: var(--color-bg-alt);
    font-weight: 600;
    font-size: 13.5px;
    cursor: pointer;
}
.user-chip .avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700;
}

.content {
    padding: 28px;
    max-width: 1400px;
    width: 100%;
}

/* ---------------- BUTTONS ---------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    background: var(--color-surface-alt);
    color: var(--color-text);
    transition: background 0.15s ease;
}

.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-accent { background: var(--color-accent); color: #fff; }
.btn-outline { background: transparent; border-color: var(--color-border); }
.btn-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------------- CARDS / SURFACES ---------------- */

.card {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    padding: 20px;
}

.card-title-row {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px;
}
.card-title-row h3 { margin: 0; font-size: 15px; }

.stat-card {
    display: flex; align-items: center; gap: 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 18px 20px;
}
.stat-card .stat-icon {
    width: 44px; height: 44px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0;
    background: var(--color-accent-soft); color: var(--color-accent);
}
.stat-card .stat-value { font-size: 22px; font-weight: 800; line-height: 1.1; }
.stat-card .stat-label { color: var(--color-text-muted); font-size: 12.5px; margin-top: 2px; }
.stat-card.stat-danger .stat-icon { background: var(--color-danger-soft); color: var(--color-danger); }
.stat-card.stat-success .stat-icon { background: var(--color-success-soft); color: var(--color-success); }
.stat-card.stat-info .stat-icon { background: var(--color-info-soft); color: var(--color-info); }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
}
.dashboard-grid .col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

/* ---------------- FORMS ---------------- */

label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--color-text-muted); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=datetime-local], input[type=url], textarea, select {
    width: 100%;
    padding: 10px 13px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: inherit;
    font-size: 14px;
    outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--color-primary); }
textarea { resize: vertical; min-height: 90px; }

.form-row { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; }

fieldset { border: none; padding: 0; margin: 0 0 24px; }
legend { font-size: 16px; font-weight: 800; margin-bottom: 12px; padding: 0; }

/* ---------------- TABLES ---------------- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--color-border); font-size: 13.5px; }
th { color: var(--color-text-muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }

/* ---------------- BADGES / TAGS ---------------- */

.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    background: var(--color-surface-alt);
    color: var(--color-text-muted);
}
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-info { background: var(--color-info-soft); color: var(--color-info); }

.tag-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--color-bg-alt);
    font-size: 12.5px;
    font-weight: 600;
    margin: 2px 4px 2px 0;
}

/* ---------------- BOOK GRID ---------------- */

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

.book-card {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--color-border);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.book-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

.book-cover {
    aspect-ratio: 3 / 4.4;
    background: var(--color-surface-alt);
    display: flex; align-items: center; justify-content: center;
    color: var(--color-text-faint);
    font-size: 12px;
    position: relative;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-cover .loan-badge {
    position: absolute; top: 8px; right: 8px;
    background: var(--color-accent); color: #fff;
    font-size: 10px; font-weight: 700;
    padding: 3px 8px; border-radius: 999px;
}

.book-card-body { padding: 10px 12px 14px; }
.book-card-title { font-weight: 700; font-size: 13.5px; margin-bottom: 2px; line-height: 1.3; }
.book-card-meta { font-size: 12px; color: var(--color-text-muted); }

/* ---------------- FLASH / ALERTS ---------------- */

.flash-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.flash {
    padding: 12px 16px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600;
}
.flash-success { background: var(--color-success-soft); color: var(--color-success); }
.flash-error { background: var(--color-danger-soft); color: var(--color-danger); }
.flash-warning { background: var(--color-warning-soft); color: var(--color-warning); }

/* ---------------- MISC ---------------- */

.text-muted { color: var(--color-text-muted); }
.text-faint { color: var(--color-text-faint); }
.text-danger { color: var(--color-danger); }
.mt-0 { margin-top: 0; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--color-text-muted);
}

.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 24px; }
.pagination a, .pagination span {
    width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm); border: 1px solid var(--color-border); font-size: 13px; font-weight: 600;
}
.pagination .current { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

.auth-shell {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: var(--color-bg);
    padding: 20px;
}
.auth-card {
    width: 100%; max-width: 400px;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    padding: 36px 32px;
}

.location-tree ul { padding-left: 18px; border-left: 1px dashed var(--color-border); margin-left: 6px; }
.location-tree li { padding: 4px 0; }

.qr-box { background: #fff; padding: 10px; border-radius: var(--radius-sm); display: inline-block; }

.tag-picker .tag-chip { cursor: pointer; border: 1px solid transparent; }
.tag-picker .tag-chip-selected { background: var(--color-primary); color: #fff; }

.autocomplete-wrap { position: relative; }
.autocomplete-results {
    display: none;
    position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    margin-top: 4px;
    max-height: 220px; overflow-y: auto;
}
.autocomplete-item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px; cursor: pointer; font-size: 13.5px;
}
.autocomplete-item:hover { background: var(--color-surface-alt); }

.user-menu-wrap { position: relative; }
#user-menu {
    display: none;
    position: absolute; right: 0; top: 46px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    min-width: 200px;
    z-index: 30;
    overflow: hidden;
}
#user-menu.open { display: block; }
#user-menu a, #user-menu button {
    display: block; width: 100%; text-align: left;
    padding: 10px 14px; font-size: 13.5px; font-weight: 600;
    background: none; border: none; cursor: pointer; color: var(--color-text);
}
#user-menu a:hover, #user-menu button:hover { background: var(--color-surface-alt); }

.progress-bar { height: 8px; border-radius: 999px; background: var(--color-surface-alt); overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--color-primary); }

.group-list-item, .field-list-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; border-radius: var(--radius-sm);
    background: var(--color-surface-alt);
    margin-bottom: 6px;
}

.switch {
    position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; cursor: pointer; inset: 0;
    background-color: var(--color-border); border-radius: 999px; transition: 0.15s;
}
.switch .slider:before {
    position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px;
    background-color: white; border-radius: 50%; transition: 0.15s;
}
.switch input:checked + .slider { background-color: var(--color-primary); }
.switch input:checked + .slider:before { transform: translateX(18px); }

@media (max-width: 900px) {
    .sidebar { display: none; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .content { padding: 16px; }
}
