:root {
  --bg: #eef3f1;
  --bg-accent: #d8e7e1;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --ink: #14201c;
  --muted: #5d6f68;
  --line: rgba(20, 32, 28, 0.1);
  --brand: #0f6b56;
  --brand-strong: #0a4f40;
  --brand-soft: #d6efe7;
  --warn: #b45309;
  --danger: #b42318;
  --ok: #0f766e;
  --shadow: 0 18px 50px rgba(15, 40, 32, 0.12);
  --radius: 22px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 700px at 10% -10%, #cfe8df 0%, transparent 55%),
    radial-gradient(900px 600px at 100% 0%, #f3e7d4 0%, transparent 45%),
    linear-gradient(180deg, #f7faf8 0%, var(--bg) 100%);
}

button, input, select { font: inherit; }
.hidden { display: none !important; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
}

.auth-backdrop {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(15, 107, 86, 0.12), transparent 45%),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%230f6b56' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: scale(1); opacity: 0.9; }
  to { transform: scale(1.05); opacity: 1; }
}

.auth-panel {
  position: relative;
  width: min(460px, 100%);
  padding: 28px;
  border-radius: 28px;
  background: var(--surface);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
  animation: rise 0.55s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand, .sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.brand strong, .sidebar-brand strong,
.brand span, .sidebar-brand span {
  display: block;
}

.brand strong, .sidebar-brand strong {
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.brand span, .sidebar-brand span {
  color: var(--muted);
  font-size: 0.85rem;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 700;
  background: linear-gradient(145deg, var(--brand), #1a8f74);
  box-shadow: 0 10px 24px rgba(15, 107, 86, 0.28);
}

.auth-form h1 {
  margin: 0 0 8px;
  font-size: 1.7rem;
  letter-spacing: -0.03em;
}

.auth-lead {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.45;
}

.method-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.method-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  padding: 10px 12px;
  cursor: pointer;
  color: var(--muted);
}

.method-btn.active {
  background: var(--brand-soft);
  border-color: transparent;
  color: var(--brand-strong);
  font-weight: 600;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.field > span {
  font-size: 0.86rem;
  color: var(--muted);
}

.field input,
.phone-row select,
.users-toolbar input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.9);
  outline: none;
}

.field input:focus,
.users-toolbar input:focus,
.phone-row select:focus {
  border-color: rgba(15, 107, 86, 0.45);
  box-shadow: 0 0 0 4px rgba(15, 107, 86, 0.1);
}

.phone-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px;
}

.phone-box {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.9);
}

.phone-box input {
  border: 0;
  padding: 12px 0;
  background: transparent;
  box-shadow: none !important;
  width: 100%;
}

.primary-btn,
.ghost-btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.primary-btn:hover,
.ghost-btn:hover { transform: translateY(-1px); }

.primary-btn {
  width: 100%;
  background: linear-gradient(145deg, var(--brand), var(--brand-strong));
  color: white;
  font-weight: 600;
}

.primary-btn.compact,
.ghost-btn.compact {
  width: auto;
  padding: 10px 14px;
}

.ghost-btn {
  width: 100%;
  margin-top: 10px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.error-text {
  min-height: 1.2em;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 0.92rem;
}

.test-code {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff7ed;
  color: var(--warn);
  font-family: var(--mono);
  font-size: 0.9rem;
}

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

.sidebar {
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar-nav {
  display: grid;
  gap: 8px;
}

.nav-btn {
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--muted);
  cursor: pointer;
}

.nav-btn.active {
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-weight: 600;
}

.sidebar-foot {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.admin-identity {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  font-size: 0.9rem;
}

.admin-identity strong { display: block; }
.admin-identity span { color: var(--muted); font-size: 0.82rem; }

.main {
  padding: 28px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 22px;
}

.page-header h1 {
  margin: 0 0 6px;
  font-size: 1.8rem;
  letter-spacing: -0.03em;
}

.page-header p {
  margin: 0;
  color: var(--muted);
}

.stamp {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
}

.stat-grid,
.metric-grid {
  display: grid;
  gap: 16px;
}

.stat-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.metric-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-card,
.metric-card {
  background: var(--surface-solid);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(20, 40, 32, 0.06);
  animation: rise 0.5s ease both;
}

.stat-card {
  padding: 18px;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 10px;
}

.stat-card strong {
  font-size: 2rem;
  letter-spacing: -0.04em;
}

.metric-card {
  padding: 18px 18px 10px;
}

.metric-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.metric-head h2 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.metric-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.metric-value {
  font-family: var(--mono);
  font-size: 1.35rem;
  color: var(--brand-strong);
}

.users-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.table-wrap {
  overflow: auto;
  background: var(--surface-solid);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(20, 40, 32, 0.06);
}

.users-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.users-table th,
.users-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
  vertical-align: top;
}

.users-table th {
  color: var(--muted);
  font-weight: 600;
  background: #f7faf8;
  position: sticky;
  top: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge.ok { background: #dcfce7; color: #166534; }
.badge.off { background: #fee2e2; color: #991b1b; }
.badge.admin { background: var(--brand-soft); color: var(--brand-strong); margin-left: 6px; }
.badge.role { background: #e8eefc; color: #1e3a8a; margin: 0 4px 4px 0; }

.roles-list {
  display: grid;
  gap: 14px;
}

.role-card {
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 10px 30px rgba(20, 40, 32, 0.06);
  animation: rise 0.45s ease both;
}

.role-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 10px;
}

.role-card h3 {
  margin: 0 0 4px;
  font-size: 1.15rem;
}

.role-card .role-key {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 0.82rem;
}

.role-card p {
  margin: 0 0 12px;
  color: var(--muted);
}

.role-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.role-perms {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 28, 24, 0.42);
  backdrop-filter: blur(4px);
}

.modal-card {
  width: min(560px, 100%);
  max-height: min(90vh, 820px);
  overflow: auto;
  background: var(--surface-solid);
  border-radius: 22px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: rise 0.3s ease both;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 0;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-body {
  padding: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.9);
  resize: vertical;
  min-height: 84px;
  outline: none;
  font: inherit;
}

.field textarea:focus {
  border-color: rgba(15, 107, 86, 0.45);
  box-shadow: 0 0 0 4px rgba(15, 107, 86, 0.1);
}

.permissions-box {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f7faf8;
  max-height: 260px;
  overflow: auto;
}

.perm-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
  align-items: start;
  padding: 8px;
  border-radius: 10px;
  background: white;
  border: 1px solid transparent;
}

.perm-item:hover {
  border-color: var(--line);
}

.perm-item strong {
  display: block;
  font-size: 0.92rem;
}

.perm-item span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 16px;
}

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .sidebar-nav { grid-template-columns: 1fr 1fr; }
  .main { padding: 18px; }
  .phone-row { grid-template-columns: 1fr; }
}
