:root {
  --bg: #f1f1f1;
  --panel: #ffffff;
  --panel-soft: #ffffff;
  --sidebar: #000000;
  --sidebar-2: #111111;
  --sidebar-text: #ffffff;
  --text: #000000;
  --muted: #5b5b5b;
  --primary: #000000;
  --primary-hover: #111111;
  --secondary: #f3f3f3;
  --secondary-hover: #e7e7e7;
  --secondary-text: #000000;
  --danger: #cf2f43;
  --danger-bg: #ffdfe5;
  --ok: #136b39;
  --ok-bg: #e7f7ee;
  --status-ok-text: #0f6b3a;
  --status-ok-bg: #dcf6e8;
  --status-danger-text: #b71f33;
  --status-danger-bg: #ffd7df;
  --warn-text: #b71f33;
  --warn-border: #e9a8b2;
  --warn-bg: #fff4f6;
  --warn-hover-bg: #ffe8ec;
  --focus-ring: rgba(33, 84, 170, 0.16);
  --border: #d9d9d9;
  --header-bg: #000000;
  --header-text: #ffffff;
  --sort-hover-bg: rgba(0, 0, 0, 0.06);
  --sort-active-bg: #000000;
  --sort-active-text: #ffffff;
  --sort-active-border: rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.04);
}

:root[data-theme="dark"] {
  --bg: #000000;
  --panel: #0d0d0d;
  --panel-soft: #141414;
  --sidebar: #000000;
  --sidebar-2: #101010;
  --sidebar-text: #ffffff;
  --text: #ffffff;
  --muted: #b8b8b8;
  --primary: #ffffff;
  --primary-hover: #f1f1f1;
  --secondary: #1a1a1a;
  --secondary-hover: #242424;
  --secondary-text: #ffffff;
  --danger: #ff7284;
  --danger-bg: #4a2630;
  --ok: #76e8a6;
  --ok-bg: #173325;
  --status-ok-text: #8ef2ba;
  --status-ok-bg: #1f3c2d;
  --status-danger-text: #ffc1ca;
  --status-danger-bg: #60303a;
  --warn-text: #ffb6c1;
  --warn-border: #c06072;
  --warn-bg: #3f232a;
  --warn-hover-bg: #55303a;
  --focus-ring: rgba(139, 177, 245, 0.16);
  --border: #2a2a2a;
  --header-bg: #ffffff;
  --header-text: #000000;
  --sort-hover-bg: rgba(255, 255, 255, 0.08);
  --sort-active-bg: #ffffff;
  --sort-active-text: #000000;
  --sort-active-border: rgba(255, 255, 255, 0.14);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 12px 30px rgba(0, 0, 0, 0.18);
  --shadow-sm: 0 6px 16px rgba(0, 0, 0, 0.14);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-layout {
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: var(--sidebar-text);
  padding: 1.5rem 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100vh;
  overflow: hidden;
  z-index: 50;
}

.sidebar-brand {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.2rem 0.3rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.sidebar-brand--logo-only {
  min-height: 108px;
}

.brand-badge {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  background: rgba(255,255,255,0.12);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.7rem;
}

.sidebar-brand strong {
  display: block;
  font-size: 1.7rem;
  line-height: 1.05;
}

.sidebar-brand span,
.admin-card span,
.nav-group-title {
  color: rgba(232, 241, 251, 0.74);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.nav-group-title {
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.11em;
  padding: 0.5rem 0.55rem;
}

.page-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 0.95rem 1rem;
  border-radius: 16px;
  background: rgba(255,255,255,0.08);
  border: 1px solid transparent;
  font-weight: 700;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.page-nav .nav-link:hover {
  transform: translateX(4px);
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.1);
}

.page-nav .nav-link.active {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.14);
  box-shadow: inset 3px 0 0 #ffffff;
}

.nav-dot {
  width: 2rem;
  height: 2rem;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  font-size: 1rem;
}

.sidebar-footer {
  margin-top: auto;
  position: sticky;
  bottom: 0;
  padding-top: 0.75rem;
  background: linear-gradient(180deg, rgba(0,0,0,0), var(--sidebar) 24%);
}

.main-content {
  margin-left: 280px;
  min-height: 100vh;
  padding: 1.4rem 1.6rem 2rem;
}

.hero-panel {
  background: linear-gradient(135deg, var(--panel), var(--panel-soft));
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
  padding: 1.7rem;
  display: grid;
  grid-template-columns: 1.6fr minmax(260px, 340px);
  gap: 1.2rem;
}

.hero-copy h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1;
}

.hero-copy p,
.section-subtitle {
  margin: 0;
  color: var(--muted);
  max-width: 62rem;
}

.hero-aside,
.metrics-row {
  display: grid;
  gap: 1rem;
}

.info-tile,
.metric-card,
.panel,
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}

.info-tile {
  border-radius: 20px;
  padding: 1rem 1.1rem;
}

.tile-label,
.metric-card span,
.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.info-tile strong,
.metric-card strong { font-size: 1.12rem; }
.info-tile small { color: var(--muted); }

.metrics-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 1.2rem 0;
}

.metrics-row--overview {
  grid-template-columns: minmax(220px, 0.85fr) repeat(3, minmax(0, 1fr));
  margin-top: 0;
}

.page-title-card {
  background: linear-gradient(135deg, var(--panel), var(--panel-soft));
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  padding: 1rem 1.15rem;
  display: flex;
  align-items: center;
}

.page-title-card h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.35rem);
  line-height: 1.05;
}

.metric-card {
  border-radius: 20px;
  padding: 1rem 1.15rem;
}
.metric-card strong { font-size: 2rem; }
.metric-card.danger { background: linear-gradient(135deg, var(--panel), var(--danger-bg)); }

.single-layout {
  display: grid;
  gap: 1.2rem;
}

.section-card,
.panel {
  border-radius: 24px;
  padding: 1.3rem;
}

.section-head,
.panel-title-row,
.table-tools,
.history-tools,
.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
}

.section-head h2,
.panel h2,
.modal-card h3 {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
}

.form-grid,
.client-form-grid,
.rental-grid,
.form-card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.9rem;
  margin: 1.1rem 0 1.2rem;
}

.rental-grid {
  grid-template-columns: 1.35fr 1.35fr 0.8fr auto;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: var(--text);
  border-radius: 16px;
  padding: 0.95rem 1rem;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

input::placeholder { color: var(--muted); }
input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--focus-ring);
}

.btn-primary,
.action-btn,
.theme-toggle {
  border: 1px solid transparent;
  border-radius: 16px;
  padding: 0.95rem 1.15rem;
  font-weight: 700;
  transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.btn-primary {
  background: var(--primary);
  color: var(--header-text);
}
:root[data-theme="dark"] .btn-primary { color: #000000; }
.btn-primary:hover { transform: translateY(-1px); background: var(--primary-hover); }

.btn-secondary {
  background: var(--secondary);
  color: var(--secondary-text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--secondary-hover); }

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: rgba(217, 74, 92, 0.15);
}
.btn-danger:hover { background: var(--warn-hover-bg); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  width: 100%;
  min-height: 50px;
}

.theme-icon {
  width: 22px;
  height: 22px;
  display: inline-block;
  background-size: contain;
  background-repeat: no-repeat;
}

:root[data-theme="light"] .theme-icon {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' fill='black' viewBox='0 0 24 24'><path d='M21 12.79A9 9 0 1111.21 3c.5 0 .99.04 1.47.12A7 7 0 0021 12.79z'/></svg>");
}
:root[data-theme="dark"] .theme-icon {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' fill='white' viewBox='0 0 24 24'><path d='M12 18a1 1 0 011 1v2a1 1 0 11-2 0v-2a1 1 0 011-1zm6.36-2.95l1.42 1.41a1 1 0 11-1.42 1.42l-1.41-1.42a1 1 0 011.41-1.41zM21 11a1 1 0 110 2h-2a1 1 0 110-2h2zM12 5a1 1 0 01-1-1V2a1 1 0 112 0v2a1 1 0 01-1 1zM5.64 6.05A1 1 0 114.22 4.63l1.42-1.41a1 1 0 111.41 1.41L5.64 6.05zM7 12a5 5 0 1110 0 5 5 0 01-10 0zm-4 1a1 1 0 100-2H1a1 1 0 100 2h2zm3.22 6.88a1 1 0 010-1.42l1.41-1.41a1 1 0 111.42 1.41l-1.42 1.42a1 1 0 01-1.41 0z'/></svg>");
}

.table-tools { margin-bottom: 1rem; }
.card-tools { justify-content: flex-start; }
.search-with-icon { position: relative; display: inline-flex; align-items: center; }
.wide-search { width: min(100%, 440px); }
.search-icon {
  position: absolute;
  left: 1rem;
  display: inline-flex;
  color: var(--muted);
}
.search-with-icon input { padding-left: 2.7rem; }
.compact-search { min-width: min(100%, 320px); }
.panel-search { min-width: 280px; }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--panel-soft);
}

.data-table,
.books-table,
.clients-table,
.rentals-table,
.history-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

th, td {
  text-align: left;
  padding: 1rem 0.95rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

thead th {
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: color-mix(in srgb, var(--panel) 88%, var(--secondary)); }

.sort-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 0.45rem 0.7rem;
  font-weight: 700;
}
.sort-trigger:hover { background: var(--sort-hover-bg); }
.sort-trigger.active {
  background: var(--sort-active-bg);
  color: var(--sort-active-text);
  border-color: var(--sort-active-border);
}
.sort-indicator { line-height: 1; }

.action-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.action-btn.compact {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 0.78rem 1rem;
  border-radius: 14px;
  white-space: nowrap;
}

.action-btn svg,
.inline-icon {
  width: 1rem;
  height: 1rem;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  font-size: 0.9rem;
  font-weight: 700;
}
.status-badge.ok {
  color: var(--status-ok-text);
  background: var(--status-ok-bg);
}
.status-badge.overdue,
.status-badge.danger {
  color: var(--status-danger-text);
  background: var(--status-danger-bg);
}
.status-badge::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.9;
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.pagination-group {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.pagination button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 0.6rem 0.85rem;
}
.pagination button.active {
  background: var(--primary);
  color: var(--header-text);
}
:root[data-theme="dark"] .pagination button.active { color: #000000; }

details > summary {
  list-style: none;
  cursor: pointer;
}
details > summary::-webkit-details-marker { display: none; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 20, 0.48);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 80;
}
.modal.show { display: flex; }
.modal-card {
  width: min(780px, 100%);
  border-radius: 24px;
  padding: 1.3rem;
}
.modal-grid,
.modal-grid-client {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}
.modal-actions { grid-column: 1 / -1; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%) translateY(20px);
  background: #152235;
  color: #fff;
  padding: 0.95rem 1.1rem;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 90;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 1.4rem;
}

@media (max-width: 1080px) {
  .sidebar {
    position: static;
    width: auto;
    height: auto;
    min-height: auto;
    overflow: visible;
  }
  .main-content { margin-left: 0; }
  .hero-panel { grid-template-columns: 1fr; }
  .metrics-row--overview {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .page-title-card {
    grid-column: 1 / -1;
  }
  .metrics-row,
  .form-grid,
  .client-form-grid,
  .rental-grid,
  .modal-grid,
  .modal-grid-client { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .main-content { padding: 1rem; }
  .section-card, .panel, .hero-panel { padding: 1rem; border-radius: 20px; }
  .metrics-row--overview {
    grid-template-columns: 1fr;
  }
  .page-title-card {
    grid-column: auto;
  }
  .metrics-row,
  .form-grid,
  .client-form-grid,
  .rental-grid,
  .modal-grid,
  .modal-grid-client { grid-template-columns: 1fr; }
  .wide-search, .compact-search, .panel-search { min-width: 100%; width: 100%; }
  .theme-toggle { justify-content: center; }
}


.modal.open{display:flex;}
.status{display:inline-flex;align-items:center;gap:.45rem;border-radius:999px;padding:.45rem .8rem;font-size:.9rem;font-weight:700;}
.status::before{content:"";width:.55rem;height:.55rem;border-radius:999px;background:currentColor;opacity:.9;}
.status-ok{color:var(--status-ok-text);background:var(--status-ok-bg);}
.status-danger{color:var(--status-danger-text);background:var(--status-danger-bg);}
.pagination-controls,.pagination-group{display:flex;gap:.45rem;flex-wrap:wrap;align-items:center;}
.pagination-summary{color:var(--muted);font-weight:600;}
.pagination-btn[disabled]{opacity:.5;cursor:not-allowed;}
#overdueCard.active{outline:2px solid color-mix(in srgb, var(--danger) 35%, transparent);}


.sidebar-logo {
  width: 500px;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
  filter: brightness(0) invert(1);
}

.sidebar-brand strong {
  font-size: 1.2rem;
  line-height: 1.1;
}

.sidebar-brand span {
  font-size: 0.9rem;
}

.brand-badge { display: none; }

.icon-dot {
  width: 2.1rem;
  height: 2.1rem;
}

.icon-dot svg {
  width: 1.1rem;
  height: 1.1rem;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hero-panel {
  background: linear-gradient(135deg, var(--panel), var(--panel-soft));
}

.info-tile, .metric-card, .panel, .modal-card {
  background: var(--panel);
}

.section-head-actions, .history-tools {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.history-tools {
  justify-content: flex-end;
}

.compact-search {
  min-width: min(100%, 320px);
  flex: 1 1 280px;
}

.history-tools .action-btn,
.section-head-actions .action-btn {
  flex: 0 0 auto;
}

.action-btn, .btn-primary, .btn-secondary, .btn-danger {
  box-shadow: none;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: nowrap;
}

.icon-btn {
  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

.icon-btn.warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: var(--warn-border);
}

.icon-btn.warn:hover {
  background: var(--warn-hover-bg);
}

@media (max-width: 900px) {
  .history-tools { justify-content: stretch; }
  .history-tools > * { width: 100%; }
  .history-tools .action-btn { width: 100%; }
}


.theme-toggle {
  width: 100%;
}
