/* 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; }
.cosmos-brand-block .cosmos-brand-logo,
.hub-login-logo {
  display: block;
  max-width: 200px;
  max-height: 56px;
  width: auto;
  height: auto;
  margin: 0 auto 8px;
  object-fit: contain;
}
.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);
}

.field-password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.field-password-wrap input {
  width: 100%;
  padding-right: 44px;
}

.field-password-toggle {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ios-text2);
  cursor: pointer;
  touch-action: manipulation;
  transition: color 0.15s, background 0.15s;
}

.field-password-toggle:hover {
  color: var(--ios-text);
  background: rgba(0, 0, 0, 0.04);
}

.field-password-toggle:focus-visible {
  outline: 2px solid var(--ios-blue);
  outline-offset: 1px;
}

.field-password-icon {
  display: block;
}

.field-password-icon--hide {
  display: none;
}

.field-password-toggle[aria-pressed="true"] .field-password-icon--show {
  display: none;
}

.field-password-toggle[aria-pressed="true"] .field-password-icon--hide {
  display: block;
}

.login-error {
  font-size: 13px;
  color: var(--ios-red);
  min-height: 18px;
  line-height: 1.4;
}

.hub-login-clear-session {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 8px 4px;
  border: none;
  background: none;
  color: var(--text2, #64748b);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  min-height: 44px;
  touch-action: manipulation;
}

.hub-login-clear-session[hidden] {
  display: none !important;
}

.hub-login-clear-session:hover,
.hub-login-clear-session:focus-visible {
  color: var(--ios-blue);
  text-decoration: underline;
}

.hub-auth-recovery-bar {
  position: fixed;
  left: env(safe-area-inset-left, 0px);
  right: env(safe-area-inset-right, 0px);
  bottom: env(safe-area-inset-bottom, 0px);
  z-index: 700;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2, 8px);
  justify-content: center;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--card, #fff);
  border-top: 1px solid var(--border, #e2e8f0);
  box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.08);
}

.hub-auth-recovery-bar[hidden] {
  display: none !important;
}

.hub-auth-recovery-btn {
  min-height: var(--tap-target-mobile, 44px);
  padding: 8px 14px;
  border-radius: var(--radius-md, 8px);
  border: 1px solid var(--border, #e2e8f0);
  background: var(--bg, #f8fafc);
  color: var(--acc2, #1d4ed8);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

body.hub-auth-recovery-visible #screen-login.active .login-wrap,
body.hub-auth-recovery-visible #screen-hub.active .hub-main {
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}

.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-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding-right: 10px;
}

.hub-brand-icon {
  width: 32px;
  height: 32px;
}

.hub-brand {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2.5px;
  color: var(--ios-text);
  text-transform: uppercase;
  flex-shrink: 0;
}

.hub-tile-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--ios-red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  pointer-events: none;
  box-shadow: 0 0 0 2px var(--ios-card);
  z-index: 1;
}

.hub-tile-badge[hidden] {
  display: none !important;
}

.hub-header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin-left: auto;
  border: none;
  background: none;
  padding: 4px 0 4px 8px;
  cursor: pointer;
  border-radius: 10px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  text-align: right;
}
.hub-header-user.is-pressing {
  opacity: 0.72;
}
.hub-header-user:focus-visible {
  outline: 2px solid var(--ios-blue);
  outline-offset: 2px;
}

.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;
  overflow: hidden;
}
.hub-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.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 profile sheet (long-press avatar) ── */
.hub-profile-backdrop {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.35);
  animation: hubProfileFadeIn 0.15s ease;
}
.hub-profile-backdrop[hidden] {
  display: none !important;
}

.hub-profile-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 301;
  background: var(--ios-card);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.15);
  padding: 0 20px calc(20px + env(safe-area-inset-bottom, 0px));
  animation: hubProfileSheetUp 0.22s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
.hub-profile-sheet[hidden] {
  display: none !important;
}

@keyframes hubProfileFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes hubProfileSheetUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.hub-profile-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: #D1D1D6;
  margin: 12px auto 18px;
}

.hub-profile-sheet-user {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.12);
  margin-bottom: 12px;
}

.hub-profile-sheet-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #007AFF, #5AC8FA);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.hub-profile-sheet-avatar .hub-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hub-profile-sheet-meta {
  min-width: 0;
  flex: 1;
}

.hub-profile-sheet-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--ios-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hub-profile-sheet-role {
  font-size: 13px;
  color: var(--ios-text2);
  margin-top: 2px;
  text-transform: capitalize;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hub-profile-sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hub-profile-action {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  width: 100%;
  border: none;
  border-radius: 12px;
  background: var(--ios-bg);
  color: var(--ios-text);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}
.hub-profile-action:hover {
  background: rgba(0, 0, 0, 0.06);
}
.hub-profile-action--danger {
  color: var(--ios-red);
  background: rgba(255, 59, 48, 0.08);
}
.hub-profile-action--danger:hover {
  background: rgba(255, 59, 48, 0.14);
}

/* ── 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 2.5px var(--ios-blue), 0 4px 14px rgba(0, 122, 255, 0.35);
}

.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;
}

.app-tile-icon-shell {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.app-tile-icon-wrap {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 16px;
  border: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  line-height: 1;
  overflow: hidden;
  transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.app-tile-icon-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28) 0%, rgba(255, 255, 255, 0) 48%);
  pointer-events: none;
  z-index: 1;
}

.app-tile-icon-wrap--storepilot {
  background: linear-gradient(145deg, #007AFF 0%, #5AC8FA 100%);
  box-shadow: 0 4px 14px rgba(0, 122, 255, 0.38);
}

.app-tile-icon-wrap--foundry {
  background: linear-gradient(145deg, #EA580C 0%, #FBBF24 100%);
  box-shadow: 0 4px 14px rgba(234, 88, 12, 0.35);
}

.app-tile-icon-wrap--foundry_purchase {
  background: linear-gradient(145deg, #D97706 0%, #FBBF24 100%);
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.35);
}

.app-tile-icon-wrap--foundry_stock {
  background: linear-gradient(145deg, #EA580C 0%, #F59E0B 100%);
  box-shadow: 0 4px 14px rgba(234, 88, 12, 0.35);
}

.app-tile-icon-wrap--foundry_lab {
  background: linear-gradient(145deg, #2563EB 0%, #60A5FA 100%);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.app-tile-icon-wrap--finance {
  background: linear-gradient(145deg, #16A34A 0%, #4ADE80 100%);
  box-shadow: 0 4px 14px rgba(22, 163, 74, 0.35);
}

.app-tile-icon-wrap--analyst {
  background: linear-gradient(145deg, #6366F1 0%, #A78BFA 100%);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.app-tile-icon-wrap--crew {
  background: linear-gradient(145deg, #0D9488 0%, #2DD4BF 100%);
  box-shadow: 0 4px 14px rgba(13, 148, 136, 0.35);
}

.app-tile-icon-wrap--captain {
  background: linear-gradient(145deg, #B45309 0%, #F59E0B 100%);
  box-shadow: 0 4px 14px rgba(180, 83, 9, 0.35);
}

.app-tile-icon-wrap--owner {
  background: linear-gradient(145deg, #059669 0%, #34D399 100%);
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.35);
}

.app-tile-icon-wrap--army {
  background: linear-gradient(145deg, #DC2626 0%, #F87171 100%);
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.35);
}

.app-tile-icon-wrap--command_unit {
  background: linear-gradient(145deg, #6366F1 0%, #A78BFA 100%);
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.app-tile-icon-wrap--talk {
  background: linear-gradient(145deg, #0284C7 0%, #38BDF8 100%);
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);
}

.app-tile-icon-wrap--talkbox {
  background: linear-gradient(145deg, #0891B2 0%, #22D3EE 100%);
  box-shadow: 0 4px 14px rgba(8, 145, 178, 0.35);
}

.app-tile-icon-wrap--push {
  background: linear-gradient(145deg, #4F46E5 0%, #818CF8 100%);
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
}

.app-tile-icon-wrap .hub-tile-svg {
  width: 36px;
  height: 36px;
  display: block;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.app-tile-icon-wrap .hub-tile-svg--modern {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.12));
}

.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-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; }

/* ── Reinstall nudge banner ── */
.hub-pwa-reinstall-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: #1E3A5F;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  color: #fff;
}

.hub-pwa-reinstall-banner[hidden] { display: none !important; }

.hub-reinstall-icon {
  font-size: 22px;
  flex-shrink: 0;
  line-height: 1;
  margin-top: 2px;
}

.hub-reinstall-body {
  flex: 1;
  min-width: 0;
}

.hub-reinstall-title {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 4px;
}

.hub-reinstall-sub {
  font-size: 12px;
  color: rgba(255,255,255,0.8);
  line-height: 1.4;
}

.hub-reinstall-ios-steps {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: rgba(255,255,255,0.8);
  flex-wrap: wrap;
}

.hub-reinstall-share-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.hub-reinstall-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  align-items: stretch;
}

.hub-reinstall-actions .btn-primary {
  font-size: 13px;
  padding: 7px 14px;
  white-space: nowrap;
}

.hub-reinstall-actions .hub-pwa-dismiss-btn {
  font-size: 12px;
  text-align: center;
}
