/**
 * auth.css — модалка входа и кабинет.
 * Отдельно от style.css: переменные и кнопки берём оттуда, здесь только
 * то, что появляется вместе с авторизацией.
 */

/* --- Навигация: гость / пользователь --- */
.nav-auth { display: flex; align-items: center; gap: 10px; }
.nav-auth[hidden] { display: none; }

.nav-user {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 12px 5px 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.2s;
}
.nav-user:hover { border-color: var(--accent); }
.nav-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  background-size: cover;
  background-position: center;
  color: #04121b;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 26px;
}
.nav-user-name {
  font-size: 13px;
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-logout {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.2s, color 0.2s;
}
.btn-logout:hover { border-color: #ef4444; color: #f87171; }

/* --- Модалка --- */
.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 6, 12, 0.78);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.auth-modal.open { opacity: 1; }
.auth-modal[hidden] { display: none; }

.auth-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 30px 28px 26px;
  position: relative;
  transform: translateY(14px) scale(0.98);
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.auth-modal.open .auth-card { transform: translateY(0) scale(1); }
.auth-card.busy { opacity: 0.6; pointer-events: none; }

.auth-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  background: none;
  color: var(--muted);
  border-radius: 9px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.auth-close:hover { border-color: var(--accent); color: var(--text); }

.auth-card h2 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 22px;
  margin: 0 0 6px;
}
.auth-lead { color: var(--muted); font-size: 14px; margin: 0 0 20px; }

.auth-field { margin-bottom: 13px; }
.auth-field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
.auth-field input {
  width: 100%;
  padding: 11px 13px;
  background: #05070d;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.auth-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 212, 170, 0.12);
}
.auth-field input::placeholder { color: #5b6678; }

.auth-error {
  display: none;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}
.auth-error.visible { display: block; }

.auth-submit { width: 100%; margin-top: 6px; }

.auth-switch { text-align: center; font-size: 13px; color: var(--muted); margin: 16px 0 0; }
.auth-switch a { color: var(--accent); cursor: pointer; }
.auth-switch a:hover { text-decoration: underline; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 16px;
  color: var(--muted);
  font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.auth-oauth-wrap[hidden] { display: none; }
.auth-oauth { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.auth-oauth[hidden] { display: none; }
#google-btn { min-height: 44px; display: flex; justify-content: center; }
#telegram-btn { display: flex; justify-content: center; }
.oauth-fallback { color: var(--muted); font-size: 12px; }

.auth-legal { color: var(--muted); font-size: 11px; text-align: center; margin: 18px 0 0; line-height: 1.5; }
.auth-legal a { color: var(--muted); text-decoration: underline; }
.auth-legal a:hover { color: var(--accent); }

/* --- Кабинет --- */
.dashboard[hidden] { display: none; }

.dash-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.dash-head h2 { font-family: "Space Grotesk", sans-serif; font-size: clamp(24px, 3.4vw, 34px); margin: 0 0 4px; }
.dash-sub { color: var(--muted); font-size: 14px; margin: 0; }

.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}
.dash-tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  transition: border-color 0.2s;
}
.dash-tile:hover { border-color: rgba(0, 212, 170, 0.35); }
.dash-tile-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; letter-spacing: 0.02em; }
.dash-tile-value {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 24px;
  color: var(--accent);
}
.dash-tile-value.plain { color: var(--text); }
.dash-tile-hint { color: var(--muted); font-size: 11px; margin-top: 6px; }
.dash-tile[hidden] { display: none; }

.dash-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
}
.dash-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.dash-panel-head h3 { font-family: "Space Grotesk", sans-serif; font-size: 17px; margin: 0; }
.dash-panel-head .muted { font-size: 13px; }

/* Прогресс-бар квоты */
.usage-bar {
  height: 7px;
  background: #05070d;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
  margin: 10px 0 8px;
}
.usage-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.usage-fill.warn { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.usage-fill.danger { background: linear-gradient(90deg, #ef4444, #f87171); }
.usage-legend { color: var(--muted); font-size: 12px; }

/* Форма нового ключа */
.newkey-form {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}
.newkey-form .auth-field { margin: 0; }
.newkey-status { color: var(--accent); font-size: 12px; min-height: 16px; margin-top: 10px; }

/* Карточка ключа */
.key-list { display: grid; gap: 12px; }
.key-empty {
  color: var(--muted);
  font-size: 14px;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
}
.key-empty code { color: var(--accent); font-size: 13px; }

.key-item {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  transition: border-color 0.2s;
}
.key-item:hover { border-color: rgba(0, 212, 170, 0.35); }
.key-item.revoked { opacity: 0.55; }

.key-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.key-name { font-family: "Space Grotesk", sans-serif; font-weight: 700; font-size: 15px; }
.key-badges { display: flex; gap: 6px; }
.key-badge {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.key-badge.on { color: var(--green); border-color: rgba(52, 211, 153, 0.4); background: rgba(52, 211, 153, 0.08); }
.key-badge.off { color: #f87171; border-color: rgba(239, 68, 68, 0.4); background: rgba(239, 68, 68, 0.08); }

.key-token {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #05070d;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px 9px 12px;
}
.key-token code {
  flex: 1;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 12px;
  color: #c7d2fe;
  overflow-x: auto;
  white-space: nowrap;
}
.key-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 5px 11px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: border-color 0.2s, color 0.2s;
}
.key-btn:hover { border-color: var(--accent); color: var(--text); }
.key-btn.done { border-color: var(--green); color: var(--green); }
.key-btn.danger { margin-top: 10px; }
.key-btn.danger:hover { border-color: #ef4444; color: #f87171; }

.key-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

/* Гостю CTA скрываем, когда вошёл */
body.signed-in #start[hidden] { display: none; }

@media (max-width: 720px) {
  .newkey-form { grid-template-columns: 1fr 1fr; }
  .newkey-form .auth-field:first-child { grid-column: 1 / -1; }
  .newkey-form .btn { grid-column: 1 / -1; }
  .nav-user-name { max-width: 90px; }
  .auth-card { padding: 26px 20px 22px; }
  .dash-grid { grid-template-columns: repeat(2, 1fr); }
}
