/* ============================================================
   AppSistems — Portal de sistemas
   Tema escuro "workspace com abas"
   ============================================================ */

:root {
  --bg: #0f1416;
  --panel: #151c1f;
  --panel-2: #1a2226;
  --tabbar: #11171a;
  --line: #222c31;
  --line-2: #2c3a42;
  --text: #e6ecea;
  --soft: #c9d4d0;
  --muted: #9aaba4;
  --accent: #4ade80;
  --accent-text: #6ee7a0;
  --accent-ink: #0f1416;
  --active: #22312a;
  --hover: #1c2529;
  --warn-bg: #3a2c12;
  --warn-text: #f5c56b;
  --strong: #ffffff;
  --nav-text: #dfe7e4;
  --sub-text: #a9b8b2;
  --sub-open: #cfe9da;
  --tab-hover: rgba(255,255,255,.03);
  --card-line: #26323a;
  --accent-hover: #6ee7a0;
  --shadow: none;
  color-scheme: dark;

  --side-w: 264px;
  --side-w-collapsed: 76px;
  --radius: 16px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- Tema claro (sol) ---------- */
:root[data-theme="light"] {
  --bg: #eef1ef;
  --panel: #ffffff;
  --panel-2: #ffffff;
  --tabbar: #f5f7f6;
  --line: #dde3df;
  --line-2: #cdd6d0;
  --text: #17201b;
  --soft: #3a4640;
  --muted: #5a6961;
  --accent: #15803d;
  --accent-text: #15803d;
  --accent-ink: #ffffff;
  --accent-hover: #166534;
  --active: #dcf3e4;
  --hover: #e4e9e6;
  --warn-bg: #fdf0d9;
  --warn-text: #8a4b08;
  --strong: #0b130f;
  --nav-text: #24302a;
  --sub-text: #4a5851;
  --sub-open: #166534;
  --tab-hover: rgba(0,0,0,.04);
  --card-line: #dde3df;
  --shadow: 0 1px 2px rgba(16,40,28,.06);
  color-scheme: light;
}
:root[data-theme="light"] .card { box-shadow: var(--shadow); }
:root[data-theme="light"] .panel { box-shadow: 0 1px 3px rgba(16,40,28,.06); }

.theme-btn { margin-left: auto; width: 40px; height: 40px; flex: 0 0 40px; }
.theme-btn .sun { display: none; }
:root[data-theme="light"] .theme-btn .sun { display: block; }
:root[data-theme="light"] .theme-btn .moon { display: none; }
.app.collapsed .user { flex-direction: column; gap: 8px; }
.app.collapsed .theme-btn { margin-left: 0; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
a { color: var(--accent-text); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Estrutura ---------- */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Menu lateral ---------- */
.sidebar {
  width: var(--side-w);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  padding: 12px 12px 16px;
  background: var(--bg);
  transition: width .2s ease;
  overflow: hidden;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px;
  padding: 0 4px 14px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; white-space: nowrap; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 12px; color: var(--muted); }

.icon-btn {
  width: 44px; height: 44px; flex: 0 0 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 10px;
  background: var(--hover); color: var(--soft);
  cursor: pointer;
}
.icon-btn:hover { color: var(--strong); background: var(--line-2); }

.nav { flex: 1; overflow-y: auto; overflow-x: hidden; margin: 0 -4px; padding: 0 4px; scrollbar-width: thin; }
.nav-section {
  font-size: 11px; font-weight: 600; letter-spacing: 1.2px;
  color: var(--muted);
  padding: 18px 12px 6px;
  white-space: nowrap;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 44px;
  padding: 10px 12px;
  border: 0; border-radius: 10px;
  background: transparent; color: var(--nav-text);
  font-weight: 600; text-align: left;
  cursor: pointer; white-space: nowrap;
}
.nav-item:hover { background: var(--hover); }
.nav-item.is-active { background: var(--active); color: var(--strong); }
.nav-item.has-active { color: var(--accent-text); }
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-item .chev { width: 16px; height: 16px; transition: transform .15s; color: var(--muted); }
.nav-group.is-open .chev { transform: rotate(180deg); }

.sub { display: none; flex-direction: column; gap: 2px; padding: 2px 0 6px 30px; }
.nav-group.is-open .sub { display: flex; }
.sub-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; min-height: 36px;
  padding: 7px 10px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--sub-text);
  font-size: 13px; text-align: left;
  cursor: pointer; white-space: nowrap;
}
.sub-item:hover { background: var(--hover); color: var(--strong); }
.sub-item.is-open { color: var(--sub-open); }
.sub-item.is-open::before { content: ""; width: 5px; height: 5px; border-radius: 99px; background: var(--accent); margin-left: -13px; }
.sub-item.is-active { background: var(--active); color: var(--strong); font-weight: 600; }
.sub-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; }

.badge {
  font-size: 10px; font-weight: 700; letter-spacing: .3px;
  padding: 2px 7px; border-radius: 99px;
  background: var(--warn-bg); color: var(--warn-text);
  white-space: nowrap; flex: 0 0 auto;
}
.card-top { gap: 8px; }

.user {
  display: flex; align-items: center; gap: 10px;
  padding-top: 14px; margin-top: 12px;
  border-top: 1px solid var(--line);
  white-space: nowrap;
}
.avatar {
  width: 36px; height: 36px; flex: 0 0 36px;
  margin-left: 4px;
  border-radius: 99px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-ink);
  font-size: 13px; font-weight: 700;
}
.user-name { font-size: 13px; font-weight: 600; }

/* Menu recolhido (desktop) */
.app.collapsed .sidebar { width: var(--side-w-collapsed); }
.app.collapsed .brand-text,
.app.collapsed .nav-section,
.app.collapsed .nav-item .label,
.app.collapsed .nav-item .chev,
.app.collapsed .sub,
.app.collapsed .user-name { display: none; }
.app.collapsed .nav-item { justify-content: center; padding: 10px 0; }

/* ---------- Área principal ---------- */
.main {
  flex: 1; min-width: 0;
  display: flex;
  padding: 12px 12px 12px 0;
}
.panel {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

/* Abas */
.tabbar {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px 0;
  background: var(--tabbar);
  border-bottom: 1px solid var(--line);
}
.tabs { display: flex; align-items: flex-end; gap: 4px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: flex; align-items: center; gap: 2px;
  flex: 0 0 auto;
  padding: 0 6px 0 2px;
  border: 1px solid transparent;
  border-radius: 10px 10px 0 0;
  margin-bottom: -1px;
}
.tab:hover { background: var(--tab-hover); }
.tab.is-active { background: var(--panel); border-color: var(--line); border-bottom-color: var(--panel); }
.tab-btn {
  display: flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 10px;
  border: 0; background: transparent;
  color: var(--muted); font-size: 13px; font-weight: 500;
  white-space: nowrap; cursor: pointer;
}
.tab.is-active .tab-btn { color: var(--strong); font-weight: 600; }
.tab-btn svg { width: 15px; height: 15px; }
.tab-close {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 6px;
  background: transparent; color: var(--muted);
  cursor: pointer;
}
.tab-close:hover { background: var(--line-2); color: var(--strong); }
.tab-close svg { width: 14px; height: 14px; stroke-width: 2.4; }

/* Página inicial */
.home { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.home-inner { padding: 36px; display: flex; flex-direction: column; gap: 28px; max-width: 1280px; width: 100%; }
.home-head { display: flex; flex-direction: column; gap: 6px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 1.2px; color: var(--accent-text); }
.home-head h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -.3px; }
.home-head p { margin: 0; font-size: 15px; color: var(--muted); }

.search {
  display: flex; align-items: center; gap: 10px;
  max-width: 520px; height: 46px; padding: 0 14px;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 12px;
  color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; color: var(--text); font: 15px var(--font); }
.search kbd { font: 11px var(--font); color: var(--muted); border: 1px solid var(--line-2); border-radius: 6px; padding: 2px 6px; }

.home-group { display: flex; flex-direction: column; gap: 12px; margin-bottom: 8px; }
.home-group h2 { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  min-height: 116px; padding: 18px;
  background: var(--panel-2); border: 1px solid var(--card-line); border-radius: 12px;
  color: var(--text); text-align: left; cursor: pointer;
  transition: border-color .15s, transform .15s, background-color .2s;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card-top { display: flex; align-items: center; justify-content: space-between; width: 100%; }
.card-name { font-size: 16px; font-weight: 600; }
.card-desc { font-size: 13px; color: var(--muted); }
.card .open-dot { font-size: 11px; color: var(--accent-text); font-weight: 600; }
.empty { color: var(--muted); }
.home-foot { margin-top: auto; padding: 20px 36px; font-size: 12px; color: var(--muted); }

/* Sistema aberto */
.viewer { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.viewer-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.crumb { font-size: 13px; color: var(--muted); }
.crumb::after { content: " /"; }
.viewer-bar strong { font-size: 15px; }
.spacer { flex: 1; }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: 8px;
  background: transparent; color: var(--soft);
  font-size: 13px; font-weight: 500; text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--hover); color: var(--strong); }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-ink); }
.btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }

.frames { flex: 1; position: relative; background: #fff; }
.frame { position: absolute; inset: 0; display: none; }
.frame.is-active { display: block; }
.frame iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.frame-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--panel); color: var(--muted);
}
.spinner { width: 22px; height: 22px; border: 3px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.frame-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 24px; text-align: center;
  background: var(--panel); color: var(--muted);
}
.frame-empty strong { color: var(--text); font-size: 17px; }

/* ---------- Celular / tablet ---------- */
.only-mobile { display: none; }
.backdrop { display: none; }

@media (max-width: 900px) {
  .only-mobile { display: inline-flex; margin-bottom: 6px; }
  .sidebar {
    position: fixed; z-index: 30; top: 0; bottom: 0; left: 0;
    width: 280px !important;
    border-right: 1px solid var(--line);
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .app.drawer-open .sidebar { transform: none; }
  .app.drawer-open .backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.5); }
  .main { padding: 0; }
  .panel { border-radius: 0; border: 0; }
  .home-inner { padding: 24px 16px; }
  .home-foot { padding: 16px; }
  .btn-label-long { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
