/* ROYS License Platform - admin panel styles.
   Dark by default with an automatic light variant, mobile first. */

:root {
  --bg: #0e1117;
  --bg-soft: #161b23;
  --bg-raised: #1c222c;
  --border: #2a323f;
  --text: #e6edf3;
  --text-dim: #9aa7b6;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, .14);
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --neutral: #7d8590;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --bg-soft: #ffffff;
    --bg-raised: #ffffff;
    --border: #d8dee6;
    --text: #1a1f26;
    --text-dim: #5b6672;
    --accent: #1f6feb;
    --accent-soft: rgba(31, 111, 235, .10);
    --shadow: 0 4px 16px rgba(20, 30, 50, .10);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- layout */
.topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1rem;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 700; letter-spacing: .3px; color: var(--text); }
.brand span { color: var(--accent); }
.spacer { flex: 1; }
.who { color: var(--text-dim); font-size: .85rem; }
.inline { display: inline; }

.env-badge {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: .18rem .5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.env-production { color: var(--bad); border-color: var(--bad); }
.env-staging { color: var(--warn); border-color: var(--warn); }

.nav-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: .25rem .55rem;
  font-size: 1.1rem;
  cursor: pointer;
}

.layout { display: flex; align-items: flex-start; }

.sidebar {
  width: 210px;
  flex: 0 0 210px;
  padding: 1rem .6rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  position: sticky;
  top: 53px;
  max-height: calc(100vh - 53px);
  overflow-y: auto;
}
.sidebar a {
  color: var(--text-dim);
  padding: .5rem .7rem;
  border-radius: 8px;
  font-size: .9rem;
}
.sidebar a:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.content { flex: 1; min-width: 0; padding: 1.2rem 1.4rem 4rem; }
.centered {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

/* ----------------------------------------------------------- typography */
h1 { font-size: 1.45rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.8rem 0 .7rem; }
h3 { font-size: .95rem; margin: 1.2rem 0 .5rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--text-dim); }
.small { font-size: .82rem; }
code, .mono { font-family: var(--mono); font-size: .86em; }

/* --------------------------------------------------------------- panels */
.card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.grid { display: grid; gap: .9rem; }
.grid-stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.stat {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .85rem 1rem;
}
.stat .value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.stat .label { color: var(--text-dim); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
.stat.ok .value { color: var(--ok); }
.stat.warn .value { color: var(--warn); }
.stat.bad .value { color: var(--bad); }

/* --------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-dim); font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; }
tbody tr:hover { background: var(--bg-raised); }
td.wrap, th.wrap { white-space: normal; }

.pill {
  display: inline-block;
  padding: .1rem .5rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .04em;
  border: 1px solid currentColor;
}
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }
.pill.bad { color: var(--bad); }
.pill.neutral { color: var(--neutral); }

/* ---------------------------------------------------------------- forms */
label { display: block; font-size: .8rem; color: var(--text-dim); margin-bottom: .25rem; }
input[type=text], input[type=password], input[type=number], input[type=email],
input[type=date], input[type=search], select, textarea {
  width: 100%;
  padding: .5rem .6rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: .8rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .7rem; }
.checkbox { display: flex; align-items: center; gap: .5rem; }
.checkbox input { width: auto; }
.checkbox label { margin: 0; color: var(--text); font-size: .9rem; }

.btn {
  display: inline-block;
  padding: .48rem .9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  font-size: .87rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn-danger:hover { background: var(--bad); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: .28rem .55rem; font-size: .78rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }

/* --------------------------------------------------------------- alerts */
.alert {
  padding: .65rem .85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: .9rem;
  font-size: .88rem;
}
.alert-success { border-color: var(--ok); color: var(--ok); }
.alert-warning { border-color: var(--warn); color: var(--warn); }
.alert-error { border-color: var(--bad); color: var(--bad); }
.alert-info { border-color: var(--accent); color: var(--accent); }

/* ----------------------------------------------------------------- tabs */
.tabs { display: flex; flex-wrap: wrap; gap: .3rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.tabs a {
  padding: .45rem .75rem;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
  font-size: .85rem;
}
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* -------------------------------------------------------------- keybox */
.keybox {
  background: var(--bg);
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  padding: .8rem;
  font-family: var(--mono);
  font-size: .9rem;
  max-height: 340px;
  overflow: auto;
  white-space: pre;
  user-select: all;
}

.auth-card {
  width: min(410px, 100%);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.6rem;
  box-shadow: var(--shadow);
}
.auth-card h1 { text-align: center; margin-bottom: .3rem; }
.auth-card .sub { text-align: center; color: var(--text-dim); font-size: .85rem; margin-bottom: 1.3rem; }

.qr { background: #fff; padding: .7rem; border-radius: 8px; display: inline-block; }
.qr svg { display: block; width: 190px; height: 190px; }

.pager { display: flex; gap: .4rem; align-items: center; margin-top: .9rem; flex-wrap: wrap; }

dl.kv { display: grid; grid-template-columns: minmax(140px, max-content) 1fr; gap: .35rem .9rem; margin: 0; }
dl.kv dt { color: var(--text-dim); font-size: .82rem; }
dl.kv dd { margin: 0; font-size: .88rem; }

.notes { white-space: pre-wrap; font-size: .86rem; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: .7rem; }

details.danger { border: 1px solid var(--bad); border-radius: var(--radius); padding: .7rem .9rem; margin-top: 1rem; }
details.danger summary { cursor: pointer; color: var(--bad); font-weight: 600; }

/* ------------------------------------------------------------- responsive */
@media (max-width: 860px) {
  .nav-toggle { display: block; }
  .layout { flex-direction: column; }
  .sidebar {
    display: none;
    width: 100%;
    flex: 1 1 auto;
    position: static;
    max-height: none;
    flex-direction: row;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
  }
  .sidebar.open { display: flex; }
  .content { padding: 1rem .8rem 3rem; }
  .who { display: none; }
  dl.kv { grid-template-columns: 1fr; }
}
