:root {
  --bg: #f3efe8;
  --panel: #ffffff;
  --ink: #1f1d19;
  --muted: #655f53;
  --accent: #0f5b4f;
  --accent-soft: #d7ece7;
  --danger: #a02222;
  --warn: #7e5800;
  --ok: #1d6b3f;
  --line: #ddd2c4;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: radial-gradient(circle at 15% 10%, #fff4de 0, transparent 36%), var(--bg);
  font-family: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
}

a {
  color: inherit;
}

.shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  background: linear-gradient(190deg, #0d2421, #123430);
  color: #e5f3f0;
  padding: 1.2rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1.2rem;
}

.brand-mark {
  background: #64d2bd;
  color: #072119;
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.brand-title {
  font-weight: 700;
}

.brand-subtitle {
  opacity: 0.7;
  font-size: 0.85rem;
}

nav {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.nav-item {
  text-decoration: none;
  padding: 0.65rem 0.75rem;
  border-radius: 0.7rem;
  transition: background-color 140ms ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-item.active {
  background: rgba(100, 210, 189, 0.26);
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0.2rem 0 0.6rem 0.3rem;
  padding-left: 0.6rem;
  border-left: 1px solid rgba(229, 243, 240, 0.2);
}

.nav-sub-item {
  text-decoration: none;
  padding: 0.4rem 0.55rem;
  border-radius: 0.55rem;
  color: rgba(229, 243, 240, 0.9);
  font-size: 0.9rem;
}

.nav-sub-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-sub-item.active {
  background: rgba(100, 210, 189, 0.26);
}

.content {
  padding: 1.25rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.topbar-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.topbar-email {
  color: var(--muted);
  font-size: 0.92rem;
}

.gear-menu {
  position: relative;
}

.gear-button {
  list-style: none;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1rem;
}

.gear-button::-webkit-details-marker {
  display: none;
}

.gear-menu[open] .gear-button {
  border-color: var(--accent);
  color: var(--accent);
}

.gear-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.45rem);
  min-width: 220px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  padding: 0.45rem;
  display: grid;
  gap: 0.25rem;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
  z-index: 40;
}

.gear-menu:not([open]) .gear-dropdown {
  display: none;
}

.gear-item {
  text-decoration: none;
  color: var(--ink);
  padding: 0.45rem 0.55rem;
  border-radius: 0.45rem;
}

.gear-item:hover {
  background: var(--accent-soft);
}

.gear-logout {
  width: 100%;
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 0.45rem;
  text-align: left;
  padding: 0.45rem 0.55rem;
  cursor: pointer;
}

.gear-logout:hover {
  background: #fff8ef;
}

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

h1, h2 {
  margin-top: 0;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  text-align: left;
  padding: 0.6rem;
  vertical-align: top;
}

.btn {
  appearance: none;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 0.6rem;
  padding: 0.52rem 0.8rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

.btn.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.max-600 {
  max-width: 600px;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.55rem;
  border-radius: 0.5rem;
  border: 1px solid var(--line);
  font: inherit;
}

.live-search-input {
  margin-bottom: 0.45rem;
  background: #f8f8fa;
}

select[multiple] {
  min-height: 5.8rem;
}

.inline-form {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.row {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.row.between {
  justify-content: space-between;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.8rem;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.table-wrap {
  overflow-x: auto;
}

.text-right {
  text-align: right;
}

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

.crm-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.kpi {
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.75rem;
  background: #fbfaf7;
}

.kpi-label {
  margin: 0 0 0.2rem 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.kpi-value {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.crm-links {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.alerts {
  margin-bottom: 0.8rem;
}

.alert {
  border-radius: 0.5rem;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
}

.alert.error {
  background: #ffe9e9;
  color: var(--danger);
}

.alert.success {
  background: #e9f9ef;
  color: var(--ok);
}

.alert.warning {
  background: #fff6df;
  color: var(--warn);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-card {
  width: min(420px, 92vw);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 1.2rem;
}

.oauth-divider {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.25rem 0;
}

.oauth-divider::before,
.oauth-divider::after {
  content: "";
  border-top: 1px solid var(--line);
  flex: 1;
}

.oauth-divider span {
  color: var(--muted);
  font-size: 0.85rem;
}

.oauth-btn {
  width: 100%;
  text-align: center;
}

.small {
  font-size: 0.88rem;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding-bottom: 0.2rem;
  }

  nav {
    flex-direction: row;
    overflow-x: auto;
  }

  .nav-item {
    white-space: nowrap;
  }

  .nav-group {
    flex-direction: row;
    border-left: none;
    margin: 0;
    padding-left: 0;
    gap: 0.35rem;
  }

  .nav-sub-item {
    white-space: nowrap;
  }

  .crm-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
