:root {
  --background: #fafafa;
  --foreground: #18181b;
  --muted: #71717a;
  --card: rgba(255, 255, 255, 0.82);
  --border: rgba(24, 24, 27, 0.1);
  --primary: #18181b;
  --primary-fg: #fafafa;
  --accent: #0f766e;
  --accent-deep: #115e59;
  --accent-soft: #ccfbf1;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #059669;
  --success-soft: #d1fae5;
  --sidebar: #f4f4f5;
  --shadow: 0 18px 50px rgba(24, 24, 27, 0.08);
  --radius: 14px;
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--foreground);
  font-family: var(--font-body);
  background: var(--background);
  line-height: 1.5;
}

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

a {
  color: inherit;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 70% 55% at 10% -10%, rgba(15, 118, 110, 0.12), transparent 55%),
    radial-gradient(ellipse 55% 45% at 95% 5%, rgba(251, 191, 36, 0.12), transparent 50%),
    linear-gradient(180deg, #f4f4f5 0%, #fafafa 100%);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--accent-soft), #99f6e4);
  color: var(--accent-deep);
  font-family: var(--font-display);
  font-weight: 700;
}

.brand-mark.sm {
  width: 2.4rem;
  height: 2.4rem;
  font-size: 0.85rem;
  border-radius: 10px;
}

.app-logo {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 10px;
  background: var(--primary);
  flex-shrink: 0;
}

.app-logo img {
  display: block;
}

.app-name {
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.2;
}

.btn,
.icon-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  transition:
    transform 0.2s var(--ease),
    background 0.2s ease,
    opacity 0.2s ease;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.6rem;
  padding: 0.65rem 1rem;
  border-radius: 10px;
  font-weight: 600;
  text-decoration: none;
}

.btn:hover {
  transform: translateY(-1px);
}
.btn:disabled {
  opacity: 0.6;
  cursor: wait;
  transform: none;
}
.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
}
.btn-primary:hover {
  background: #27272a;
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover {
  background: rgba(24, 24, 27, 0.05);
  color: var(--foreground);
}
.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.btn-block {
  width: 100%;
}

.icon-btn {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 10px;
  background: rgba(24, 24, 27, 0.05);
  color: var(--foreground);
  font-size: 1.1rem;
  line-height: 1;
}

.field,
.select-field,
.search-field,
.checkbox-field {
  display: grid;
  gap: 0.45rem;
}

.field span,
.select-field span,
.search-field span {
  font-size: 0.88rem;
  font-weight: 600;
}

.field input,
.field select,
.field textarea,
.select-field select,
.search-field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--foreground);
  padding: 0.75rem 0.9rem;
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.search-field input:focus {
  border-color: rgba(15, 118, 110, 0.45);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.12);
}

.checkbox-field {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.stack {
  display: grid;
  gap: 1rem;
}

.form-error {
  margin: 0;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: rgba(220, 38, 38, 0.08);
  color: #b91c1c;
  font-size: 0.95rem;
}

.hidden {
  display: none !important;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  z-index: 40;
  min-width: min(360px, calc(100% - 2rem));
  padding: 0.95rem 1.15rem;
  border-radius: 12px;
  background: var(--foreground);
  color: #fff;
  text-align: center;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition:
    opacity 0.28s ease,
    transform 0.28s var(--ease);
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Auth */
.auth-layout {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--background);
}

.auth-visual {
  position: relative;
  overflow: hidden;
  background: #eef2f6;
}

.auth-illustration {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem;
  background: var(--background);
}

.auth-panel-inner {
  width: min(400px, 100%);
  display: grid;
  gap: 2rem;
  transform: translateY(-1.5rem);
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--foreground);
  text-decoration: none;
}

.auth-brand .app-name {
  font-size: 1.05rem;
}

.auth-card-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.auth-card-header p,
.auth-footer {
  margin: 0;
  color: var(--muted);
}

.auth-card {
  width: 100%;
  margin-bottom: 16rem;
}

@media (max-width: 991px) {
  .auth-card {
    margin-bottom: 6rem;
  }
}

.auth-card-header {
  margin-bottom: 1.5rem;
}
.auth-footer {
  margin-top: 1.25rem;
}
.auth-footer a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.password-field {
  position: relative;
}
.password-field input {
  padding-right: 2.8rem;
}
.password-field .icon-btn {
  position: absolute;
  top: 50%;
  right: 0.35rem;
  transform: translateY(-50%);
  width: 2rem;
  height: 2rem;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 100vh;
  padding: 1.25rem;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 0.75rem;
  row-gap: 0.15rem;
  align-items: center;
  color: var(--foreground);
  text-decoration: none;
}

.sidebar-brand .app-logo {
  grid-row: span 2;
}

.sidebar-brand .app-name {
  font-size: 0.95rem;
  align-self: end;
}

.app-version {
  grid-column: 2;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.2;
}

.sidebar-logout {
  width: 100%;
  justify-content: flex-start;
  padding-left: 0.85rem;
}

.sidebar-nav {
  display: grid;
  gap: 0.35rem;
  align-content: start;
}

.sidebar-footer {
  display: grid;
  gap: 0.35rem;
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.dashboard-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
  position: relative;
}

.dashboard-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  padding: 0;
  max-width: none;
}

.page-header {
  flex-shrink: 0;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.82);
}

.page-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: #fff;
}

.breadcrumbs {
  margin: 0;
}

.breadcrumbs-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.875rem;
}

.breadcrumbs-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.breadcrumbs-item:not(:last-child)::after {
  content: "/";
  color: var(--border);
}

.breadcrumbs-item a {
  color: var(--muted);
  text-decoration: none;
}

.breadcrumbs-item a:hover {
  color: var(--foreground);
}

.breadcrumbs-current {
  color: var(--foreground);
  font-weight: 500;
}

.users-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.users-panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.users-table-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.users-table-shell .table-wrap {
  flex: 1;
  overflow: auto;
}

.users-table-shell .table-footer {
  flex-shrink: 0;
}

.sidebar-toggle {
  display: none;
}

.sidebar-link {
  display: block;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
}

.sidebar-link:hover,
.sidebar-link.active {
  background: #fff;
  color: var(--foreground);
}

.dashboard-content .settings-panel .settings-grid .card:first-child,
.dashboard-content .access-denied-panel .access-denied .card {
  margin-top: 0;
}

.toolbar-card,
.table-card,
.card {
  margin-top: 1.25rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  background: var(--card);
  box-shadow: var(--shadow);
}

.toolbar-card,
.card {
  padding: 1.25rem;
}

.toolbar-filters {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.search-field-compact {
  flex: none;
  width: min(240px, 36vw);
}

.select-field-compact {
  flex: none;
  width: 9.5rem;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.search-field {
  flex: 1;
  min-width: 220px;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.data-table th,
.data-table td {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-cell strong {
  display: block;
}
.user-cell span {
  color: var(--muted);
  font-size: 0.85rem;
}

.avatar,
.avatar-fallback,
.avatar-image {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-fallback {
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--accent-soft), #99f6e4);
  color: var(--accent-deep);
  font-weight: 700;
  font-size: 0.85rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-icon {
  display: inline-flex;
  width: 0.85rem;
  height: 0.85rem;
  flex-shrink: 0;
}

.badge-icon svg {
  width: 100%;
  height: 100%;
}

.badge-success {
  background: var(--success-soft);
  color: var(--success);
}
.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}
.badge-muted {
  background: #f4f4f5;
  color: var(--muted);
}
.badge-admin {
  background: #dbeafe;
  color: #1d4ed8;
}
.badge-user {
  background: #f4f4f5;
  color: var(--muted);
}

.table-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
}

.pagination {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.pagination button {
  min-width: 2.2rem;
  height: 2.2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

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

.loading-cell {
  text-align: center;
  color: var(--muted);
  padding: 2rem !important;
}

.actions-menu {
  position: relative;
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  min-width: 180px;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
  z-index: 10;
}

.menu-panel button {
  display: block;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.menu-panel button:hover {
  background: #f4f4f5;
}

.settings-panel {
  flex: 1;
  overflow: auto;
  padding: 1.5rem;
}

.settings-panel .settings-grid {
  max-width: 1200px;
}

.access-denied-panel {
  flex: 1;
  overflow: auto;
  padding: 1.5rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.settings-side {
  display: grid;
  gap: 1.25rem;
}

.settings-side .card {
  margin-top: 0;
}

.card-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1.1rem;
}
.card-header .muted {
  margin: 0;
}
.card-actions {
  margin-top: 0.5rem;
}

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

.profile-name {
  margin: 0;
  font-weight: 600;
}

.avatar-button {
  position: relative;
  width: 5rem;
  height: 5rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  background: transparent;
}

.avatar-button .avatar-image,
.avatar-button .avatar-fallback {
  width: 100%;
  height: 100%;
}

.avatar-overlay {
  position: absolute;
  inset: auto 0 0;
  padding: 0.45rem;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.65));
  color: #fff;
  font-size: 0.68rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.avatar-button:hover .avatar-overlay {
  opacity: 1;
}

.detail-list {
  display: grid;
  gap: 0.85rem;
  margin: 0;
}

.detail-list div {
  display: grid;
  gap: 0.2rem;
}

.detail-list dt {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.detail-list dd {
  margin: 0;
}

.access-denied {
  display: grid;
  place-items: center;
  min-height: 50vh;
}

.card-centered {
  max-width: 420px;
  text-align: center;
}

.sheet {
  width: min(480px, calc(100% - 1.5rem));
  margin: auto;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
}

.sheet::backdrop {
  background: rgba(16, 24, 27, 0.38);
  backdrop-filter: blur(4px);
}

.sheet-card {
  padding: 1.4rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  background: #fff;
  box-shadow: var(--shadow);
  overflow: visible;
}

.role-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.role-option {
  position: relative;
  display: block;
  cursor: pointer;
}

.role-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.role-option-label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.6rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-weight: 600;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.role-option input:checked + .role-option-label {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-fg);
}

.role-option input:focus-visible + .role-option-label {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.sheet-header h2 {
  margin: 0;
  font-size: 1.2rem;
}
.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

@media (max-width: 960px) {
  .auth-layout {
    grid-template-columns: 1fr;
  }
  .auth-visual {
    display: none;
  }
  .dashboard-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.25s var(--ease);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-toggle {
    display: inline-grid;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 15;
  }
  .page-header,
  .users-panel-toolbar {
    padding-left: 4rem;
  }

  .settings-panel,
  .access-denied-panel {
    padding-left: 4rem;
  }

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

@media (min-width: 961px) {
  .sidebar-toggle {
    display: none;
  }
}
