:root {
  color-scheme: light;
  --accent: #4c7cf0;
  --accent-hover: #3f6adb;
  --accent-soft: rgba(76, 124, 240, 0.14);
  --glow: color-mix(in srgb, var(--accent) 9%, transparent);
  --bg: #f2f4fa;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f0f2f8;
  --border: #dbe0ea;
  --border-soft: #e6e9f1;
  --text: #1b2233;
  --text-muted: #6b7487;
  --text-dim: #3f4859;
  --ok: #16a34a;
  --ok-bg: rgba(22, 163, 74, 0.12);
  --warn: #d97706;
  --warn-bg: rgba(245, 158, 11, 0.16);
  --err: #e11d48;
  --err-bg: rgba(225, 29, 72, 0.1);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius: 18px;
  --radius-sm: 14px;
  --shadow-sm: 0 1px 2px rgba(31, 41, 90, 0.05), 0 8px 22px -10px rgba(31, 41, 90, 0.14);
  --shadow-md: 0 22px 44px -20px rgba(31, 41, 90, 0.28);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Garante que o atributo "hidden" sempre esconda o elemento, mesmo quando
   uma regra mais especifica (ex: "#algo { display: flex }") do proprio CSS
   da pagina mexe no display dele - sem isso, JS que faz "el.hidden = true"
   pode nao ter efeito nenhum. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  background:
    radial-gradient(900px circle at 0% 0%, var(--glow), transparent 55%),
    radial-gradient(800px circle at 100% 100%, var(--glow), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
}

::selection {
  background: var(--accent-soft);
}

a {
  color: var(--accent-hover);
}

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

/* -------------------------------------------------------------------- */
/* Icones                                                               */
/* -------------------------------------------------------------------- */

.ico {
  display: inline-flex;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  font-style: normal;
}
.ico svg {
  width: 100%;
  height: 100%;
}

/* Quadradinho arredondado colorido que acompanha titulos e menus. */
.chip {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 14px;
  flex-shrink: 0;
  background: var(--accent-soft);
  color: var(--accent);
}
.chip .ico {
  width: 20px;
  height: 20px;
}
.chip.tone-green {
  background: rgba(22, 163, 74, 0.12);
  color: #16a34a;
}
.chip.tone-amber {
  background: rgba(245, 158, 11, 0.16);
  color: #d97706;
}
.chip.tone-rose {
  background: rgba(225, 29, 72, 0.1);
  color: #e11d48;
}
.chip.tone-violet {
  background: rgba(124, 58, 237, 0.11);
  color: #7c3aed;
}
.chip.tone-cyan {
  background: rgba(8, 145, 178, 0.12);
  color: #0891b2;
}

/* -------------------------------------------------------------------- */
/* Marca                                                                */
/* -------------------------------------------------------------------- */

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  flex-shrink: 0;
  color: #fff;
  background: linear-gradient(145deg, var(--accent), var(--accent-hover));
  box-shadow: 0 10px 22px -10px var(--accent);
}
.brand-mark .ico {
  width: 22px;
  height: 22px;
}
.brand.has-logo .brand-mark {
  display: none;
}
.brand img[data-brand-logo] {
  height: 34px;
  width: auto;
  max-width: 130px;
  display: block;
  border-radius: 10px;
  object-fit: contain;
}
.brand h1[data-brand-name] {
  font-size: 17px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* -------------------------------------------------------------------- */
/* Componentes                                                          */
/* -------------------------------------------------------------------- */

.status {
  font-size: 11.5px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--border);
  color: var(--text-dim);
  font-weight: 600;
}
.status.ok {
  background: var(--ok-bg);
  color: var(--ok);
}
.status.warn {
  background: var(--warn-bg);
  color: var(--warn);
}
.status.err {
  background: var(--err-bg);
  color: var(--err);
}

button {
  font-family: inherit;
  transition: border-color 0.15s ease, background-color 0.15s ease, opacity 0.15s ease, transform 0.08s ease,
    box-shadow 0.15s ease, color 0.15s ease;
}
button:active:not(:disabled) {
  transform: translateY(1px) scale(0.99);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--bg-input);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn .ico {
  width: 16px;
  height: 16px;
}
.btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.btn-sm {
  padding: 6px 13px;
  font-size: 12.5px;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 20px -10px var(--accent);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}
.btn-soft {
  background: var(--accent-soft);
  color: var(--text);
}
.btn-soft:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
}
.btn-ghost:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--text);
}

/* Campos de formulario */
.card input:not([type="color"]):not([type="file"]):not([type="checkbox"]),
.card select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
  font-family: inherit;
}
.card select {
  cursor: pointer;
}
.card input[type="color"] {
  width: 100%;
  height: 42px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  cursor: pointer;
}
.card input[type="file"] {
  width: 100%;
  font-size: 12.5px;
  color: var(--text-muted);
}
.card input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 7px 14px;
  border: none;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
input,
select {
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder {
  color: var(--text-muted);
  opacity: 0.75;
}
input:focus,
select:focus {
  outline: none;
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-muted);
  margin: 2px 0 6px;
}

.msg {
  font-size: 12.5px;
  color: var(--text-muted);
}
.msg.ok {
  color: var(--ok);
}
.msg.err {
  color: var(--err);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.card-title h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--text);
}

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.hint {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  margin: 12px 0 0;
}

/* -------------------------------------------------------------------- */
/* App shell: menu flutuante na lateral esquerda + conteudo             */
/* -------------------------------------------------------------------- */

.app-shell {
  display: flex;
  min-height: 100vh;
  align-items: stretch;
  gap: 14px;
  padding: 14px;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  padding: 22px 14px 14px;
  position: sticky;
  top: 14px;
  align-self: flex-start;
  height: calc(100vh - 28px);
}

.sidebar .brand {
  padding: 0 8px;
  margin-bottom: 28px;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 12px 7px 8px;
  border-radius: 20px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: inherit;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.nav-chip {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 14px;
  background: var(--bg-input);
  color: var(--text-muted);
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.nav-chip .ico {
  width: 19px;
  height: 19px;
}
.nav-item:hover {
  background: var(--bg-input);
  color: var(--text);
}
.nav-item:hover .nav-chip {
  color: var(--text);
  transform: scale(1.06);
}
.nav-item.active {
  background: var(--accent-soft);
  color: var(--text);
}
.nav-item.active .nav-chip {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 16px -8px var(--accent);
}
.nav-item.danger:hover {
  background: var(--err-bg);
  color: var(--err);
}
.nav-item.danger:hover .nav-chip {
  background: var(--err-bg);
  color: var(--err);
}

.sidebar-footer {
  border-top: 1px solid var(--border-soft);
  padding-top: 12px;
  margin-top: 12px;
}

.main-content {
  flex: 1;
  min-width: 0;
  padding: 14px 18px 24px;
}
.main-content .page-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 22px;
}
.main-content .page-head h2 {
  font-size: 26px;
  margin: 0;
  font-weight: 750;
  letter-spacing: -0.03em;
}
.main-content .page-head .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  padding: 5px 12px 5px 10px;
  border-radius: 999px;
}
.main-content .page-head .badge .ico {
  width: 15px;
  height: 15px;
  color: var(--ok);
}

/* Telas estreitas: o menu vira uma barra no topo. */
@media (max-width: 820px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 12px;
  }
  .sidebar .brand {
    margin: 0 6px 0 4px;
    padding: 0;
  }
  .sidebar nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 1;
  }
  .nav-item {
    width: auto;
  }
  .sidebar-footer {
    border: none;
    padding: 0;
    margin: 0;
  }
  .main-content {
    padding: 4px 2px 20px;
  }
}

/* Papel de quem esta logado (body.is-admin / body.is-client, aplicado por
   /js/role.js a partir de /api/me): ate carregar, nenhum dos dois grupos
   aparece - o cliente nunca ve, nem por um instante, opcoes de admin. */
body:not(.is-admin) [data-admin-only],
body:not(.is-client) [data-client-only] {
  display: none !important;
}

/* Acesso rapido aos clientes (so admin) - lista no menu lateral que filtra o
   Painel por cliente (/js/clientQuick.js). Ocupa o espaco livre do menu e
   rola sozinha quando ha muitos clientes. */
body.is-admin .sidebar nav {
  flex: 0 0 auto;
}
.client-quick {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border-soft);
}
.client-quick-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 6px;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.client-quick-search {
  margin: 0 4px 6px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
}
.client-quick-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.client-quick-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 12px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  font-weight: 550;
}
.client-quick-item:hover {
  background: var(--bg-input);
  color: var(--text);
}
.client-quick-item.active {
  background: var(--accent-soft);
  color: var(--text);
}
.client-quick-item .dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}
.client-quick-item .dot.on {
  background: var(--ok);
}
.client-quick-item .dot.off {
  background: var(--err);
}
.client-quick-item .label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.client-quick-item.inactive .label {
  color: var(--text-muted);
  text-decoration: line-through;
}
.client-quick-item .count {
  flex: none;
  font-size: 11px;
  font-weight: 650;
  color: var(--text-muted);
  background: var(--bg-input);
  padding: 1px 7px;
  border-radius: 999px;
}
.client-quick-empty {
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-muted);
}
@media (max-width: 820px) {
  .client-quick {
    display: none !important;
  }
  body.is-admin .sidebar nav {
    flex: 1;
  }
}
