/* ============================================================
   e-translate · admin console
   Dark, modern, self-contained (no external fonts/CSS — CSP 'self')
   ============================================================ */

:root {
  /* surfaces */
  --bg:           #0a0b10;
  --bg-grad-a:    #11121b;
  --bg-grad-b:    #0a0b10;
  --surface:      #14161f;
  --surface-2:    #1b1e2a;
  --surface-3:    #232737;
  --border:       #2a2e3f;
  --border-soft:  #21242f;

  /* text */
  --text:         #eef0f7;
  --text-dim:     #a4a9bd;
  --text-faint:   #6e7488;

  /* accent — e-cosplay magenta/violet */
  --accent:       #b14bff;
  --accent-2:     #7c3aed;
  --accent-soft:  rgba(177, 75, 255, 0.14);
  --accent-glow:  rgba(177, 75, 255, 0.35);

  /* semantic */
  --danger:       #ff5d6c;
  --danger-soft:  rgba(255, 93, 108, 0.12);
  --success:      #34d399;
  --success-soft: rgba(52, 211, 153, 0.12);
  --warn:         #fbbf24;

  --radius:       14px;
  --radius-sm:    10px;
  --radius-lg:    20px;

  --shadow:       0 10px 40px rgba(0, 0, 0, 0.45);
  --shadow-lg:    0 24px 70px rgba(0, 0, 0, 0.6);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
          Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 12% -10%, rgba(124, 58, 237, 0.18), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(177, 75, 255, 0.12), transparent 55%),
    linear-gradient(180deg, var(--bg-grad-a), var(--bg-grad-b));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.5;
}

[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;
}

code { font-family: var(--mono); }

/* ===================== BOOT ===================== */
.boot {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-dim);
}
.boot-spinner {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== BRAND ===================== */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 20px var(--accent-glow);
  flex: none;
}
.brand-sm .brand-mark { width: 38px; height: 38px; border-radius: 10px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1.05rem; letter-spacing: -0.01em; }
.brand-text span { font-size: 0.78rem; color: var(--text-faint); }

/* ===================== LOGIN ===================== */
.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, var(--surface), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 34px 32px 26px;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}
.login-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.7;
}
.login-card .brand { margin-bottom: 28px; }
.login-card h1 {
  margin: 0 0 6px;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}
.login-sub {
  margin: 0 0 24px;
  color: var(--text-dim);
  font-size: 0.92rem;
}

.pin-group {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.pin-box {
  width: 100%;
  aspect-ratio: 3 / 4;
  text-align: center;
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  caret-color: var(--accent);
}
.pin-box:focus {
  border-color: var(--accent);
  background: var(--surface-3);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.pin-box.filled { border-color: var(--accent-2); }
.pin-group.shake { animation: shake 0.4s; }
.pin-group.error .pin-box { border-color: var(--danger); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-7px); }
  40%, 80% { transform: translateX(7px); }
}

.login-error {
  margin: 0 0 16px;
  color: var(--danger);
  font-size: 0.88rem;
  font-weight: 500;
  text-align: center;
}
.login-back {
  display: block;
  text-align: center;
  margin-top: 18px;
  color: var(--text-faint);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.15s;
}
.login-back:hover { color: var(--text-dim); }

/* ===================== BUTTONS ===================== */
.btn {
  --btn-bg: var(--surface-3);
  --btn-fg: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s, background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
  user-select: none;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; filter: none; }
.btn svg { flex: none; }

.btn-primary {
  --btn-fg: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px var(--accent-glow);
}
.btn-ghost {
  --btn-bg: transparent;
  --btn-fg: var(--text-dim);
  border-color: var(--border);
}
.btn-ghost:hover { --btn-fg: var(--text); background: var(--surface-2); }
.btn-danger-soft {
  --btn-bg: var(--danger-soft);
  --btn-fg: var(--danger);
  border-color: rgba(255, 93, 108, 0.3);
}
.btn-block { width: 100%; }

/* button spinner */
.btn-spinner {
  display: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  animation: spin 0.6s linear infinite;
}
.btn.loading .btn-spinner { display: inline-block; }
.btn.loading .btn-label,
.btn.loading svg { display: none; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s, background 0.15s, transform 0.4s;
}
.icon-btn:hover { color: var(--text); background: var(--surface-3); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn.spinning svg { animation: spin 0.7s linear infinite; }

/* ===================== DASHBOARD LAYOUT ===================== */
.dashboard {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--border-soft);
  background: rgba(10, 11, 16, 0.7);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.content {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 36px) clamp(16px, 4vw, 40px);
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.foot {
  padding: 22px;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-soft);
}

/* ===================== PANELS ===================== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.panel-head h2 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}
.panel-sub {
  margin: 4px 0 0;
  color: var(--text-faint);
  font-size: 0.84rem;
}
.panel-sub code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.85em;
  color: var(--text-dim);
}

/* ----- cache panel ----- */
.cache-panel { border-color: var(--border); }
.cache-stat {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.cache-count {
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #fff, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-variant-numeric: tabular-nums;
}
.cache-count-label { color: var(--text-dim); font-size: 0.9rem; }
.cache-stat .icon-btn { margin-left: auto; align-self: center; }

/* ----- create form ----- */
.create-form {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}
.field {
  flex: 1;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-dim);
}
.field input {
  padding: 11px 14px;
  font: inherit;
  font-size: 0.92rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input::placeholder { color: var(--text-faint); }
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.create-form .btn { height: 44px; }

/* ===================== KEYS TABLE ===================== */
.table-wrap { overflow-x: auto; }
.keys-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.keys-table thead th {
  text-align: left;
  padding: 0 14px 12px;
  color: var(--text-faint);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.keys-table th.num, .keys-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.keys-table th.actions-col, .keys-table td.actions-col { text-align: right; width: 1%; }
.keys-table tbody tr {
  border-bottom: 1px solid var(--border-soft);
  transition: background 0.12s;
}
.keys-table tbody tr:last-child { border-bottom: none; }
.keys-table tbody tr:hover { background: var(--surface-2); }
.keys-table td {
  padding: 14px;
  vertical-align: middle;
}
.keys-table td.row-removing { opacity: 0.4; }

.key-label-cell { font-weight: 600; max-width: 240px; }
.key-label-cell .label-text {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.key-masked {
  font-family: var(--mono);
  font-size: 0.84rem;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 9px;
  border-radius: 7px;
  white-space: nowrap;
}
.cell-dim { color: var(--text-dim); white-space: nowrap; }
.cell-never { color: var(--text-faint); font-style: italic; }

.btn-del {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--danger);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-del:hover { background: var(--danger-soft); border-color: rgba(255, 93, 108, 0.3); }
.btn-del:focus-visible { outline: 2px solid var(--danger); outline-offset: 2px; }
.btn-del:disabled { opacity: 0.5; cursor: not-allowed; }

/* empty / skeleton */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 44px 20px;
  text-align: center;
  color: var(--text-faint);
}
.empty-state svg { color: var(--accent); opacity: 0.7; margin-bottom: 6px; }
.empty-state p { margin: 0; font-weight: 600; color: var(--text-dim); }
.empty-state span { font-size: 0.85rem; }

.skel {
  display: inline-block;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ===================== MODAL ===================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 5, 8, 0.72);
  backdrop-filter: blur(4px);
  animation: fade 0.2s ease;
}
.modal-card {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 30px 28px 24px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: pop 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.modal-icon {
  display: grid;
  place-items: center;
  width: 54px; height: 54px;
  margin: 0 auto 14px;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px var(--accent-glow);
}
.modal-card h2 { margin: 0 0 10px; font-size: 1.25rem; letter-spacing: -0.02em; }
.modal-warn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 0 20px;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--warn);
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.25);
  border-radius: var(--radius-sm);
  text-align: left;
}
.modal-warn svg { flex: none; }
.key-reveal {
  display: flex;
  gap: 10px;
  align-items: stretch;
  margin-bottom: 16px;
}
.key-value {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 12px 14px;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  word-break: break-all;
  text-align: left;
  user-select: all;
}
.btn-copy { flex: none; min-width: 96px; }
.btn-copy.copied {
  background: linear-gradient(135deg, var(--success), #10b981);
  box-shadow: 0 6px 18px var(--success-soft);
}
.modal-label {
  margin: 0 0 18px;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.modal-label strong { color: var(--text); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.97); } }

/* ===================== TOASTS ===================== */
.toasts {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 32px));
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  color: var(--text);
  animation: toast-in 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
.toast.leaving { animation: toast-out 0.25s forwards; }
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.info    { border-left-color: var(--accent); }
.toast-icon { flex: none; display: grid; place-items: center; }
.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon   { color: var(--danger); }
.toast.info .toast-icon    { color: var(--accent); }
@keyframes toast-in  { from { opacity: 0; transform: translateX(40px); } }
@keyframes toast-out { to   { opacity: 0; transform: translateX(40px); } }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 620px) {
  .login-card { padding: 28px 22px 22px; }
  .pin-group { gap: 7px; }
  .pin-box { font-size: 1.35rem; }
  .panel { padding: 18px; }
  .panel-head { flex-direction: column; align-items: stretch; }
  .panel-head > .icon-btn { align-self: flex-end; }
  .cache-count { font-size: 2rem; }
  .create-form .btn { width: 100%; }
  .brand-text span { display: none; }

  /* card-ify the table */
  .keys-table thead { display: none; }
  .keys-table, .keys-table tbody, .keys-table tr, .keys-table td { display: block; width: 100%; }
  .keys-table tr {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 12px;
  }
  .keys-table tr:hover { background: var(--surface-2); }
  .keys-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding: 7px 0;
    text-align: right;
  }
  .keys-table td::before {
    content: attr(data-label);
    font-size: 0.74rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-faint);
    text-align: left;
  }
  .keys-table td.num { text-align: right; }
  .keys-table td.actions-col { justify-content: flex-end; }
  .keys-table td.actions-col::before { content: none; }
  .key-label-cell { max-width: none; }
  .toasts { left: 16px; right: 16px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
