:root {
  --bg: #09090b;
  --surface: #111114;
  --surface-2: #18181c;
  --surface-3: #202026;
  --border: #23232a;
  --border-hi: #32323c;
  --ink: #f4f4f6;
  --ink-2: #a1a1aa;
  --ink-3: #71717a;
  --primary: #fafafa;
  --primary-ink: #09090b;
  --ok: #22c55e;
  --ok-bg: rgba(34, 197, 94, 0.12);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.12);
  --bad: #ef4444;
  --bad-bg: rgba(239, 68, 68, 0.12);
  --info: #38bdf8;
  --info-bg: rgba(56, 189, 248, 0.12);
  --r-lg: 16px;
  --r-md: 12px;
  --r-sm: 9px;
  --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
  background: var(--bg);
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100dvh;
  overflow-x: clip;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
  max-width: 100%;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

.mono {
  font-family: var(--mono);
}

.auth-screen {
  min-height: 100dvh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px 18px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--surface-3);
  border: 1px solid var(--border-hi);
  display: grid;
  place-items: center;
  color: var(--ink);
  flex-shrink: 0;
}

.auth-title {
  margin: 14px 0 4px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.auth-sub {
  margin: 0 0 18px;
  color: var(--ink-2);
  font-size: 13px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  min-width: 0;
  width: 100%;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
}

.input, .select, .textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.14s ease;
}

.select {
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--ink-2);
}

.textarea {
  min-height: 88px;
  resize: vertical;
  line-height: 1.5;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  max-width: 100%;
  transition: opacity 0.12s ease, background 0.12s ease, transform 0.08s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-ink);
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-ghost {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
}

.btn-ghost:hover {
  background: var(--surface-3);
}

.btn-danger {
  background: var(--bad-bg);
  border: 1px solid rgba(239, 68, 68, 0.28);
  color: var(--bad);
}

.btn-success {
  background: var(--ok-bg);
  border: 1px solid rgba(34, 197, 94, 0.28);
  color: var(--ok);
}

.btn-sm {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-full {
  width: 100%;
}

.shell {
  display: flex;
  width: 100%;
  max-width: 100%;
  min-height: 100dvh;
}

.sidebar {
  display: none;
  width: 236px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100dvh;
}

.side-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
}

.side-title {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.02em;
}

.side-role {
  font-size: 11px;
  color: var(--ink-3);
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 9px;
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  width: 100%;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.nav-item.active {
  background: var(--surface-3);
  color: var(--ink);
}

.main-wrap {
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(74px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: 52px;
  padding: 0 14px;
  background: rgba(9, 9, 11, 0.92);
  border-bottom: 1px solid var(--border);
  width: 100%;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.top-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-2);
  max-width: 100%;
  white-space: nowrap;
}

.pill.green { background: var(--ok-bg); border-color: rgba(34, 197, 94, 0.25); color: var(--ok); }
.pill.amber { background: var(--warn-bg); border-color: rgba(245, 158, 11, 0.25); color: var(--warn); }
.pill.rose { background: var(--bad-bg); border-color: rgba(239, 68, 68, 0.25); color: var(--bad); }
.pill.blue { background: var(--info-bg); border-color: rgba(56, 189, 248, 0.25); color: var(--info); }

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.content {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.grid-2, .grid-3 {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  width: 100%;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px;
  min-width: 0;
  width: 100%;
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  min-width: 0;
}

.card-head > div {
  min-width: 0;
  flex: 1 1 160px;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
}

.card-sub {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
}

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-val {
  font-size: clamp(16px, 4.6vw, 20px);
  font-weight: 700;
  letter-spacing: -0.025em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-sub {
  font-size: 11px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.canvas-box {
  width: 100%;
  height: 168px;
  position: relative;
  overflow: hidden;
}

.canvas-box canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.bar-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--ink);
  transition: width 0.25s ease;
}

.bar-fill.green { background: var(--ok); }
.bar-fill.amber { background: var(--warn); }
.bar-fill.rose { background: var(--bad); }
.bar-fill.violet { background: var(--info); }

.list-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  width: 100%;
}

.row-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 11px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  min-width: 0;
  width: 100%;
}

.row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.row-main {
  min-width: 0;
  flex: 1;
}

.row-title {
  font-weight: 600;
  font-size: 13px;
  overflow-wrap: anywhere;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.row-meta {
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 2px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  width: 100%;
}

.seg-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  max-width: 100%;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.seg-tabs::-webkit-scrollbar {
  display: none;
}

.seg-btn {
  padding: 7px 12px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
  flex-shrink: 0;
}

.seg-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-ink);
}

.switch {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border-hi);
  transition: background 0.16s ease;
  flex-shrink: 0;
}

.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 0.16s ease;
}

.switch.on {
  background: var(--ok);
  border-color: var(--ok);
}

.switch.on::after {
  transform: translateX(18px);
}

.chat-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: 10px;
}

.chat-msg {
  max-width: 88%;
  padding: 8px 11px;
  border-radius: 11px;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--primary);
  color: var(--primary-ink);
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
}

.chat-bar {
  display: flex;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.chat-bar .input {
  flex: 1;
  min-width: 0;
}

.plan-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.plan-card.selected {
  border-color: var(--primary);
  background: var(--surface-2);
}

.plan-price {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.plan-feats {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--ink-2);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  background: rgba(17, 17, 20, 0.96);
  border-top: 1px solid var(--border);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  width: 100%;
}

.bnav-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 46px;
  border-radius: 10px;
  color: var(--ink-3);
  font-size: 10px;
  font-weight: 600;
}

.bnav-btn.active {
  color: var(--ink);
  background: var(--surface-3);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 40;
  display: flex;
  align-items: flex-end;
}

.sheet-panel {
  width: 100%;
  background: var(--surface);
  border-top: 1px solid var(--border-hi);
  border-radius: 18px 18px 0 0;
  padding: 14px 14px calc(18px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.76);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: 18px;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal-desc {
  font-size: 13px;
  color: var(--ink-2);
  margin: 0;
}

.tappable {
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.14s ease, background 0.14s ease;
}

.tappable:hover {
  border-color: var(--border-hi);
}

.tappable:active {
  transform: scale(0.98);
  background: var(--surface-2);
}

.detail-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12px;
}

.detail-row span:first-child {
  color: var(--ink-2);
  flex-shrink: 0;
}

.detail-row span:last-child {
  font-weight: 600;
  text-align: right;
  overflow-wrap: anywhere;
}

.detail-preview {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: var(--r-md);
  background: var(--bg);
  border: 1px solid var(--border);
}

.toast-root {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 99;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.toast {
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border-hi);
  color: var(--ink);
  max-width: 100%;
  text-align: center;
}

.toast.ok { border-color: rgba(34, 197, 94, 0.4); color: var(--ok); }
.toast.err { border-color: rgba(239, 68, 68, 0.4); color: var(--bad); }

.empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--ink-3);
  font-size: 13px;
}

.key-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
  min-width: 0;
  width: 100%;
}

.key-box span {
  min-width: 0;
  flex: 1;
  overflow-wrap: anywhere;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.media-tile {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.media-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border-radius: 8px;
  background: var(--bg);
}

.media-thumb.cover {
  object-fit: cover;
}

.media-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: 11px;
  color: var(--ink-2);
}

@media (min-width: 720px) {
  .media-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .row-item {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .row-actions {
    width: auto;
    flex-shrink: 0;
  }
  .toast-root {
    left: auto;
    right: 16px;
    align-items: flex-end;
  }
}

@media (min-width: 960px) {
  .sidebar { display: flex; }
  .bottom-nav { display: none; }
  .main-wrap { padding-bottom: 24px; }
  .content { padding: 20px 24px; }
}
