/* ===== WOMSI DESIGN SYSTEM ===== */

:root {
  --bg-page: #F8FAFC;
  --bg-card: #FFFFFF;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;

  --border: #E2E8F0;
  --border-hover: #CBD5E1;

  /* Amber accent */
  --accent: #B47318;
  --accent-bg: #FEF3DC;
  --accent-border: #F2C96A;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.10), 0 4px 10px rgba(0,0,0,0.06);

  /* Member tints */
  --matthew-bg: #FEF3DC;
  --matthew-text: #7A4A0A;
  --sofia-bg: #E1F5EE;
  --sofia-text: #0F6E56;
  --ivy-bg: #EEEDFE;
  --ivy-text: #3C3489;

  --sidebar-width: 236px;
  --mobile-topbar-height: 52px;
}

[data-theme="dark"] {
  --bg-page: #0F172A;
  --bg-card: #1E293B;

  --text-primary: #F8FAFC;
  --text-secondary: #CBD5E1;
  --text-muted: #64748B;

  --border: #334155;
  --border-hover: #475569;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4), 0 2px 6px rgba(0,0,0,0.2);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.5), 0 4px 10px rgba(0,0,0,0.3);

  --matthew-bg: rgba(180,115,24,0.18);
  --matthew-text: #F2C96A;
  --sofia-bg: rgba(15,110,86,0.18);
  --sofia-text: #34D399;
  --ivy-bg: rgba(60,52,137,0.18);
  --ivy-text: #A5B4FC;
}

/* ===== RESET ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  overflow: hidden;
}

/* ===== VIEWS ===== */
.view {
  display: none;
}

.view.active {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
#view-login {
  align-items: center;
  justify-content: center;
  background: var(--bg-page);
  padding: 1.5rem;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.login-wordmark {
  font-size: 2rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.12em;
  line-height: 1;
}

.login-subtitle {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: -1rem;
  text-align: center;
}

/* Member cards */
.member-cards {
  display: flex;
  gap: 0.875rem;
  width: 100%;
  justify-content: center;
}

.member-card {
  flex: 1;
  max-width: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.625rem;
  padding: 1rem 0.5rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  background: var(--bg-card);
}

.member-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-sm);
}

.member-card.selected {
  border-color: var(--accent-border);
  background: var(--accent-bg);
  box-shadow: 0 0 0 3px rgba(180,115,24,0.12);
}

.member-card .member-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 600;
}

.member-name {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-primary);
}

/* PIN section */
.pin-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.3s ease;
}

.pin-section.visible {
  max-height: 400px;
  opacity: 1;
}

.pin-display {
  display: flex;
  gap: 0.625rem;
  justify-content: center;
}

.pin-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border-hover);
  background: transparent;
  transition: background 0.15s, border-color 0.15s;
}

.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  width: 100%;
  max-width: 260px;
}

.pin-btn {
  aspect-ratio: 1;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 10px;
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
  font-family: inherit;
  user-select: none;
  -webkit-user-select: none;
}

.pin-btn:hover {
  background: var(--bg-page);
  border-color: var(--border-hover);
}

.pin-btn:active {
  transform: scale(0.93);
  background: var(--border);
}

.pin-btn-action {
  background: var(--bg-page);
  color: var(--text-secondary);
}

.pin-btn-confirm {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.pin-btn-confirm:hover {
  background: #9d6414;
  border-color: #9d6414;
  color: #fff;
}

.pin-btn-confirm:active {
  background: #854f0e;
  border-color: #854f0e;
}

.pin-btn-confirm:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.pin-error {
  font-size: 0.8125rem;
  color: #991B1B;
  text-align: center;
  min-height: 1.25rem;
  font-weight: 500;
}

[data-theme="dark"] .pin-error {
  color: #F87171;
}

/* ============================================================
   HUB — SHELL WORDMARK / SHARED ATOMS
   ============================================================ */
.shell-wordmark {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.08em;
  line-height: 1;
}

.shell-subtitle {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.01em;
  margin-top: 3px;
  line-height: 1;
}

/* Member chip (avatar circle) */
.member-chip {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}

.avatar-matthew { background: var(--matthew-bg); color: var(--matthew-text); }
.avatar-sofia   { background: var(--sofia-bg);   color: var(--sofia-text); }
.avatar-ivy     { background: var(--ivy-bg);     color: var(--ivy-text); }

/* Icon button */
.icon-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-page);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

/* Sign out button */
.sign-out-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.3125rem 0.625rem;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
  font-family: inherit;
  flex-shrink: 0;
}

.sign-out-btn:hover {
  background: var(--bg-page);
  border-color: var(--border-hover);
  color: var(--text-primary);
}

/* Theme icon toggle via CSS — no JS needed */
.theme-icon-moon { display: none; }
[data-theme="dark"] .theme-icon-sun  { display: none; }
[data-theme="dark"] .theme-icon-moon { display: block; }

/* ============================================================
   HUB — MOBILE TOPBAR
   ============================================================ */
.mobile-topbar {
  display: none;
  height: var(--mobile-topbar-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  align-items: center;
  justify-content: space-between;
  position: relative;
  z-index: 20;
  flex-shrink: 0;
}

.mobile-menu-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s;
}

.mobile-menu-btn:hover {
  background: var(--bg-page);
}

/* ============================================================
   HUB — LAYOUT SHELL
   ============================================================ */
#view-hub {
  overflow: hidden;
}

.hub-layout {
  display: flex;
  flex: 1;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  transition: background 0.2s;
}

.sidebar-brand {
  padding: 1.25rem 1.125rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ===== SIDEBAR NAV ===== */
.sidebar-nav {
  flex: 1;
  padding: 0.625rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

/* System entries — top-level, prominent */
.nav-system {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.nav-system:hover {
  background: var(--bg-page);
  color: var(--text-primary);
}

.nav-system.active {
  background: var(--accent-bg);
  color: var(--accent);
}

.nav-system-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg-page);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: inherit;
  transition: background 0.15s;
}

.nav-system.active .nav-system-icon {
  background: var(--accent-border);
  color: var(--accent);
}

/* Divider between systems and tools group */
.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 0.5rem 0.25rem;
}

/* Tools group */
.nav-group-label {
  font-size: 0.675rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.5rem 0.75rem 0.25rem;
}

/* Tool entries — compact */
.nav-tool {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.845rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.nav-tool:hover {
  background: var(--bg-page);
  color: var(--text-primary);
}

.nav-tool.active {
  background: var(--accent-bg);
  color: var(--accent);
}

/* Sidebar member row — clickable, opens profile */
.sidebar-member-row {
  cursor: pointer;
  border-radius: 8px;
  padding: 0.375rem 0.25rem;
  transition: background 0.15s;
}

.sidebar-member-row:hover {
  background: var(--bg-page);
}

.sidebar-edit-icon {
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: auto;
}

/* ===== SIDEBAR FOOTER ===== */
.sidebar-footer {
  padding: 0.875rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  flex-shrink: 0;
}

.sidebar-member-row {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.sidebar-member-name {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-primary);
}

.sidebar-footer-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar-footer-actions .sign-out-btn {
  flex: 1;
  justify-content: center;
}

/* ============================================================
   SIDEBAR BACKDROP (mobile)
   ============================================================ */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 29;
}

.sidebar-backdrop.visible {
  display: block;
}

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
.hub-main {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg-page);
  min-width: 0;
}

.content-pane {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: auto;
  height: 100%;
}

.content-pane.active {
  display: flex;
}

/* Dashboard */
.dashboard {
  padding: 3rem 2.5rem;
  max-width: 700px;
}

.dashboard-greeting {
  font-size: 1.625rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.dashboard-hint {
  font-size: 0.9375rem;
  color: var(--text-secondary);
}

/* Tool iframe */
.tool-frame {
  flex: 1;
  width: 100%;
  border: none;
  height: 100%;
}

/* ============================================================
   MOBILE — responsive overrides
   ============================================================ */
@media (max-width: 768px) {
  .mobile-topbar {
    display: flex;
  }

  .hub-layout {
    height: calc(100vh - var(--mobile-topbar-height));
  }

  .sidebar {
    position: fixed;
    left: calc(var(--sidebar-width) * -1);
    top: var(--mobile-topbar-height);
    height: calc(100vh - var(--mobile-topbar-height));
    z-index: 30;
    box-shadow: var(--shadow-lg);
    transition: left 0.25s ease;
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar-brand {
    display: none; /* wordmark shown in mobile topbar instead */
  }
}

@media (max-width: 400px) {
  .login-card {
    padding: 2rem 1.25rem;
  }

  .member-cards {
    gap: 0.5rem;
  }

  .pin-pad {
    max-width: 220px;
  }

  .dashboard {
    padding: 2rem 1.25rem;
  }
}

/* ============================================================
   PROFILE MODAL
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  max-height: calc(100vh - 3rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.125rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.modal-close-btn:hover {
  background: var(--bg-page);
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.modal-divider {
  height: 1px;
  background: var(--border);
  margin: 0 -1.25rem;
}

/* ===== PROFILE PHOTO ===== */
.profile-photo-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.875rem;
}

.profile-avatar-wrap {
  position: relative;
  width: 80px;
  height: 80px;
  flex-shrink: 0;
}

.profile-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 600;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  overflow: hidden;
}

.profile-avatar-overlay {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.15s;
}

.profile-avatar-wrap:hover .profile-avatar-overlay {
  opacity: 1;
}

.profile-remove-btn {
  background: none;
  border: none;
  font-size: 0.8125rem;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  padding: 0;
  transition: color 0.15s;
  display: none;
}

.profile-remove-btn:hover {
  color: #991B1B;
}

[data-theme="dark"] .profile-remove-btn:hover {
  color: #F87171;
}

.profile-remove-btn.visible {
  display: block;
}

/* ===== PIN SECTION ===== */
.profile-pin-section {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.profile-section-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.profile-field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.profile-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.profile-input {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 0.9375rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  letter-spacing: 0.2em;
}

.profile-input:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(180,115,24,0.12);
}

.profile-feedback {
  font-size: 0.8125rem;
  font-weight: 500;
  min-height: 1.25rem;
}

.profile-feedback.error {
  color: #991B1B;
}

.profile-feedback.success {
  color: #166534;
}

[data-theme="dark"] .profile-feedback.error   { color: #F87171; }
[data-theme="dark"] .profile-feedback.success { color: #4ADE80; }

.profile-save-btn {
  width: 100%;
  padding: 0.65rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, opacity 0.15s;
}

.profile-save-btn:hover {
  background: #9d6414;
}

.profile-save-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Avatar with photo on login screen */
.member-avatar.has-photo {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: transparent;
  font-size: 0;
}
