/* JayLia Client Portal — Phase 0 styles.
   Design tokens mirrored from the main site (css/variables.css) so the portal
   looks native to the brand. Light by default; follows the OS dark preference. */

:root {
  --color-primary-400: #60a5fa;
  --color-primary-500: #3b82f6;
  --color-primary-600: #2563eb;
  --color-accent-500:  #FF7A3E;

  --bg:             #ffffff;
  --bg-alt:         #f9fafb;
  --bg-card:        #ffffff;
  --text:           #111827;
  --text-secondary: #4b5563;
  --text-muted:     #9ca3af;
  --border:         #e5e7eb;
  --primary:        var(--color-primary-500);
  --primary-hover:  var(--color-primary-600);
  --accent:         var(--color-accent-500);
  --accent-light:   #fff5ec;
  --primary-light:  #eff6ff;

  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
  --radius-md: .5rem;
  --radius-lg: .75rem;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:             #121217;
    --bg-alt:         #1a1a22;
    --bg-card:        #1e1e28;
    --text:           #f0f0f5;
    --text-secondary: #a0a0b0;
    --text-muted:     #606070;
    --border:         #2a2a38;
    --primary:        var(--color-primary-400);
    --primary-hover:  #93c5fd;
    --accent-light:   rgba(255, 180, 89, .13);
    --primary-light:  rgba(96, 165, 250, .15);
  }
}

* { box-sizing: border-box; }

/* Always reserve the scrollbar track so page width never shifts between
   short and tall pages (fixes the layout "wiggle" when navigating). */
html { overflow-y: scroll; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg-alt);
  line-height: 1.5;
}

a { color: var(--primary); }

/* App shell: sidebar + content */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px;
  background: var(--bg-card); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { padding: 1.1rem 1.25rem; font-weight: 800; font-size: 1.1rem; border-bottom: 1px solid var(--border); }
.sidebar-brand a { color: inherit; text-decoration: none; }
.sidebar-brand .accent { color: var(--accent); }
.sidebar-nav { display: flex; flex-direction: column; padding: .75rem .5rem; gap: .15rem; flex: 1 1 auto; overflow-y: auto; }
.nav-link {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .8rem;
  border-radius: var(--radius-md); color: var(--text-secondary);
  text-decoration: none; font-size: .9rem; font-weight: 500;
}
.nav-link:hover { background: var(--bg-alt); color: var(--text); }
.nav-link.active { background: var(--primary-light, rgba(59,130,246,.14)); color: var(--primary); }
.sidebar-foot { border-top: 1px solid var(--border); padding: .85rem 1rem; display: flex; flex-direction: column; gap: .5rem; }
.sidebar-user { font-size: .85rem; color: var(--text-secondary); display: flex; flex-direction: column; }
.sidebar-role { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.content { flex: 1 1 auto; min-width: 0; }

.container { max-width: 960px; margin: 2rem auto; padding: 0 1.5rem; }

@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: auto; flex: none; height: auto; position: static;
    flex-direction: row; align-items: center; flex-wrap: wrap;
  }
  .sidebar-brand { border-bottom: 0; border-right: 1px solid var(--border); }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; flex: 1 1 100%; padding: .5rem; }
  .sidebar-foot { border-top: 0; flex-direction: row; align-items: center; margin-left: auto; }
  .container { margin: 1.25rem auto; }
}

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.5rem; box-shadow: var(--shadow-md);
  margin-bottom: 1.25rem;
}
.badge {
  display: inline-block; font-size: .75rem; font-weight: 600;
  padding: .15rem .5rem; border-radius: 999px;
  background: var(--bg-alt); color: var(--text-secondary); border: 1px solid var(--border);
}
.muted { color: var(--text-muted); font-size: .875rem; }

/* Auth / centered card pages */
body.auth { display: grid; place-items: center; min-height: 100vh; }
.auth-card {
  width: 100%; max-width: 380px; margin: 1.5rem;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 2rem; box-shadow: var(--shadow-md);
}
.auth-card h1 { margin: 0 0 .25rem; font-size: 1.5rem; }
.auth-card .brand { font-weight: 800; margin-bottom: 1rem; }
.auth-card .brand .accent { color: var(--accent); }

label { display: block; margin: .85rem 0; font-size: .875rem; color: var(--text-secondary); }
input {
  display: block; width: 100%; margin-top: .35rem; padding: .6rem .7rem;
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md);
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }

.btn {
  display: inline-block; width: 100%; margin-top: .5rem; padding: .65rem 1rem;
  font: inherit; font-weight: 600; text-align: center; text-decoration: none;
  color: #fff; background: var(--primary); border: 0; border-radius: var(--radius-md);
  cursor: pointer;
}
.btn:hover { background: var(--primary-hover); }
.btn.small { width: auto; padding: .4rem .8rem; font-size: .8rem; }
.btn.ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }

.err { color: #b91c1c; background: #fef2f2; border: 1px solid #fecaca;
       padding: .6rem .75rem; border-radius: var(--radius-md); font-size: .875rem; }
.ok  { color: #166534; background: #f0fdf4; border: 1px solid #bbf7d0;
       padding: .6rem .75rem; border-radius: var(--radius-md); font-size: .875rem; }

/* Top-bar bits */
.topbar .brand a { color: inherit; text-decoration: none; }
.topbar .who { display: flex; align-items: center; gap: .75rem; }
.nav { display: flex; gap: 1.25rem; }
.nav a { color: var(--text-secondary); text-decoration: none; font-size: .9rem; font-weight: 500; }
.nav a:hover { color: var(--text); }

/* Page head */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; gap: .75rem; }
.page-head h1 { margin: 0; }
.page-head > div { display: flex; gap: .5rem; align-items: center; }

/* Card header with an action button on the right */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin-top: 0; }
h3 { font-size: .95rem; color: var(--text-secondary); margin: 1.5rem 0 .5rem; }

/* Two-column layout for wider screens */
.cols { display: grid; grid-template-columns: 1fr; gap: 1.25rem; margin-bottom: 1.25rem; }
.cols .card { margin-bottom: 0; }   /* grid gap handles spacing inside columns */
@media (min-width: 800px) { .cols { grid-template-columns: 3fr 2fr; } }

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--bg-card); border: 1px solid var(--border);
        border-radius: var(--radius-lg); padding: 1.1rem 1.25rem; box-shadow: var(--shadow-md); }
.stat-num { font-size: 1.8rem; font-weight: 700; letter-spacing: -.02em; }
.stat-label { color: var(--text-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; color: var(--text-muted); font-weight: 600; font-size: .78rem;
            text-transform: uppercase; letter-spacing: .03em; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
.table td { padding: .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table td.actions { text-align: right; }
.table td.actions form { display: inline; }

.badge-ok { color: #166534; background: #f0fdf4; border-color: #bbf7d0; }
@media (prefers-color-scheme: dark) {
  .badge-ok { color: #86efac; background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.3); }
}

/* Form controls added for admin */
select, textarea {
  display: block; width: 100%; margin-top: .35rem; padding: .55rem .7rem;
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md);
}
textarea { resize: vertical; }

/* Inline invite form */
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.inline-form input { width: auto; flex: 1 1 12rem; margin-top: 0; }
.inline-form select { width: auto; margin-top: 0; }
.inline-form .btn { width: auto; margin-top: 0; }

/* Inline role dropdown in member tables */
.role-form { display: inline; margin: 0; }
.role-form select { width: auto; margin-top: 0; padding: .3rem .5rem; font-size: .82rem; }

/* Vault */
.vault-entry-head { display: flex; align-items: center; gap: .6rem; }
.vault-entry-head h2 { margin: 0; }
.vault-entry-head .icon-btn { margin-left: auto; }
.icon-btn {
  background: none; border: 0; padding: .3rem; cursor: pointer; line-height: 0;
  color: var(--text-muted); border-radius: var(--radius-md);
}
.icon-btn:hover { color: var(--primary); background: var(--bg-alt); }
.modal-actions .spacer { flex: 1; }
.vault-creds td { vertical-align: middle; }
.cred-field { display: inline-flex; align-items: center; gap: .35rem; }
.cred-field input {
  width: auto; min-width: 10rem; margin-top: 0; padding: .35rem .5rem;
  font-family: var(--font-mono, monospace); font-size: .85rem;
}
.cred-field .btn.small { width: auto; margin-top: 0; padding: .3rem .55rem; }
.btn.small.danger-btn { width: auto; }
.vault-edit { margin-top: 1rem; }
.vault-edit summary { cursor: pointer; color: var(--text-secondary); font-size: .875rem; }
.vault-edit summary:hover { color: var(--text); }

/* Project cards (client dashboard) */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.project-card {
  display: block; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.1rem; text-decoration: none;
  color: var(--text); box-shadow: var(--shadow-md); transition: border-color var(--transition-fast, 150ms);
}
.project-card:hover { border-color: var(--primary); }
.project-title { font-weight: 600; margin-bottom: .6rem; }

/* Status badges */
.status-active, .status-completed { color: #166534; background: #f0fdf4; border-color: #bbf7d0; }
.status-scheduled { color: #92400e; background: #fffbeb; border-color: #fde68a; }
.status-on_hold, .status-archived { color: var(--text-secondary); }
@media (prefers-color-scheme: dark) {
  .status-active, .status-completed { color: #86efac; background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.3); }
  .status-scheduled { color: #fcd34d; background: rgba(245,158,11,.12); border-color: rgba(245,158,11,.3); }
}

ul code, p code { background: var(--bg-alt); padding: .1rem .35rem; border-radius: 4px; font-size: .85em; }

/* Correspondence thread */
.thread { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1.25rem; }
.msg {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: .9rem 1.1rem; box-shadow: var(--shadow-sm);
}
.msg-internal { border-left: 3px solid var(--accent); background: var(--accent-light); }
.msg-system { background: transparent; border-style: dashed; box-shadow: none; }
.msg-head { display: flex; align-items: center; gap: .5rem; font-size: .85rem; margin-bottom: .4rem; }
.msg-head .muted { margin-left: auto; }
.msg-body { white-space: normal; }
.msg-atts { margin-top: .6rem; display: flex; flex-wrap: wrap; gap: .5rem; }
.att {
  display: inline-block; font-size: .85rem; text-decoration: none;
  background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: .3rem .6rem; color: var(--text);
}
.att:hover { border-color: var(--primary); }

/* Form extras */
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.file-label { font-size: .8rem; }
.file-label input { margin-top: .3rem; }

/* Style the native file input's button to match the app's ghost buttons */
input[type="file"] { font: inherit; color: var(--text-secondary); }
input[type="file"]::file-selector-button {
  font: inherit; font-weight: 600; cursor: pointer;
  color: var(--text); background: var(--bg-alt);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: .45rem .85rem; margin-right: .7rem;
  transition: border-color var(--transition-fast, 150ms), color var(--transition-fast, 150ms);
}
input[type="file"]::file-selector-button:hover { border-color: var(--primary); color: var(--primary); }
.check { display: flex; align-items: center; gap: .5rem; font-size: .85rem; }
.check input { width: auto; margin: 0; }

/* Newly polled-in messages */
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-new { animation: msg-in .35s ease; }

/* Danger button + card */
.btn.danger-btn { background: #dc2626; }
.btn.danger-btn:hover { background: #b91c1c; }
.btn.danger-btn:disabled { background: #e79a9a; cursor: not-allowed; }
.card.danger { border-color: #fecaca; }
@media (prefers-color-scheme: dark) { .card.danger { border-color: #5b2323; } }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1100; padding: 1rem;
  background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.5rem; width: 100%; max-width: 480px;
  max-height: calc(100vh - 2rem); overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0,0,0,.35);
}
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.confirm-input { font-family: var(--font-mono, monospace); letter-spacing: .05em; }

/* Priority pills */
.prio { display: inline-block; font-size: .75rem; font-weight: 600; text-transform: capitalize;
        padding: .1rem .5rem; border-radius: 999px; border: 1px solid var(--border); color: var(--text-secondary); }
.prio-urgent { color: #b91c1c; background: #fef2f2; border-color: #fecaca; }
.prio-high   { color: #b45309; background: #fffbeb; border-color: #fde68a; }
@media (prefers-color-scheme: dark) {
  .prio-urgent { color: #fca5a5; background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.3); }
  .prio-high   { color: #fcd34d; background: rgba(245,158,11,.12); border-color: rgba(245,158,11,.3); }
}

/* Toast notifications (PrimeNG-style: colored left bar + icon + summary/detail) */
.toasts {
  position: fixed; top: 1.25rem; right: 1.25rem; z-index: 1000;
  display: flex; flex-direction: column; gap: 1rem;
  width: min(25rem, calc(100vw - 2rem));
}
.toast {
  position: relative; overflow: hidden;
  display: flex; align-items: flex-start; gap: .75rem;
  padding: 1rem 1.1rem; border-radius: 10px;
  border: solid; border-width: 0 0 0 6px;
  box-shadow: 0 6px 16px rgba(0,0,0,.18), 0 2px 6px rgba(0,0,0,.1);
  opacity: 0; transform: translateX(24px);
  transition: opacity .3s ease, transform .3s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast-icon { flex: 0 0 auto; line-height: 0; margin-top: .05rem; }
.toast-content { flex: 1 1 auto; min-width: 0; }
.toast-summary { font-weight: 700; }
.toast-detail { margin-top: .2rem; font-size: .9rem; word-wrap: break-word; }
.toast-close {
  flex: 0 0 auto; background: none; border: 0; padding: 0; margin: -.15rem -.1rem 0 .25rem;
  font-size: 1.3rem; line-height: 1; cursor: pointer; color: inherit; opacity: .55;
}
.toast-close:hover { opacity: 1; }
.toast-progress { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: currentColor; opacity: .35; }

.toast-ok  { background: #d0f5e6; border-color: #1ea97c; color: #0f7a57; }
.toast-err { background: #ffd9d7; border-color: #ff5757; color: #d63b3b; }
@media (prefers-color-scheme: dark) {
  .toast-ok  { background: #10261c; border-color: #1ea97c; color: #5be59a; }
  .toast-err { background: #2a1414; border-color: #ff5757; color: #ff9b9b; }
}
@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity .3s ease; transform: none; }
}
