:root {
  --bg: #0b1020;
  --panel: #121933;
  --panel-2: #0f162f;
  --line: #263159;
  --text: #eef2ff;
  --muted: #9aa6d1;
  --primary: #5b8cff;
  --primary-2: #7aa2ff;
  --success: #22c55e;
  --danger: #ef4444;
  --danger-2: #b91c1c;
  --warning: #f59e0b;
  --shadow: 0 20px 45px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Arial, sans-serif;
  background: linear-gradient(180deg, #0a0f1d 0%, #0d1430 100%);
  color: var(--text);
}

/* =========================
   LOGIN E REGISTRO
========================= */

body {
  min-height: 100vh;
}

.container {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.container .card {
  width: 100%;
  max-width: 380px;
}

.card {
  background: rgba(18, 25, 51, 0.92);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin-top: 0;
  margin-bottom: 10px;
}

label {
  display: block;
  margin: 14px 0 8px;
  font-size: 14px;
  color: var(--muted);
}

input,
textarea,
select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 0 12px;
  font-size: 14px;
}

input,
select {
  height: 42px;
}

textarea {
  min-height: 100px;
  resize: vertical;
  padding: 12px;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--panel-2) inset;
  box-shadow: 0 0 0 1000px var(--panel-2) inset;
  transition: background-color 5000s ease-in-out 0s;
  border: 1px solid var(--line);
}

button {
  border: none;
  cursor: pointer;
  font-weight: 700;
  border-radius: 12px;
}

.container form button[type="submit"] {
  width: 100%;
  margin-top: 16px;
  height: 42px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white;
}

.message {
  margin-top: 10px;
  text-align: center;
  font-size: 14px;
}

.subtitle {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.password-wrap {
  position: relative;
}

.password-wrap input {
  padding-right: 48px;
}

.toggle-password {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  height: 34px;
  width: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  margin-top: 0;
}

.toggle-password ion-icon {
  font-size: 18px;
  color: var(--muted);
}

.toggle-password:hover {
  color: var(--text);
  border-color: var(--primary);
}

/* =========================
   DASHBOARD
========================= */

.app-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: rgba(8, 12, 24, 0.92);
  border-right: 1px solid var(--line);
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-badge {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: grid;
  place-items: center;
  font-weight: 700;
  color: white;
}

.brand h1 {
  font-size: 16px;
  margin: 0;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.sidebar-nav {
  margin-top: 20px;
}

.nav-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 10px 10px;
}

.nav-btn {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  cursor: pointer;
  margin-bottom: 8px;
  transition: 0.2s ease;
  font-size: 14px;
  font-weight: 600;
}

.nav-btn:hover,
.nav-btn.active {
  background: var(--panel);
  border-color: var(--line);
}

.sidebar-footer {
  margin-top: 28px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
}

.sidebar-footer strong {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
}

.sidebar-footer span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.main-content {
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.topbar h2 {
  margin: 0;
  font-size: 26px;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.select {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
  min-width: 220px;
  min-height: 44px;
}

.btn {
  width: auto;
  min-width: 120px;
  min-height: 44px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: 0.2s ease;
  margin-top: 0;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
}

.btn.danger {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.08);
  color: #fff;
}

.btn.danger:hover {
  border-color: rgba(239, 68, 68, 0.7);
  background: rgba(239, 68, 68, 0.14);
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 24px;
}

.card-header {
  padding: 20px 22px 0;
}

.card-header h3 {
  margin: 0;
  font-size: 18px;
}

.card-header p {
  color: var(--muted);
  margin: 8px 0 0;
  font-size: 13px;
}

.card-body {
  padding: 20px 22px 22px;
}

.stat {
  padding: 18px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.stat small {
  color: var(--muted);
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
}

.stat strong {
  font-size: 30px;
  display: block;
}

.placeholder-box {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
}

.grid-two {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 18px;
  align-items: start;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 8px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}

.prefeitura-list {
  display: grid;
  gap: 12px;
}

.list-item {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.02);
}

.list-item strong {
  font-size: 15px;
}

.list-item span {
  color: var(--muted);
  font-size: 13px;
}

textarea.input,
.textarea {
  min-height: 100px;
  resize: vertical;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
}

.textarea:focus,
textarea.input:focus {
  outline: none;
  border-color: var(--primary);
}

#prefeituraMessage,
#agenteMessage,
#regraMessage,
#templateMessage {
  min-height: 20px;
  margin: 0;
  font-size: 14px;
}

.list-item .btn {
  min-width: 95px;
  min-height: 38px;
  padding: 8px 12px;
  font-size: 13px;
}

.list-item .btn-delete-prefeitura,
.list-item .btn-delete-agente,
.list-item .btn-delete-regra,
.list-item .btn-delete-template {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.08);
}

.list-item .btn-delete-prefeitura:hover,
.list-item .btn-delete-agente:hover,
.list-item .btn-delete-regra:hover,
.list-item .btn-delete-template:hover {
  border-color: rgba(239, 68, 68, 0.7);
  background: rgba(239, 68, 68, 0.14);
}

.list-item .btn-edit-prefeitura:hover,
.list-item .btn-edit-agente:hover,
.list-item .btn-edit-regra:hover,
.list-item .btn-edit-template:hover {
  border-color: var(--primary);
}

@media (max-width: 1100px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    position: relative;
  }

  .grid.stats {
    grid-template-columns: 1fr;
  }

  .grid-two,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .main-content {
    padding: 18px;
  }
}