/* ===== User dashboard (dashboard.js) ===== */
/* Several blocks set display:flex/grid, which would otherwise beat the
   hidden attribute the script toggles. */
[hidden] { display: none !important; }
.dash-wrap { max-width: 1100px; }
.dash-header.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; }
.auth-card.narrow { max-width: 480px; margin-inline: auto; }
.auth-card { padding: 24px; }
.form-error {
  margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
  background: var(--red-bg); color: var(--red); font-size: 13px;
}
.fine { font-size: 12px; color: var(--text-secondary); line-height: 1.9; margin-top: 10px; }
.muted { color: var(--text-muted); }
.mono { font-family: ui-monospace, monospace; font-size: 12px; }
.empty { padding: 26px; text-align: center; color: var(--text-secondary); font-size: 14px; line-height: 2.2; }
.empty.big { padding: 46px 20px; border: 2px dashed var(--border-bright); border-radius: var(--radius); }

.btn-primary, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 12px;
  font-family: 'Vazirmatn', sans-serif; font-size: 14px; font-weight: 700;
  cursor: pointer; text-decoration: none; transition: var(--transition);
}
.btn-primary { border: none; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-light)); }
.btn-primary:hover { transform: translateY(-2px); }
.btn-primary:disabled { opacity: .6; cursor: wait; transform: none; }
.btn-primary.sm { min-height: 34px; padding: 4px 12px; font-size: 13px; margin-inline-start: 8px; }
.btn-ghost { border: 1px solid var(--border-bright); background: transparent; color: var(--text-primary); }
.btn-ghost:hover { border-color: var(--accent); }
.btn-ghost.danger { color: var(--red); }
.btn-ghost.danger:hover { border-color: var(--red); }
.icon-btn {
  min-width: 36px; min-height: 36px; border-radius: 10px; border: 1px solid var(--border-bright);
  background: var(--bg-card); color: var(--text-primary); cursor: pointer; font-size: 15px;
}

/* tabs */
.dtabs {
  display: flex; gap: 6px; overflow-x: auto; padding: 5px; margin-bottom: 22px;
  border-radius: 14px; background: var(--bg-secondary); border: 1px solid var(--border);
  scrollbar-width: none;
}
.dtab {
  flex: 1 0 auto; min-height: 42px; padding: 8px 14px; border: none; border-radius: 10px;
  background: transparent; color: var(--text-secondary); white-space: nowrap;
  font-family: 'Vazirmatn', sans-serif; font-size: 14px; font-weight: 700; cursor: pointer;
}
.dtab.active { background: var(--bg-card); color: var(--accent); box-shadow: 0 2px 10px rgba(0, 0, 0, .06); }

.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-head h2 { font-size: 1.2rem; }
.panel-head select, #usage-range {
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border-bright);
  background: var(--bg-card); color: var(--text-primary); font-family: 'Vazirmatn', sans-serif;
}
.card-h { font-size: 15px; font-weight: 800; margin-bottom: 14px; }
.card-h.sm { font-size: 13px; color: var(--text-secondary); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

.callout {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  padding: 14px 16px; margin-bottom: 18px; border-radius: var(--radius-sm);
  background: rgba(99, 102, 241, .1); border: 1px solid rgba(99, 102, 241, .3);
  font-size: 14px; line-height: 1.9;
}
.callout.warn { background: var(--gold-bg); border-color: rgba(245, 158, 11, .4); }
.callout.soft { background: var(--bg-secondary); border-color: var(--border); font-size: 13px; display: block; }
.callout a { color: var(--accent); font-weight: 700; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
@media (max-width: 900px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { padding: 16px; border-radius: var(--radius-sm); background: var(--bg-card); border: 1px solid var(--border); }
.tile small { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.tile b { font-size: 1.4rem; font-weight: 900; }
.tile span { display: block; font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.meter { height: 6px; border-radius: 99px; background: var(--bg-secondary); overflow: hidden; margin-top: 10px; }
.meter i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--accent-light)); }
.meter i.hot { background: linear-gradient(90deg, #f59e0b, #ef4444); }

/* chart */
.chart { min-height: 170px; }
.chart.tall { min-height: 230px; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 170px; }
.chart.tall .bars { height: 230px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.stack { flex: 1; width: 100%; max-width: 30px; display: flex; flex-direction: column; justify-content: flex-end; border-radius: 6px 6px 0 0; overflow: hidden; background: var(--bg-secondary); }
.stack i { display: block; width: 100%; }
.stack i.ok, .legend i.ok { background: var(--accent); }
.stack i.rej, .legend i.rej { background: var(--red); }
.bar small { font-size: 9px; color: var(--text-muted); margin-top: 4px; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 12px; font-size: 12px; color: var(--text-secondary); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: middle; margin-left: 4px; }

.kv { display: grid; gap: 10px; margin: 6px 0 16px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding-bottom: 8px; border-bottom: 1px dashed var(--border); }
.kv dt { color: var(--text-secondary); }
.kv dd { font-weight: 700; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }

/* key cards */
.keys-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-bottom: 18px; }
.key-card { min-width: 0; padding: 20px; border-radius: var(--radius); background: var(--bg-card); border: 1px solid var(--border); }
.key-card.revoked, .key-card.rejected { opacity: .72; }
.kc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.key-card h3 { font-size: 16px; }
.kc-head small { color: var(--text-secondary); font-size: 12px; }
.status { display: inline-block; white-space: nowrap; padding: 3px 10px; border-radius: 99px; font-size: 11px; font-weight: 800; background: var(--bg-secondary); color: var(--text-secondary); }
.status.ok { background: var(--green-bg); color: #047857; }
.status.wait { background: rgba(99, 102, 241, .12); color: var(--accent); }
.status.bad { background: var(--red-bg); color: #b91c1c; }
body.dark-mode .status.ok { color: var(--green); }
body.dark-mode .status.bad { color: var(--red); }
.note { padding: 10px 12px; border-radius: 10px; font-size: 13px; line-height: 1.9; margin-bottom: 12px; }
.note.wait { background: rgba(99, 102, 241, .1); }
.note.bad { background: var(--red-bg); }
.note.ok { background: var(--green-bg); }
.key-box { display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 12px; background: var(--bg-secondary); border: 1px solid var(--border); }
.key-box.disabled { opacity: .6; }
.key-text { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; font-size: 13px; color: var(--accent-2); }
.key-text.masked { filter: blur(5px); user-select: none; }
.key-meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin: 16px 0 6px; }
.key-meta div.wide { grid-column: 1 / -1; }
.key-meta dt { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; }
.key-meta dd { font-size: 13px; line-height: 1.8; overflow-wrap: anywhere; }
.key-meta a { color: var(--accent); }
.sample { margin-top: 10px; font-size: 13px; }
.sample summary { cursor: pointer; color: var(--text-secondary); }
.sample pre { margin-top: 8px; padding: 12px; border-radius: 10px; background: var(--bg-secondary); overflow-x: auto; font-size: 12px; color: var(--accent-2); }
.kc-foot { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.kc-foot .btn-ghost { min-height: 36px; font-size: 13px; padding: 6px 12px; }

/* tables */
.table-scroll { overflow-x: auto; }
.dtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.dtable th, .dtable td { padding: 10px 8px; border-top: 1px solid var(--border); text-align: right; white-space: nowrap; }
.dtable th { font-size: 12px; color: var(--text-secondary); border-top: none; }
.dtable a { color: var(--accent); }

/* key form modal */
.kmodal {
  position: fixed; inset: 0; z-index: 1000; display: none; align-items: flex-start; justify-content: center;
  padding: 24px 12px; overflow-y: auto; background: rgba(2, 6, 23, .6); backdrop-filter: blur(3px);
}
.kmodal.open { display: flex; }
.kmodal-box {
  width: 100%; max-width: 640px; padding: 24px; border-radius: var(--radius);
  background: var(--bg-card); border: 1px solid var(--border-bright); box-shadow: var(--shadow);
}
.kmodal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.kmodal-head h3 { font-size: 18px; }
.kmodal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.kmodal fieldset { border: none; margin: 14px 0; padding: 0; }
.kmodal legend { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.type-choice {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 12px 8px; border-radius: 12px; border: 1px solid var(--border-bright); cursor: pointer; text-align: center;
}
.type-choice input { position: absolute; opacity: 0; pointer-events: none; }
.type-choice span { font-size: 22px; }
.type-choice b { font-size: 12px; }
.type-choice:has(input:checked) { border: 2px solid var(--accent); background: rgba(99, 102, 241, .08); }
.type-choice:has(input:focus-visible) { outline: 3px solid var(--accent-light); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }
.kmodal textarea, .kmodal select, .form-group select {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border-bright);
  background: var(--bg-secondary); color: var(--text-primary); font-family: 'Vazirmatn', sans-serif; font-size: 14px;
}
.kmodal textarea { resize: vertical; }
.form-group small { display: block; font-size: 11px; color: var(--text-muted); margin-top: 4px; line-height: 1.8; }
.count { text-align: left; }
.count.ok { color: var(--green); }
.restrict { margin: 6px 0 14px; padding: 12px 14px; border-radius: 12px; border: 1px dashed var(--border-bright); }
.restrict summary { cursor: pointer; font-size: 13px; font-weight: 700; }
.restrict[open] summary { margin-bottom: 12px; }
.terms { padding: 12px 14px; border-radius: 12px; background: var(--bg-secondary); font-size: 12px; line-height: 2; }
.terms ul { padding-right: 18px; margin-bottom: 8px; color: var(--text-secondary); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; cursor: pointer; }
.check input { width: 18px; height: 18px; }

.dash-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); z-index: 2000;
  padding: 10px 22px; border-radius: 99px; background: #16a34a; color: #fff; font-size: 14px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: all .3s; max-width: calc(100% - 32px); text-align: center;
}
.dash-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.dash-toast.bad { background: #dc2626; }

@media (max-width: 640px) {
  .auth-card, .key-card, .kmodal-box { padding: 16px; }
  .dash-header h1 { font-size: 20px; }
}
