:root {
  --primary: #0f766e;
  --primary-dark: #0a4d48;
  --primary-soft: #e7f1f0;
  --accent: #f59e0b;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f3f5f8;
  --card: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 6px 20px rgba(15, 23, 42, .05);
  --side-w: 264px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); line-height: 1.5; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; line-height: 1.2; }
.muted { color: var(--muted); }
img { max-width: 100%; display: block; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em; border: 0; border-radius: 12px; padding: .72em 1.15em;
  font: inherit; font-weight: 700; font-size: .92rem; cursor: pointer; text-decoration: none; transition: background .2s, box-shadow .2s, color .2s, opacity .2s; white-space: nowrap;
}
.btn:disabled { opacity: .6; cursor: wait; }
.btn-sm { padding: .5em .85em; font-size: .84rem; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; color: var(--ink-2); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn-outline:hover { box-shadow: inset 0 0 0 1.5px var(--primary); color: var(--primary); }
.btn-danger { background: #fef2f2; color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-light { background: rgba(255, 255, 255, .12); color: #fff; }
.btn-light:hover { background: rgba(255, 255, 255, .22); }
.btn-text { background: none; color: rgba(255, 255, 255, .7); }
.btn-text:hover { color: #fff; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; cursor: pointer; font-size: 1.15rem; display: inline-grid; place-items: center; color: var(--ink-2); flex: none; }
.icon-btn:hover { background: var(--bg); }
.icon-btn.danger:hover { background: #fef2f2; color: var(--danger); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(800px 400px at 80% 0%, var(--primary-soft), transparent), var(--bg); }
.login-card { width: min(400px, 100%); background: #fff; padding: 36px 32px; border-radius: 24px; box-shadow: 0 20px 60px rgba(15, 23, 42, .12); display: grid; gap: 14px; text-align: center; }
.login-mark { font-size: 2.4rem; }
.login-card h1 { font-size: 1.5rem; }
.login-card p { margin: 0; }
.login-card label { text-align: left; }
.login-hint { font-size: .85rem; color: var(--muted); background: #fffbeb; border-radius: 10px; padding: 10px; }
.login-hint:empty { display: none; }
.back-link { color: var(--muted); font-size: .88rem; text-decoration: none; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--side-w); background: #0b1220; color: #fff; display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 30; transition: transform .25s; }
.side-brand { padding: 22px 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.side-brand .mark { width: 40px; height: 40px; border-radius: 12px; background: var(--primary); display: grid; place-items: center; font-weight: 800; font-size: .85rem; flex: none; overflow: hidden; }
.side-brand .mark img { width: 100%; height: 100%; object-fit: cover; }
.side-brand strong { display: block; font-size: .95rem; line-height: 1.2; }
.side-brand small { color: rgba(255, 255, 255, .5); font-size: .75rem; }
.side-nav { padding: 14px 12px; display: grid; gap: 2px; flex: 1; overflow-y: auto; align-content: start; }
.side-nav a { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; color: rgba(255, 255, 255, .75); text-decoration: none; font-weight: 600; font-size: .93rem; }
.side-nav a span { width: 22px; text-align: center; }
.side-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.side-nav a.active { background: var(--primary); color: #fff; }
.side-foot { padding: 16px; display: grid; gap: 6px; border-top: 1px solid rgba(255, 255, 255, .08); }
.side-overlay { display: none; }
.main { flex: 1; margin-left: var(--side-w); min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 14px 32px; background: rgba(243, 245, 248, .9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 1.25rem; flex: 1; }
#sideToggle { display: none; }
.mode-badge { font-size: .76rem; font-weight: 700; padding: .35em .8em; border-radius: 999px; background: #dcfce7; color: #166534; }
.mode-badge.demo { background: #fef3c7; color: #92400e; }
.content { padding: 28px 32px 80px; max-width: 1100px; }

/* Cards e grids */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.card h2 { font-size: 1.08rem; margin-bottom: 4px; }
.card > .muted:first-of-type { margin: 0 0 18px; font-size: .9rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { background: #fff; border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; transition: transform .15s; }
.kpi:hover { transform: translateY(-2px); }
.kpi span { font-size: 1.5rem; width: 50px; height: 50px; border-radius: 14px; display: grid; place-items: center; background: var(--primary-soft); flex: none; }
.kpi strong { display: block; font-size: 1.6rem; line-height: 1; }
.kpi small { color: var(--muted); font-weight: 600; }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.quick button, .quick a { display: flex; align-items: center; gap: 12px; text-align: left; padding: 16px; border-radius: 14px; border: 1.5px dashed var(--line); background: #fff; font: inherit; font-weight: 600; cursor: pointer; color: var(--ink); text-decoration: none; transition: border-color .2s, background .2s; }
.quick button:hover, .quick a:hover { border-color: var(--primary); background: var(--primary-soft); }
.quick span { font-size: 1.4rem; }
.notice { display: flex; gap: 14px; align-items: flex-start; padding: 16px 18px; border-radius: 14px; background: #fffbeb; border: 1px solid #fde68a; margin-bottom: 20px; font-size: .92rem; }
.notice strong { display: block; margin-bottom: 2px; }
.notice p { margin: 0; color: var(--ink-2); }
.notice.info { background: #eff6ff; border-color: #bfdbfe; }

/* Toolbar e lista */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; align-items: center; }
.toolbar .grow { flex: 1 1 220px; }
.list { display: grid; gap: 10px; }
.row { display: flex; align-items: center; gap: 14px; background: #fff; border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.row.inactive { opacity: .6; }
.row-thumb { width: 64px; height: 48px; border-radius: 10px; flex: none; overflow: hidden; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .9rem; }
.row-thumb img { width: 100%; height: 100%; object-fit: cover; }
.row-main { flex: 1; min-width: 0; }
.row-main strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.pill { font-size: .72rem; font-weight: 700; padding: .25em .65em; border-radius: 999px; background: var(--bg); color: var(--muted); margin-left: 6px; vertical-align: middle; }
.pill.star { background: #fef3c7; color: #92400e; }
.pill.off { background: #fee2e2; color: #991b1b; }
.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); background: #fff; border-radius: var(--radius); border: 2px dashed var(--line); }
.empty-state div { font-size: 2.2rem; }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: .82rem; font-weight: 600; color: var(--muted); user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { width: 38px; height: 22px; border-radius: 999px; background: #cbd5e1; position: relative; transition: background .2s; flex: none; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.switch input:checked + i { background: var(--primary); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { outline: 3px solid var(--primary-soft); }

/* Formulários */
label, .label { display: grid; gap: 6px; font-weight: 600; font-size: .88rem; color: var(--ink-2); }
input[type="text"], input[type="password"], input[type="search"], input[type="email"], input[type="tel"], input[type="url"], input[type="date"], input:not([type]), select, textarea {
  width: 100%; font: inherit; font-weight: 400; font-size: .95rem; color: var(--ink); border: 1.5px solid var(--line); border-radius: 12px; padding: .7em .9em; background: #fff; transition: border-color .2s, box-shadow .2s;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.stack { display: grid; gap: 16px; }
.full { grid-column: 1 / -1; }
.color-field { display: flex; gap: 10px; align-items: center; }
.color-field input[type="color"] { width: 52px; height: 44px; border: 1.5px solid var(--line); border-radius: 12px; padding: 3px; background: #fff; cursor: pointer; flex: none; }
.form-section { font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--primary); margin: 10px 0 -4px; }
.save-bar { position: sticky; bottom: 16px; display: flex; justify-content: flex-end; gap: 10px; align-items: center; background: #fff; padding: 12px 16px; border-radius: 14px; box-shadow: 0 10px 30px rgba(15, 23, 42, .14); margin-top: 8px; z-index: 5; }
.save-bar span { flex: 1; color: var(--muted); font-size: .88rem; }
.save-bar.dirty span { color: #b45309; font-weight: 600; }

/* Lista repetível */
.repeat { display: grid; gap: 8px; }
.repeat-row { display: flex; gap: 8px; align-items: center; }
.repeat-row input { flex: 1; }
.repeat-row input.small { flex: 0 0 120px; }
.add-link { justify-self: start; background: none; border: 0; color: var(--primary); font: inherit; font-weight: 700; cursor: pointer; padding: 4px 0; }

/* Imagens */
.img-field { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.img-preview { width: 120px; height: 80px; border-radius: 12px; background: var(--bg) center / cover no-repeat; border: 1.5px dashed var(--line); display: grid; place-items: center; color: var(--muted); font-size: .78rem; flex: none; overflow: hidden; }
.img-preview.square { width: 80px; }
.img-preview img { width: 100%; height: 100%; object-fit: cover; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.photo { position: relative; aspect-ratio: 4 / 3; border-radius: 12px; overflow: hidden; background: var(--bg); }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo .cover-tag { position: absolute; top: 6px; left: 6px; background: var(--accent); color: #1f1300; font-size: .7rem; font-weight: 800; padding: .2em .6em; border-radius: 999px; }
.photo .ph-actions { position: absolute; inset: auto 6px 6px 6px; display: flex; gap: 4px; justify-content: flex-end; }
.photo .ph-actions button { width: 30px; height: 30px; border-radius: 8px; border: 0; background: rgba(255, 255, 255, .95); cursor: pointer; font-size: .85rem; box-shadow: 0 1px 4px rgba(0, 0, 0, .2); }
.photo .ph-actions button:hover { background: #fff; color: var(--primary); }
.photo .ph-actions button.del:hover { color: var(--danger); }
.dropzone { aspect-ratio: 4 / 3; border-radius: 12px; border: 2px dashed var(--line); display: grid; place-items: center; text-align: center; color: var(--muted); font-size: .82rem; font-weight: 600; cursor: pointer; background: #fff; transition: border-color .2s, background .2s; padding: 8px; }
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }
.dropzone b { display: block; font-size: 1.6rem; }
.uploading { pointer-events: none; opacity: .6; }

/* Categorias */
.cat-row input.emoji { width: 64px; text-align: center; font-size: 1.2rem; padding: .45em; flex: none; }
.cat-row .cat-names { flex: 1; min-width: 0; display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 6px; }
.cat-row input.tr { font-size: .86rem; background: var(--bg); }
.tr-card summary { cursor: pointer; list-style: none; position: relative; padding-right: 32px; }
.tr-card summary::-webkit-details-marker { display: none; }
.tr-card summary::after { content: "▾"; position: absolute; right: 0; top: 0; font-size: 1.2rem; color: var(--muted); transition: transform .2s; }
.tr-card[open] summary::after { transform: rotate(180deg); }
.tr-card:not([open]) summary .muted { margin-bottom: 0; }
.tr-card summary .muted { margin: 4px 0 18px; font-size: .9rem; }
@media (max-width: 760px) { .cat-row .cat-names { grid-template-columns: 1fr; } }
.cat-row .count { font-size: .8rem; color: var(--muted); white-space: nowrap; width: 80px; text-align: right; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 4px; }
.emoji-pick button { width: 36px; height: 36px; border: 0; background: var(--bg); border-radius: 8px; cursor: pointer; font-size: 1.1rem; }
.emoji-pick button:hover { background: var(--primary-soft); }

/* Visitas */
.seg { display: inline-flex; background: #fff; border-radius: 12px; padding: 4px; box-shadow: var(--shadow); }
.seg button { border: 0; background: none; font: inherit; font-weight: 700; font-size: .85rem; color: var(--muted); padding: .5em .9em; border-radius: 9px; cursor: pointer; }
.seg button.active { background: var(--primary); color: #fff; }
.toolbar .grow, .card .grow { flex: 1; }
.kpi-hint { display: block; font-style: normal; font-size: .74rem; color: var(--muted); margin-top: 2px; }
.vgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; margin-bottom: 20px; }
.vgrid .card { margin: 0; }
.small-empty { font-size: .9rem; margin: 0; }

.chart { display: flex; gap: 8px; height: 220px; padding-top: 8px; }
.chart-y { display: flex; flex-direction: column; justify-content: space-between; font-size: .72rem; color: var(--muted); text-align: right; padding-bottom: 22px; min-width: 22px; }
.chart-plot { position: relative; flex: 1; min-width: 0; }
.chart-grid { position: absolute; inset: 0 0 22px 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.chart-grid i { border-top: 1px dashed var(--line); }
.chart-grid i:last-child { border-top: 1px solid #cbd5e1; }
.bars { position: absolute; inset: 0; display: flex; align-items: stretch; gap: 2px; }
.bar-col { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; padding-bottom: 22px; cursor: default; outline: none; }
.bar-col i { display: block; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 0; transition: opacity .15s; max-width: 28px; width: 100%; margin: 0 auto; }
.bar-col:hover i, .bar-col:focus i { opacity: .75; }
.bar-col:hover::before, .bar-col:focus::before { content: ""; position: absolute; inset: 0 0 22px 0; background: rgba(15, 23, 42, .04); border-radius: 6px; }
.bar-col:hover::after, .bar-col:focus::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% - 4px); left: 50%; transform: translateX(-50%); white-space: nowrap; z-index: 3;
  background: var(--ink); color: #fff; font-size: .78rem; font-weight: 600; padding: 6px 10px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
}
.bar-x { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); font-size: .7rem; color: var(--muted); white-space: nowrap; }

.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 40%) 1fr auto; gap: 10px; align-items: center; font-size: .88rem; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.hbar-track { height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.hbar-track i { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.hbar-val { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
.hbar-val small { font-weight: 500; color: var(--muted); }

.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 0 0 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; padding-left: 12px; width: 70px; }
.tbl-sub { display: block; color: var(--muted); font-size: .78rem; }

.feed { display: grid; gap: 8px; }
.feed-item { border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.feed-item summary { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 12px 14px; cursor: pointer; list-style: none; font-size: .9rem; }
.feed-item summary::-webkit-details-marker { display: none; }
.feed-item[open] summary { border-bottom: 1px solid var(--line); }
.feed-who { min-width: 130px; }
.feed-meta { color: var(--muted); font-size: .82rem; flex: 1; min-width: 160px; }
.feed-count { font-size: .82rem; font-weight: 600; color: var(--primary-dark); }
.feed-time { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.feed-acts { margin: 0; padding: 10px 14px 14px 14px; list-style: none; display: grid; gap: 8px; font-size: .88rem; }
.feed-acts li { display: flex; gap: 10px; align-items: baseline; }
.feed-acts time { color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; min-width: 40px; }

/* Gaveta */
.drawer { position: fixed; inset: 0; z-index: 60; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .5); animation: fade .2s; }
.drawer-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(720px, 100%); background: var(--bg); display: flex; flex-direction: column; animation: slide .25s ease-out; box-shadow: -20px 0 50px rgba(0, 0, 0, .15); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; background: #fff; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 1.15rem; }
.drawer-body { flex: 1; overflow-y: auto; padding: 22px 24px; display: grid; gap: 16px; align-content: start; }
.drawer-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 24px; background: #fff; border-top: 1px solid var(--line); }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; z-index: 200; background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 14px; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, .2); transition: all .3s; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: #b91c1c; }
.toast-success { background: #15803d; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .side-overlay.open { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 25; }
  .main { margin-left: 0; }
  #sideToggle { display: inline-grid; }
  .topbar { padding: 12px 16px; }
  .content { padding: 20px 16px 80px; }
}
@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .card { padding: 18px; }
  .row { flex-wrap: wrap; }
  .row-main { flex-basis: calc(100% - 80px); }
  .row-actions { width: 100%; justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 8px; }
  .drawer-body { padding: 18px 16px; }
  .drawer-head, .drawer-foot { padding: 14px 16px; }
  .cat-row .count { display: none; }
  .mode-badge { display: none; }
}
