/* ReMedia Client Portal */

.portal-app,
.portal-auth-page {
  overflow-x: hidden;
}

.portal-shell {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-primary);
  padding-top: 5.5rem;
}

.portal-header-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 0;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.portal-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.portal-header-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.portal-header-brand img {
  height: 36px;
}

.portal-header-brand span {
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 1rem;
  color: var(--text-primary);
}

.portal-user-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.portal-user-meta strong {
  color: var(--text-primary);
}

.portal-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 2rem;
  padding: 2rem 0 4rem;
  align-items: start;
}

@media (max-width: 900px) {
  .portal-layout {
    grid-template-columns: 1fr;
  }
}

.portal-sidebar {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem;
  position: sticky;
  top: 6rem;
}

.portal-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.portal-nav-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.875rem 1rem;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-fast);
}

.portal-nav-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.portal-nav-btn.active {
  background: rgba(125, 192, 53, 0.12);
  color: var(--brand-primary);
}

.portal-nav-btn svg {
  flex-shrink: 0;
}

.portal-nav-label {
  line-height: 1.2;
}

.portal-main {
  min-width: 0;
}

.portal-panel {
  display: none;
}

.portal-panel.active {
  display: block;
}

.portal-card {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 1.5rem;
}

.portal-card h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.portal-card > p.subtitle {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.portal-empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-secondary);
}

.portal-empty svg {
  margin-bottom: 1rem;
  opacity: 0.5;
}

/* Invoice list */
.invoice-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.invoice-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 1.25rem 1.5rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

@media (max-width: 700px) {
  .invoice-item {
    grid-template-columns: 1fr;
  }
}

.invoice-item h3 {
  font-size: 1.05rem;
  margin-bottom: 0.35rem;
}

.invoice-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.invoice-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.invoice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.invoice-due-soon {
  border-color: rgba(234, 179, 8, 0.4);
}

.invoice-overdue {
  border-color: rgba(239, 68, 68, 0.4);
}

/* Admin layout */
.admin-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 900px) {
  .admin-grid {
    grid-template-columns: 1fr;
  }
}

.client-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 520px;
  overflow-y: auto;
}

.client-list-item {
  width: 100%;
  text-align: left;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-body);
}

.client-list-item:hover {
  border-color: var(--brand-primary);
}

.client-list-item.active {
  border-color: var(--brand-primary);
  background: rgba(125, 192, 53, 0.08);
}

.client-list-item strong {
  display: block;
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.client-list-item span {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.admin-section {
  margin-bottom: 2rem;
}

.admin-section h3 {
  font-size: 1.125rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.form-hint {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  margin-top: 0.35rem;
}

.portal-alert {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.portal-alert-success {
  background: rgba(125, 192, 53, 0.1);
  border: 1px solid rgba(125, 192, 53, 0.3);
  color: var(--brand-primary-dark);
}

.portal-alert-error {
  background: rgba(239, 68, 68, 0.05);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #df3232;
}

[data-theme="dark"] .portal-alert-error {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
}

.portal-alert-info {
  background: rgba(9, 81, 67, 0.08);
  border: 1px solid rgba(9, 81, 67, 0.2);
  color: var(--brand-secondary);
}

/* Auth page extras */
.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  background: var(--bg-primary);
  padding: 0.35rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.auth-tab {
  flex: 1;
  padding: 0.625rem 1rem;
  border: none;
  background: transparent;
  border-radius: calc(var(--radius-sm) - 2px);
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.auth-tab.active {
  background: var(--surface);
  color: var(--brand-primary);
  box-shadow: var(--shadow-sm);
}

.auth-form-panel {
  display: none;
}

.auth-form-panel.active {
  display: block;
}

.auth-message.success {
  background: rgba(125, 192, 53, 0.1);
  border-color: rgba(125, 192, 53, 0.3);
  color: var(--brand-primary-dark);
}

[data-theme="dark"] .auth-message.success {
  color: var(--brand-primary-light);
}

.spinner {
  display: none;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: portal-spin 0.8s ease-in-out infinite;
  margin-right: 0.5rem;
  vertical-align: middle;
}

.loading .spinner {
  display: inline-block;
}

@keyframes portal-spin {
  to { transform: rotate(360deg); }
}

.note-body {
  white-space: pre-wrap;
  line-height: 1.7;
  color: var(--text-primary);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.note-updated {
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  margin-top: 1rem;
}

.admin-invoice-form .form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 600px) {
  .admin-invoice-form .form-row {
    grid-template-columns: 1fr;
  }
}

.btn-danger {
  background: transparent;
  color: #df3232;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.08);
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

/* Page content wrapper (admin dashboard) */
.portal-shell > .container {
  padding-top: 2rem;
  padding-bottom: 4rem;
}

/* Login page — slimmer site header on small screens */
@media (max-width: 768px) {
  .portal-auth-page #site-header {
    padding: 0.625rem 0;
    padding-top: calc(0.625rem + env(safe-area-inset-top, 0px));
  }

  .portal-auth-page .logo img {
    height: 36px;
  }
}

/* ── Mobile optimizations ── */
@media (max-width: 768px) {
  .portal-shell {
    padding-top: calc(3.75rem + env(safe-area-inset-top, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .portal-shell > .container {
    padding-top: 1rem;
    padding-bottom: 3rem;
  }

  .portal-dashboard .portal-shell > .container {
    padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
  }

  .portal-header-bar {
    padding: 0.625rem 0;
    padding-top: calc(0.625rem + env(safe-area-inset-top, 0px));
  }

  .portal-header-inner {
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.75rem;
  }

  .portal-header-brand {
    gap: 0.625rem;
    min-width: 0;
    flex: 1;
  }

  .portal-header-brand img {
    height: 28px;
  }

  .portal-header-brand span {
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .portal-user-meta {
    width: auto;
    flex-shrink: 0;
    gap: 0.5rem;
    font-size: 0.8125rem;
  }

  .portal-user-meta > span {
    display: none;
  }

  .portal-user-meta .btn-sm {
    flex-shrink: 0;
    min-height: 2.5rem;
    min-width: 5.5rem;
    padding: 0.5rem 0.875rem;
  }

  /* Client dashboard: fixed bottom tab bar */
  .portal-layout {
    display: block;
    padding: 0.75rem 0 0;
    gap: 0;
  }

  .portal-sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    z-index: 90;
    margin: 0;
    padding: 0.375rem 0.5rem;
    padding-bottom: calc(0.375rem + env(safe-area-inset-bottom, 0px));
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--border-color);
    background: var(--surface);
    box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.08);
  }

  [data-theme="dark"] .portal-sidebar {
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
  }

  .portal-nav {
    flex-direction: row;
    gap: 0.25rem;
  }

  .portal-nav-btn {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.2rem;
    padding: 0.375rem 0.25rem;
    min-height: 3.25rem;
    font-size: 0.6875rem;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
  }

  .portal-nav-label {
    display: block;
  }

  .portal-main {
    padding-bottom: 0.5rem;
  }

  .portal-card {
    padding: 1.25rem;
    margin-bottom: 1rem;
    border-radius: var(--radius-md);
  }

  .portal-card h2 {
    font-size: 1.25rem;
  }

  .portal-card > p.subtitle {
    margin-bottom: 1.25rem;
    font-size: 0.9375rem;
  }

  .portal-empty {
    padding: 2rem 1rem;
  }

  .invoice-item {
    padding: 1rem;
  }

  .invoice-item h3 {
    font-size: 1rem;
    overflow-wrap: anywhere;
  }

  .invoice-meta {
    gap: 0.35rem 0.75rem;
    font-size: 0.8125rem;
  }

  .invoice-meta span {
    max-width: 100%;
  }

  .invoice-actions {
    width: 100%;
  }

  .invoice-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
    min-height: 2.75rem;
    white-space: normal;
  }

  /* Admin: horizontal client picker */
  .admin-grid {
    gap: 0.75rem;
  }

  .admin-grid > .portal-card {
    padding: 1rem !important;
    margin-bottom: 0 !important;
  }

  .client-list {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    max-height: none;
    gap: 0.5rem;
    padding-bottom: 0.25rem;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .client-list::-webkit-scrollbar {
    display: none;
  }

  .client-list-item {
    flex: 0 0 auto;
    min-width: 10.5rem;
    max-width: 14rem;
    scroll-snap-align: start;
    min-height: 3rem;
    -webkit-tap-highlight-color: transparent;
  }

  .admin-section {
    margin-bottom: 1.5rem;
  }

  .admin-section h3 {
    font-size: 1rem;
  }

  .portal-alert {
    padding: 0.875rem 1rem;
    font-size: 0.8125rem;
  }

  .auth-tabs {
    margin-bottom: 1.25rem;
  }

  .auth-tab {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    min-height: 2.75rem;
    -webkit-tap-highlight-color: transparent;
  }

  /* Prevent iOS zoom on input focus */
  .portal-shell .form-control,
  .portal-auth-page .form-control {
    font-size: 16px;
  }

  .portal-shell textarea.form-control {
    min-height: 8rem;
  }

  .portal-page-intro {
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem !important;
  }

  .portal-page-intro h2 {
    font-size: 1.125rem;
    margin-bottom: 0.25rem;
  }

  .portal-page-intro .subtitle {
    margin-bottom: 0;
    font-size: 0.875rem;
  }

  .portal-shell .btn-primary,
  .portal-shell .btn-secondary {
    min-height: 2.75rem;
  }

  .admin-invoice-form input[type="file"].form-control {
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
  }
}

@media (max-width: 480px) {
  .portal-shell .container {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .portal-header-brand span {
    max-width: 10rem;
  }

  .portal-nav-btn {
    font-size: 0.625rem;
    min-height: 3rem;
  }

  .portal-nav-btn svg {
    width: 20px;
    height: 20px;
  }

  .portal-card {
    padding: 1rem;
  }

  .portal-card h2 {
    font-size: 1.125rem;
  }

  .invoice-actions {
    flex-direction: column;
  }

  .invoice-actions .btn {
    width: 100%;
    flex: none;
  }

  .admin-invoice-form .btn-primary,
  .portal-main .btn-primary,
  .portal-main .btn-secondary {
    width: 100%;
  }

  .client-list-item {
    min-width: 9rem;
  }

  #client-detail .portal-card h2 {
    font-size: 1.125rem;
    overflow-wrap: anywhere;
  }

  #client-detail .portal-card > .subtitle {
    font-size: 0.875rem;
    overflow-wrap: anywhere;
  }
}
