/* Cosmos Hub — iOS-style launcher + login (matches cosmos-ios-shell) */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ios-bg: #F2F2F7;
  --ios-card: #FFFFFF;
  --ios-border: rgba(0, 0, 0, 0.12);
  --ios-blue: #007AFF;
  --ios-blue-press: #0056CC;
  --ios-text: #000000;
  --ios-text2: #8E8E93;
  --ios-text3: #C7C7CC;
  --ios-red: #FF3B30;
  --ios-radius: 14px;
  --ios-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--ios-bg);
  color: var(--ios-text);
  -webkit-font-smoothing: antialiased;
}

body.cosmos-hub-shell {
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Screens ── */
.screen { display: none; min-height: 100vh; min-height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }

/* ── Login (iOS light) ── */
.screen#screen-login {
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--ios-bg);
}

.login-wrap {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.login-brand { text-align: center; }
.login-logo {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--ios-text);
}
.login-tagline {
  font-size: 11px;
  color: var(--ios-text2);
  letter-spacing: 0.08em;
  margin-top: 6px;
  text-transform: uppercase;
  font-weight: 600;
}

.login-card {
  background: var(--ios-card);
  border: 0.5px solid var(--ios-border);
  border-radius: var(--ios-radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--ios-shadow);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ios-text2);
  letter-spacing: 0.02em;
}
.field input {
  background: var(--ios-bg);
  border: 0.5px solid var(--ios-border);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 16px;
  color: var(--ios-text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.field input:focus {
  border-color: var(--ios-blue);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}

.login-error {
  font-size: 13px;
  color: var(--ios-red);
  min-height: 18px;
  line-height: 1.4;
}

.btn-primary {
  background: var(--ios-blue);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  margin-top: 4px;
  font-family: inherit;
  min-height: 44px;
  touch-action: manipulation;
}
.btn-primary:hover:not(:disabled) { background: var(--ios-blue-press); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }

/* ── Hub header (matches cosmos-topnav) ── */
.hub-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  min-height: 52px;
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.18);
  background: var(--ios-card);
  flex-shrink: 0;
  gap: 12px;
}

.hub-brand {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2.5px;
  color: var(--ios-text);
  text-transform: uppercase;
  flex-shrink: 0;
}

.hub-header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin-left: auto;
}

.hub-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #007AFF, #5AC8FA);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.hub-user-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  min-width: 0;
}

.hub-user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ios-text);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hub-user-role {
  font-size: 11px;
  color: var(--ios-text2);
  text-transform: capitalize;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hub-signout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 8px;
  color: var(--ios-text2);
  transition: color 0.15s, background 0.15s;
  padding: 0;
  flex-shrink: 0;
  touch-action: manipulation;
}
.hub-signout-btn:hover {
  background: var(--ios-bg);
  color: var(--ios-red);
}
.hub-signout-btn svg { width: 16px; height: 16px; }

/* ── Hub main ── */
.hub-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 20px 32px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.hub-greeting {
  width: 100%;
  max-width: 720px;
  font-size: 28px;
  font-weight: 700;
  color: var(--ios-text);
  margin-bottom: 24px;
  letter-spacing: -0.4px;
  line-height: 1.2;
}

/* ── App grid (iOS home-screen style) ── */
.hub-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px 12px;
  width: 100%;
  max-width: 720px;
}

.app-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.app-tile.is-pressing .app-tile-icon-wrap {
  transform: scale(0.92);
  opacity: 0.75;
}

.app-tile.is-default .app-tile-icon-wrap {
  box-shadow: 0 0 0 1.5px var(--ios-blue), var(--ios-shadow);
}

.app-tile.is-default .app-tile-label {
  color: var(--ios-blue);
  font-weight: 600;
}

.app-tile-open {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-decoration: none;
  color: inherit;
  padding: 4px 2px;
  cursor: pointer;
}

.hub-default-hint {
  margin: -12px 0 18px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ios-text2);
  text-align: center;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

.app-tile-icon-wrap {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: var(--ios-card);
  border: 0.5px solid var(--ios-border);
  box-shadow: var(--ios-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  line-height: 1;
  transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.app-tile-icon-wrap .hub-tile-svg {
  width: 40px;
  height: 40px;
  display: block;
  flex-shrink: 0;
}

.app-tile-icon-wrap .cosmos-icon--lg.hub-tile-module-icon {
  width: 40px;
  height: 40px;
  color: inherit;
}

.app-tile-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ios-text);
  line-height: 1.25;
  max-width: 88px;
}

.app-tile-desc {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Empty state ── */
.hub-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--ios-text2);
  font-size: 14px;
  line-height: 1.7;
  margin-top: 32px;
  padding: 24px;
  background: var(--ios-card);
  border-radius: var(--ios-radius);
  border: 0.5px solid var(--ios-border);
}

/* ── Mobile ── */
@media (max-width: 600px) {
  .hub-header { padding: 0 14px; }
  .hub-user-meta { display: none; }
  .hub-main { padding: 16px 16px 28px; }
  .hub-greeting { font-size: 22px; margin-bottom: 12px; }
  .hub-default-hint { font-size: 12px; margin-bottom: 16px; }
  .hub-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 18px 8px;
  }
  .app-tile-icon-wrap {
    width: 58px;
    height: 58px;
    border-radius: 14px;
    font-size: 26px;
  }
  .app-tile-label { font-size: 11px; max-width: 76px; }
}

@media (max-width: 360px) {
  .hub-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ── Hub PWA install / offline ── */
.hub-pwa-install-banner,
.hub-pwa-ios-hint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: #E8F2FF;
  border-bottom: 1px solid rgba(0, 122, 255, 0.2);
}
.hub-pwa-ios-hint {
  background: #FFF8E6;
  border-bottom-color: rgba(217, 119, 6, 0.25);
}
.hub-pwa-install-banner[hidden],
.hub-pwa-ios-hint[hidden] { display: none !important; }
.hub-pwa-install-copy {
  font-size: 13px;
  color: #0056CC;
  flex: 1;
  min-width: 180px;
  line-height: 1.4;
}
.hub-pwa-ios-hint .hub-pwa-install-copy { color: #B45309; font-weight: 600; }
.hub-pwa-ios-sub {
  font-size: 12px;
  color: var(--ios-text2);
  font-weight: 400;
  display: block;
  margin-top: 4px;
}
.hub-pwa-install-actions { display: flex; gap: 8px; flex-shrink: 0; }
.hub-pwa-install-btn { padding: 8px 14px; font-size: 13px; min-height: 36px; }
.hub-pwa-dismiss-btn {
  border: none;
  background: transparent;
  color: var(--ios-text2);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 10px;
  cursor: pointer;
}
.hub-pwa-offline-msg {
  font-size: 13px;
  color: #B45309;
  background: #FFF8E6;
  border: 1px solid rgba(217, 119, 6, 0.25);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.hub-pwa-offline-msg[hidden] { display: none !important; }
