/* App shell: resets, sidebar, topbar, screen container, search modal, install button, FAB */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; font-size: 14px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  overflow: hidden;
  line-height: 1.6;
}
button, input, select, textarea { font-family: var(--font); font-size: 14px; }
button { cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { outline: none; }
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* Round icon buttons (menu, search, theme): one look everywhere */
.tb-ham, .tb-search-btn, .sb-theme-btn {
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--glass);
  border: 1px solid var(--glass-bd);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--t), background var(--t);
}
.tb-ham svg, .tb-search-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
@media (hover: hover) {
  .tb-ham:hover, .tb-search-btn:hover, .sb-theme-btn:hover { border-color: var(--border2); }
}
.tb-ham:focus-visible, .tb-search-btn:focus-visible, .sb-theme-btn:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }

/* "de Guardia" in the brand name */
.brand-acc { color: var(--coral); }

/* ── SIDEBAR ── */
#sidebar {
  width: var(--sb-w);
  min-width: var(--sb-w);
  background: var(--sb-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  z-index: 20;
  flex-shrink: 0;
  transition: transform .25s ease;
}
.sb-logo {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.sb-logo-img {
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 50%; object-fit: cover;
  border: 1px solid var(--glass-bd);
}
.sb-logo-name { font-size: 15px; font-weight: 800; letter-spacing: -.3px; line-height: 1.25; }
.sb-logo-sub  { font-size: 12px; color: var(--text2); margin-top: 2px; }
.sb-logo-author { font-family: var(--mono); font-size: 10px; letter-spacing: .04em; color: var(--text3); margin-top: 2px; }
.sb-theme-btn {
  margin-left: auto;
  width: 36px; height: 36px;
  font-size: 15px;
}

.sb-search {
  padding: 12px 14px;
  flex-shrink: 0;
}
.sb-search-inp {
  width: 100%;
  height: 42px;
  background: var(--glass);
  border: 1px solid var(--glass-bd);
  border-radius: 14px;
  color: var(--text);
  padding: 0 14px;
  font-size: 14px;
  transition: border-color var(--t);
}
.sb-search-inp:focus { border-color: var(--acc); }
.sb-search-inp::placeholder { color: var(--text3); }

.sb-scroll { flex: 1; overflow-y: auto; padding: 0 10px 20px; }
.sb-scroll::-webkit-scrollbar { width: 0; }

.sb-section { margin-bottom: 2px; }
.sb-section-lbl {
  font-size: 11px; font-weight: 700;
  color: var(--text3); letter-spacing: .1em; text-transform: uppercase;
  padding: 14px 10px 5px;
}
.sb-section:first-child .sb-section-lbl { padding-top: 6px; }
.sb-item {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 14px; font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background var(--t), color var(--t);
  user-select: none;
}
@media (hover: hover) { .sb-item:hover { background: var(--glass); } }
[data-theme="light"] .sb-item:hover { background: var(--bg); }
.sb-item.active { background: var(--coral-bg); color: var(--coral); }
.sb-item.active .sb-item-name { font-weight: 600; color: var(--coral); }
.sb-item-ico { font-size: 18px; width: 22px; text-align: center; flex-shrink: 0; }
.sb-item-txt { flex: 1; min-width: 0; line-height: 1.3; }
.sb-item-name { font-size: 14px; color: var(--text); }
.sb-item-sub { font-size: 12px; color: var(--text2); margin-top: 1px; }
.sb-badge {
  font-family: var(--mono); font-size: 9.5px; font-weight: 700; letter-spacing: .04em;
  padding: 2px 7px; border-radius: var(--r-pill); flex-shrink: 0; line-height: 1.4;
}
.b-crit { background: var(--red-bg); color: var(--red); border: 1px solid var(--red-bd); }
.b-ref  { background: var(--blue-bg); color: var(--acc); border: 1px solid var(--blue-bd); }
.b-calc { background: var(--grn-bg); color: var(--green); border: 1px solid var(--grn-bd); }
.sb-div { display: none; }

/* ── SHELL ── */
#shell { flex: 1; display: flex; flex-direction: column; height: 100dvh; overflow: hidden; min-width: 0; }
/* The home paints the bordó ground under the topbar and the screen */
#shell.is-home { background: var(--hero-bg); }

#topbar {
  height: var(--top-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px; gap: 10px;
  flex-shrink: 0;
  position: relative; z-index: 10;
}
.tb-ham { display: none; width: 40px; height: 40px; }
.tb-breadcrumb { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.tb-bc-root { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 800; letter-spacing: -.3px; color: var(--text); cursor: pointer; flex-shrink: 0; }
.tb-logo { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; border: 1px solid var(--glass-bd); flex-shrink: 0; }
@media (hover: hover) { .tb-bc-root:hover .tb-brand { opacity: .8; } }
.tb-bc-sep { color: var(--text3); font-size: 14px; }
.tb-bc-cur { font-size: 15px; font-weight: 700; letter-spacing: -.2px; color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.tb-kbd { font-family: var(--mono); font-size: 10px; font-weight: 600; color: var(--text3); background: var(--glass); border: 1px solid var(--glass-bd); padding: 2px 8px; border-radius: var(--r-pill); }

/* Home: transparent topbar over the bordó ground */
#shell.is-home #topbar { background: transparent; border-bottom-color: transparent; }
#shell.is-home .tb-ham, #shell.is-home .tb-search-btn { background: var(--hero-glass); border-color: var(--hero-glass-bd); color: var(--hero-fg); }
#shell.is-home .tb-bc-root { color: var(--hero-fg); }
#shell.is-home .tb-logo { border-color: var(--hero-glass-bd); }
#shell.is-home .brand-acc { color: var(--hero-acc); }
#shell.is-home .tb-kbd { color: var(--hero-fg2); background: var(--hero-glass); border-color: var(--hero-glass-bd); }

/* ── MAIN SCREEN ── */
#screen { flex: 1; overflow-y: auto; background: var(--bg); }
#shell.is-home #screen { background: transparent; }
.view { display: none; padding: 24px; max-width: 900px; animation: fadein .18s ease; }
.view.active { display: block; }
@keyframes fadein { from { opacity:0; transform:translateY(5px); } to { opacity:1; transform:translateY(0); } }
@media (prefers-reduced-motion: reduce) { .view, .tab-pane { animation: none; } }

/* ── SEARCH MODAL ── */
#search-modal {
  position: fixed; inset: 0; z-index: 200;
  display: none; align-items: flex-start; justify-content: center;
  padding-top: 80px;
}
#search-modal.open { display: flex; }
.s-backdrop { position: absolute; inset: 0; background: rgba(8,10,14,.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.s-box {
  position: relative; z-index: 1;
  width: 100%; max-width: 560px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--r-xl);
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}
.s-inp-row {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.s-ico { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: var(--text3); stroke-width: 1.7; stroke-linecap: round; }
.s-inp-row input {
  flex: 1; min-width: 0; background: none; border: none; outline: none;
  font-size: 16px; color: var(--text);
}
.s-inp-row input::placeholder { color: var(--text3); }
.s-esc { font-family: var(--mono); font-size: 10px; font-weight: 600; background: var(--glass); border: 1px solid var(--glass-bd); padding: 2px 9px; border-radius: var(--r-pill); color: var(--text3); cursor: pointer; }
.s-results { max-height: 50vh; overflow-y: auto; padding: 6px; }
.s-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; cursor: pointer; transition: background var(--t); }
.s-item:hover, .s-item.sel { background: var(--blue-bg); }
.s-item-ico { font-size: 18px; width: 24px; text-align: center; }
.s-item-name { font-size: 14px; font-weight: 600; color: var(--text); line-height: 1.3; }
.s-item-cat  { font-size: 12px; color: var(--text3); margin-top: 1px; }
.s-item-arr  { margin-left: auto; color: var(--text3); }
.s-empty { padding: 28px 18px; text-align: center; font-size: 13.5px; color: var(--text3); }

/* ── MOBILE OVERLAY ── */
#sb-overlay { display: none; position: fixed; inset: 0; background: rgba(8,6,8,.55); z-index: 15; }

/* ── INSTALL BUTTON ── */
#btn-install {
  display: none;
  align-items: center; gap: 5px;
  height: 34px;
  padding: 0 13px;
  background: var(--acc);
  color: #fff;
  border: none; border-radius: var(--r-pill);
  font-size: 12.5px; font-weight: 700;
  cursor: pointer;
  transition: background var(--t);
  white-space: nowrap;
}
[data-theme="dark"] #btn-install { color: #0d1a2b; }
#btn-install:hover { background: var(--acc2); }
#btn-install.visible { display: flex; }

/* ── FAB SCROLL TO TOP ── */
#fab-top {
  position: fixed; bottom: 22px; right: 20px; z-index: 50;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border2);
  display: none; align-items: center; justify-content: center;
  font-size: 17px; cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
  transition: border-color .2s ease, transform .2s ease;
}
#fab-top:hover { border-color: var(--acc); transform: translateY(-2px); }
#fab-top.visible { display: flex; }

/* ── TOPBAR SEARCH BUTTON ── */
.tb-search-btn { width: 40px; height: 40px; }

/* ── COPYRIGHT NOTICE ── */
#copyright-notice {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 2px 8px;
  font-size: 9px;
  color: var(--text3, #444);
  text-align: center;
  pointer-events: none;
  z-index: 999;
  opacity: 0.4;
  user-select: none;
  -webkit-user-select: none;
}
