/* ===== cr1stal.shop — admin panel ===== */
:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #94a3b8;
  --border: #e3e8ef;
  --accent: #0891b2;
  --accent-d: #0e7490;
  --accent-l: #ecfeff;
  --side: #0f1b2d;
  --side-2: #1b2a40;
  --ok: #15803d;
  --ok-bg: #f0fdf4;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --r: 12px;
  --r-sm: 9px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 6px 18px rgba(15,23,42,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body.admin {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-d); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
h1, h2 { margin: 0; line-height: 1.25; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--text-2); }
.small { font-size: .82rem; }
.break { word-break: break-all; }
.ta-r { text-align: right; }

/* ===== buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent; border-radius: var(--r-sm); padding: 9px 16px;
  font-size: .9rem; font-weight: 600; cursor: pointer; background: var(--surface-2);
  color: var(--text); transition: .15s; font-family: inherit; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-d); }
.btn-ghost { background: var(--surface); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-d); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: .8rem; }
.btn-block { width: 100%; }

/* ===== shell ===== */
.admin-shell { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 232px; flex: none; background: var(--side); color: #cbd5e1;
  display: flex; flex-direction: column; z-index: 60;
}
.admin-brand {
  display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 800;
  font-size: 1.06rem; padding: 18px 18px; border-bottom: 1px solid rgba(255,255,255,.07);
}
.admin-brand:hover { text-decoration: none; }
.admin-brand.center { justify-content: center; border: none; }
.logo-mark { width: 26px; height: 26px; flex: none; }
.admin-nav { display: flex; flex-direction: column; padding: 12px 10px; gap: 2px; flex: 1; }
.admin-nav a {
  color: #aab8c9; padding: 10px 13px; border-radius: 9px; font-weight: 600; font-size: .92rem;
}
.admin-nav a:hover { background: var(--side-2); color: #fff; text-decoration: none; }
.admin-nav a.is-active { background: var(--accent); color: #fff; }
.admin-sidebar-foot {
  color: #7b8aa0; padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.07); font-size: .85rem;
}
.admin-sidebar-foot:hover { color: #fff; text-decoration: none; }
.admin-backdrop { display: none; }
.admin-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ===== topbar ===== */
.admin-topbar {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: 0 18px; height: 58px;
  position: sticky; top: 0; z-index: 40;
}
.topbar-title { font-weight: 700; font-size: 1.02rem; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.admin-user { font-size: .85rem; color: var(--text-2); font-weight: 600; }
.inline-form { display: inline; margin: 0; }
.lang-switch { display: inline-flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.lang-switch a { color: var(--muted); padding: 3px 8px; border-radius: 6px; font-size: .76rem; font-weight: 700; }
.lang-switch a:hover { text-decoration: none; color: var(--text); }
.lang-switch a.is-active { background: var(--accent); color: #fff; }
.burger { display: none; flex-direction: column; gap: 4px; width: 38px; height: 34px; border: 1px solid var(--border); background: #fff; border-radius: 8px; cursor: pointer; align-items: center; justify-content: center; }
.burger span { width: 17px; height: 2px; background: var(--text); border-radius: 2px; }

/* ===== content ===== */
.admin-content { padding: 20px 18px 40px; flex: 1; }
.admin-page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.admin-page-head h1 { font-size: 1.4rem; }

/* ===== flash ===== */
.flash { border-radius: var(--r-sm); padding: 11px 14px; margin-bottom: 16px; font-size: .9rem; font-weight: 600; }
.flash-success { background: var(--ok-bg); color: var(--ok); border: 1px solid #bbf7d0; }
.flash-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.flash-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #fde68a; }

/* ===== cards ===== */
.admin-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h2 { font-size: 1.08rem; }
.link { font-size: .85rem; font-weight: 600; }
.admin-cols { display: grid; gap: 16px; grid-template-columns: 1fr; }

/* ===== stats ===== */
.stat-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); margin-bottom: 18px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); }
.stat-card.accent { border-color: #a5f3fc; background: linear-gradient(180deg, #f0fdff, #fff); }
.stat-card.warn { border-color: #fde68a; background: linear-gradient(180deg, var(--warn-bg), #fff); }
.stat-value { font-size: 1.7rem; font-weight: 800; }
.stat-label { color: var(--text-2); font-size: .82rem; margin-top: 2px; }

/* ===== tables ===== */
.table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.admin-table th { text-align: left; color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .5px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.admin-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table.rows-link tbody tr:hover { background: var(--surface-2); }
.row-actions { display: inline-flex; gap: 6px; justify-content: flex-end; }
.thumb-xs { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); }
.thumb-xs.ph { display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0891b2, #22d3ee); color: #fff; font-weight: 800; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.dot.ok { background: var(--ok); }
.dot.off { background: var(--muted); }

/* ===== badges ===== */
.badge { display: inline-block; font-size: .76rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-out { background: var(--danger-bg); color: var(--danger); }
.status-badge { display: inline-block; font-size: .74rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.status-badge.pending, .status-badge.reserved { background: var(--accent-l); color: var(--accent-d); }
.status-badge.paid, .status-badge.available { background: var(--ok-bg); color: var(--ok); }
.status-badge.expired, .status-badge.sold { background: #f1f5f9; color: var(--text-2); }
.status-badge.canceled { background: var(--danger-bg); color: var(--danger); }
.status-badge.paid_needs_review { background: var(--warn-bg); color: var(--warn); }

/* ===== lists ===== */
.lowstock-list { list-style: none; margin: 0; padding: 0; }
.lowstock-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.lowstock-list li:last-child { border-bottom: none; }

/* ===== forms ===== */
.form-card { max-width: 720px; }
.form-row { margin-bottom: 15px; }
.form-label { display: block; font-weight: 600; font-size: .87rem; margin-bottom: 6px; }
.input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: .92rem; font-family: inherit; color: var(--text); background: #fff;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(8,145,178,.12); }
.input-sm { max-width: 160px; }
.textarea { resize: vertical; min-height: 80px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.hint { font-size: .79rem; color: var(--muted); margin-top: 5px; }
.cur-img { margin-bottom: 8px; }
.cur-img img { width: 110px; height: 110px; object-fit: cover; border-radius: var(--r-sm); border: 1px solid var(--border); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.form-grid-2 { display: grid; gap: 0 14px; grid-template-columns: 1fr 1fr; }
.form-section { font-size: 1.02rem; margin: 22px 0 14px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.form-section:first-child { margin-top: 0; }
.checkbox-row { display: flex; align-items: center; gap: 9px; margin-bottom: 13px; cursor: pointer; font-size: .9rem; }
.checkbox-row input { width: 17px; height: 17px; accent-color: var(--accent); }

/* ===== stock ===== */
.stock-counts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.sc-badge { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px; font-size: .82rem; }
.sc-badge.ok { background: var(--ok-bg); border-color: #bbf7d0; color: var(--ok); }
.sc-badge b { font-weight: 800; }
.stock-add-form { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 14px; margin-bottom: 16px; }
.stock-add-form .form-row { margin-bottom: 0; }
.stock-add-form .form-actions { margin-top: 12px; }
.stock-list-head { font-weight: 700; margin-bottom: 8px; }
.stock-code { font-size: .85rem; word-break: break-all; }

/* ===== filter tabs ===== */
.filter-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.filter-tabs a {
  padding: 6px 13px; border-radius: 999px; font-size: .85rem; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}
.filter-tabs a:hover { text-decoration: none; border-color: var(--accent); }
.filter-tabs a.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ===== key/value ===== */
.kv { display: flex; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.kv:last-child { border-bottom: none; }
.kv span { color: var(--text-2); flex: none; }
.kv b { text-align: right; word-break: break-word; }
.kv.col { flex-direction: column; gap: 4px; }
.kv.col b, .kv.col code { text-align: left; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.delivered-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 10px 12px; margin-bottom: 8px; }
.delivered-item code { font-size: .88rem; font-weight: 600; }

/* ===== login ===== */
.admin-login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; background: linear-gradient(135deg, #0f1b2d, #1b2a40); }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; padding: 30px 26px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
/* The forced-enrollment card needs more room — it carries a QR code, the
   plaintext secret and a verify form on the same screen. */
.login-card-wide { max-width: 520px; }
.login-card .admin-brand { color: var(--text); }
.login-title { text-align: center; font-size: 1.2rem; margin: 6px 0 18px; }
.login-foot { text-align: center; margin-top: 18px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* ===== responsive ===== */
@media (min-width: 720px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 1000px) {
  .admin-cols { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .admin-sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  body.sidebar-open .admin-sidebar { transform: translateX(0); }
  .admin-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 55; }
  body.sidebar-open .admin-backdrop { display: block; }
  .burger { display: flex; }
}
@media (max-width: 520px) {
  .form-grid-2 { grid-template-columns: 1fr; }
  .admin-user { display: none; }
}

/* ===== shared helpers (mirrors style.css for admin templates) ===== */
.center { text-align: center; }
.sm { font-size: .82rem; }
.notice { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 14px; color: var(--text-2); margin: 12px 0; }
.notice-warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.notice strong { display: block; margin-bottom: 4px; }
.hint-warn { color: var(--warn); }
.copy-field { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 8px 10px; }
.copy-value { flex: 1; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92rem; font-weight: 700; word-break: break-all; }
.copy-btn {
  font-size: .78rem; padding: 5px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer; font-weight: 600;
}
.copy-btn:hover { background: var(--accent-l); }
.copy-btn.copied { color: var(--ok); border-color: var(--ok); }
.form-subsection { font-size: .95rem; margin: 18px 0 10px; font-weight: 700; color: var(--text); }
.mini-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin-bottom: 4px; font-weight: 600; }

/* ===== 2FA-specific ===== */
.twofa-steps { padding-left: 1.4em; margin: 12px 0; }
.twofa-steps > li { margin-bottom: 22px; }
.twofa-steps > li > strong { display: block; margin-bottom: 10px; }
.twofa-qr { text-align: center; padding: 14px 0; }
.twofa-qr img { background: #fff; border-radius: var(--r-sm); padding: 8px; max-width: 100%; height: auto; }
.twofa-secret { margin-top: 12px; }
.twofa-backup { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 14px; }
.twofa-backup summary { cursor: pointer; padding: 6px 0; color: var(--text-2); font-size: .9rem; }
.twofa-backup summary:hover { color: var(--accent); }
.twofa-codes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.twofa-code-row { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 8px 10px; }
/* Backup codes are 11 chars (5-hyphen-5); MUST stay on one line so the user
   can scan them without re-assembling halves. Override the default
   word-break:break-all from .copy-value and keep the font compact. */
.twofa-code-row .copy-value { font-size: .92rem; letter-spacing: .02em; word-break: normal; white-space: nowrap; }
.twofa-codes-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 18px 0 8px; }
@media (max-width: 520px) {
  .twofa-codes { grid-template-columns: 1fr; }
}
