:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e8ec;
  --border-strong: #d4d9e0;
  --text: #1a2232;
  --muted: #667085;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-weak: #eef2ff;
  --danger: #d92d20;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.error { color: var(--danger); font-size: .88rem; }

a { color: var(--accent); }

/* ---------- controls ---------- */

input, select, button {
  font: inherit;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: .5rem .75rem;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}
select, button { cursor: pointer; }
button:hover { background: var(--surface-2); border-color: var(--border-strong); }
button:disabled { opacity: .55; cursor: default; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 550;
}
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ---------- login ---------- */

#login { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-box {
  background: var(--surface);
  padding: 2.75rem 3rem;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 380px;
  width: 100%;
}
.login-box h1 { margin: 0 0 1.5rem; font-size: 1.35rem; letter-spacing: -.01em; }
#gsi-button { display: flex; justify-content: center; }
#login-error { margin: 1rem 0 0; }

/* ---------- header ---------- */

header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1.4rem;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
header h1 {
  font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em;
  margin: 0 .5rem 0 0; white-space: nowrap;
}
.controls { display: flex; gap: .55rem; align-items: center; flex: 1; flex-wrap: wrap; }
#search {
  flex: 1; min-width: 200px;
  background: var(--surface-2);
}
#search:focus-visible { background: var(--surface); }
#whoami { color: var(--muted); font-size: .84rem; margin-left: auto; white-space: nowrap; }

/* ---------- list ---------- */

#list { padding: 1.1rem 1.4rem 3rem; max-width: 1200px; }
#list-errors { padding: 0 1.4rem; max-width: 1200px; }
.empty { color: var(--muted); padding: 2rem .2rem; }
.host-group + .host-group { margin-top: 1.75rem; }
.host-group h3 {
  display: flex; align-items: center; gap: .5rem;
  margin: 0 0 .7rem; padding-left: .1rem;
  color: var(--muted); font-size: .72rem; font-weight: 650;
  text-transform: uppercase; letter-spacing: .06em;
}
.host-group h3 .count {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); border-radius: 999px;
  padding: 0 .5rem; font-size: .7rem; letter-spacing: 0;
}

.site-grid {
  display: grid; gap: .75rem;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.site-card {
  display: flex; flex-direction: column; gap: .5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .9rem 1rem 1rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, transform .06s;
}
.site-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(79, 70, 229, .12);
  transform: translateY(-1px);
}
.site-card:active { transform: translateY(0); }

.card-top { display: flex; align-items: baseline; gap: .5rem; }
.site-card .app {
  font-weight: 600; letter-spacing: -.005em; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.site-card .badge {
  background: var(--accent-weak); color: var(--accent);
  border-radius: 999px; padding: .15rem .6rem;
  font-size: .72rem; font-weight: 550; white-space: nowrap;
}
.site-card .url {
  color: var(--accent); text-decoration: none; font-size: .88rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.site-card .url:hover { text-decoration: underline; }
.site-card .url.muted { color: var(--muted); font-style: italic; }
.card-foot {
  margin-top: auto; padding-top: .5rem;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end;
}
.site-card .sizes {
  color: var(--muted); font-size: .78rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- drawer ---------- */

#drawer {
  position: fixed; inset: 0 0 0 auto;
  width: min(460px, 100%);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: 20; overflow-y: auto;
  animation: slide-in .22s cubic-bezier(.32, .72, 0, 1);
}
@keyframes slide-in { from { transform: translateX(100%); } to { transform: translateX(0); } }
.drawer-inner { padding: 1.6rem; position: relative; }
#d-title {
  margin: 0 2rem .2rem 0; font-size: 1.15rem; font-weight: 650;
  letter-spacing: -.01em; word-break: break-all;
}

dl { display: grid; grid-template-columns: 6.5rem 1fr; gap: 0; margin: 1.2rem 0 0; }
dl > dt, dl > dd { padding: .55rem 0; border-top: 1px solid var(--border); }
dl > dt:first-of-type, dl > dd:nth-of-type(1) { border-top: none; }
dt { color: var(--muted); font-size: .85rem; }
dd { margin: 0; word-break: break-all; min-height: 1.5rem; }

.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.5rem; }
.actions button { flex: 1 1 auto; min-width: 8.5rem; }

#d-error { margin-top: 1rem; }

.close {
  position: absolute; top: 1rem; right: 1.1rem;
  width: 2rem; height: 2rem; padding: 0;
  border: none; background: transparent;
  font-size: 1.5rem; line-height: 1; color: var(--muted);
  border-radius: var(--radius-sm);
}
.close:hover { background: var(--surface-2); color: var(--text); }

/* ---------- modal ---------- */

#modal {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(16, 24, 40, .5);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem; animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-inner {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  padding: 1.75rem;
  width: min(460px, 100%);
  box-shadow: var(--shadow-lg);
  animation: pop .18s cubic-bezier(.32, .72, 0, 1);
}
@keyframes pop { from { transform: scale(.96); opacity: .6; } to { transform: scale(1); opacity: 1; } }
.modal-inner h3 { margin: 0 2rem 1rem 0; font-size: 1.1rem; font-weight: 650; }

.cred-row { display: flex; align-items: center; gap: .5rem; margin: .45rem 0; }
.cred-row span:first-child { min-width: 5rem; color: var(--muted); font-size: .85rem; }
.cred-row code {
  flex: 1; background: var(--surface-2);
  border: 1px solid var(--border);
  padding: .35rem .55rem; border-radius: var(--radius-sm);
  font-size: .85rem; overflow-x: auto; white-space: nowrap;
}
.cred-row button { padding: .3rem .6rem; font-size: .8rem; }

/* ---------- spinner ---------- */

.list-loading {
  display: flex; align-items: center; gap: .6rem;
  color: var(--muted); padding: 2rem .2rem;
}

.spinner {
  display: inline-block; width: 1rem; height: 1rem;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: -.15rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  header h1 { width: 100%; }
  #whoami { margin-left: 0; }
  .site-grid { grid-template-columns: 1fr; }
}
