:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1d2129;
  --muted: #6b7280;
  --border: #e3e5e8;
  --primary: #b91c1c;
  --primary-dark: #991b1b;
  --sidebar: #16181d;
  --sidebar-text: #c9ccd3;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --info: #1d4ed8;
  --whatsapp: #128c4a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 8px rgba(0, 0, 0, 0.04);
  font-family:
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
  font-size: 15px;
  color: var(--text);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
}

a {
  color: var(--primary);
}

h1 {
  font-size: 1.45rem;
  margin: 0;
}

h2 {
  font-size: 1.1rem;
  margin: 0 0 12px;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

/* Layout */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 230px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  padding: 18px 20px;
  font-weight: 700;
  font-size: 1.2rem;
  color: #fff;
  letter-spacing: 0.5px;
}

.brand span {
  color: #ef4444;
}

.nav {
  display: flex;
  flex-direction: column;
  padding: 0 10px 10px;
  gap: 2px;
}

.nav .group {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #7c818c;
  padding: 14px 10px 4px;
}

.nav a {
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 7px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav a:hover {
  background: #23262d;
  color: #fff;
}

.nav a.active {
  background: var(--primary);
  color: #fff;
}

.nav .count {
  background: #ef4444;
  color: #fff;
  border-radius: 999px;
  padding: 0 7px;
  font-size: 0.75rem;
}

.sidebar .user {
  margin-top: auto;
  padding: 14px 20px;
  border-top: 1px solid #262a31;
  font-size: 0.85rem;
}

.sidebar .user button {
  margin-top: 6px;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 24px 28px 60px;
}

.topbar {
  display: none;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}

.toolbar input,
.toolbar select {
  width: auto;
  min-width: 160px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.stat .label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat .value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 4px;
}

.stat .sub {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 2px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr));
  gap: 18px;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: none;
}

td.actions {
  white-space: nowrap;
  text-align: right;
}

td.num,
th.num {
  text-align: right;
  white-space: nowrap;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

/* Forms */
label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: #374151;
}

input,
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cfd3d9;
  border-radius: 7px;
  font: inherit;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(185, 28, 28, 0.25);
  border-color: var(--primary);
}

input[type='checkbox'] {
  width: auto;
}

input[type='color'] {
  height: 38px;
  padding: 2px;
}

textarea {
  min-height: 70px;
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px 14px;
}

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

.check {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 500;
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 3px;
}

/* Buttons */
button,
.btn {
  border: 1px solid #cfd3d9;
  background: #fff;
  color: var(--text);
  padding: 7px 13px;
  border-radius: 7px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

button:hover,
.btn:hover {
  background: #f3f4f6;
}

button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

button.primary:hover {
  background: var(--primary-dark);
}

button.whatsapp {
  background: var(--whatsapp);
  border-color: var(--whatsapp);
  color: #fff;
}

button.whatsapp:hover {
  background: #0e7a3f;
}

button.danger {
  color: var(--danger);
  border-color: #f0c4c4;
}

button.sm {
  padding: 4px 9px;
  font-size: 0.8rem;
}

button.link {
  border: none;
  background: none;
  color: var(--primary);
  padding: 0;
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

.sidebar button {
  background: transparent;
  color: var(--sidebar-text);
  border-color: #3a3f48;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #eef0f3;
  color: #4b5563;
  white-space: nowrap;
}

.badge.ok {
  background: #dcfce7;
  color: var(--ok);
}

.badge.warn {
  background: #fef3c7;
  color: var(--warn);
}

.badge.danger {
  background: #fee2e2;
  color: var(--danger);
}

.badge.info {
  background: #dbeafe;
  color: var(--info);
}

.belt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.belt i {
  display: inline-block;
  width: 26px;
  height: 10px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

.progress {
  height: 7px;
  background: #eceef1;
  border-radius: 99px;
  overflow: hidden;
  min-width: 80px;
}

.progress > div {
  height: 100%;
  background: var(--primary);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 21, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 640px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal header h2 {
  margin: 0;
}

.modal .body {
  padding: 18px 20px;
}

.modal footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal .error {
  color: var(--danger);
  margin-top: 10px;
}

/* Toast */
#toasts {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.toast {
  background: #1f2937;
  color: #fff;
  padding: 11px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 380px;
}

.toast.error {
  background: var(--danger);
}

.toast.warn {
  background: var(--warn);
}

/* Login */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #16181d, #3b0d0d);
  padding: 16px;
}

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

.login .brand {
  color: var(--text);
  padding: 0 0 16px;
  font-size: 1.5rem;
}

.login form > * + * {
  margin-top: 12px;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.tabs button {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  padding: 8px 12px;
}

.tabs button.active {
  border-bottom-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.kv {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 6px 12px;
  font-size: 0.92rem;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
}

pre.message {
  white-space: pre-wrap;
  font-family: inherit;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0;
}

@media (max-width: 860px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    display: none;
  }

  .sidebar.open {
    display: flex;
  }

  .topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--sidebar);
    color: #fff;
    padding: 10px 16px;
  }

  .topbar .brand {
    padding: 0;
  }

  .main {
    padding: 16px;
  }

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

/* App instalável (PWA) */
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand span {
  margin-left: -5px;
}

.brand img {
  border-radius: 50%;
}

.login .card {
  text-align: center;
}

.login form {
  text-align: left;
}

.login .brand {
  justify-content: center;
}

.login-logo {
  display: block;
  margin: 0 auto 6px;
  background: #16181d;
  border-radius: 50%;
  padding: 6px;
}

.offline {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--warn);
  color: #fff;
  text-align: center;
  font-size: 0.85rem;
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
}

.sidebar button.install {
  display: block;
  width: 100%;
  margin: 0 0 12px;
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  justify-content: center;
}

.bottom-nav {
  display: none;
}

.install-steps {
  margin: 0;
  padding-left: 20px;
  line-height: 1.8;
}

@media (max-width: 860px) {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    padding-top: calc(10px + env(safe-area-inset-top));
  }

  .topbar .brand {
    font-size: 1.05rem;
  }

  .topbar button {
    background: transparent;
    color: #fff;
    border-color: #3a3f48;
    font-size: 1.1rem;
  }

  .sidebar.open {
    position: fixed;
    inset: 0;
    z-index: 30;
    height: auto;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .main {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }

  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    background: var(--sidebar);
    border-top: 1px solid #262a31;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .bottom-nav a,
  .bottom-nav button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 2px;
    font-size: 0.7rem;
    color: var(--sidebar-text);
    text-decoration: none;
    background: none;
    border: none;
    border-radius: 0;
  }

  .bottom-nav .ico {
    font-size: 1.25rem;
    line-height: 1;
  }

  .bottom-nav a.active {
    color: #fff;
    box-shadow: inset 0 2px 0 var(--primary);
  }

  .modal-backdrop {
    padding: calc(16px + env(safe-area-inset-top)) 10px 16px;
  }

  #toasts {
    bottom: calc(76px + env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
  }

  .toast {
    max-width: none;
  }
}
