/* Family Office application styles */

/* Core palette (see docs/design-guidelines.md): light interface, white surfaces,
   #038BFF primary actions, coral + dark blue/purple as brand accents. */
:root {
  --color-bg: #f6f7fb;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-text-muted: #555;
  --color-border: #e8e8ef;
  --color-primary: #038bff;
  --color-accent: #ff6b4a;
  --color-danger: #b91c1c;
  --color-sidebar-top: #1e1b4b;
  --color-sidebar-bottom: #0f172a;
  --color-sidebar-text: #e5e7f2;
  --sidebar-width: 156px;
  --admin-submenu-width: 184px;
  --mobile-topbar-height: 52px;
}

/* Reset and base styles */
* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
}

/* ===== Left sidebar layout ===== */

.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--color-sidebar-top), var(--color-sidebar-bottom));
  color: var(--color-sidebar-text);
  z-index: 1200;
}

.sidebar-title {
  padding: 16px 12px 12px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-title a {
  color: #fff;
  text-decoration: none;
}

/* Main menu: middle section, scrolls if too long */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--color-sidebar-text);
  text-decoration: none;
  font-size: 14px;
  background: none;
  border: 0;
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.sidebar-item:hover,
.sidebar-item:focus {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.sidebar-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--color-accent);
  font-weight: 600;
}

/* Bottom-anchored: Admin menu + profile photo */
.sidebar-bottom {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-menu-wrap {
  position: relative;
}

.sidebar-item-icon {
  font-size: 16px;
  line-height: 1;
}

.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.25);
  flex: none;
}

.sidebar-avatar-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
}


/* Pop-up menus opening upward from the bottom anchors */
.popup-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 8px;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  min-width: 180px;
  padding: 6px;
  z-index: 1300;
}

.popup-menu a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--color-text);
  text-decoration: none;
}

.popup-menu a:hover,
.popup-menu a:focus {
  background: #f5f5f7;
}

/* Admin submenu: on desktop it is a persistent full-height rail to the RIGHT
   of the sidebar so users can navigate between admin sections (overridden to
   an inline accordion on mobile in the media query below). */
.popup-menu.admin-submenu {
  position: fixed;
  top: 0;
  bottom: 0;
  left: var(--sidebar-width);
  width: var(--admin-submenu-width);
  border: 0;
  border-right: 1px solid var(--color-border);
  border-radius: 0;
  box-shadow: 4px 0 16px rgba(0, 0, 0, 0.06);
  padding: 10px 8px;
  min-width: 0;
  z-index: 1190;
}

.admin-submenu-title {
  padding: 8px 10px 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.popup-menu.admin-submenu a.active {
  background: #eef2ff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--color-accent);
}

/* Shift the page content over while the admin rail is open (desktop only) */
@media (min-width: 769px) {
  body.admin-submenu-open .content {
    margin-left: calc(var(--sidebar-width) + var(--admin-submenu-width));
  }
}

/* Content area to the right of the sidebar */
.content {
  margin-left: var(--sidebar-width);
}

.content.no-sidebar {
  margin-left: 0;
}

main {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 16px;
}

/* Mobile top bar (hidden on desktop) */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--mobile-topbar-height);
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--color-sidebar-bottom);
  color: #fff;
  z-index: 1100;
}

.mobile-topbar-title {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
}

.sidebar-toggle {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  padding: 8px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-toggle span {
  display: block;
  height: 2px;
  width: 100%;
  background: #fff;
  border-radius: 2px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1150;
}

/* Legacy in-page dropdown (e.g. Admin Actions on admin/user_edit.php) */
.nav-admin-wrap {
  position: relative;
}

.nav-admin-link {
  cursor: pointer;
}

.admin-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  min-width: 160px;
  padding: 6px;
  z-index: 1000;
}

.admin-menu a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--color-text);
  text-decoration: none;
}

.admin-menu a:hover,
.admin-menu a:focus {
  background: #f5f5f7;
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

/* Cards */
.card {
  background: var(--color-surface);
  border-radius: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  padding: 16px;
  margin-bottom: 6px;
}

/* Typography */
h2 {
  margin: 8px 0 16px;
}

h3 {
  margin: 6px 0 10px;
}

.small {
  font-size: 12px;
  color: var(--color-text-muted);
}

/* Forms */
.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stack label {
  display: block;
  margin: 8px 0;
}

.stack .actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-weight: 500;
}

label.inline {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

input,
textarea,
select {
  width: 100%;
  padding: 8px;
  border: 1px solid #d9d9e3;
  border-radius: 8px;
  background: #fff;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(3, 139, 255, 0.25);
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  height: auto;
  padding: 0;
  border: 0;
  vertical-align: middle;
}

/* Buttons */
button,
.button {
  display: inline-block;
  background: #111;
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  text-decoration: none;
}

button.primary,
.button.primary {
  background: var(--color-primary);
}

button.danger {
  background: var(--color-danger);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.inline {
  display: inline;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Messages */
.flash {
  background: #e8f6ee;
  color: #0f5d2f;
  padding: 10px;
  border-radius: 8px;
}

.error {
  background: #ffe8e8;
  color: #7a0000;
  padding: 10px;
  border-radius: 8px;
}

.announcement {
  background: #fff7e6;
  border: 1px solid #ffd699;
  color: #7a4a00;
  padding: 10px;
  border-radius: 8px;
}

/* Tables */
.list {
  width: 100%;
  border-collapse: collapse;
}

.list th,
.list td {
  padding: 8px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

.list th {
  background: #f8f9fa;
  font-weight: 600;
}

.list tr:hover {
  background: #f8f9fa;
}

/* Status indicators */
.due-overdue {
  color: #b91c1c;
  font-weight: 600;
}

.due-today {
  color: #b45309;
  font-weight: 600;
}

.due-soon {
  color: #1d4ed8;
  font-weight: 500;
}

.status-verified {
  color: #28a745;
  font-weight: 500;
}

.status-pending {
  color: #ffc107;
  font-weight: 500;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
}

.badge.success {
  background: #e6fbf0;
  color: #0b7042;
}

/* Auth pages */
.auth {
  display: grid;
  place-items: center;
  height: 100vh;
  background: var(--color-sidebar-bottom);
  color: #000;
}

.auth .card {
  width: 360px;
}

.auth .card .logo {
  display: block;
  max-width: 120px;
  height: auto;
  margin: 0 auto 16px auto;
}

.auth .card .subtitle {
  text-align: center;
  color: #666;
  font-size: 14px;
  margin: 8px 0 24px 0;
  font-weight: 500;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #fff;
  max-width: 520px;
  width: 100%;
  border-radius: 16px;
  padding: 16px;
  position: relative;
}

.modal .close {
  position: absolute;
  right: 8px;
  top: 8px;
  background: #eee;
  color: #333;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  line-height: 28px;
  font-size: 20px;
  border: 0;
  padding-top: 3px;
  padding-left: 10px;
}

/* Utility */
.hidden {
  display: none !important;
}

details summary {
  cursor: pointer;
  color: var(--color-primary);
}

.description {
  padding-bottom: 10px;
}

/* Responsive: sidebar collapses behind the top-left menu icon */
@media (max-width: 768px) {
  .mobile-topbar {
    display: flex;
  }

  .sidebar {
    width: 240px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.35);
  }

  .sidebar.open {
    transform: none;
  }

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

  .content {
    margin-left: 0;
    padding-top: var(--mobile-topbar-height);
  }

  /* Admin submenu: inline accordion beneath the Admin item. The bottom block
     is anchored, so expanding the menu pushes the Admin item up. */
  .popup-menu.admin-submenu {
    position: static;
    width: auto;
    background: transparent;
    border: 0;
    box-shadow: none;
    border-radius: 0;
    min-width: 0;
    padding: 2px 0 4px 26px;
  }

  .admin-submenu-title {
    display: none;
  }

  .popup-menu.admin-submenu a.active {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
  }

  .popup-menu.admin-submenu a {
    color: var(--color-sidebar-text);
    padding: 9px 12px;
  }

  .popup-menu.admin-submenu a:hover,
  .popup-menu.admin-submenu a:focus {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
  }

  main {
    padding: 16px;
    margin: 0 auto;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .grid {
    grid-template-columns: 1fr !important;
  }
}
