/* ==========================================================================
   Malay Glen — client/admin portal app shell
   Extends the v2 dark-cyan design system (assets/styles.css): same tokens,
   fonts, reset, skip-link, and focus rings. Adds the app-shell/forms/tables
   components the marketing site's single CSS file doesn't need.
   ========================================================================== */

@import url("../../assets/styles.css");

:root {
  --border: rgba(255, 255, 255, 0.09);
  --border-cyan: rgba(18, 224, 237, 0.16);
  --surface: rgba(18, 224, 237, 0.03);
  --surface-strong: rgba(18, 224, 237, 0.06);
  --danger: #FCA5A5;
  --danger-border: rgba(252, 165, 165, 0.35);
  --danger-bg: rgba(252, 165, 165, 0.08);
  --success: #86EFAC;
}

/* Prevent iOS Safari auto-zoom on focus (inputs below 16px trigger it) ----- */
input, select, textarea, button {
  font-size: max(16px, 1rem);
  font-family: var(--font-body);
}

/* The `hidden` attribute must always win over component display rules.
   .portal / .app-shell (imported or defined below) set display:flex, which
   would otherwise override the UA's [hidden]{display:none} — author rules
   beat user-agent rules regardless of selector specificity or source order.
   Without this, toggling `hidden` on the login/account views does nothing
   visually even though the DOM state is correct. */
[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Auth views (login screens, client + admin)
   ========================================================================== */

.auth-card {
  padding-top: 40px;
}

.auth-card h1 {
  font-size: 1.35rem;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  text-align: left;
  margin-top: 8px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.form-input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
  border-color: var(--cyan);
}

.form-input--file {
  padding: 10px 12px;
  cursor: pointer;
}

textarea.form-input {
  resize: vertical;
  min-height: 84px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text);
  min-height: 44px;
}

.checkbox-label input[type="checkbox"],
input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--cyan);
}

.form-error {
  margin: 0;
  font-size: 0.8rem;
  color: var(--danger);
}

.form-error:not([hidden]) {
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
}

.save-success,
.upload-success {
  margin: 0;
  font-size: 0.8rem;
  color: var(--success);
}

.auth-hint {
  margin: 20px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.auth-hint a {
  color: var(--cyan);
}

.dev-panel {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px dashed var(--border);
}

.dev-panel-title {
  margin: 0 0 10px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.dev-account-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dev-account-btn {
  padding: 9px 12px;
  min-height: 44px;
  border-radius: 8px;
  border: 1px dashed var(--border-cyan);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.dev-account-btn:hover {
  color: var(--cyan);
  border-color: var(--cyan);
}
.dev-account-btn--reset {
  color: var(--danger);
  border-color: var(--danger-border);
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn-primary,
.btn-secondary,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity 0.2s ease, background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.btn-primary {
  background: var(--cyan);
  color: #04191c;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-cyan);
}
.btn-secondary:hover { border-color: var(--cyan); color: var(--cyan); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger-border);
}
.btn-danger:hover { background: var(--danger-bg); }

.btn-small {
  min-height: 36px;
  padding: 7px 14px;
  font-size: 0.75rem;
}

/* ==========================================================================
   Loading / error states
   ========================================================================== */

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 64px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid rgba(18, 224, 237, 0.2);
  border-top-color: var(--cyan);
  animation: mg-spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
    border-top-color: rgba(18, 224, 237, 0.2);
    opacity: 0.6;
  }
}

.error-state {
  max-width: 440px;
  margin: 48px auto;
  padding: 32px 28px;
  text-align: center;
  border-radius: 16px;
  border: 1px solid var(--danger-border);
  background: var(--danger-bg);
}

.error-state-title {
  margin: 0 0 8px;
  font-family: var(--font-head);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.error-state-body {
  margin: 0 0 20px;
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* ==========================================================================
   App shell (account + admin views)
   ========================================================================== */

.app-shell {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px max(20px, env(safe-area-inset-right)) 14px max(20px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: rgba(8, 9, 12, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.app-brand {
  display: inline-flex;
  width: 108px;
  flex-shrink: 0;
}
.app-brand img {
  width: 100%;
  height: auto;
  mix-blend-mode: screen;
}

.app-topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.role-badge {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-cyan);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cyan);
}
.role-badge--admin {
  border-color: rgba(252, 165, 165, 0.35);
  color: var(--danger);
}

.app-signed-in-as {
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 32px max(20px, env(safe-area-inset-right)) 64px max(20px, env(safe-area-inset-left));
}

.page-title {
  margin: 0 0 24px;
  font-family: var(--font-head);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
}

.section-label {
  margin: 0 0 6px;
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.section-sublabel {
  margin: 20px 0 8px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.section-caption {
  margin: 0 0 14px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.section-empty {
  padding: 14px 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Sections stack with generous rhythm, each a quiet card ------------------- */
.poc-block,
.approved-block,
.profile-block,
.doc-block,
.admin-section {
  padding: 24px;
  margin-bottom: 24px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
}

/* Point of contact — the one thing that must read as unmistakably prominent */
.poc-block {
  border-color: var(--border-cyan);
  background: var(--surface-strong);
}
.poc-name {
  margin: 0;
  font-family: var(--font-head);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
}
.poc-title {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Approved-to-request-changes list ----------------------------------------- */
.approved-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.approved-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}
.approved-name {
  font-weight: 600;
  color: var(--text);
}
.approved-title {
  font-size: 0.82rem;
  color: var(--text-muted);
}
.approved-email {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: auto;
}

/* Profile block (view-only) -------------------------------------------------- */
.profile-grid {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px 24px;
}
.profile-grid dt {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.profile-grid dd {
  margin: 2px 0 0;
  font-size: 0.92rem;
  color: var(--text);
}
.profile-note {
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
}
.profile-note a {
  color: var(--cyan);
}

@media (min-width: 640px) {
  .profile-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Documents ------------------------------------------------------------------ */
.doc-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
}
.doc-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.doc-name {
  font-size: 0.88rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
}
.doc-download-btn {
  flex-shrink: 0;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 7px;
  border: 1px solid var(--border-cyan);
  background: transparent;
  color: var(--cyan);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}
.doc-download-btn:hover {
  background: var(--surface-strong);
}
.doc-empty {
  padding: 10px 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ==========================================================================
   Admin — client list
   ========================================================================== */

.admin-list-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.admin-list-header .page-title {
  margin: 0;
}

.client-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 640px) {
  .client-list {
    grid-template-columns: 1fr 1fr;
  }
}

.client-card-btn {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.client-card-btn:hover {
  border-color: var(--border-cyan);
  background: var(--surface-strong);
}
.client-card-name {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 1.05rem;
}
.client-card-project {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.status-pill {
  margin-top: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--cyan);
  border: 1px solid var(--border-cyan);
}

/* ==========================================================================
   Admin — contact table
   ========================================================================== */

.contact-table-wrap {
  overflow-x: auto;
  margin-bottom: 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.contact-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  min-width: 560px;
}
.contact-table th,
.contact-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.contact-table th {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.02);
}
.contact-table tbody tr:last-child td {
  border-bottom: none;
}

/* Below 640px the table becomes a stack of cards instead of scrolling
   sideways. A wide table inside an overflow-x:auto wrapper can still make
   an ancestor's scrollable area wider than the viewport in some browsers
   even though the overflow looks contained — the safe fix is to never let
   the table need to be wider than the screen in the first place. Each td's
   column name comes from the data-label attribute set in admin.js. */
@media (max-width: 860px) {
  .contact-table-wrap {
    overflow-x: visible;
    border: none;
  }
  .contact-table {
    display: block;
    min-width: 0;
  }
  .contact-table thead {
    display: none;
  }
  .contact-table tbody {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  .contact-table tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.02);
    padding: 4px 14px;
  }
  .contact-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    white-space: normal;
    text-align: right;
  }
  .contact-table tr td:last-child {
    border-bottom: none;
  }
  .contact-table td[data-label]::before {
    content: attr(data-label);
    flex-shrink: 0;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    text-align: left;
  }
  .contact-table td:not([data-label]),
  .contact-table td[data-label=""] {
    justify-content: flex-end;
  }
}

.form--inline {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
}
.form--inline .form-field {
  flex: 1 1 140px;
  min-width: 120px;
}
.form--inline .form-field--checkbox {
  flex: 0 0 auto;
}
.form--inline .form-actions {
  flex: 0 0 auto;
}

.form--grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px 20px;
}
@media (min-width: 640px) {
  .form--grid {
    grid-template-columns: 1fr 1fr;
  }
}
.form-field--wide {
  grid-column: 1 / -1;
}
.form-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

/* ==========================================================================
   Admin — pricing (Contract vs internal-cost groups)
   ========================================================================== */

.pricing-group-title {
  font-family: var(--font-head);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.pricing-group-title--contract {
  margin-bottom: -6px;
  color: var(--cyan);
}
.pricing-group-title--internal {
  color: var(--text-muted);
}
.pricing-group-caption {
  margin-top: -10px;
}

/* Internal-cost group must read as clearly separate from the client-visible
   Contract fields at a glance: hairline border + faint muted background,
   distinct from the cyan-tinted surface the rest of the admin card uses. */
.pricing-group--internal {
  padding: 16px 16px 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}
.pricing-internal-note {
  margin: 2px 0 14px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.pricing-internal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px 20px;
}

/* Money inputs: a "$" prefix sits inside the field, left-padded so it never
   overlaps the typed value. */
.money-input {
  position: relative;
}
.money-sign {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}
.money-input-field {
  padding-left: 28px;
}

/* Two/three money fields in the Contract group also collapse to one column
   on mobile via the existing .form--grid breakpoint (min-width:640px). On
   narrower admin layouts the auto-fit internal grid does the same. */

/* ==========================================================================
   Modal (native <dialog> — create client account)
   ========================================================================== */

.modal {
  width: min(520px, calc(100vw - 40px));
  max-height: min(88vh, 88dvh);
  padding: 28px;
  border: 1px solid var(--border-cyan);
  border-radius: 16px;
  background: #0B0D11;
  color: var(--text);
}
.modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.modal-title {
  margin: 0 0 6px;
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 600;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
}

/* Create-client success panel: shows the one-time generated password --------- */
.cc-pw-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.cc-pw-row .form-input {
  flex: 1 1 auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.02em;
}
.cc-pw-row .btn-secondary {
  flex: 0 0 auto;
  white-space: nowrap;
}
.cc-copy-status {
  margin: 6px 0 0;
  font-size: 0.8rem;
  color: var(--success);
  min-height: 1em;
}
.cc-warning {
  margin: 4px 0 16px;
  padding: 10px 12px;
  font-size: 0.8rem;
  color: var(--text);
  background: rgba(252, 165, 165, 0.08);
  border: 1px solid var(--danger-border);
  border-radius: 8px;
}

/* Small screens -------------------------------------------------------------- */
@media (max-width: 480px) {
  .app-main { padding-top: 24px; }
  .app-signed-in-as { max-width: 100%; }
  .app-topbar { flex-wrap: wrap; }
  .approved-email { margin-left: 0; }
  .modal { padding: 20px; }
}
