/* ============================================================
   Components — buttons, cards, tables, tags, forms, filters,
   modal, toast, KPIs, book & work cards
   A∴R∴L∴S∴ Justiça e Liberdade
   ============================================================ */

/* ============== Buttons ============== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.04s;
}
.btn:hover { background: var(--bg-soft); border-color: var(--ink-soft); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--ink);
  color: var(--bg-elev);
  border-color: var(--ink);
}
.btn.primary:hover { background: #0f1822; }
.btn.danger {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}
.btn.danger:hover { background: #872c20; }
.btn.ghost {
  background: transparent;
  border-color: transparent;
}
.btn.ghost:hover { background: var(--bg-soft); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.lg { height: 44px; padding: 0 20px; font-size: 14px; }

.icon-btn {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--ink-soft);
}
.icon-btn:hover { background: var(--bg-soft); color: var(--ink); }
.icon-btn.active { background: var(--ink); color: var(--bg-elev); border-color: var(--ink); }

.btn-group {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elev);
}
.btn-group button {
  height: 36px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  border-right: 1px solid var(--line);
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-group button:last-child { border-right: 0; }
.btn-group button:hover { background: var(--bg-soft); color: var(--ink); }
.btn-group button.active { background: var(--ink); color: var(--bg-elev); }

/* ============== Cards & Tables ============== */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table thead th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding: 12px var(--pad-3);
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
  position: sticky; top: 0;
}
.table tbody td {
  padding: 12px var(--pad-3);
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
.table tbody tr:hover { background: var(--bg-soft); }
.table .num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; color: var(--ink-soft); font-size: 12px; }

/* ============== Filters ============== */
.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: var(--pad-3);
  align-items: center;
}
.filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px 0 12px;
  border: 1px dashed var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink-soft);
  background: transparent;
}
.filter:hover { border-color: var(--ink-soft); color: var(--ink); background: var(--bg-elev); }
.filter.active {
  border-style: solid;
  border-color: var(--ink);
  background: var(--bg-elev);
  color: var(--ink);
}
.filter .val { color: var(--ink); font-weight: 500; }
.filter .x { color: var(--muted); margin-left: 4px; }

.filter-bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--pad-3);
  align-items: center;
  margin-bottom: var(--pad-3);
}

/* ============== Tags / status ============== */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  font-size: 11px;
  border-radius: 999px;
  font-weight: 500;
  letter-spacing: 0.02em;
  background: var(--bg-soft);
  color: var(--ink-soft);
  border: 1px solid var(--line-soft);
}
.tag .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag.avail { color: #2e6b3d; background: #e8efe0; border-color: #cfdcc0; }
.tag.lent  { color: #9a4a1f; background: #f1e6d5; border-color: #ddc8a8; }
.tag.queue { color: #7a4a8c; background: #ede1f0; border-color: #d4bcd9; }
.tag.over  { color: #a0392a; background: #f3dcd6; border-color: #e0b6ad; }
[data-theme="dark"] .tag.avail { color: #b4d49a; background: #1f2a1f; border-color: #2e3f2a; }
[data-theme="dark"] .tag.lent  { color: #d4a574; background: #2a221b; border-color: #3f3325; }
[data-theme="dark"] .tag.queue { color: #c8a8d0; background: #2a1f2c; border-color: #3f2e44; }
[data-theme="dark"] .tag.over  { color: #d8806b; background: #2e1f1b; border-color: #44261e; }

.grau-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--f-display);
  font-style: italic;
  font-size: 12.5px;
  color: var(--gold-deep);
  white-space: nowrap;
}
[data-theme="dark"] .grau-tag { color: var(--gold); }
.grau-tag .pip { font-family: var(--f-ui); font-style: normal; }

/* ============== Forms ============== */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--pad-3);
}
.field > label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 500;
}
.field input[type=text],
.field input[type=email],
.field input[type=password],
.field input[type=number],
.field input[type=date],
.field input[type=time],
.field select,
.field textarea,
.input {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  outline: none;
  font-size: 13.5px;
  transition: border 0.15s, background 0.15s;
}
.field textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 80px; }
.field input:focus, .field select:focus, .field textarea:focus,
.input:focus { border-color: var(--ink); background: var(--bg-elev); }
[data-theme="dark"] .field input[type=text],
[data-theme="dark"] .field input[type=email],
[data-theme="dark"] .field input[type=password],
[data-theme="dark"] .field input[type=number],
[data-theme="dark"] .field input[type=date],
[data-theme="dark"] .field input[type=time],
[data-theme="dark"] .field select,
[data-theme="dark"] .field textarea,
[data-theme="dark"] .input {
  background: #6f7790;
  color: #ffffff;
}
[data-theme="dark"] .field input::placeholder,
[data-theme="dark"] .field textarea::placeholder,
[data-theme="dark"] .input::placeholder {
  color: #ffeaac;
  opacity: 1;
}
[data-theme="dark"] .field input:focus,
[data-theme="dark"] .field select:focus,
[data-theme="dark"] .field textarea:focus,
[data-theme="dark"] .input:focus {
  background: #7c849d;
}
.field .hint { font-size: 11.5px; color: var(--muted); font-style: italic; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--pad-3); }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }

/* ============== KPI ============== */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--pad-3); margin-bottom: var(--pad-4); }
.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad-3);
}
.kpi .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin-bottom: 6px; }
.kpi .v { font-family: var(--f-display); font-size: 30px; font-weight: 600; line-height: 1; }
.kpi .d { font-size: 11.5px; color: var(--ink-soft); margin-top: 4px; font-style: italic; }

/* ============== Modal ============== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 23, 28, 0.4);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  padding: 40px;
  z-index: 1000;
  animation: fadein 0.15s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-elev);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-pop);
  max-width: 560px;
  width: 100%;
  max-height: calc(100vh - 80px);
  overflow: auto;
  border: 1px solid var(--line);
}
.modal .head {
  padding: var(--pad-4);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal .head h2 {
  font-family: var(--f-display);
  font-size: 22px;
  margin: 0;
  font-weight: 600;
}
.modal .body { padding: var(--pad-4); }
.modal .foot {
  padding: var(--pad-3) var(--pad-4);
  border-top: 1px solid var(--line);
  display: flex; gap: 8px; justify-content: flex-end;
}

/* ============== Toast ============== */
.toast-stack {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 2000;
}
.toast {
  background: var(--ink);
  color: var(--bg-elev);
  padding: 12px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  font-size: 13px;
  display: flex; align-items: center; gap: 10px;
  max-width: 360px;
  animation: slidein 0.2s ease;
}
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ============== Tabs ============== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--pad-4);
}
.tabs button {
  background: transparent;
  border: 0;
  padding: 10px 16px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  position: relative;
  font-family: var(--f-ui);
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--ink); }
.tabs button.active::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 12px; right: 12px;
  height: 2px;
  background: var(--gold);
}

/* ============== Avatar ============== */
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  display: grid; place-items: center;
  font-family: var(--f-display);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}
.avatar.mini {
  width: 22px; height: 22px; font-size: 9.5px;
  color: var(--bg-elev);
}

/* ============== Book grid & cards ============== */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--pad-4);
}
.book-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
}
.book-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-pop);
  border-color: var(--ink-soft);
}
.book-spine {
  aspect-ratio: 2/3;
  position: relative;
  overflow: hidden;
  background: var(--bg-soft);
}
.book-spine .cover {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  padding: 14px 12px;
  font-family: var(--f-display);
  color: rgba(255,255,255,0.92);
}
.book-spine .cover .title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.15;
  text-wrap: balance;
  letter-spacing: -0.005em;
}
.book-spine .cover .author {
  margin-top: auto;
  font-size: 11px;
  font-style: italic;
  opacity: 0.85;
}
.book-spine .cover .ornament {
  position: absolute;
  bottom: 12px; right: 12px;
  opacity: 0.4;
}
.book-spine .cover .topline {
  width: 30px; height: 1px;
  background: currentColor;
  opacity: 0.6;
  margin-bottom: 10px;
}
.book-meta {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line-soft);
}
.book-meta .t {
  font-family: var(--f-display);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.15;
  margin-bottom: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book-meta .a { font-size: 11.5px; color: var(--muted); font-style: italic; }
.book-meta .row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 6px; }
.book-meta .row .num { font-size: 10.5px; color: var(--muted); font-family: var(--f-mono); }

/* ============== Trabalhos (work) cards ============== */
.work-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--pad-3);
}
.work-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad-3);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.work-card:hover { border-color: var(--ink-soft); box-shadow: var(--shadow-card); }
.work-card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.work-card .glyph {
  width: 36px; height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  display: grid; place-items: center;
  color: var(--brown);
  flex-shrink: 0;
}
.work-card .t {
  font-family: var(--f-display);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.2;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.work-card .a { font-size: 12px; color: var(--muted); font-style: italic; font-family: var(--f-display); }
.work-card .desc {
  font-size: 12.5px;
  color: var(--ink-soft);
  line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.work-card .foot {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px dashed var(--line-soft);
  font-size: 11px; color: var(--muted);
}
.work-card .foot .pages { font-family: var(--f-mono); }
.work-card.locked { opacity: 0.55; filter: saturate(0.6); }
