/* ==========================================================================
   main.css: AdiClasses Books Portal design system
   Tokens -> base -> shell (sidebar/topbar) -> components -> utilities
   ========================================================================== */
:root {
  --orange: #FF6600;  --orange-600: #E65C00;  --orange-soft: #FFF1E6;
  --blue: #0D6EFD;    --blue-600: #0B5ED7;    --blue-soft: #E7F0FF;
  --purple: #7C5CFC;  --purple-soft: #EFEBFF;
  --green: #16A34A;   --green-soft: #E6F7EC;
  --red: #DC3545;     --red-soft: #FDECEE;
  --amber: #F59E0B;   --amber-soft: #FEF3DC;

  --ink: #1B2559;  --ink-2: #4A5578;  --muted: #8A94B2;  --line: #E7EBF5;
  --surface: #FFFFFF;  --glass: rgba(255, 255, 255, .74);

  --radius-sm: 10px;  --radius: 16px;  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(27, 37, 89, .05), 0 2px 8px rgba(27, 37, 89, .04);
  --shadow: 0 10px 28px rgba(27, 37, 89, .08);
  --shadow-orange: 0 8px 20px rgba(255, 102, 0, .28);

  --sidebar-w: 268px;  --topbar-h: 72px;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Verdana, sans-serif;
  --font-head: 'Poppins', 'Inter', system-ui, sans-serif;

  --bs-body-font-family: var(--font-body);
  --bs-body-color: var(--ink);
  --bs-border-color: var(--line);
  --bs-border-radius: var(--radius-sm);
  --bs-link-color: var(--blue);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body); color: var(--ink); font-size: .94rem;
  background:
    radial-gradient(1100px 560px at 100% -8%, #FFE7D3 0, transparent 60%),
    radial-gradient(900px 520px at -8% 0, #DDEAFF 0, transparent 58%),
    #F6F8FE;
  background-attachment: fixed;
  min-height: 100vh;
}
h1, h2, h3, h4, h5, h6, .font-head { font-family: var(--font-head); color: var(--ink); letter-spacing: -.01em; }
a { text-decoration: none; }
::selection { background: var(--orange-soft); }
:focus-visible { outline: 3px solid rgba(13, 110, 253, .35); outline-offset: 2px; }

/* ---------- App shell ---------- */
.app-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 1040;
  display: flex; flex-direction: column; padding: 18px 14px;
  background: var(--glass); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-right: 1px solid rgba(255, 255, 255, .8); box-shadow: var(--shadow-sm);
  overflow-y: auto; transition: transform .25s ease;
}
.app-main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.app-content { flex: 1; padding: 8px 28px 32px; width: 100%; max-width: 1480px; }
.app-sidebar-overlay { display: none; }

.brand { display: flex; align-items: center; gap: 12px; padding: 6px 10px 18px; color: var(--ink); }
.brand-mark {
  width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; flex: none;
  color: #fff; font-size: 1.1rem;
  background: linear-gradient(135deg, var(--orange) 0%, #FF9142 55%, var(--blue) 140%);
  box-shadow: var(--shadow-orange);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-family: var(--font-head); font-size: 1.12rem; color: var(--blue); }
.brand-text small { font-weight: 600; color: var(--orange); font-size: .8rem; }

.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-link {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 14px; border: 0; border-radius: 12px; background: transparent;
  color: var(--ink-2); font-weight: 500; font-size: .93rem; text-align: left;
  transition: background .15s, color .15s;
}
.side-link > i:first-child { width: 20px; text-align: center; font-size: 1rem; color: var(--muted); }
.side-link:hover { background: rgba(13, 110, 253, .06); color: var(--ink); }
.side-link.active { background: linear-gradient(90deg, var(--orange-soft), #FFF8F2); color: var(--orange-600); font-weight: 600; box-shadow: inset 3px 0 0 var(--orange); }
.side-link.active > i:first-child { color: var(--orange); }
.side-link .chev { margin-left: auto; font-size: .72rem; transition: transform .2s; color: var(--muted); }
.side-link[aria-expanded="true"] .chev { transform: rotate(180deg); }
.sub-nav { display: flex; flex-direction: column; gap: 2px; padding: 4px 0 6px 22px; margin-left: 20px; border-left: 2px solid var(--line); }
.sub-link { padding: 8px 12px; border-radius: 9px; color: var(--ink-2); font-size: .88rem; }
.sub-link:hover { background: rgba(13, 110, 253, .06); color: var(--blue); }
.sub-link.active { color: var(--orange-600); font-weight: 600; background: var(--orange-soft); }
.side-divider { height: 1px; background: var(--line); margin: 10px 6px; }

.topbar {
  position: sticky; top: 0; z-index: 1020; height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px; padding: 0 28px;
  background: rgba(246, 248, 254, .72); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.topbar-spacer { flex: 1; }
.icon-btn {
  position: relative; width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); display: inline-grid; place-items: center;
  box-shadow: var(--shadow-sm); transition: transform .15s, color .15s;
}
.icon-btn:hover { color: var(--blue); transform: translateY(-1px); }
.icon-btn .dot {
  position: absolute; top: -5px; right: -5px; min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 10px; background: var(--orange); color: #fff; font-size: .68rem; font-weight: 700;
  display: grid; place-items: center; border: 2px solid #fff;
}
.sidebar-toggle { display: none; }

.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 5px 12px 5px 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-sm);
  color: var(--ink); cursor: pointer;
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-weight: 700; font-size: .82rem; color: #fff; background: linear-gradient(135deg, var(--blue), var(--purple));
}
.user-chip .who { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.user-chip .who strong { font-size: .86rem; }
.role-pill { font-size: .68rem; font-weight: 600; color: var(--blue); background: var(--blue-soft); padding: 1px 8px; border-radius: 20px; width: fit-content; margin-top: 2px; }

.app-footer { padding: 18px 28px 26px; color: var(--muted); font-size: .82rem; display: flex; flex-wrap: wrap; gap: 8px 22px; justify-content: space-between; }
.app-footer a { color: var(--ink-2); }
.app-footer a:hover { color: var(--blue); }

/* ---------- Page header ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; margin: 6px 0 22px; }
.page-header h1 { font-size: 1.65rem; font-weight: 600; margin: 0; }
.page-header .subtitle { color: var(--ink-2); margin: 4px 0 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Cards ---------- */
.glass-card, .card-soft {
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, .85); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-soft { background: var(--surface); }
.card-pad { padding: 22px; }
.card-title { font-size: 1.05rem; font-weight: 600; margin: 0 0 14px; display: flex; align-items: center; gap: 10px; }
.card-title .link { margin-left: auto; font-size: .84rem; font-weight: 600; font-family: var(--font-body); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card {
  display: flex; gap: 14px; align-items: center; padding: 18px; border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, .9); box-shadow: var(--shadow-sm); transition: transform .2s, box-shadow .2s;
  background: linear-gradient(135deg, var(--tint, #fff) 0%, #fff 90%);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon { width: 50px; height: 50px; border-radius: 14px; display: grid; place-items: center; font-size: 1.25rem; flex: none; color: var(--accent); background: #fff; box-shadow: var(--shadow-sm); }
.stat-label { color: var(--ink-2); font-size: .82rem; font-weight: 500; }
.stat-value { font-family: var(--font-head); font-size: 1.55rem; font-weight: 600; line-height: 1.2; }
.stat-delta { font-size: .76rem; font-weight: 600; margin-top: 2px; }
.stat-delta.up { color: var(--green); }  .stat-delta.down { color: var(--red); }
.stat-delta small { color: var(--muted); font-weight: 400; }
.tone-blue   { --accent: var(--blue);   --tint: var(--blue-soft); }
.tone-orange { --accent: var(--orange); --tint: var(--orange-soft); }
.tone-purple { --accent: var(--purple); --tint: var(--purple-soft); }
.tone-green  { --accent: var(--green);  --tint: var(--green-soft); }
.tone-red    { --accent: var(--red);    --tint: var(--red-soft); }

/* ---------- Buttons ---------- */
.btn { border-radius: 12px; font-weight: 600; padding: .55rem 1.1rem; transition: transform .12s, box-shadow .15s, background .15s; }
.btn:active { transform: translateY(1px); }
.btn-brand { color: #fff; background: linear-gradient(180deg, #FF7A1F, var(--orange)); border: 0; box-shadow: var(--shadow-orange); }
.btn-brand:hover, .btn-brand:focus { color: #fff; background: linear-gradient(180deg, var(--orange), var(--orange-600)); }
.btn-brand:disabled, .btn-brand.disabled { opacity: .65; box-shadow: none; }
.btn-primary { background: var(--blue); border-color: var(--blue); box-shadow: 0 8px 18px rgba(13, 110, 253, .22); }
.btn-soft { background: var(--blue-soft); color: var(--blue-600); border: 0; }
.btn-soft:hover { background: #D6E6FF; color: var(--blue-600); }
.btn-ghost { background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); }
.btn-ghost:hover { color: var(--blue); border-color: #C9D8F5; }
.btn-sm { padding: .35rem .75rem; border-radius: 10px; font-size: .84rem; }

/* ---------- Forms ---------- */
.form-label { font-weight: 600; font-size: .84rem; color: var(--ink); margin-bottom: .35rem; }
.form-label.req::after { content: ' *'; color: var(--red); }
.form-control, .form-select {
  border-radius: 12px; border: 1px solid #DCE3F2; padding: .62rem .9rem; background-color: #fff; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.form-control::placeholder { color: #A9B2CC; }
.form-control:focus, .form-select:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(13, 110, 253, .12); }
.form-text { color: var(--muted); font-size: .78rem; }
.input-icon { position: relative; }
.input-icon > i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon > .form-control { padding-left: 40px; }
.form-section { padding-bottom: 6px; margin-bottom: 20px; border-bottom: 1px dashed var(--line); }

/* ---------- Tables ---------- */
.table-card { padding: 0; overflow: hidden; }
.table-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.table-toolbar .grow { flex: 1; min-width: 200px; }
.table-modern { margin: 0; --bs-table-bg: transparent; }
.table-modern thead th { background: #F7F9FF; color: var(--ink-2); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; border-bottom: 1px solid var(--line); white-space: nowrap; padding: .8rem 1rem; }
.table-modern td { padding: .85rem 1rem; vertical-align: middle; border-color: var(--line); }
.table-modern tbody tr:hover { background: rgba(13, 110, 253, .035); }
.table-modern .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); color: var(--ink-2); font-size: .84rem; }
.row-actions { display: inline-flex; gap: 6px; }
.row-actions .btn { padding: .3rem .55rem; }

/* ---------- Badges ---------- */
.badge-soft { display: inline-flex; align-items: center; gap: 6px; padding: .28rem .7rem; border-radius: 20px; font-size: .74rem; font-weight: 600; white-space: nowrap; }
.badge-soft::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-soft.tone-success { color: #12803A; background: var(--green-soft); }
.badge-soft.tone-warning { color: #B45309; background: var(--amber-soft); }
.badge-soft.tone-danger  { color: #B4232F; background: var(--red-soft); }
.badge-soft.tone-info    { color: var(--blue-600); background: var(--blue-soft); }
.badge-soft.tone-purple  { color: #5B3FD6; background: var(--purple-soft); }
.badge-soft.tone-muted   { color: var(--ink-2); background: #EEF1F8; }

/* ---------- Misc components ---------- */
.empty-state { text-align: center; padding: 46px 20px; color: var(--ink-2); }
.empty-state .icon { width: 74px; height: 74px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 14px; font-size: 1.8rem; color: var(--orange); background: var(--orange-soft); }
.empty-state h3 { font-size: 1.08rem; margin-bottom: 6px; }

.flash-stack { margin-bottom: 14px; display: grid; gap: 10px; }
.flash-item { display: flex; align-items: center; gap: 12px; border: 0; border-radius: 14px; box-shadow: var(--shadow-sm); margin: 0; padding-right: 3rem; }
.flash-item > i { font-size: 1.1rem; }

.toast-stack { position: fixed; top: 18px; right: 18px; z-index: 2000; display: grid; gap: 10px; width: min(360px, calc(100vw - 36px)); }
.toast { border: 0; border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.toast .toast-body { display: flex; align-items: flex-start; gap: 10px; font-weight: 500; }

.pagination { gap: 4px; margin: 0; }
.page-link { border-radius: 10px !important; border: 1px solid var(--line); color: var(--ink-2); min-width: 36px; text-align: center; }
.page-item.active .page-link { background: var(--orange); border-color: var(--orange); color: #fff; }

.modal-content { border: 0; border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.modal-header { border-bottom: 1px solid var(--line); }
.modal-footer { border-top: 1px solid var(--line); }
.dropdown-menu { border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 8px; }
.dropdown-item { border-radius: 9px; padding: .5rem .8rem; font-size: .9rem; }
.dropdown-item:hover { background: var(--blue-soft); }

.text-muted-2 { color: var(--muted) !important; }
.w-fit { width: fit-content; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-102%); box-shadow: var(--shadow); width: min(86vw, 300px); }
  body.sidebar-open .app-sidebar { transform: translateX(0); }
  body.sidebar-open { overflow: hidden; }
  .app-sidebar-overlay { display: block; position: fixed; inset: 0; z-index: 1030; background: rgba(27, 37, 89, .38); opacity: 0; pointer-events: none; transition: opacity .2s; }
  body.sidebar-open .app-sidebar-overlay { opacity: 1; pointer-events: auto; }
  .app-main { margin-left: 0; }
  .sidebar-toggle { display: inline-grid; }
  .topbar, .app-footer { padding-left: 16px; padding-right: 16px; }
  .app-content { padding: 6px 16px 26px; }
}
@media (max-width: 575.98px) {
  .user-chip .who { display: none; }
  .user-chip { padding: 4px; }
  .page-header h1 { font-size: 1.35rem; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-card { flex-direction: column; align-items: flex-start; padding: 14px; }
  .stat-value { font-size: 1.3rem; }
  .table-toolbar { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print {
  .app-sidebar, .topbar, .app-footer, .app-sidebar-overlay, .page-actions, .no-print { display: none !important; }
  .app-main { margin: 0; } body { background: #fff; }
}

/* ---- images: logo, sidebar art, empty states ---- */
.brand-mark:has(> img) { background: none; box-shadow: none; }       /* a real logo needs no gradient tile */
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-mark img ~ i { display: none; }

.app-sidebar::after { content: ''; flex: none; height: 150px; margin-top: 12px;
  background: url('../images/sidebar-books.png') center bottom / contain no-repeat; }
@media (max-height: 780px) { .app-sidebar::after { display: none; } }   /* short screens: keep the menu roomy */

.empty-img { display: block; width: min(220px, 60%); margin: 0 auto 12px; }
.empty-img ~ .icon { display: none; }