:root {
  --navy: #0F3D6E;
  --navy-dark: #0A2C51;
  --navy-deep: #0B1626;
  --green: #1FA35A;
  --gold: #D8B23C;
  --red: #CE2E3D;
  --text: #1F2430;
  --muted: #6E7278;
  --border: #E4E7EB;
  --bg: #F5F7FA;
  --card-bg: #FFFFFF;
  --sidebar-w: 236px;
  --toast-bg: #1F2430;
  --toast-text: #fff;
  --overlay-bg: rgba(10, 24, 42, .62);
}

@media (prefers-color-scheme: dark) {
  :root {
    --navy: #1a5a9e;
    --navy-dark: #0e3a6b;
    --navy-deep: #0a1420;
    --green: #2bc96e;
    --gold: #e6c84a;
    --red: #e85563;
    --text: #E4E8EE;
    --muted: #8E929A;
    --border: #2D3540;
    --bg: #111820;
    --card-bg: #19212B;
    --toast-bg: #E4E8EE;
    --toast-text: #111820;
    --overlay-bg: rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ============ Sidebar ============ */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 100;
  background: linear-gradient(180deg, #0D1B2E 0%, var(--navy-deep) 100%);
  display: flex; flex-direction: column; padding: 20px 14px 16px;
  border-right: 1px solid rgba(255,255,255,.06);
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.side-brand .brand-icon { border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.4); flex-shrink: 0; }
.side-brand .brand-mark { color: #fff; font-weight: 800; letter-spacing: .05em; font-size: 17px; }
.side-brand .brand-sub { display: block; font-size: 10.5px; font-weight: 500; letter-spacing: .02em; color: rgba(255,255,255,.45); margin-top: 1px; }

.side-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 18px; flex: 1; }
.side-nav a {
  display: flex; align-items: center; gap: 11px;
  color: rgba(255,255,255,.72); text-decoration: none;
  font-size: 13.5px; font-weight: 600; padding: 10px 12px; border-radius: 9px;
  border-left: 3px solid transparent; transition: all .13s ease;
}
.side-nav a svg { flex-shrink: 0; opacity: .85; }
.side-nav a:hover { color: #fff; background: rgba(255,255,255,.06); }
.side-nav a.nav-active {
  color: #fff; background: rgba(216,178,60,.12); border-left-color: var(--gold);
}
.side-actions { padding: 12px 4px; border-top: 1px solid rgba(255,255,255,.08); }
.side-actions .btn { width: 100%; text-align: center; }
.side-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 8px 0; }
.side-user .who { font-size: 12px; color: rgba(255,255,255,.55); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user a { color: rgba(255,255,255,.75); font-size: 12.5px; font-weight: 700; text-decoration: none; }
.side-user a:hover { color: #fff; }

/* ============ Conteúdo ============ */
.content { margin-left: var(--sidebar-w); min-height: 100vh; }
main { max-width: 1080px; margin: 0 auto; padding: 34px 28px 70px; }

h1 { font-size: 23px; font-weight: 800; margin: 4px 0 22px; color: var(--text); letter-spacing: -.01em; }
h3 { font-size: 16px; font-weight: 700; margin: 0 0 4px; color: var(--text); }
h4 { font-size: 12.5px; font-weight: 700; margin: 20px 0 4px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ============ Tabelas ============ */
table { width: 100%; border-collapse: collapse; background: var(--card-bg); box-shadow: 0 1px 3px rgba(16,24,40,.07); border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: 12px 15px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { background: var(--bg); color: var(--muted); font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s ease; }
tbody tr:hover { background: rgba(0,0,0,.02); }

/* ============ Botões ============ */
.btn {
  display: inline-block; padding: 8px 16px; border-radius: 9px; border: none; cursor: pointer;
  font-size: 13px; font-weight: 700; text-decoration: none; transition: all .12s ease;
}
.btn:hover { filter: brightness(1.07); transform: translateY(-1px); box-shadow: 0 3px 10px rgba(15,61,110,.18); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn-primary { background: linear-gradient(135deg, #145087 0%, var(--navy) 100%); color: #fff; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-danger { background: #FBE7E8; color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; box-shadow: 0 3px 10px rgba(206,46,61,.25); }

/* ============ Cards ============ */
.card {
  background: var(--card-bg); padding: 24px; border-radius: 14px;
  box-shadow: 0 1px 3px rgba(16,24,40,.07); border: 1px solid var(--border); margin-bottom: 20px;
}
.card > h3 { margin-bottom: 2px; }
.card > p { margin-top: 4px; }

/* ============ Formulários ============ */
label { display: block; font-size: 12.5px; font-weight: 700; margin: 13px 0 5px; color: var(--text); opacity: .8; }
input[type=text], input[type=email], input[type=number], input[type=password], select, textarea {
  width: 100%; padding: 10px 11px; border: 1px solid var(--border); border-radius: 9px; box-sizing: border-box;
  font-size: 14px; background: var(--card-bg); color: var(--text); font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(15,61,110,.12);
}
.filter-row { display: grid; grid-template-columns: 1fr 1fr 120px 1fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }
form.inline { display: inline; }

/* ============ Tags / Pills ============ */
.tag { display: inline-block; background: #EAF1FB; color: var(--navy); padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; margin: 0 4px 4px 0; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.status-ok, .pill-ok { color: var(--green); background: rgba(31,163,90,.12); }
.status-off, .pill-off { color: var(--muted); background: rgba(110,114,120,.12); }
.pill-error { color: var(--red); background: rgba(206,46,61,.12); }
.status-ok, .status-off { padding: 3px 10px; border-radius: 999px; font-weight: 700; font-size: 11.5px; }

/* ============ Busy overlay ============ */
#busy-overlay {
  display: none; position: fixed; inset: 0; z-index: 9999;
  background: var(--overlay-bg); backdrop-filter: blur(2px);
  align-items: center; justify-content: center;
}
.busy-box {
  background: var(--card-bg); border-radius: 14px; padding: 30px 38px; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,.3); max-width: 420px; margin: 0 16px;
}
.busy-spinner {
  width: 42px; height: 42px; margin: 0 auto;
  border: 4px solid var(--border); border-top-color: var(--navy); border-radius: 50%;
  animation: busy-spin .9s linear infinite;
}
@keyframes busy-spin { to { transform: rotate(360deg); } }

/* ============ Toast notifications ============ */
#toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 99999;
  display: flex; flex-direction: column-reverse; gap: 10px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--toast-bg); color: var(--toast-text);
  padding: 14px 18px; border-radius: 11px; font-size: 13.5px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  display: flex; align-items: center; gap: 10px;
  animation: toast-in .3s ease;
  max-width: 380px;
}
.toast.toast-success { border-left: 4px solid var(--green); }
.toast.toast-error { border-left: 4px solid var(--red); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ Modal de confirmação ============ */
#confirm-modal {
  display: none; position: fixed; inset: 0; z-index: 99998;
  background: var(--overlay-bg); backdrop-filter: blur(2px);
  align-items: center; justify-content: center;
}
.confirm-box {
  background: var(--card-bg); border-radius: 14px; padding: 28px 32px;
  box-shadow: 0 10px 40px rgba(0,0,0,.3); max-width: 440px; margin: 0 16px;
  text-align: center;
}
.confirm-box h3 { margin: 0 0 6px; }
.confirm-box p { margin: 6px 0 18px; color: var(--muted); font-size: 14px; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }

/* ============ Mobile ============ */
@media (max-width: 900px) {
  .sidebar { position: static; width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 14px; gap: 6px 10px; }
  .side-brand { border: none; padding: 0; }
  .side-brand .brand-sub { display: none; }
  .side-nav { flex-direction: row; flex-wrap: wrap; justify-content: center; margin: 0; flex: 1 1 100%; gap: 2px 4px; }
  .side-nav a { border-left: none; border-bottom: 2px solid transparent; padding: 7px 9px; font-size: 12px; white-space: nowrap; }
  .side-nav a.nav-active { border-left: none; border-bottom-color: var(--gold); background: none; }
  .side-actions, .side-user .who { display: none; }
  .content { margin-left: 0; }
  main { padding: 20px 14px 50px; }
  table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  .filter-row { grid-template-columns: 1fr; }
  #toast-container { bottom: 16px; right: 16px; left: 16px; }
  .toast { max-width: 100%; }
}
