/*
  Moved from the inline <style> block in index.html during cleanup pass 2.
  Kept at the top of app-redesign.css so the cascade order remains the same:
  base feature CSS -> these header/skeleton rules -> existing app redesign rules.
*/
:root {
      --header-height: 64px;
      --header-bg: rgba(255, 255, 255, 0.86);
      --header-border: rgba(226, 228, 240, 0.9);
      --header-text: #171b2f;
      --header-muted: #66708f;
      --header-primary: #5b35f5;
      --header-soft: #f3f0ff;
    }

    body {
      font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    }

    /* Small smart app header */

    .top-header.smart-header {
      height: var(--header-height);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 16px;
      padding: 0 20px;
      position: sticky;
      top: 0;
      z-index: 300;
      border-bottom: 1px solid var(--header-border);
      background: var(--header-bg);
      backdrop-filter: blur(16px);
      -webkit-backdrop-filter: blur(16px);
    }

    .smart-header-brand {
      display: flex;
      align-items: center;
      gap: 11px;
      min-width: 0;
      color: inherit;
      text-decoration: none;
    }

    .smart-header-logo {
      width: 38px;
      height: 38px;
      display: grid;
      place-items: center;
      flex: 0 0 auto;
      border-radius: 14px;
      background: linear-gradient(135deg, #ffffff, var(--header-soft));
      color: var(--header-primary);
      box-shadow: 0 8px 24px rgba(91, 53, 245, 0.12);
      font-size: 17px;
    }

    .smart-header-title {
      min-width: 0;
    }

    .smart-header-title h1 {
      margin: 0;
      color: var(--header-text);
      font-size: 18px;
      font-weight: 800;
      letter-spacing: -0.04em;
      line-height: 1.1;
    }

    .smart-header-title p {
      margin: 3px 0 0;
      color: var(--header-muted);
      font-size: 12px;
      font-weight: 600;
      line-height: 1;
    }

    .smart-header-search {
      max-width: 560px;
      flex: 1;
    }

    .smart-header-actions {
      display: flex;
      align-items: center;
      gap: 9px;
      flex: 0 0 auto;
    }

    .smart-header-actions .icon-button {
      width: 38px;
      height: 38px;
      display: grid;
      place-items: center;
      border: none;
      border-radius: 14px;
      background: #f6f7fb;
      color: var(--header-muted);
      cursor: pointer;
      position: relative;
      transition:
        background 0.18s ease,
        color 0.18s ease,
        transform 0.18s ease;
    }

    .smart-header-actions .icon-button:hover {
      transform: translateY(-1px);
      background: var(--header-soft);
      color: var(--header-primary);
    }

    .smart-header-actions .profile-menu {
      height: 38px;
      display: flex;
      align-items: center;
      gap: 7px;
      padding: 0 8px;
      border-radius: 14px;
      background: #f6f7fb;
      cursor: pointer;
    }

    .smart-header-actions .profile-menu img {
      width: 28px;
      height: 28px;
      border-radius: 50%;
      object-fit: cover;
    }

    .smart-header-actions .profile-menu i {
      color: var(--header-muted);
      font-size: 12px;
    }

    /* Initial loading skeletons prevent old demo-template flashes */

    .sync-skeleton-list {
      display: grid;
      gap: 10px;
    }

    .sync-skeleton-conversation {
      display: grid;
      grid-template-columns: 48px 1fr;
      gap: 12px;
      align-items: center;
      padding: 12px;
      border-radius: 18px;
      background: #fbfbff;
    }

    .sync-skeleton-conversation span,
    .sync-skeleton-conversation strong,
    .sync-skeleton-conversation p,
    .sync-skeleton-message span,
    .sync-skeleton-message p,
    .sync-side-skeleton div,
    .sync-profile-skeleton,
    .sync-user-name-skeleton,
    .sync-user-handle-skeleton {
      display: block;
      border-radius: 999px;
      background: linear-gradient(
        90deg,
        #eef0f7 0%,
        #f8f8fc 45%,
        #eef0f7 100%
      );
      background-size: 220% 100%;
      animation: syncSkeletonPulse 1.15s ease-in-out infinite;
    }

    .sync-skeleton-conversation span {
      width: 48px;
      height: 48px;
      border-radius: 50%;
    }

    .sync-skeleton-conversation strong {
      width: 58%;
      height: 13px;
      margin-bottom: 9px;
    }

    .sync-skeleton-conversation p {
      width: 82%;
      height: 11px;
      margin: 0;
    }

    .sync-chat-skeleton {
      display: grid;
      gap: 14px;
      padding-top: 12px;
    }

    .sync-skeleton-message {
      display: flex;
      align-items: flex-end;
      gap: 10px;
    }

    .sync-skeleton-message span {
      width: 34px;
      height: 34px;
      border-radius: 50%;
      flex: 0 0 auto;
    }

    .sync-skeleton-message p {
      width: min(320px, 70%);
      height: 46px;
      border-radius: 18px;
      margin: 0;
    }

    .sync-skeleton-message.outgoing {
      justify-content: flex-end;
    }

    .sync-skeleton-message.outgoing p {
      width: min(280px, 64%);
    }

    .sync-side-skeleton {
      display: grid;
      gap: 12px;
      margin-top: 18px;
    }

    .sync-side-skeleton div {
      height: 64px;
      border-radius: 18px;
    }

    .sync-profile-skeleton {
      width: 58px;
      height: 58px;
      border-radius: 50%;
      flex: 0 0 auto;
    }

    .sync-user-name-skeleton {
      width: 128px;
      height: 18px;
      margin-bottom: 9px;
    }

    .sync-user-handle-skeleton {
      width: 92px;
      height: 12px;
    }

    @keyframes syncSkeletonPulse {
      0% {
        background-position: 220% 0;
      }

      100% {
        background-position: -220% 0;
      }
    }

    /* Layout hardening while chat.css is being restored */

    .message-list-panel {
      height: calc(100vh - 118px);
      min-height: 0;
      padding: 20px;
      border: 1px solid var(--border);
      border-radius: var(--radius-xl);
      background: var(--bg-card);
      box-shadow: var(--shadow-card);
      overflow: hidden;
      display: flex;
      flex-direction: column;
    }

    .conversation-list {
      min-height: 0;
      overflow-y: auto;
      display: grid;
      gap: 8px;
    }

    .conversation {
      width: 100%;
      display: grid;
      grid-template-columns: 52px minmax(0, 1fr);
      align-items: center;
      gap: 12px;
      padding: 12px;
      border-radius: 18px;
      text-align: left;
      background: transparent;
    }

    .conversation.active,
    .conversation:hover {
      background: var(--primary-soft);
    }

    .conversation img {
      width: 52px;
      height: 52px;
      border-radius: 50%;
      object-fit: cover;
      flex: 0 0 auto;
    }

    .conversation-top {
      display: flex;
      justify-content: space-between;
      gap: 8px;
      min-width: 0;
    }

    .conversation-top strong,
    .conversation p {
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .conversation-top strong {
      white-space: normal;
      font-size: 14px;
      line-height: 1.25;
    }

    .conversation-top small {
      color: var(--text-muted);
      font-size: 12px;
      flex: 0 0 auto;
    }

    .conversation p {
      margin-top: 4px;
      color: var(--text-muted);
      font-size: 13px;
      white-space: nowrap;
    }

    .chat-user,
    .chat-actions,
    .composer-actions {
      display: flex;
      align-items: center;
    }

    .chat-user {
      gap: 12px;
      min-width: 0;
    }

    .chat-user > div:last-child {
      min-width: 0;
    }

    .chat-user h2 {
      font-size: 16px;
      line-height: 1.2;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .chat-user p {
      color: var(--text-muted);
      font-size: 13px;
    }

    .avatar-stack img,
    .chat-header .avatar-stack img {
      width: 42px;
      height: 42px;
      border-radius: 50%;
      object-fit: cover;
    }

    .back-button {
      width: 36px;
      height: 36px;
      display: grid;
      place-items: center;
      border-radius: 12px;
      color: #66708f;
      background: transparent;
    }

    .chat-actions {
      gap: 10px;
    }

    .chat-actions button {
      width: 38px;
      height: 38px;
      display: grid;
      place-items: center;
      border-radius: 13px;
      color: #66708f;
      background: transparent;
    }

    .chat-actions button:hover {
      background: var(--primary-soft);
      color: var(--primary);
    }

    .message-row.incoming > img {
      width: 36px;
      height: 36px;
      border-radius: 50%;
      object-fit: cover;
      flex: 0 0 auto;
    }

    .message-composer input {
      min-width: 0;
      flex: 1;
      border: none;
      outline: none;
      background: transparent;
      color: var(--text-main);
    }

    .send-button {
      width: 46px;
      height: 46px;
      display: grid;
      place-items: center;
      border-radius: 50%;
      color: #ffffff;
      background: linear-gradient(135deg, var(--primary), var(--primary-dark));
      box-shadow: 0 12px 26px rgba(91, 53, 245, 0.25);
      flex: 0 0 auto;
    }

    #messagesTab > .right-sidebar {
      display: flex;
      flex-direction: column;
      gap: 18px;
    }

    .chat-calendar-loading {
      display: grid;
      gap: 12px;
      margin-top: 16px;
    }

    .chat-calendar-loading-line {
      height: 52px;
      border-radius: 16px;
      background: #f1f3f9;
    }

    .chat-calendar-loading-line.short {
      width: 70%;
    }

    @media (max-width: 760px) {
      .top-header.smart-header {
        height: 60px;
        padding: 0 14px;
      }

      .smart-header-title h1 {
        font-size: 17px;
      }

      .smart-header-title p {
        display: none;
      }

      .smart-header-search {
        display: none;
      }
    }

/* Existing app-redesign.css */
/* =========================================================
   FamilyChat UI refresh
   Load this file last. It is mostly visual, keeping existing IDs/classes intact.
   ========================================================= */

:root {
  --primary: #6d5dfc;
  --primary-dark: #4b35d9;
  --primary-soft: #f0edff;
  --text-main: #12152b;
  --text-muted: #667085;
  --text-light: #98a2b3;
  --bg-main: #f7f7fb;
  --bg-card: rgba(255, 255, 255, 0.92);
  --border: #e7e9f3;
  --green: #19b56b;
  --blue: #2f80ed;
  --pink: #f7548b;
  --purple: #7862ff;
  --orange: #f59e0b;
  --shadow-card: 0 18px 50px rgba(22, 28, 45, 0.08);
  --shadow-soft: 0 26px 70px rgba(22, 28, 45, 0.11);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
}

html,
body {
  background:
    radial-gradient(circle at 10% 0%, rgba(109, 93, 252, 0.14), transparent 30%),
    radial-gradient(circle at 92% 18%, rgba(247, 84, 139, 0.12), transparent 28%),
    linear-gradient(180deg, #fbfbff 0%, #f4f6fb 100%);
}

body {
  color: var(--text-main);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100vh;
  background: transparent;
}

button,
a,
input {
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Header ---------- */

.top-header.smart-header {
  height: 70px;
  padding: 0 28px;
  border-bottom: 1px solid rgba(231, 233, 243, 0.8);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 10px 40px rgba(22, 28, 45, 0.04);
}

.smart-header-logo {
  width: 42px;
  height: 42px;
  border-radius: 16px;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.9), transparent 32%),
    linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #ffffff;
  box-shadow: 0 14px 34px rgba(109, 93, 252, 0.24);
}

.smart-header-title h1 {
  font-size: 19px;
  letter-spacing: -0.05em;
}

.smart-header-title p {
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.global-search,
.message-search,
.friends-search,
.explore-search {
  border: 1px solid rgba(231, 233, 243, 0.9);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75), 0 12px 32px rgba(22, 28, 45, 0.04);
}

.smart-header-actions .icon-button,
.smart-header-actions .profile-menu,
.panel-actions button,
.chat-actions button,
.composer-actions button,
.back-button {
  border: 1px solid rgba(231, 233, 243, 0.82);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 10px 24px rgba(22, 28, 45, 0.04);
}

/* ---------- Desktop shell ---------- */

.main-layout {
  padding: 20px 28px 28px;
  gap: 18px;
}

.left-sidebar,
.message-list-panel,
.chat-panel,
.right-sidebar,
.full-page-panel,
.tab-card,
.overview-card,
.settings-detail-card,
.settings-menu-card {
  border: 1px solid rgba(231, 233, 243, 0.86);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.left-sidebar {
  padding: 14px;
  border-radius: var(--radius-xl);
}

.user-card {
  min-height: 104px;
  border: 1px solid rgba(231, 233, 243, 0.72);
  background:
    radial-gradient(circle at 86% 14%, rgba(109, 93, 252, 0.14), transparent 30%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(245, 242, 255, 0.92));
}

.user-card img,
.avatar-stack img,
.conversation img,
.profile-menu img {
  box-shadow: 0 8px 24px rgba(22, 28, 45, 0.1);
}

.premium-badge {
  background: rgba(255, 255, 255, 0.78);
  color: var(--primary);
  border: 1px solid rgba(109, 93, 252, 0.16);
}

.side-nav button {
  height: 48px !important;
  border-radius: 17px;
  color: #344054;
  font-weight: 750;
  transition: transform 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.side-nav button:hover {
  transform: translateX(2px);
  background: rgba(109, 93, 252, 0.07);
  color: var(--primary);
}

.side-nav button.active {
  background: linear-gradient(135deg, rgba(109, 93, 252, 0.14), rgba(109, 93, 252, 0.08));
  color: var(--primary-dark);
  box-shadow: inset 0 0 0 1px rgba(109, 93, 252, 0.12);
}

.side-nav button.is-on {
  background: rgba(25, 181, 107, 0.1);
  color: #118a50;
}

.side-action-button small {
  font-weight: 850;
  color: inherit;
}

/* ---------- Chat and message list ---------- */

.message-list-panel,
.chat-panel {
  border-radius: 30px;
}

.panel-header h2,
.tab-page-header h2 {
  letter-spacing: -0.055em;
}

.message-tabs button {
  border-radius: 999px;
  font-weight: 850;
}

.message-tabs button.active {
  box-shadow: 0 14px 28px rgba(109, 93, 252, 0.18);
}

.conversation {
  border: 1px solid transparent;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.conversation:hover,
.conversation.active {
  transform: translateY(-1px);
  border-color: rgba(109, 93, 252, 0.13);
  background: linear-gradient(135deg, rgba(109, 93, 252, 0.09), rgba(255, 255, 255, 0.78));
  box-shadow: 0 14px 30px rgba(22, 28, 45, 0.06);
}

.chat-header {
  border-bottom: 1px solid rgba(231, 233, 243, 0.86);
  background: rgba(255, 255, 255, 0.74);
}

.chat-body {
  background:
    radial-gradient(circle at 18% 10%, rgba(109, 93, 252, 0.06), transparent 26%),
    radial-gradient(circle at 88% 56%, rgba(247, 84, 139, 0.05), transparent 32%),
    #ffffff;
}

.date-divider {
  color: var(--text-light);
  font-weight: 800;
}

.message-bubble {
  border-radius: 20px;
  line-height: 1.48;
  box-shadow: 0 10px 26px rgba(22, 28, 45, 0.06);
}

.message-row.incoming .message-bubble,
.incoming .message-bubble {
  background: #f2f4f8;
  color: #1f2937;
  border-bottom-left-radius: 8px;
}

.message-row.outgoing .message-bubble,
.outgoing .message-bubble {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #ffffff;
  border-bottom-right-radius: 8px;
}

.message-composer {
  border-top: 1px solid rgba(231, 233, 243, 0.86);
  background: rgba(255, 255, 255, 0.88);
}

.message-composer input,
#messageInput {
  height: 46px;
  padding: 0 16px;
  border-radius: 999px;
  background: #f5f6fb !important;
}

.send-button,
.primary-tab-button,
.primary-login-button {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  box-shadow: 0 16px 34px rgba(109, 93, 252, 0.28);
}

/* ---------- Full-page sections ---------- */

.full-page-panel {
  border-radius: 30px;
}

.tab-eyebrow {
  background: rgba(109, 93, 252, 0.1);
  color: var(--primary-dark);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.overview-card {
  background:
    radial-gradient(circle at 92% 18%, rgba(109, 93, 252, 0.08), transparent 30%),
    rgba(255, 255, 255, 0.88);
}

.overview-icon,
.primary-tab-button,
.secondary-settings-button,
.danger-settings-button {
  box-shadow: 0 14px 28px rgba(22, 28, 45, 0.08);
}

.mobile-bottom-nav {
  display: none;
}

/* ---------- Phone app layout ---------- */

@media (max-width: 820px) {
  html,
  body {
    overflow: hidden;
  }

  body {
    background: #f6f7fb;
  }

  .app {
    height: 100dvh;
    overflow: hidden;
  }

  .top-header.smart-header {
    height: 64px !important;
    padding: max(8px, env(safe-area-inset-top)) 14px 8px !important;
    border-bottom: 1px solid rgba(231, 233, 243, 0.72) !important;
    background: rgba(255, 255, 255, 0.92) !important;
  }

  .mobile-menu-button {
    width: 44px !important;
    height: 44px !important;
    border-radius: 16px !important;
    background: #f1f3f8 !important;
    color: var(--primary-dark) !important;
  }

  .smart-header-brand {
    gap: 9px;
  }

  .smart-header-logo {
    width: 38px;
    height: 38px;
    border-radius: 15px;
  }

  .smart-header-title h1 {
    font-size: 18px;
  }

  .main-layout {
    height: calc(100dvh - 64px - 78px) !important;
    padding: 0 !important;
    overflow: hidden !important;
  }

  body.mobile-chat-open .main-layout {
    height: calc(100dvh - 64px) !important;
  }

  body.mobile-chat-open .mobile-bottom-nav {
    transform: translateY(120%);
    opacity: 0;
    pointer-events: none;
  }

  .message-list-panel,
  .conversation-panel,
  .chat-panel,
  .full-page-panel {
    background: #ffffff !important;
  }

  .message-list-panel,
  .conversation-panel {
    padding: 16px 0 0 !important;
  }

  .message-list-panel .panel-header {
    padding: 0 18px 2px !important;
  }

  .panel-header h2 {
    font-size: 28px;
  }

  .message-search {
    height: 50px !important;
    margin: 12px 16px 14px !important;
    border-radius: 18px !important;
    background: #f4f6fb !important;
    box-shadow: none;
  }

  .message-tabs {
    margin-bottom: 12px !important;
  }

  .conversation-list {
    height: calc(100dvh - 64px - 78px - 178px) !important;
    padding: 0 10px 18px !important;
  }

  body.mobile-chat-open .conversation-list {
    height: calc(100dvh - 64px - 178px) !important;
  }

  .conversation {
    min-height: 76px !important;
    padding: 11px 12px !important;
    border-radius: 24px !important;
  }

  .conversation:hover,
  .conversation.active {
    transform: none;
  }

  .chat-header {
    height: 64px !important;
    padding: 0 10px !important;
    background: rgba(255, 255, 255, 0.96) !important;
  }

  .chat-actions button {
    width: 36px !important;
    height: 36px !important;
    border-radius: 14px !important;
  }

  .chat-body {
    padding: 16px 14px 18px !important;
  }

  .message-bubble {
    max-width: 80vw !important;
    padding: 11px 14px !important;
    font-size: 14.5px !important;
  }

  .message-composer {
    min-height: 72px !important;
    padding: 10px 12px calc(12px + env(safe-area-inset-bottom)) !important;
  }

  .composer-actions button:nth-child(n+2) {
    display: none !important;
  }

  #messageInput {
    height: 44px !important;
  }

  .send-button {
    width: 44px !important;
    height: 44px !important;
  }

  .full-page-panel {
    height: calc(100dvh - 64px - 78px) !important;
    padding: 20px 16px 26px !important;
  }

  .tab-page-header h2 {
    font-size: 30px !important;
  }

  .tab-card,
  .overview-card,
  .settings-detail-card,
  .settings-menu-card {
    border-radius: 24px !important;
    box-shadow: 0 14px 34px rgba(22, 28, 45, 0.06) !important;
  }

  .left-sidebar {
    border-radius: 0 30px 30px 0 !important;
    background: #ffffff !important;
  }

  .mobile-bottom-nav {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 850;
    height: 66px;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
    border: 1px solid rgba(231, 233, 243, 0.88);
    border-radius: 26px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 18px 46px rgba(22, 28, 45, 0.16);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  .mobile-bottom-nav .side-tab {
    width: 100% !important;
    height: 54px !important;
    min-width: 0;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 20px;
    color: #75809a;
    font-size: 11px;
    font-weight: 850;
  }

  .mobile-bottom-nav .side-tab i {
    width: auto;
    color: inherit;
    font-size: 18px;
  }

  .mobile-bottom-nav .side-tab.active {
    background: linear-gradient(135deg, rgba(109, 93, 252, 0.15), rgba(109, 93, 252, 0.08));
    color: var(--primary-dark);
  }

  .mobile-bottom-nav .side-tab span {
    line-height: 1;
  }
}

@media (max-width: 420px) {
  .smart-header-actions .icon-button {
    width: 36px;
    height: 36px;
  }

  .smart-header-actions .profile-menu {
    display: none !important;
  }

  .chat-actions button:nth-child(2) {
    display: none !important;
  }

  .mobile-bottom-nav {
    left: 8px;
    right: 8px;
  }
}
