:root {
  color-scheme: light;
  --bg: #f7f9fb;
  --ink: #111827;
  --muted: #64748b;
  --soft: #94a3b8;
  --line: #e5eaf0;
  --surface: #ffffff;
  --surface-2: #f2f6f8;
  --surface-3: #eaf3f2;
  --accent: #12b8a6;
  --accent-dark: #0f766e;
  --accent-ink: #064e4a;
  --accent-soft: #e7f8f6;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fff7ed;
  --ok: #16a34a;
  --ok-soft: #ecfdf5;
  --shadow: 0 18px 42px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,.96) 0%, rgba(247,249,251,.96) 44%, rgba(238,243,246,.98) 100%),
    radial-gradient(circle at 72% 0%, rgba(18, 184, 166, .12), transparent 28%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .72; }
a { color: var(--accent-dark); text-decoration: none; font-weight: 700; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 30px; }
.brand-mark, .login-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: #111827;
  color: #fff;
  border-radius: 8px;
  font-weight: 850;
  box-shadow: 0 12px 28px rgba(15, 23, 42, .18);
}
.brand strong { display: block; font-size: 15px; line-height: 1.1; }
.brand span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.nav { display: grid; gap: 4px; }

.nav-item, .logout, .ghost-btn, .tab, .primary-btn, .danger-btn, .mini-btn {
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
  transition: background .16s ease, color .16s ease, transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.nav-item {
  background: transparent;
  color: #526173;
  font-weight: 650;
}
.nav-item:hover, .logout:hover, .ghost-btn:hover, .tab:hover, .mini-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.nav-item.active, .tab.active {
  background: #111827;
  color: #fff;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .16);
}
.logout {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 20px;
  background: transparent;
  color: var(--muted);
}

.workspace {
  flex: 1;
  padding: 32px 40px 56px;
  max-width: 1520px;
  margin: 0 auto;
  width: 100%;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding: 0 0 22px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
}
.topbar h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.08;
  letter-spacing: 0;
}
.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}
.ghost-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-align: center;
  min-width: 90px;
  font-weight: 700;
}
.ghost-btn:hover {
  border-color: rgba(18, 184, 166, .42);
  box-shadow: 0 8px 22px rgba(15, 23, 42, .06);
}

.view { display: none; animation: rise .22s ease both; }
.view.active { display: block; }
@keyframes rise {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.metric {
  min-height: 104px;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}
.metric strong {
  display: block;
  margin-top: 16px;
  font-size: 32px;
  line-height: 1;
  letter-spacing: 0;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.surface {
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.section-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}
.section-head span {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.list { display: grid; gap: 0; }
.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 13px 0;
  border-top: 1px solid var(--line);
}
.item:first-child { border-top: 0; }
.item strong {
  display: block;
  font-size: 15px;
  overflow-wrap: anywhere;
}
.item span, .item p {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}
.pill {
  align-self: start;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: #526173;
  font-size: 12px;
  white-space: nowrap;
}

.issue-list { display: grid; gap: 8px; }
.muted-issues { margin-top: 12px; }
.issue {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.issue.error { background: var(--danger-soft); color: var(--danger); }
.issue p { margin: 5px 0 0; color: inherit; opacity: .78; }
.ok-issue { background: var(--ok-soft); color: var(--ok); }
.known-title { color: var(--muted); font-size: 13px; margin: 6px 0 2px; }

.project-list { display: grid; gap: 12px; }
.project-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 188px;
  gap: 18px;
  padding: 18px;
  border: 1px solid rgba(203, 213, 225, .74);
  border-radius: 8px;
  background: rgba(255,255,255,.97);
  box-shadow: 0 14px 34px rgba(15, 23, 42, .055);
}
.project-row:hover {
  border-color: rgba(18, 184, 166, .36);
  box-shadow: 0 18px 42px rgba(15, 23, 42, .075);
}
.project-main { min-width: 0; }
.project-head {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}
.project-avatar {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid rgba(203, 213, 225, .78);
  background: var(--surface-2);
  box-shadow: 0 10px 24px rgba(15, 23, 42, .08);
}
.avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--accent-ink);
  background: linear-gradient(135deg, #e7f8f6, #f8fafc);
  font-weight: 850;
  font-size: 20px;
}
.project-heading { min-width: 0; }
.project-title {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: baseline;
}
.project-title strong {
  font-size: 19px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.project-title span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.project-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}
.project-links span {
  min-width: 0;
  overflow-wrap: anywhere;
}
.ai-panel {
  margin-top: 14px;
  padding: 14px 15px;
  border: 1px solid rgba(18, 184, 166, .24);
  background: linear-gradient(180deg, rgba(243,255,253,.95), rgba(255,255,255,.96));
  border-radius: 8px;
}
.ai-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 850;
  margin-bottom: 7px;
}
.ai-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(18, 184, 166, .13);
}
.project-analysis {
  margin: 0;
  color: #0f172a;
  font-size: 15px;
  line-height: 1.6;
  font-weight: 680;
  overflow-wrap: anywhere;
}
.project-meta-note {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.analysis-grid div {
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid rgba(18, 184, 166, .18);
  border-radius: 8px;
  background: rgba(255, 255, 255, .72);
}
.analysis-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}
.analysis-grid strong {
  display: block;
  color: #0f172a;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.project-side {
  display: grid;
  gap: 8px;
  align-content: start;
}
.project-stat {
  padding: 11px 12px;
  background: #f4f7f9;
  border-radius: 8px;
  border: 1px solid rgba(229, 234, 240, .92);
}
.project-stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.project-stat strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  line-height: 1.1;
}
.mini-btn {
  border: 1px solid rgba(18, 184, 166, .3);
  background: var(--accent-soft);
  color: var(--accent-ink);
  text-align: center;
  font-size: 12px;
  font-weight: 760;
  padding: 9px 10px;
}
.mini-btn:hover {
  background: #dff6f3;
  border-color: rgba(18, 184, 166, .48);
}

.data-table { width: 100%; overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}
th, td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  vertical-align: top;
}
th {
  color: var(--muted);
  font-weight: 760;
  background: #fbfdfe;
}
td { overflow-wrap: anywhere; }

.watcher-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.watcher-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-bottom: 8px;
}
.watcher-form input, .login-form input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  background: #fff;
  outline: none;
}
.watcher-form input:focus, .login-form input:focus {
  border-color: rgba(18, 184, 166, .65);
  box-shadow: 0 0 0 3px rgba(18, 184, 166, .12);
}
.primary-btn {
  background: var(--accent);
  color: white;
  text-align: center;
  font-weight: 780;
  box-shadow: 0 10px 24px rgba(18, 184, 166, .2);
}
.primary-btn:hover { background: #0ea594; }
.form-message {
  min-height: 20px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}
.watcher {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
}
.watcher strong { display: block; overflow-wrap: anywhere; }
.watcher-link {
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}
.watcher-link:hover {
  color: var(--accent-dark);
  text-decoration: underline;
}
.watcher span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}
.danger-btn {
  border: 1px solid rgba(220, 38, 38, .22);
  color: var(--danger);
  background: rgba(220, 38, 38, .05);
  padding: 7px 9px;
  text-align: center;
  white-space: nowrap;
}
.danger-btn:hover { background: rgba(220, 38, 38, .09); }

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.tab {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
}
.log-box {
  margin: 0;
  max-height: 66vh;
  overflow: auto;
  padding: 14px;
  background: #0f172a;
  color: #e5e7eb;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.log-line-error { color: #fca5a5; }
.log-line-warning { color: #fde68a; }

.health-list { display: grid; gap: 9px; }
.health-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 220px) minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}
.health-row:first-child { border-top: 0; }
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  background: var(--danger);
}
.dot.ok { background: var(--ok); }
.health-row strong {
  min-width: 0;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.health-row span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.admin-form {
  display: grid;
  grid-template-columns: 120px 120px 180px minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}
.admin-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.admin-form input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255,255,255,.06);
  color: var(--ink);
  padding: 0 10px;
}
.code-box {
  display: none;
  white-space: pre-wrap;
  margin: 8px 0 14px;
  padding: 12px;
  border: 1px solid rgba(20, 184, 166, .35);
  border-radius: 7px;
  background: rgba(20, 184, 166, .08);
  color: #0f766e;
}
.code-box:not(:empty) { display: block; }
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.06);
  color: var(--muted);
  white-space: nowrap;
}
.status-active,
.status-sent,
.status-unused {
  color: #047857;
  border-color: rgba(4,120,87,.22);
  background: rgba(4,120,87,.08);
}
.status-disabled,
.status-expired,
.status-error {
  color: var(--danger);
  border-color: rgba(220,38,38,.22);
  background: rgba(220,38,38,.07);
}
.status-used,
.status-token_ok {
  color: #1d4ed8;
  border-color: rgba(29,78,216,.22);
  background: rgba(29,78,216,.07);
}
.danger-inline {
  color: var(--danger);
  border-color: rgba(220,38,38,.22);
}

.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
}
.login-shell { width: min(440px, calc(100vw - 32px)); }
.login-panel {
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 34px;
}
.login-panel h1 {
  margin: 18px 0 4px;
  font-size: 34px;
  letter-spacing: 0;
}
.login-panel p {
  margin: 0 0 24px;
  color: var(--muted);
}
.login-form { display: grid; gap: 10px; }
.login-form input { width: 100%; }
.login-form button {
  border: 0;
  border-radius: 8px;
  padding: 13px 14px;
  background: var(--accent);
  color: white;
  font-weight: 780;
}
.login-error {
  min-height: 20px;
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
}

@media (max-width: 980px) {
  .app { display: block; }
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px 14px 10px;
  }
  .brand { margin-bottom: 12px; }
  .nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }
  .nav-item {
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .logout {
    position: static;
    margin-top: 8px;
    width: 100%;
    text-align: center;
  }
  .workspace { padding: 20px 14px 32px; }
  .topbar { align-items: stretch; }
  .topbar h1 { font-size: 28px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
  .project-row { grid-template-columns: 1fr; }
  .project-head { grid-template-columns: 48px minmax(0, 1fr); }
  .project-avatar { width: 48px; height: 48px; }
  .project-side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .watcher-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .topbar { display: grid; }
  .topbar h1 { font-size: 26px; }
  .metric-grid { grid-template-columns: 1fr; }
  .item { grid-template-columns: 1fr; }
  .section-head { display: block; }
  .section-head span {
    display: block;
    margin-top: 4px;
    text-align: left;
  }
  .project-title { display: block; }
  .project-title span {
    display: block;
    margin-top: 5px;
    white-space: normal;
  }
  .analysis-grid { grid-template-columns: 1fr; }
  .project-side { grid-template-columns: 1fr; }
  .watcher-form { grid-template-columns: 1fr; }
  .watcher-grid { grid-template-columns: 1fr; }
  .admin-form { grid-template-columns: 1fr; }
  .health-row { grid-template-columns: 18px 1fr; }
  .health-row span { grid-column: 2; }
}
