
:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --line: #e8edf3;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #3b82f6;
  --primary-soft: #eff6ff;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #ef4444;
  --purple: #8b5cf6;
  --radius: 16px;
  --shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
}
button, input, select { font: inherit; }
button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0 14px;
  color: #fff;
  background: var(--primary);
  font-weight: 600;
  cursor: pointer;
}
button:active { transform: scale(.98); }
button:disabled { opacity: .6; }
.secondary {
  color: var(--primary);
  background: #fff;
  border-color: #dbe7fb;
}
.danger {
  color: var(--danger);
  background: #fff;
  border-color: #ffd6d9;
}
.small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.hidden { display: none !important; }

.shell {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px calc(26px + env(safe-area-inset-bottom));
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
}
header h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 30px);
  line-height: 1.2;
}
header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}
header > button { flex: 0 0 auto; }

.narrow {
  max-width: 420px;
  margin: 48px auto 0;
  padding: 22px;
}
.card, .stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.card { padding: 16px; }
.card h2 { margin: 0; font-size: 19px; }

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  min-height: 40px;
  flex: 0 0 auto;
  padding: 0 14px;
  color: #475569;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: none;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.tab.active {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: #dbeafe;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.stat {
  min-height: 110px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
}
.stat strong {
  display: block;
  font-size: 32px;
  line-height: 1;
  color: var(--text);
}
.stat:nth-child(1) strong { color: var(--primary); }
.stat:nth-child(2) strong { color: var(--success); }
.stat:nth-child(3) strong { color: #0891b2; }
.stat:nth-child(4) strong { color: var(--purple); }
.stat:nth-child(5) strong, .stat:nth-child(6) strong { color: var(--warning); }
.stat:nth-child(7) strong { color: var(--danger); }

.section-gap { margin-top: 12px; }
.row-head, .generated-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}
.wide { grid-column: 1 / -1; }
label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: #475569;
  font-size: 13px;
  font-weight: 600;
}
input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
input:focus, select:focus {
  border-color: #bfdbfe;
  box-shadow: 0 0 0 3px rgba(59,130,246,.10);
}

.toolbar, .usage-toolbar {
  display: grid;
  grid-template-columns: 170px 190px 1fr auto;
  gap: 8px;
  margin-bottom: 12px;
}
.usage-toolbar { grid-template-columns: 165px 180px 180px 1fr auto; }
.list, .generated { display: grid; gap: 10px; }
.row {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.row strong { min-width: 0; word-break: break-word; }
.inventory-item {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  align-items: center;
  gap: 12px;
}
.inventory-count {
  min-width: 52px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary);
  text-align: center;
  font-size: 26px;
  font-weight: 700;
}
.generated-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.code {
  color: #334155;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  word-break: break-all;
}
.meta {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #f3f4f6;
  color: #4b5563;
  font-size: 12px;
  font-weight: 600;
}
.badge-active, .badge-used, .badge-today, .badge-recent { background: #ecfdf3; color: #15803d; }
.badge-suspended, .badge-inactive-7d { background: #fff7ed; color: #c2410c; }
.badge-revoked { background: #fef2f2; color: #dc2626; }
.badge-unused, .badge-never { background: #f5f3ff; color: #7c3aed; }

.usage-numbers {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 8px;
}
.usage-numbers div {
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafcff;
  text-align: center;
}
.usage-numbers span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11.5px;
}
.usage-numbers strong {
  color: var(--text);
  font-size: 20px;
  line-height: 1;
}
.message { min-height: 20px; margin-top: 8px; color: var(--danger); font-size: 13px; }
.success { color: var(--success); }
.generated-toolbar { margin-top: 12px; }
#generatedSummary { padding-top: 2px; color: var(--muted); font-size: 13px; }

dialog {
  width: min(430px, calc(100vw - 28px));
  border: 0;
  border-radius: 18px;
  padding: 0;
  background: transparent;
}
dialog::backdrop { background: rgba(15,23,42,.28); }
.dialog-card {
  padding: 18px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 20px 40px rgba(15,23,42,.16);
}
.dialog-card h3 { margin: 0 0 14px; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .toolbar, .usage-toolbar, .grid { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
}

@media (max-width: 640px) {
  .shell {
    padding: max(12px, env(safe-area-inset-top)) 12px calc(84px + env(safe-area-inset-bottom));
  }
  header {
    position: relative;
    align-items: flex-start;
    padding: 16px;
    border-radius: 18px;
  }
  header h1 { font-size: 22px; padding-right: 78px; }
  header p { font-size: 13px; padding-right: 50px; }
  header > button {
    position: absolute;
    right: 12px;
    top: 12px;
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
  }
  .tabs {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(5, minmax(0,1fr));
    gap: 6px;
    margin: 0;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: rgba(255,255,255,.96);
    box-shadow: 0 10px 24px rgba(15,23,42,.08);
  }
  .tab {
    min-width: 0;
    min-height: 48px;
    padding: 6px 4px;
    border-radius: 12px;
    font-size: 10.5px;
    line-height: 1.15;
    white-space: normal;
  }
  .tab::before {
    display: block;
    margin: 0 auto 4px;
    font-size: 15px;
    line-height: 1;
    color: #94a3b8;
  }
  .tab.active::before { color: var(--primary); }
  .tab[data-tab="dashboard"]::before { content: "□"; }
  .tab[data-tab="generate"]::before { content: "＋"; }
  .tab[data-tab="codes"]::before { content: "◇"; }
  .tab[data-tab="licenses"]::before { content: "✓"; }
  .tab[data-tab="usage"]::before { content: "≣"; }

  .stats { gap: 10px; }
  .stat {
    min-height: 96px;
    padding: 14px;
    border-radius: 14px;
    font-size: 12px;
  }
  .stat strong { font-size: 28px; }

  .card { padding: 14px; border-radius: 14px; }
  .card h2 { font-size: 18px; }
  .row { padding: 12px; }
  .inventory-count { min-width: 48px; font-size: 24px; }
  input, select { min-height: 44px; font-size: 16px; }
  .usage-numbers { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 390px) {
  header h1 { font-size: 20px; }
  .tab { font-size: 10px; }
  .stat strong { font-size: 26px; }
}

.codes-toolbar { grid-template-columns: 150px 180px minmax(180px, 1fr) auto auto; }
@media (max-width: 900px) { .codes-toolbar { grid-template-columns: 1fr; } }
