/* Kitdir Admin — utilitarian list/table UI */
:root {
  --bg: #f6f7f8;
  --panel: #fff;
  --text: #1a1d21;
  --muted: #5c6570;
  --border: #d8dde3;
  --border-strong: #b8c0c9;
  --accent: #1f4b99;
  --accent-hover: #163a78;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --high: #b42318;
  --high-bg: #fef3f2;
  --medium: #b54708;
  --medium-bg: #fffaeb;
  --low: #475467;
  --low-bg: #f2f4f7;
  --focus: #2e6bd9;
  --radius: 4px;
  --font: "IBM Plex Sans", "Segoe UI", "PingFang SC", "Noto Sans SC",
    "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
}

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

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

#app {
  min-height: 100vh;
}

.boot {
  padding: 2rem;
  color: var(--muted);
}

/* —— Shell —— */
.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0 1.25rem;
  height: 48px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.brand:hover {
  text-decoration: none;
  color: var(--accent);
}

.nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}
.nav a {
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
}
.nav a:hover {
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
}
.nav a.active {
  background: #e8eef8;
  color: var(--accent);
  font-weight: 560;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.main {
  flex: 1;
  padding: 1.25rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.page-head h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.015em;
}
.page-head .sub {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* —— Forms / controls —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  height: 32px;
  padding: 0 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  white-space: nowrap;
}
.btn:hover {
  background: var(--bg);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn-danger {
  color: var(--danger);
  border-color: #f3b4b0;
  background: var(--danger-bg);
}
.btn-danger:hover {
  background: #fce8e6;
}
.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover {
  background: var(--bg);
  color: var(--text);
}
.btn-sm {
  height: 28px;
  padding: 0 0.55rem;
  font-size: 0.875rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.9rem;
}
.field label {
  font-size: 0.8rem;
  font-weight: 560;
  color: var(--muted);
}
.field .hint {
  font-size: 0.78rem;
  color: var(--muted);
}
.field .err {
  font-size: 0.78rem;
  color: var(--danger);
}
.field.has-error input,
.field.has-error select,
.field.has-error textarea {
  border-color: #f04438;
  background: #fff8f7;
}

.input,
.select,
.textarea {
  height: 34px;
  padding: 0 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  outline: none;
}
.textarea {
  height: auto;
  min-height: 72px;
  padding: 0.5rem 0.6rem;
  resize: vertical;
}
.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(46, 107, 217, 0.15);
}
.input[readonly] {
  background: var(--bg);
  color: var(--muted);
}

.row-inline {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 0.75rem;
  padding: 0.65rem 0.75rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.toolbar .grow {
  flex: 1;
  min-width: 160px;
}
.toolbar .input,
.toolbar .select {
  height: 32px;
}

/* —— Table —— */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.data th,
table.data td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data th {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: #fafbfc;
  white-space: nowrap;
}
table.data tr:last-child td {
  border-bottom: none;
}
table.data tbody tr:hover td {
  background: #fafbfc;
}
table.data tr.risk-high td {
  background: #fff8f7;
}
table.data tr.risk-high:hover td {
  background: #ffefed;
}
table.data .name-cell {
  font-weight: 560;
}
table.data .name-cell .id {
  display: block;
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--muted);
  font-weight: 400;
}
table.data .actions {
  white-space: nowrap;
  text-align: right;
}
table.data .actions a,
table.data .actions button {
  margin-left: 0.25rem;
}

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

/* —— Badges —— */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  height: 22px;
  padding: 0 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-high {
  color: var(--high);
  background: var(--high-bg);
  border-color: #fecdca;
}
.badge-medium {
  color: var(--medium);
  background: var(--medium-bg);
  border-color: #fedf89;
}
.badge-low {
  color: var(--low);
  background: var(--low-bg);
  border-color: #d0d5dd;
}
.badge-ok {
  color: var(--ok);
  background: var(--ok-bg);
  border-color: #abefc6;
}
.badge-no {
  color: var(--muted);
  background: var(--low-bg);
  border-color: var(--border);
}
.badge-pin {
  color: var(--high);
  background: var(--high-bg);
  border-color: #fecdca;
}

/* —— Login —— */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.5rem;
}
.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.15rem;
}
.login-card .sub {
  margin: 0 0 1.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.login-card .btn {
  width: 100%;
  height: 36px;
  margin-top: 0.35rem;
}
.banner {
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius);
  margin-bottom: 0.9rem;
  font-size: 0.875rem;
}
.banner-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #fecdca;
}
.banner-ok {
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid #abefc6;
}
.banner-info {
  background: #eff4ff;
  color: #3538cd;
  border: 1px solid #c7d7fe;
}

/* —— Form layout —— */
.form-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 1rem;
  align-items: start;
}
@media (max-width: 860px) {
  .form-layout {
    grid-template-columns: 1fr;
  }
}
.form-card,
.side-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.side-card h2 {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 0.85rem;
}
@media (max-width: 560px) {
  .form-grid-2 {
    grid-template-columns: 1fr;
  }
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  height: 28px;
  padding: 0 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}
.chip input {
  margin: 0;
}
.chip.on {
  border-color: #98b5e8;
  background: #eef4ff;
  color: var(--accent);
}
.chip-add {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.45rem;
}
.chip-add .input {
  flex: 1;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}
.toggle input {
  width: 16px;
  height: 16px;
}

.counter {
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}
.counter.over {
  color: var(--danger);
  font-weight: 600;
}

.preview-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  background: #fafbfc;
}
.preview-row .pname {
  font-weight: 600;
  margin-bottom: 0.15rem;
}
.preview-row .pline {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 0.4rem;
  word-break: break-word;
}
.preview-row .pmeta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

/* —— Analytics —— */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.65rem;
  margin-bottom: 1rem;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}
.stat .label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.stat .value {
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin-top: 0.15rem;
  font-variant-numeric: tabular-nums;
}
.stat .value.danger {
  color: var(--danger);
}

.kv {
  margin: 0;
}
.kv dt {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.65rem;
}
.kv dd {
  margin: 0.15rem 0 0;
  word-break: break-word;
}

.flash {
  margin-bottom: 0.75rem;
}

.stat .hint {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}
.stat-accent {
  border-color: #c7d7fe;
  background: #f8faff;
}
.analytics-panel {
  padding: 1rem 1.1rem;
  margin-bottom: 0.85rem;
}
.analytics-panel .panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.analytics-panel .panel-head h2 {
  margin: 0;
  font-size: 0.95rem;
}
.analytics-panel .muted {
  color: var(--muted);
  font-size: 0.8rem;
}
.spark {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
  min-height: 84px;
  overflow-x: auto;
  padding-bottom: 0.15rem;
}
.spark-col {
  flex: 1 0 28px;
  min-width: 28px;
  max-width: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}
.spark-bar {
  width: 100%;
  max-width: 28px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
}
.spark-lbl {
  font-size: 0.65rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.range-toggle {
  display: inline-flex;
  gap: 0.25rem;
}
.foot-note {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.analytics-toolbar {
  margin-bottom: 0.85rem;
}
.section-title {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  font-weight: 650;
}
.analytics-section {
  margin-bottom: 1.25rem;
}
.risk-section {
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
}
.analytics-toolbar .muted {
  color: var(--muted);
  font-size: 0.85rem;
}
.analytics-toolbar .input {
  height: 28px;
  margin-left: 0.25rem;
}
