:root {
  --bg: #edf4ff;
  --panel: #ffffff;
  --soft: #f5f8ff;
  --primary: #1d4ed8;
  --primary-deep: #123bb3;
  --secondary: #7c3aed;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --text: #172033;
  --muted: #53647d;
  --line: #dfe9fb;
  --shadow: 0 18px 45px rgba(31, 73, 151, 0.12);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(180deg, #edf4ff 0%, #eef7ff 100%);
}

body {
  font-family: "Segoe UI", Tahoma, sans-serif;
  direction: ltr;
  color: var(--text);
}

button, input, select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--primary);
  text-decoration: none;
}

.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 26px 20px 40px;
}

.topbar {
  background: linear-gradient(135deg, var(--primary-deep), var(--primary), var(--secondary));
  color: white;
  border-radius: 22px;
  padding: 22px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  box-shadow: var(--shadow);
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.85rem;
  font-weight: 700;
}

.user-action {
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  font-size: 0.8rem;
}

.topbar h1 {
  margin: 0;
  font-size: 2rem;
}

.tabs {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.tabs button {
  background: rgba(255, 255, 255, 0.14);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 8px 15px;
  font-size: 0.92rem;
  font-weight: 700;
}

.tabs button.active {
  background: white;
  color: var(--primary);
}

.panel {
  background: var(--panel);
  border-radius: 22px;
  margin-top: 24px;
  padding: 24px;
  box-shadow: var(--shadow);
}

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

.section-header h2,
.sidebar h3,
.sidebar h4,
.category-group h3 {
  margin: 0;
}

.form-card {
  margin-bottom: 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(29, 78, 216, 0.07);
}

.form-card-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  margin: 0;
  padding: 14px 20px;
  color: var(--primary-deep);
  background: linear-gradient(135deg, #e8f1ff, #dceaff);
  border-bottom: 1px solid #c8dcfb;
}

.form-card-heading h3,
.form-card-heading p {
  margin: 0;
}

.form-card-heading h3 {
  color: var(--primary-deep);
  font-size: 1.05rem;
}

.form-card-heading p {
  margin-top: 4px;
  color: #5d7190;
  font-size: 0.85rem;
}

.form-card-icon {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  color: var(--primary-deep);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 16px rgba(5, 25, 80, 0.18);
  font-size: 1.2rem;
}

.primary-button {
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 800;
  min-height: 42px;
  font-size: 0.92rem;
}

.primary-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 16px;
  margin: 0;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-weight: 700;
  color: var(--muted);
}

input, select {
  width: 100%;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
}

input:focus, select:focus {
  outline: none;
  border-color: rgba(29, 78, 216, 0.7);
  box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.08);
}

.form-card .form-grid {
  padding: 22px 20px 20px;
}

.form-card .form-grid .primary-button {
  grid-column: 1 / -1;
  justify-self: center;
  min-width: 190px;
}

.toolbar-row {
  margin-bottom: 18px;
}

.toolbar-row input {
  max-width: 380px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
}

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

th, td {
  border-bottom: 1px solid #edf3ff;
  padding: 14px 16px;
  text-align: left;
}

th {
  background: #f4f8ff;
  color: var(--muted);
  font-weight: 800;
}

tbody tr:hover {
  background: #f9fbff;
}

.email-page {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 20px;
}

.sidebar {
  background: linear-gradient(180deg, #f9fbff 0%, #f3f8ff 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.7);
}

.tree-header {
  margin-bottom: 16px;
}

.tree-menu {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tree-node {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  overflow: hidden;
  box-shadow: 0 8px 22px rgba(29, 78, 216, 0.06);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tree-node:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(29, 78, 216, 0.08);
}

.tree-main-row {
  display: flex;
  align-items: stretch;
  background: linear-gradient(135deg, #f5f9ff, #edf4ff);
}

.tree-main,
.tree-sub,
.tree-toggle {
  width: 100%;
  border: none;
  background: transparent;
  padding: 10px 12px;
  font-size: 0.92rem;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tree-main {
  flex: 1;
  background: transparent;
}

.tree-main:hover,
.tree-sub:hover,
.tree-toggle:hover {
  background: rgba(29, 78, 216, 0.07);
}

.tree-main.active {
  background: linear-gradient(135deg, #ebf3ff, #dfeaff);
  color: var(--primary-deep);
}

.tree-toggle {
  width: 36px;
  flex: 0 0 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--primary);
}

.chevron {
  display: inline-block;
  font-size: 1.35rem;
  line-height: 1;
  transform: rotate(0deg) translateY(-2px);
  transition: transform 0.25s ease;
}

.tree-toggle.open .chevron {
  transform: rotate(180deg) translateY(2px);
}

.tree-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.tree-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(29, 78, 216, 0.08);
  font-size: 1rem;
}

.tree-icon.small {
  width: 22px;
  height: 22px;
  font-size: 0.9rem;
}

.tree-submenu {
  max-height: 0;
  overflow: hidden;
  padding: 0 10px 10px;
  background: linear-gradient(180deg, #fbfdff, #f6faff);
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.3s ease;
}

.tree-submenu.visible {
  max-height: 420px;
  padding: 0 10px 10px;
  opacity: 1;
}

.tree-sub {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  text-align: left;
  padding: 8px 10px 8px calc(10px + (var(--category-depth, 0) * 18px));
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.03);
}

.tree-category-branch {
  position: relative;
}

.tree-category-branch:not(:first-child)::before {
  content: '';
  position: absolute;
  left: 14px;
  top: 0;
  bottom: 0;
  width: 2px;
  border-radius: 2px;
  background: #d6e3f7;
}

.tree-category-branch .tree-sub {
  position: relative;
  z-index: 1;
}

.tree-sub.active {
  background: linear-gradient(135deg, #eff8ff, #ebf3ff);
  border-color: #b7ddff;
  color: var(--primary-deep);
}

.count {
  min-width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  box-shadow: 0 8px 16px rgba(29, 78, 216, 0.22);
}

.empty-state {
  padding: 12px 8px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at top right, #dceaff 0, transparent 36%), linear-gradient(135deg, #edf4ff, #f8fbff);
}

.auth-card {
  width: min(100%, 460px);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 24px 60px rgba(31, 73, 151, 0.16);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary-deep);
  font-size: 1.05rem;
}

.auth-brand span {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
}

.auth-heading {
  margin: 42px 0 22px;
}

.auth-heading h1,
.auth-heading p:last-child {
  margin: 0;
}

.auth-heading h1 {
  font-size: 2rem;
}

.auth-heading p:last-child {
  margin-top: 8px;
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-form .primary-button {
  width: 100%;
  margin-top: 4px;
}

.auth-error {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--danger);
  font-size: 0.86rem;
  font-weight: 700;
}

.auth-switch {
  border: none;
  padding: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 800;
}

.admin-users {
  min-height: 80px;
}

.admin-profile {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(135deg, #f5f9ff, #ffffff);
  box-shadow: 0 10px 24px rgba(29, 78, 216, 0.06);
}

.profile-avatar {
  width: 54px;
  height: 54px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  font-size: 1.35rem;
  font-weight: 900;
}

.profile-details {
  display: grid;
  gap: 4px;
}

.profile-details strong {
  color: var(--primary-deep);
  font-size: 1.05rem;
}

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

.admin-members-heading {
  margin-top: 28px;
  margin-bottom: 12px;
}

.role-badge {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e8f0ff;
  color: var(--primary-deep);
  font-size: 0.78rem;
  font-weight: 800;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(130px, 1fr));
  gap: 6px 10px;
  min-width: 260px;
}

.permission-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}

.permission-item input {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
}

.dashboard-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(135deg, #ffffff, #f5f9ff);
  box-shadow: 0 10px 24px rgba(29, 78, 216, 0.07);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 16px 28px rgba(29, 78, 216, 0.12);
}

.stat-card.accent {
  background: linear-gradient(135deg, #eef4ff, #f3edff);
}

.stat-icon {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  font-size: 1.15rem;
  box-shadow: 0 8px 16px rgba(29, 78, 216, 0.2);
}

.stat-card strong,
.stat-card span {
  display: block;
}

.stat-card strong {
  font-size: 1.35rem;
  color: var(--primary-deep);
}

.stat-card div span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.email-panel {
  min-width: 0;
}

.action-cell,
.action-cell-inline,
.group-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.action-cell,
.action-cell-inline {
  justify-content: flex-end;
}

.small-btn,
.mini-btn {
  border: none;
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 0.84rem;
  font-weight: 700;
  color: white;
}

.small-btn.copy,
.mini-btn.copy {
  background: var(--success);
}

.small-btn.edit,
.mini-btn.edit {
  background: var(--warning);
}

.small-btn.delete,
.mini-btn.delete {
  background: var(--danger);
}

.email-form {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto;
  gap: 16px;
  align-items: end;
  margin-top: 24px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

.email-form label {
  width: 100%;
}

.email-form .primary-button {
  justify-self: end;
}

.grouped-categories {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.category-group {
  background: linear-gradient(180deg, #fafcff 0%, #f4f8ff 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

.category-group h3 {
  color: var(--primary);
  margin-bottom: 12px;
}

.category-group ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.category-group > ul {
  gap: 8px;
}

.category-tree-item {
  display: block;
}

.category-tree-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: left;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.category-tree-row:hover {
  border-color: #b8cdf0;
  box-shadow: 0 6px 14px rgba(29, 78, 216, 0.08);
  transform: translateX(2px);
}

.category-tree-name {
  min-width: 0;
  font-weight: 700;
}

.category-tree-children {
  position: relative;
  margin: 8px 0 0 18px !important;
  padding: 0 0 0 16px !important;
  gap: 8px !important;
}

.category-tree-children::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 0;
  bottom: 12px;
  width: 2px;
  border-radius: 2px;
  background: #c8daf7;
}

.empty-state {
  color: var(--muted);
  padding: 14px 0;
}

@media (max-width: 980px) {
  .topbar,
  .section-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .form-grid,
  .email-page,
  .email-form,
  .dashboard-strip {
    grid-template-columns: 1fr;
  }

  .user-menu {
    margin-left: 0;
  }
}
