:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --accent: #6366f1;
  --accent-2: #4f46e5;
  --accent-soft: #eef2ff;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --sidebar: #0a0e1a;
  --sidebar-2: #111827;
  --sidebar-text: #94a3b8;
  --shadow: 0 10px 30px rgba(15, 23, 42, .08);
  --radius: 14px;
}

html[data-theme="dark"] {
  --bg: #0b1220;
  --panel: #141a2a;
  --panel-2: #101728;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #243044;
  --border-strong: #334155;
  --accent-soft: rgba(99, 102, 241, .18);
  --ok-soft: rgba(16, 185, 129, .14);
  --warn-soft: rgba(245, 158, 11, .14);
  --danger-soft: rgba(239, 68, 68, .14);
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
code { font: 13px/1.4 Consolas, ui-monospace, monospace; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px; }

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

input, select, textarea, button { font: inherit; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .18);
}

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

label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
label input, label select, label textarea { font-weight: 400; color: var(--text); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: wait; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }

.btn-ghost { border-color: var(--border-strong); background: var(--panel); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-ok { background: var(--ok-soft); color: var(--ok); }
.btn-ok:hover { background: var(--ok); color: #fff; }

.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; margin-top: 6px; }

.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-weight: 600; }
.link.danger { color: var(--danger); }

/* Login */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(99, 102, 241, .18), transparent 60%),
    radial-gradient(800px 500px at 90% 100%, rgba(14, 165, 233, .12), transparent 55%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 430px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 34px;
}
.login-logo { height: 42px; width: auto; display: block; margin-bottom: 26px; }
html[data-theme="dark"] .login-logo { content: url("/brand/pdvpro-logo-dark.png?v=41.6-logo"); }
.login-card h1 { margin-bottom: 6px; }
.login-card p { margin: 0 0 20px; font-size: 14px; }
.login-card form { display: grid; gap: 14px; }
.login-foot { margin: 20px 0 0 !important; font-size: 12px; color: var(--muted); }
.alert {
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
}

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

.sidebar {
  width: 248px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 16px;
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: var(--sidebar-text);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; flex-direction: column; gap: 10px; padding: 2px 8px 10px; border-bottom: 1px solid rgba(148, 163, 184, .14); }
.brand img { height: 34px; width: auto; align-self: flex-start; }
.brand span { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: #64748b; }

.nav { display: grid; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--sidebar-text);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 19px; height: 19px; fill: currentColor; flex: none; }
.nav-item:hover { background: rgba(148, 163, 184, .09); color: #e2e8f0; }
.nav-item.is-active { background: rgba(99, 102, 241, .18); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; font-size: 12px; padding: 12px 8px 0; border-top: 1px solid rgba(148, 163, 184, .14); overflow: hidden; }
.sidebar-foot span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .link { color: #a5b4fc; text-align: left; }

.shell { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar .muted { margin: 4px 0 0; font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.content { padding: 26px 28px 48px; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.card b { display: block; font-size: 30px; line-height: 1.1; letter-spacing: -.02em; }
.card span { display: block; margin-top: 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
.card.accent b { color: var(--accent); }
.card.ok b { color: var(--ok); }
.card.warn b { color: var(--warn); }
.card.danger b { color: var(--danger); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1050px) { .grid-2 { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.head-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search { min-width: 230px; padding: 8px 12px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); background: var(--panel-2); white-space: nowrap; }
tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
tbody tr:last-child td { border-bottom: 0; }
td .sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
td.num { white-space: nowrap; }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); font-size: 14px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ativa { background: var(--ok-soft); color: var(--ok); }
.badge.agendada { background: var(--accent-soft); color: var(--accent); }
.badge.vencida, .badge.suspensa, .badge.cancelada, .badge.invalida { background: var(--danger-soft); color: var(--danger); }
.badge.neutra { background: var(--panel-2); color: var(--muted); }

.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip { padding: 2px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700; }
.chip.off { background: var(--panel-2); color: var(--muted); }

.key { font: 12px/1.4 Consolas, ui-monospace, monospace; letter-spacing: .04em; background: var(--panel-2); border: 1px solid var(--border); border-radius: 7px; padding: 3px 8px; white-space: nowrap; }

/* Menu */
.menu { position: relative; display: inline-block; }
.menu summary {
  list-style: none;
  cursor: pointer;
  padding: 5px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  user-select: none;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover { border-color: var(--accent); color: var(--accent); }
.menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 210px;
  z-index: 20;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
}
.menu-pop.floating {
  position: fixed;
  right: auto;
  top: 0;
  left: 0;
  z-index: 40;
  max-height: calc(100vh - 16px);
  overflow-y: auto;
}
.menu-pop button {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text);
  text-align: left;
  font-size: 13px;
  cursor: pointer;
}
.menu-pop button:hover { background: var(--accent-soft); color: var(--accent); }
.menu-pop button.danger { color: var(--danger); }
.menu-pop button.danger:hover { background: var(--danger-soft); }
.menu-pop hr { border: 0; border-top: 1px solid var(--border); margin: 5px 0; }

.tabs { display: flex; gap: 6px; padding: 12px 16px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  padding: 6px 13px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--accent); }
.tab.is-active { background: var(--accent); color: #fff; }

/* Lists */
.list { display: grid; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item b { display: block; font-size: 14px; }
.list-item small { color: var(--muted); }
.list-item .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.list-item .icon-dot { width: 32px; height: 32px; flex: none; border-radius: 9px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 12px; }

/* Config */
.config-row { padding: 16px 18px; border-bottom: 1px solid var(--border); display: grid; gap: 8px; }
.config-row:last-child { border-bottom: 0; }
.config-row label { font-weight: 500; color: var(--muted); font-size: 13px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font: 12px/1.4 Consolas, ui-monospace, monospace; }
.form-grid { padding: 18px; display: grid; gap: 14px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 6, 23, .55);
  backdrop-filter: blur(3px);
  overflow-y: auto;
}
.modal {
  width: 100%;
  max-width: 620px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.modal.wide { max-width: 780px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.modal-head h3 { font-size: 17px; }
.modal-close { border: 0; background: var(--panel-2); color: var(--muted); width: 32px; height: 32px; border-radius: 8px; font-size: 18px; cursor: pointer; }
.modal-close:hover { color: var(--danger); }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--panel); }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid-2 .full { grid-column: 1 / -1; }
@media (max-width: 620px) { .form-grid-2 { grid-template-columns: 1fr; } }

.check-row { display: flex; gap: 10px; flex-wrap: wrap; }
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.check input { width: auto; accent-color: var(--accent); }
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.result {
  margin-top: 4px;
  padding: 16px;
  border-radius: 12px;
  background: var(--ok-soft);
  border: 1px solid color-mix(in srgb, var(--ok) 28%, transparent);
  display: grid;
  gap: 10px;
}
.result h4 { margin: 0; font-size: 15px; color: var(--ok); }
.result .copy-row input { background: var(--panel); }
.note { padding: 11px 13px; border-radius: 9px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.danger-text { color: var(--danger); font-weight: 600; }

/* Toast */
.toast-root { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: grid; gap: 8px; max-width: 360px; }
.toast { padding: 12px 15px; border-radius: 10px; background: #0f172a; color: #f8fafc; box-shadow: var(--shadow); font-size: 13px; font-weight: 600; animation: toastIn .18s ease-out; }
.toast.ok { background: #065f46; }
.toast.err { background: #991b1b; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* Responsive */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; gap: 14px; padding: 14px; overflow-x: auto; }
  .brand { border: 0; padding: 0; flex: none; }
  .brand span { display: none; }
  .nav { display: flex; gap: 4px; }
  .nav-item { width: auto; padding: 9px 12px; white-space: nowrap; }
  .nav-item.is-active { box-shadow: inset 0 -3px 0 var(--accent); }
  .sidebar-foot { display: none; }
  .topbar { padding: 16px 18px; }
  .content { padding: 18px; }
}

@media (max-width: 560px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1; }
  .search { min-width: 0; width: 100%; }
  .panel-head { align-items: stretch; flex-direction: column; }
  .head-tools { width: 100%; }
  .modal { max-height: calc(100vh - 24px); }
}
