:root {
  --navy:    #0C1F33;
  --navy-2:  #0A1A2B;
  --navy-3:  #14334f;
  --gray-bg: #E4E3E0;
  --card:    #FFFFFF;
  --text:    #0C1F33;
  --muted:   #5b6a78;
  --line:    #d8d7d3;
  --accent:  #3a6ea5;
  --danger:  #b3403a;
  --ok:      #2e7d57;
  --sidebar-w: 264px;
  --radius:  14px;
  --shadow:  0 1px 2px rgba(12,31,51,.06), 0 8px 24px rgba(12,31,51,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: var(--gray-bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font-family: inherit; cursor: pointer; }

/* ========================= LAYOUT APP ========================= */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 34px 22px 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar__logo { width: 84px; margin: 0 auto 12px; display: block; }
.sidebar__tag {
  font-size: 11px; letter-spacing: 3px; text-transform: uppercase;
  color: rgba(255,255,255,.55); margin-bottom: 24px; text-align: center;
}
.sidebar__nav { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1; }
.navlink {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 10px;
  color: rgba(255,255,255,.78); text-decoration: none; font-size: 14px;
  border: none; background: transparent; text-align: left; width: 100%;
  transition: background .15s, color .15s;
}
.navlink:hover { background: var(--navy-3); color: #fff; }
.navlink.is-active { background: var(--navy-3); color: #fff; }
.navlink.is-disabled { opacity: .4; cursor: not-allowed; }
.navlink.is-disabled:hover { background: transparent; color: rgba(255,255,255,.78); }
.navlink svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar__user {
  border-top: 1px solid rgba(255,255,255,.1);
  padding-top: 16px; margin-top: 16px;
  font-size: 13px;
}
.sidebar__user .name { font-weight: 600; }
.sidebar__user .role { color: rgba(255,255,255,.5); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.sidebar__actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.sidebar__actions a, .sidebar__actions button {
  font-size: 12px; color: rgba(255,255,255,.8); text-decoration: none;
  background: rgba(255,255,255,.08); border: none; border-radius: 8px;
  padding: 7px 11px; transition: background .15s;
}
.sidebar__actions a:hover, .sidebar__actions button:hover { background: rgba(255,255,255,.18); color:#fff; }

.main { flex: 1; padding: 48px 56px; overflow-y: auto; }
.main__head {
  display: flex; align-items: flex-end; justify-content: space-between;
  flex-wrap: wrap; gap: 18px; margin-bottom: 34px;
}
.main__title { font-size: 30px; font-weight: 700; letter-spacing: -.4px; }
.main__subtitle { color: var(--muted); font-size: 15px; margin-top: 6px; }

.search {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: 9px 16px; min-width: 240px;
}
.search input { border: none; outline: none; font-size: 14px; width: 100%; background: transparent; color: var(--text); }
.search svg { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }

/* ========================= CARDS ========================= */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; text-decoration: none; color: var(--text);
  display: flex; flex-direction: column; gap: 14px; position: relative;
  transition: transform .16s, box-shadow .16s, border-color .16s; box-shadow: var(--shadow);
}
.card:hover { transform: translateY(-3px); border-color: var(--navy); box-shadow: 0 12px 30px rgba(12,31,51,.16); }
.card__icon {
  width: 46px; height: 46px; border-radius: 11px; background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.card__icon svg { width: 24px; height: 24px; }
.card__name { font-size: 17px; font-weight: 650; }
.card__desc { font-size: 13px; color: var(--muted); line-height: 1.45; }
.card__go { margin-top: auto; display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--accent); }
.card__go svg { width: 15px; height: 15px; transition: transform .16s; }
.card:hover .card__go svg { transform: translateX(3px); }
.card.is-disabled { pointer-events: none; opacity: .6; }
.card.is-disabled .card__icon { background: #aeb6bd; }
.card__badge {
  position: absolute; top: 16px; right: 16px; font-size: 10px; letter-spacing: .5px;
  text-transform: uppercase; background: var(--gray-bg); color: var(--muted);
  padding: 4px 9px; border-radius: 999px; font-weight: 600;
}
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 60px 0; font-size: 15px; }

/* ========================= LOGIN ========================= */
.login {
  min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr;
}
.login__brand {
  background: var(--navy); color: #fff;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: 40px; gap: 20px;
}
.login__brand img { width: 180px; }
.login__brand p { color: rgba(255,255,255,.55); letter-spacing: 3px; text-transform: uppercase; font-size: 12px; }
.login__form-wrap { display: flex; align-items: center; justify-content: center; padding: 40px; }
.login__form { width: 100%; max-width: 340px; }
.login__form h1 { font-size: 24px; margin-bottom: 6px; }
.login__form .sub { color: var(--muted); font-size: 14px; margin-bottom: 26px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; outline: none; background: #fff; color: var(--text);
}
.field input:focus { border-color: var(--navy); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--navy); color: #fff; border: none; border-radius: 10px;
  padding: 12px 18px; font-size: 15px; font-weight: 600; width: 100%;
  transition: background .15s;
}
.btn:hover { background: var(--navy-3); }
.btn:disabled { opacity: .6; cursor: default; }
.btn--ghost { background: #fff; color: var(--navy); border: 1px solid var(--line); width: auto; }
.btn--ghost:hover { background: var(--gray-bg); }
.btn--sm { padding: 8px 13px; font-size: 13px; width: auto; }
.btn--danger { background: var(--danger); }
.btn--danger:hover { background: #922f2a; }
.alert {
  background: #fbe7e6; color: var(--danger); border: 1px solid #f3c9c6;
  border-radius: 10px; padding: 11px 14px; font-size: 13px; margin-bottom: 16px; display: none;
}
.alert.show { display: block; }

/* ========================= ADMIN ========================= */
.tabs { display: flex; gap: 6px; margin-bottom: 26px; border-bottom: 1px solid var(--line); }
.tab {
  background: transparent; border: none; padding: 12px 18px; font-size: 14px; font-weight: 600;
  color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.is-active { color: var(--navy); border-bottom-color: var(--navy); }
.panel { display: none; }
.panel.is-active { display: block; }

.toolbar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; align-items: center; }
.toolbar .spacer { flex: 1; }

.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--line); }
th { background: #f4f4f2; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
tr:last-child td { border-bottom: none; }
td .muted { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }

.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.tag--admin { background: #e3edf7; color: var(--accent); }
.tag--off { background: #f3d9d7; color: var(--danger); }
.tag--on { background: #d8efe3; color: var(--ok); }
.tag--ad { background: #ece9f7; color: #6a4ea5; }

/* toggle switch */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { display: none; }
.switch .slider {
  position: absolute; inset: 0; background: #c4c8cc; border-radius: 999px; transition: .15s;
}
.switch .slider::before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .15s;
}
.switch input:checked + .slider { background: var(--navy); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* modal */
.modal-bg {
  position: fixed; inset: 0; background: rgba(12,31,51,.45);
  display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50;
}
.modal-bg.show { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); width: 100%; max-width: 460px;
  padding: 26px; box-shadow: 0 20px 60px rgba(12,31,51,.3); max-height: 90vh; overflow-y: auto;
}
.modal h2 { font-size: 19px; margin-bottom: 18px; }
.modal .field textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; outline: none; resize: vertical; min-height: 64px; font-family: inherit;
}
.modal .field select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; background: #fff;
}
.modal .field input[type="text"], .modal .field input[type="url"] {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; outline: none;
}
.check-row { display: flex; align-items: center; gap: 10px; font-size: 14px; margin: 4px 0 4px; }
.modal__actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

/* access matrix */
.access-list { display: flex; flex-direction: column; gap: 4px; }
.access-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 4px; border-bottom: 1px solid var(--line);
}
.access-row:last-child { border-bottom: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: #fff; border: none; padding: 7px 12px; font-size: 12px; font-weight: 600; color: var(--muted); border-left: 1px solid var(--line); }
.seg button:first-child { border-left: none; }
.seg button.is-on { background: var(--navy); color: #fff; }
.access-row .eff { font-size: 11px; color: var(--muted); min-width: 90px; text-align: right; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; box-shadow: var(--shadow); z-index: 60; opacity: 0; transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.err { background: var(--danger); }

/* ========================= PAGINACAO ========================= */
.pager {
  display: flex; align-items: center; gap: 14px;
  justify-content: flex-end; margin-top: 16px;
}
.pager__info { font-size: 13px; color: var(--muted); }
.pager .btn:disabled { opacity: .45; cursor: default; }

/* ========================= ICONES IMAGEM ========================= */
.icon-img { width: 100%; height: 100%; object-fit: contain; display: block; border-radius: 6px; }
.navlink__icon { display: inline-flex; width: 18px; height: 18px; align-items: center; justify-content: center; flex-shrink: 0; }
.navlink__icon svg { width: 18px; height: 18px; }
.navlink__icon img { width: 18px; height: 18px; object-fit: contain; }
.card__icon.has-img { padding: 6px; } /* mantem o fundo navy do .card__icon */

/* editor de icone no modal */
.icon-edit { display: flex; gap: 14px; align-items: flex-start; }
.icon-preview {
  width: 52px; height: 52px; border-radius: 12px; background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; overflow: hidden;
}
.icon-preview.has-img { padding: 6px; } /* mantem o fundo navy */
.icon-preview svg { width: 26px; height: 26px; }
.icon-edit__body { flex: 1; }
.icon-src { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 10px; }
.icon-src button { background: #fff; border: none; padding: 7px 12px; font-size: 12px; font-weight: 600; color: var(--muted); border-left: 1px solid var(--line); }
.icon-src button:first-child { border-left: none; }
.icon-src button.is-on { background: var(--navy); color: #fff; }
.icon-pane { display: none; }
.icon-pane.is-on { display: block; }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* busca AD (adicionar manualmente) */
.ad-results { margin-top: 14px; max-height: 320px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.ad-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.ad-item:last-child { border-bottom: none; }
.ad-item .meta .nm { font-weight: 600; font-size: 14px; }
.ad-item .meta .un { color: var(--muted); font-size: 12px; }
.ad-empty { padding: 18px; color: var(--muted); font-size: 13px; text-align: center; }

/* ========================= RESPONSIVE ========================= */
@media (max-width: 860px) {
  .login { grid-template-columns: 1fr; }
  .login__brand { display: none; }
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static; flex-direction: row;
    align-items: center; padding: 14px 18px; flex-wrap: wrap; gap: 10px;
  }
  .sidebar__tag, .sidebar__nav, .sidebar__user { display: none; }
  .sidebar__logo { margin: 0; width: 90px; }
  .main { padding: 24px 18px; }
  .main__head { flex-direction: column; align-items: stretch; }
}
