/* SkillCoach — Phenom Business Coaching Systems
   Light theme · Montserrat · soft diagonal gradients */

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800&display=swap');

:root {
  --ink: #1e2440;
  --ink-soft: #5a6178;
  --indigo: #4f46e5;
  --indigo-dark: #3b34b8;
  --periwinkle: #eef1ff;
  --gold: #c99a2e;
  --surface: #ffffff;
  --line: #e4e7f2;
  --danger: #c0392b;
  --ok: #1e8e5a;
  --radius: 12px;
  --shadow: 0 4px 18px rgba(30, 36, 64, .08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Montserrat', sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, #f7f8fd 0%, var(--periwinkle) 55%, #f2ecff 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { font-weight: 700; }
a { color: var(--indigo); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px;
  background: rgba(255,255,255,.85); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .app { font-size: 20px; font-weight: 800; letter-spacing: -.5px; }
.brand .org { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.topbar .who { font-size: 13px; color: var(--ink-soft); }
.topbar .who b { color: var(--ink); }

/* ---------- Layout ---------- */
.wrap { flex: 1; display: flex; width: 100%; max-width: 1240px; margin: 0 auto; padding: 22px; gap: 22px; }
.sidebar { width: 250px; flex-shrink: 0; display: flex; flex-direction: column; gap: 10px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}
.card h2 { font-size: 16px; margin-bottom: 14px; }

/* ---------- Nav tabs ---------- */
.nav { display: flex; flex-direction: column; gap: 6px; }
.nav button {
  text-align: left; padding: 11px 14px; border: none; border-radius: 10px;
  background: transparent; font-family: inherit; font-size: 14px; font-weight: 600;
  color: var(--ink-soft); cursor: pointer;
}
.nav button:hover { background: rgba(79,70,229,.07); color: var(--ink); }
.nav button.active {
  background: linear-gradient(120deg, var(--indigo), #6d5ff0);
  color: #fff;
}

/* ---------- Forms & buttons ---------- */
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin: 10px 0 4px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font-family: inherit; font-size: 14px;
  border: 1px solid var(--line); border-radius: 8px; background: #fbfcff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--indigo); border-color: transparent; }
textarea { resize: vertical; min-height: 110px; }

.btn {
  display: inline-block; padding: 10px 18px; border: none; border-radius: 8px;
  font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
  background: linear-gradient(120deg, var(--indigo), #6d5ff0); color: #fff;
}
.btn:hover { background: var(--indigo-dark); }
.btn.ghost { background: transparent; color: var(--indigo); border: 1px solid var(--indigo); }
.btn.small { padding: 6px 12px; font-size: 12px; }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
     color: var(--ink-soft); padding: 8px 10px; border-bottom: 2px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:hover td { background: #fafbff; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.pill.on  { background: #e2f5ec; color: var(--ok); }
.pill.off { background: #fdecea; color: var(--danger); }

/* ---------- Chat ---------- */
.chat-box { display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 420px; }
.chat-msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 6px 2px; }
.msg { max-width: 78%; padding: 12px 15px; border-radius: 14px; font-size: 14px; line-height: 1.55; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: linear-gradient(120deg, var(--indigo), #6d5ff0); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--periwinkle); border-bottom-left-radius: 4px; }
.msg.thinking { align-self: flex-start; color: var(--ink-soft); font-style: italic; background: transparent; }
.chat-input { display: flex; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); margin-top: 10px; }
.chat-input textarea { min-height: 48px; max-height: 140px; }

.conv-list { display: flex; flex-direction: column; gap: 4px; max-height: 40vh; overflow-y: auto; }
.conv-list button {
  text-align: left; padding: 9px 11px; border: none; border-radius: 8px; background: transparent;
  font-family: inherit; font-size: 13px; color: var(--ink-soft); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-list button:hover { background: rgba(79,70,229,.07); }
.conv-list button.active { background: var(--periwinkle); color: var(--ink); font-weight: 600; }

.usage-bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 6px; }
.usage-bar > div { height: 100%; background: linear-gradient(90deg, var(--indigo), var(--gold)); }

.notice { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; display: none; }
.notice.err { background: #fdecea; color: var(--danger); display: block; }
.notice.ok  { background: #e2f5ec; color: var(--ok); display: block; }

/* ---------- Login ---------- */
.login-page { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; }
.login-card .app-title { font-size: 30px; font-weight: 800; letter-spacing: -1px; text-align: center; }
.login-card .org { text-align: center; font-size: 13px; color: var(--ink-soft); font-weight: 600; margin: 4px 0 22px; }
.login-card .org::before, .login-card .org::after { content: "—"; color: var(--gold); margin: 0 8px; }

/* ---------- Footer ---------- */
footer {
  padding: 16px; text-align: center; font-size: 12px; color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
footer img { height: 22px; vertical-align: middle; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(30,36,64,.45); display: none;
            align-items: center; justify-content: center; z-index: 50; }
.modal-bg.open { display: flex; }
.modal { width: 100%; max-width: 480px; max-height: 85vh; overflow-y: auto; }

@media (max-width: 760px) {
  .wrap { flex-direction: column; }
  .sidebar { width: 100%; }
  .nav { flex-direction: row; flex-wrap: wrap; }
}

/* processing state */
body.busy, body.busy * { cursor: progress !important; }


/* ---------- Overflow fixes ---------- */

/* Topbar: allow items to wrap instead of clipping */
.topbar { flex-wrap: wrap; gap: 8px 16px; }
.topbar .who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.brand { flex-wrap: wrap; min-width: 0; }

/* Wide tables: scroll inside the card instead of spilling out */
.card { overflow-x: auto; }
.card table { min-width: 640px; }

/* Compact/flexible tables that size to their content instead of stretching */
.card table.fit { min-width: 0; width: auto; table-layout: auto; }
.card table.fit th, .card table.fit td { white-space: nowrap; padding: 6px 8px; }
.card table.fit td { border-bottom: 1px solid var(--line); }

/* On mobile, make it obvious a wide table can be swiped — default mobile
   scrollbars are invisible until touched, which reads as "cut off". */
@media (max-width: 640px) {
  .card { -webkit-overflow-scrolling: touch; }
  .card::-webkit-scrollbar { height: 6px; }
  .card::-webkit-scrollbar-thumb { background: var(--indigo); border-radius: 4px; opacity: .5; }
  .card table { position: relative; }
}

/* Chat card must keep its layout — exclude it from table min-width */
.chat-box { overflow-x: hidden; }

/* Action buttons: slightly tighter so rows fit more often */
.btn.small { padding: 5px 9px; font-size: 11px; }

/* At narrow widths, let action cells wrap into two lines */
@media (max-width: 900px) {
  td[style*="nowrap"] { white-space: normal !important; }
  td .btn.small { margin: 2px 0; }
}

/* Safety net: any card header row using inline flex + space-between
   (title next to action buttons) wraps instead of overlapping on
   narrow screens, even if a future addition forgets flex-wrap inline. */
@media (max-width: 640px) {
  .card > div[style*="justify-content:space-between"] {
    flex-wrap: wrap !important;
    row-gap: 10px;
  }
}
/* ---------- Markdown inside assistant bubbles ---------- */
.msg.md p { margin: 0 0 10px; } .msg.md p:last-child { margin-bottom: 0; }
.msg.md h1, .msg.md h2, .msg.md h3 { margin: 12px 0 6px; font-size: 15px; }
.msg.md ul, .msg.md ol { margin: 6px 0 10px 20px; }
.msg.md li { margin: 3px 0; }
.msg.md code { background: rgba(30,36,64,.08); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.msg.md pre { background: #2d2d38; color: #eee; padding: 10px 12px; border-radius: 8px;
              overflow-x: auto; margin: 8px 0; }
.msg.md pre code { background: none; padding: 0; color: inherit; }
.msg.md table { border-collapse: collapse; margin: 8px 0; }
.msg.md td, .msg.md th { border: 1px solid var(--line); padding: 4px 9px; font-size: 13px; }
.msg.md blockquote { border-left: 3px solid var(--indigo); margin: 8px 0; padding: 2px 12px; color: var(--ink-soft); }
.msg.md a { color: inherit; }

/* ---------- Category list ---------- */
.cat-list { display: flex; flex-direction: column; gap: 4px; }
.cat-list button {
  text-align: left; padding: 8px 11px; border: none; border-radius: 8px; background: transparent;
  font-family: inherit; font-size: 13px; font-weight: 600; color: var(--ink-soft); cursor: pointer;
}
.cat-list button:hover { background: rgba(79,70,229,.07); color: var(--ink); }
.cat-list button.active { background: var(--periwinkle); color: var(--indigo); }

/* ---------- Edit button on user messages ---------- */
.msg.user { position: relative; }
.msg.user .edit-btn {
  position: absolute; top: 4px; right: 6px; border: none; background: none;
  cursor: pointer; font-size: 12px; opacity: 0; transition: opacity .15s;
}
.msg.user:hover .edit-btn { opacity: .85; }
.msg.user.editing textarea { background: rgba(255,255,255,.95); color: var(--ink); }

/* ---------- Superseded messages in report transcripts ---------- */
.msg.superseded { opacity: .5; border: 1px dashed var(--line); }
.msg .sup-label { display:block; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; opacity: .8; margin-bottom: 4px; }
