:root {
  --navy: #24384f;
  --navy-deep: #16273a;
  --blue: #7fb0e0;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f4f6f9;
  --white: #fff;
  --won: #2f9e5f;
  --lost: #b04a4a;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(16,39,58,.08);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Jost', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow-x: hidden;   /* never allow the whole page to swipe sideways; inner
                           scroll strips (stats, tables) still scroll on their own */
}
h1,h2,h3 { font-family: 'Cormorant Garamond', Georgia, serif; font-weight: 600; margin: 0; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--navy); color: #fff; padding: 14px 24px;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark {
  font-family: 'Cormorant Garamond', serif; font-weight: 600; font-size: 20px;
  background: var(--blue); color: var(--navy-deep); padding: 2px 8px; border-radius: 6px;
}
.brand-name { font-family: 'Cormorant Garamond', serif; font-size: 24px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.view-toggle { display: flex; background: rgba(255,255,255,.1); border-radius: 8px; overflow: hidden; }
.view-toggle button {
  border: 0; background: transparent; color: #cdd8e5; padding: 8px 16px; cursor: pointer;
  font-family: inherit; font-size: 14px;
}
.view-toggle button.active { background: var(--blue); color: var(--navy-deep); font-weight: 500; }

/* Global client search (topbar) */
.client-search {
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2);
  color: #fff; border-radius: 8px; padding: 8px 12px; font-family: inherit;
  font-size: 14px; width: 200px; min-width: 0;
}
.client-search::placeholder { color: #aebcce; }
.client-search:focus { outline: none; border-color: var(--blue); background: rgba(255,255,255,.18); }

/* Buttons */
.btn { border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer; font-family: inherit; font-size: 14px; }
.btn-primary { background: var(--blue); color: var(--navy-deep); font-weight: 500; }
.btn-primary:hover { background: #9cc4ea; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn-danger { background: transparent; border: 1px solid var(--lost); color: var(--lost); }
.btn-danger:hover { background: var(--lost); color: #fff; }

/* Stats */
.stats { display: flex; gap: 16px; padding: 20px 24px 0; flex-wrap: wrap; }
.stat-card {
  background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 20px; min-width: 150px;
}
.stat-card .num { font-family: 'Cormorant Garamond', serif; font-size: 30px; color: var(--navy); }
.stat-card .label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }

/* Pipeline */
.content { padding: 20px 24px 60px; }
.pipeline { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.col { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 200px; }
.col-head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.col-head .title { font-family: 'Cormorant Garamond', serif; font-size: 18px; color: var(--navy); }
.col-head .count { background: var(--bg); color: var(--muted); border-radius: 20px; padding: 1px 9px; font-size: 12px; }
.col-body { padding: 10px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.card {
  border: 1px solid var(--line); border-left: 3px solid var(--blue); border-radius: 8px;
  padding: 10px 12px; cursor: pointer; background: #fff; transition: box-shadow .15s;
}
.card:hover { box-shadow: var(--shadow); }
.card .company { font-weight: 500; }
.card .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.card .val { color: var(--navy); font-size: 13px; margin-top: 6px; }
.col[data-stage="won"] .card { border-left-color: var(--won); }
.col[data-stage="lost"] .card { border-left-color: var(--lost); opacity: .8; }

/* List */
.list table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list th, .list td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 14px; }
.list th { background: var(--navy); color: #fff; font-weight: 400; font-family: 'Cormorant Garamond', serif; font-size: 16px; }
.list tr { cursor: pointer; }
.list tbody tr:hover { background: #f0f4f9; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; background: var(--bg); color: var(--muted); }
.pill.lead { background:#eef2f7; } .pill.contacted{ background:#e3edf7; color:#3a6ea5;}
.pill.proposal{ background:#fef3e0; color:#b07d2a;} .pill.won{ background:#e4f5ec; color:var(--won);} .pill.lost{ background:#f8e8e8; color:var(--lost);}

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(22,39,58,.55); display: flex; align-items: center; justify-content: center; padding: 24px 16px; z-index: 50; }
.modal {
  background: #fff; border-radius: var(--radius); width: 100%; max-width: 640px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  display: flex; flex-direction: column;      /* header / scrolling body / footer */
  max-height: 90vh;                            /* never taller than the viewport */
  overflow: hidden;                            /* corners stay rounded */
}
.modal-head { flex: 0 0 auto; display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); background: #fff; }
.modal-head h2 { font-size: 26px; color: var(--navy); }
.modal-close { border: 0; background: none; font-size: 28px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { flex: 1 1 auto; overflow-y: auto; padding: 20px 22px; }   /* only the body scrolls */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
input, select, textarea { font-family: inherit; font-size: 14px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
.req { color: var(--lost); }
.modal-foot {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
  padding: 14px 22px; border-top: 1px solid var(--line);
  background: #fff;                                /* always visible: it's a flex child of .modal, pinned below the scrolling body */
}
.modal-foot .spacer { flex: 1; }
.autosave-status { font-size: 12px; color: var(--won); min-width: 60px; }
.autosave-status.saving { color: var(--muted); }
.autosave-status.error { color: var(--lost); }

/* Activities */
.activities { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.activities h3 { font-size: 20px; color: var(--navy); margin-bottom: 10px; }
.activity-add { display: flex; gap: 8px; margin-bottom: 12px; }
.activity-add select { flex: 0 0 110px; }
.activity-add input { flex: 1; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 240px; overflow-y: auto; }
.timeline li { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; }
.timeline .ttype { flex: 0 0 auto; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--blue); background: var(--navy); padding: 2px 7px; border-radius: 5px; margin-top: 1px; }
.timeline .tbody { flex: 1; white-space: pre-line; }
.timeline .tdate { color: var(--muted); font-size: 11px; }
.timeline .tdel { border: 0; background: none; color: var(--muted); cursor: pointer; }

/* Websites */
.websites { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.websites h3 { font-size: 20px; color: var(--navy); margin-bottom: 10px; }
.website-add { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.website-add input { flex: 1 1 100%; }
.website-add .website-label { flex: 1 1 100%; }
.website-add button { flex: 0 0 auto; }
.website-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.website-list li { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.website-link { flex: 1; color: var(--navy); word-break: break-all; }
.website-link:hover { color: var(--blue); }

/* Tasks board */
.board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.task-card { border: 1px solid var(--line); border-left: 3px solid var(--blue); border-radius: 8px; padding: 10px 12px; background: #fff; cursor: pointer; transition: box-shadow .15s; }
.task-card:hover { box-shadow: var(--shadow); }
.task-card.prio-high { border-left-color: var(--lost); }
.task-card.prio-medium { border-left-color: #b07d2a; }
.task-card.prio-low { border-left-color: var(--won); }
.task-title { font-weight: 500; font-size: 14px; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pill.prio { text-transform: capitalize; }
.pill.prio.high { background:#f8e8e8; color:var(--lost); }
.pill.prio.medium { background:#fef3e0; color:#b07d2a; }
.pill.prio.low { background:#e4f5ec; color:var(--won); }
.pill.agent { background: var(--navy); color: var(--blue); }
.pill.client-link { background:#e3edf7; color:#3a6ea5; }
.task-moves { display: flex; gap: 6px; margin-top: 8px; }
.move-btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; min-width: 30px; padding: 4px 8px; cursor: pointer; color: var(--navy); font-size: 14px; }
.move-btn:hover { background: var(--bg); }

/* Tasks inside client modal */
.client-tasks { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.client-tasks h3 { font-size: 20px; color: var(--navy); margin-bottom: 10px; }
.task-add { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.task-add input[name="title"] { flex: 1 1 auto; }
.agent-check, .agent-check-full { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; white-space: nowrap; }
.agent-check-full { align-self: end; }
.client-task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.client-task { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; padding: 4px 0; }
.client-task:hover .ct-title { color: var(--blue); }
.task-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; background: var(--muted); }
.task-dot.s-backlog { background:#9aa5b1; } .task-dot.s-todo { background:#3a6ea5; }
.task-dot.s-in-progress { background:#b07d2a; } .task-dot.s-done { background:var(--won); }
.ct-title { flex: 1; }
.ct-status { color: var(--muted); font-size: 12px; }

/* New-client hint */
.hint { background:#eef4fb; border:1px solid #d6e4f2; color:#3a6ea5; padding:10px 12px; border-radius:8px; font-size:13px; margin:0 0 4px; }

/* Pricing fields block */
.pricing-fields{margin-top:18px;padding-top:16px;border-top:1px solid var(--line);}
.pricing-fields h3{font-size:20px;color:var(--navy);margin-bottom:10px;}

/* SEO block + pricing */
.seo-block { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.seo-block h3 { font-size: 20px; color: var(--navy); margin-bottom: 10px; }
.btn-light { background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.25); }
.btn-light:hover { background: rgba(255,255,255,.24); }
.pricing-table { width: 100%; border-collapse: collapse; margin: 6px 0 20px; font-size: 14px; }
.pricing-table th, .pricing-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.pricing-table th { background: var(--bg); color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.pricing-table .intro-price { color: var(--won); font-weight: 600; }

/* Utility */
.hidden { display: none !important; }
.empty { color: var(--muted); text-align: center; padding: 30px; font-size: 13px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 12px 22px; border-radius: 10px; box-shadow: var(--shadow); z-index: 100; font-size: 14px; }

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

/* ---- Mobile / tablet (<= 720px) ---------------------------------------- */
@media (max-width: 720px) {
  /* Topbar: stack brand on row 1, actions on row 2 — clean on narrow phones. */
  .topbar {
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px;
  }
  .brand {
    flex: 1 1 100%;          /* brand takes the whole first row */
    align-items: center;
    min-width: 0;
  }
  .brand-name {
    font-size: 20px;
    white-space: nowrap;     /* never wrap "Client CRM" onto two lines */
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar-actions {
    flex: 1 1 100%;          /* actions take the whole second row */
    width: 100%;
    flex-wrap: wrap;         /* let the toggle + action buttons stack onto rows */
    justify-content: stretch;
    gap: 10px;
  }
  /* View toggle gets its OWN full-width row and wraps so ALL views stay reachable
     on narrow phones (previously it was squeezed by the action buttons and clipped
     everything after "Pipeline" behind overflow:hidden). */
  .view-toggle {
    flex: 1 1 100%;
    width: 100%;
    flex-wrap: wrap;         /* buttons wrap to a 2nd line instead of being clipped */
    overflow: visible;       /* override base overflow:hidden that hid buttons */
    background: rgba(255,255,255,.1);
    border-radius: 8px;
  }
  .view-toggle button {
    flex: 1 1 30%;           /* ~3 per row, wrapping as needed; all visible */
    min-width: 0;
    padding: 12px 8px;
    min-height: 44px;
    border-radius: 8px;      /* round each button — the wrapper no longer clips
                                (overflow:visible for wrapping) so the active button
                                would otherwise show square corners */
    white-space: nowrap;
  }
  /* Action buttons share the next full-width row and split the space evenly. */
  #addClientBtn, #addTaskBtn, #pricingBtn, #logoutBtn {
    flex: 1 1 auto;
    white-space: nowrap;
  }
  /* Search box: its own full-width row on mobile. */
  .client-search { flex: 1 1 100%; width: 100%; order: -1; min-height: 44px; }

  /* Stats: horizontal scroll strip so cards keep their size. */
  .stats {
    gap: 12px;
    padding: 16px 16px 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .stat-card { min-width: 46%; flex: 0 0 auto; }

  /* Pipeline: single column stack, each stage a full-width section. */
  .content { padding: 16px 16px 48px; }
  .pipeline { grid-template-columns: 1fr; gap: 12px; }
  .board { grid-template-columns: 1fr; gap: 12px; }
  .col { min-height: 0; }

  /* List: drop lower-priority columns so the table fits. */
  .list { overflow-x: auto; }
  .list th:nth-child(3), .list td:nth-child(3) { display: none; } /* Type */
  .list th, .list td { padding: 12px; }

  /* Modal: full-screen sheet. Reuses the flex-column structure (body scrolls,
     header + footer pinned) from the base .modal rule — just fill the screen. */
  .modal-overlay { padding: 0; align-items: stretch; background: #fff; }
  .modal {
    max-width: 100%;
    max-height: 100vh;
    max-height: 100dvh;   /* dvh accounts for mobile browser chrome so the footer stays on-screen */
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    background: #fff;
  }
  .grid2 { grid-template-columns: 1fr; gap: 12px; }

  /* Websites: stack the old/new columns on mobile. */
  .websites { grid-template-columns: 1fr; gap: 16px; }

  /* Tap targets: 44px min height for inputs, selects and buttons. */
  input, select, textarea { font-size: 16px; padding: 12px; } /* 16px avoids iOS zoom */
  .btn { padding: 12px 16px; min-height: 44px; }
  .modal-close { min-width: 44px; min-height: 44px; }

  /* Activity add row: stack so the input isn't cramped. */
  .activity-add { flex-wrap: wrap; }
  .activity-add select { flex: 1 1 100%; }
  .activity-add input { flex: 1 1 100%; }
  .activity-add button { flex: 1 1 100%; }
}

/* Fix the required-field asterisk sitting on its own line inside column labels. */
label .req { display: inline; }


/* Hosting block (host/kill a client's docker site) */
.hosting{margin-top:1.25rem}
.hosting-row{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
.host-spacer{flex:1}
.host-status{font-weight:600;font-size:.95rem}
.host-status.is-live{color:#1a7f4b}
.host-status.is-off{color:#8a8a8a}
.host-link{font-size:.85rem;color:#3355cc;text-decoration:none}
.host-link:hover{text-decoration:underline}
.host-hint{font-size:.8rem;margin:.4rem 0 0;word-break:break-word}
@media(max-width:720px){.hosting-row{gap:8px}.host-spacer{flex-basis:100%;height:0}.hosting-row .btn{flex:1 1 auto;min-height:44px}}

/* Validated markers on cards / list rows */
.validated-tick {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin-right: 6px; border-radius: 50%;
  background: var(--won); color: #fff; font-size: 11px; font-weight: 700; line-height: 1;
  vertical-align: middle;
}
.card.is-validated { border-left: 3px solid var(--won); }

/* Validated toggle at top of client modal */
.validated-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #eef5ec; border: 1px solid #cfe3c7; border-left: 4px solid var(--won);
  padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; cursor: pointer;
}
.validated-row input[type="checkbox"] { width: 20px; height: 20px; min-height: 20px; accent-color: var(--won); cursor: pointer; }
.validated-row .validated-label { font-weight: 500; font-size: 16px; }
.validated-row .validated-hint { color: var(--muted); font-size: 13px; }

/* Pipeline value page */
.pipeline-value { padding: 8px 0 40px; }
.pv-summary { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.pv-group {
  flex: 1 1 200px; background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; text-align: left;
}
.pv-group.is-validated { border-top: 4px solid var(--won); }
.pv-group.is-unvalidated { border-top: 4px solid #d1a54a; }
.pv-group.is-total { border-top: 4px solid var(--navy); }
.pv-group h3 { font-size: 20px; margin-bottom: 8px; }
.pv-group .pv-num { font-size: 26px; font-weight: 500; font-family: 'Jost', sans-serif; }
.pv-group .pv-sub { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.pv-section { margin-bottom: 28px; }
.pv-section h3 { font-size: 22px; margin-bottom: 10px; }
.pv-section table { width: 100%; border-collapse: collapse; background: var(--white); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.pv-section th, .pv-section td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.pv-section tbody tr { cursor: pointer; }
.pv-section tbody tr:hover { background: #f7f9fc; }

@media (max-width: 720px) {
  .pv-summary { flex-direction: column; }
  /* Let each breakdown table scroll inside its own section instead of pushing the
     whole page wide (which allowed left/right swiping of the site). */
  .pv-section { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .pv-section table { min-width: 480px; }
}

/* Login / challenge page */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--navy);
}
.login-card {
  background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 32px 28px; width: 100%; max-width: 360px; margin: 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.login-card .brand { justify-content: center; margin-bottom: 4px; }
.login-card .brand-name { color: var(--navy); }
.login-card h1 { font-size: 28px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.login-card input[type="password"] {
  font-size: 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-family: inherit; min-height: 44px;
}
.login-card .btn-primary { min-height: 44px; }
.login-error { color: var(--lost); font-size: 14px; margin: 0; }

/* ---- Sites view (currently running site containers) -------------------- */
.sites-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.sites-count { font-size: 22px; color: var(--navy); }
.sites-refresh { min-height: 40px; }
.sites-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.site-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); padding: 16px; display: flex;
  flex-direction: column; gap: 8px;
}
.site-title { font-weight: 600; font-size: 1.05rem; color: var(--ink); }
.site-url { color: #3355cc; text-decoration: none; font-size: .9rem; word-break: break-all; }
.site-url:hover { text-decoration: underline; }
.site-note { font-size: .78rem; color: var(--muted); }
.site-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.site-status { font-size: .8rem; color: var(--muted); }
.site-port {
  font-size: .78rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg); color: var(--ink); padding: 1px 6px; border-radius: 6px;
}
.site-container {
  font-size: .75rem; color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  border-top: 1px solid var(--line); padding-top: 8px; margin-top: 2px; word-break: break-all;
}
.health-badge {
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: 2px 8px; border-radius: 999px; color: #fff; background: var(--muted);
}
.health-badge.h-healthy { background: var(--won); }
.health-badge.h-unhealthy { background: var(--lost); }
.health-badge.h-health--starting { background: #c78a1e; }

.site-actions { display: flex; gap: 8px; margin-top: 4px; }
.site-kill { padding: 8px 14px; font-size: .85rem; }
.site-kill:disabled { opacity: .6; cursor: default; }

@media (max-width: 720px) {
  .sites-grid { grid-template-columns: 1fr; gap: 12px; }
  .sites-refresh { flex: 1 1 auto; min-height: 44px; }
  .site-kill { width: 100%; min-height: 44px; }
}
