/* QWPA CRM — shares the marketing site's palette so the two feel like one product. */

@import url('https://fonts.googleapis.com/css2?family=Archivo:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
    --paper:        #F4F2EC;
    --card:         #FFFFFF;
    --ink:          #0F2E3D;
    --ink-soft:     #3D5766;
    --slate:        #5B7280;
    --amber:        #E0A94E;
    --amber-hover:  #C9902F;
    --core:         #241A0A;
    --coral:        #F26D5B;
    --good:         #2E6B5E;
    --good-bg:      #E3EDE9;
    --bad:          #A8433A;
    --bad-bg:       #F5E3E0;
    --line:         #DFDACD;
    --line-soft:    #ECE8DE;
    --font-display: 'Archivo', system-ui, sans-serif;
    --font-body:    'Inter', system-ui, sans-serif;
    --font-mono:    'IBM Plex Mono', ui-monospace, monospace;
    --radius: 10px;

    /*
     * Ported-module bridge: the Meeting module's own assets/style.css
     * (untouched, per Task 7) is written against a different design
     * system's variable names — --panel, --text, --muted, --accent etc.,
     * from the dark-themed portal it was built for. None of those exist
     * here, so without these aliases every one of its panels, borders and
     * accents would render as transparent/inherited rather than fighting
     * visibly with this palette. Aliasing them onto QWPA's own tokens is
     * how a module page inherits this palette instead of carrying its own.
     */
    --panel:                 var(--card);
    --text:                  var(--ink);
    --muted:                 var(--slate);
    --accent:                var(--amber);
    --accent2:               var(--good);
    --overlay-border:        var(--line-soft);
    --overlay-border-strong: var(--line);
    --overlay-bg:            var(--line-soft);
    --overlay-bg-strong:     var(--line);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--good); }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.015em; }
h1 { font-size: 1.7rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.02rem; font-weight: 600; }
p  { margin: 0 0 1em; }
p:last-child { margin-bottom: 0; }

/* ---------------- top bar ---------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 26px;
    padding: 0 22px;
    height: 58px;
    background: var(--core);
    border-bottom: 1px solid #3A2C14;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: #F4EFE4;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: .04em;
    flex: none;
}
.brand em { font-style: normal; color: var(--amber); margin-left: 2px; }

.mainnav {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 100%;
    flex: 1;
}

.navgroup { position: relative; height: 100%; display: flex; align-items: center; }
.navgroup-end { margin-left: auto; }

.navlink {
    display: flex;
    align-items: center;
    gap: 7px;
    height: 100%;
    padding: 0 14px;
    text-decoration: none;
    color: #C8BFAE;
    font-size: .93rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}
.navlink:hover { color: #FFF; background: rgba(255,255,255,.05); }
.navlink.is-active { color: #FFF; border-bottom-color: var(--amber); }
.navuser { color: #8E8271; cursor: default; }

/* dropdowns open on hover and on keyboard focus */
.navmenu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 208px;
    background: #FFF;
    border: 1px solid var(--line);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 10px 26px rgba(15,46,61,.16);
    padding: 7px;
    display: none;
}
.navmenu-right { left: auto; right: 0; }
.navgroup:hover .navmenu,
.navgroup:focus-within .navmenu { display: block; }

.navmenu a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 11px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--ink);
    font-size: .91rem;
}
.navmenu a:hover { background: var(--paper); }
.navmenu hr { border: none; border-top: 1px solid var(--line-soft); margin: 6px 4px; }

.pip {
    font-family: var(--font-mono);
    font-size: .7rem;
    font-weight: 600;
    background: var(--coral);
    color: #FFF;
    border-radius: 999px;
    padding: 1px 7px;
    line-height: 1.5;
}

.btn-star {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 2px 4px;
    color: var(--slate);
}
.btn-star:hover { color: var(--amber); }
.btn-star.is-starred { color: var(--amber); }

.nav-burger { display: none; background: none; border: 0; cursor: pointer; padding: 10px; }
.nav-burger span { display: block; width: 20px; height: 2px; background: #E5DCCB; margin: 4px 0; }

/* ---------------- page ---------------- */

.page { max-width: 1280px; margin: 0 auto; padding: 26px 22px 70px; }

.pagehead {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 20px;
}
.pagehead h1 { margin: 0; }
.pagesub { margin: 4px 0 0; color: var(--slate); font-size: .93rem; }
.pagehead-actions { display: flex; gap: 9px; flex-wrap: wrap; }

/* ---------------- cards & tables ---------------- */

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 18px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-flush { padding: 0; overflow: hidden; }

.tablewrap { overflow-x: auto; }

table.grid { width: 100%; border-collapse: collapse; font-size: .91rem; }
table.grid th {
    text-align: left;
    font-family: var(--font-display);
    font-size: .78rem;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--slate);
    padding: 11px 14px;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
table.grid td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.grid tbody tr:hover { background: #FBFAF6; }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid td.num { font-family: var(--font-mono); text-align: right; white-space: nowrap; }
table.grid a.rowlink { font-weight: 600; text-decoration: none; color: var(--ink); }
table.grid a.rowlink:hover { color: var(--good); text-decoration: underline; }
tr.is-unread td { background: #FFFCF3; }
tr.is-unread a.rowlink { font-weight: 700; }

.empty { padding: 44px 20px; text-align: center; color: var(--slate); font-size: .93rem; }

/* ---------------- pills ---------------- */

.pill {
    display: inline-block;
    font-size: .74rem;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 999px;
    white-space: nowrap;
}
.pill-customer { background: var(--good-bg); color: var(--good); }
.pill-partner  { background: #EAE6F3; color: #55458C; }
.pill-lead     { background: #FBEEDA; color: #8A6216; }
.pill-active   { background: var(--good-bg); color: var(--good); }
.pill-archived { background: #ECE9E1; color: var(--slate); }
.pill-new      { background: var(--coral); color: #FFF; }
.pill-read     { background: #ECE9E1; color: var(--slate); }
.pill-converted{ background: var(--good-bg); color: var(--good); }
.pill-sent     { background: var(--good-bg); color: var(--good); }
.pill-pending  { background: #FBEEDA; color: #8A6216; }
.pill-failed   { background: var(--bad-bg); color: var(--bad); }

/* ---------------- buttons ---------------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-family: var(--font-body);
    font-size: .9rem;
    font-weight: 600;
    padding: 9px 17px;
    border-radius: 7px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.3;
}
.btn-primary { background: var(--amber); color: var(--core); border-color: var(--amber); }
.btn-primary:hover { background: var(--amber-hover); border-color: var(--amber-hover); }
.btn-ghost { background: #FFF; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--paper); }
.btn-danger { background: #FFF; color: var(--bad); border-color: #E3BDB7; }
.btn-danger:hover { background: var(--bad-bg); }
.btn-sm { padding: 6px 12px; font-size: .84rem; }

:focus-visible { outline: 3px solid var(--good); outline-offset: 2px; }

/* ---------------- forms ---------------- */

.formgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.formgrid .full { grid-column: 1 / -1; }

.field { display: grid; gap: 5px; }
.field label { font-size: .84rem; font-weight: 600; color: var(--ink); }
.field .hint { font-size: .8rem; color: var(--slate); }

.field input[type=text], .field input[type=email], .field input[type=tel],
.field input[type=password], .field input[type=number], .field input[type=url],
.field select, .field textarea {
    font-family: var(--font-body);
    font-size: .95rem;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #FFF;
    color: var(--ink);
    width: 100%;
}
.field textarea { resize: vertical; min-height: 110px; }
.field textarea.code { font-family: var(--font-mono); font-size: .85rem; min-height: 220px; }

.checkrow { display: flex; align-items: flex-start; gap: 9px; }
.checkrow input { margin-top: 3px; }
.checkrow label { font-weight: 500; font-size: .9rem; }

.formactions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line-soft);
}

/* ---------------- flash ---------------- */

.flash {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: .92rem;
    margin-bottom: 16px;
    border: 1px solid transparent;
    white-space: pre-wrap;
    word-break: break-word;
}
.flash-success { background: var(--good-bg); color: var(--good); border-color: #BFD8D0; }
.flash-error   { background: var(--bad-bg);  color: var(--bad);  border-color: #E3BDB7; }
.flash-info    { background: #E9EFF3; color: var(--ink-soft); border-color: #CBD9E1; }

/* ---------------- filters / toolbar ---------------- */

.toolbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.toolbar input[type=search] {
    font-family: var(--font-body);
    font-size: .92rem;
    padding: 9px 13px;
    border: 1px solid var(--line);
    border-radius: 7px;
    min-width: 250px;
    background: #FFF;
}
.toolbar select {
    font-family: var(--font-body);
    font-size: .92rem;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #FFF;
}

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs a {
    padding: 9px 15px;
    text-decoration: none;
    color: var(--slate);
    font-size: .92rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.tabs a.is-active { color: var(--ink); border-bottom-color: var(--amber); font-weight: 600; }

/* ---------------- mail folder sidebar ---------------- */

.mailgrid { display: grid; grid-template-columns: 160px 1fr; gap: 18px; align-items: start; }
.mail-sidebar { display: flex; flex-direction: column; gap: 2px; }
.mail-sidebar a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--slate);
    font-size: .92rem;
    font-weight: 500;
}
.mail-sidebar a:hover { background: var(--line-soft); }
.mail-sidebar a.is-active { background: var(--amber); color: var(--core); font-weight: 600; }
.mail-sidebar a.is-active .pip { background: var(--core); color: var(--amber); }

@media (max-width: 720px) {
    .mailgrid { grid-template-columns: 1fr; }
    .mail-sidebar { flex-direction: row; flex-wrap: wrap; gap: 6px; }
    .mail-sidebar a { padding: 6px 10px; }
}

/* ---------------- detail layout ---------------- */

.split { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; align-items: start; }

/* Settings: cards that wrap on their own rather than a fixed column split. */
.settingsgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; align-items: start; }
.settingsgrid > .card { margin-bottom: 0; }

.checklist { display: grid; gap: 12px; }
.checkitem { display: flex; gap: 10px; align-items: flex-start; }
.checkitem-icon {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .78rem;
    font-weight: 700;
    margin-top: 1px;
}
.checkitem-ok .checkitem-icon   { background: var(--good-bg); color: var(--good); }
.checkitem-fail .checkitem-icon { background: var(--bad-bg);  color: var(--bad); }

.deflist { display: grid; gap: 0; }
.deflist > div {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 14px;
    padding: 9px 0;
    border-bottom: 1px solid var(--line-soft);
    font-size: .92rem;
}
.deflist > div:last-child { border-bottom: none; }
.deflist dt { color: var(--slate); margin: 0; }
.deflist dd { margin: 0; }

.thread { display: grid; gap: 12px; }
.msg { border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: #FFF; }
.msg-head {
    display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 11px 15px; background: var(--paper); border-bottom: 1px solid var(--line-soft);
    font-size: .87rem;
}
.msg-body { padding: 15px; font-size: .93rem; }
.msg-body pre { white-space: pre-wrap; word-wrap: break-word; font-family: var(--font-body); margin: 0; }
.msg.is-out { border-left: 3px solid var(--amber); }
.msg.is-in  { border-left: 3px solid var(--good); }

.mailbody { border: 1px solid var(--line); border-radius: 9px; background: #FFF; padding: 18px; }
.mailbody img { max-width: 100%; height: auto; }

/* ---------------- compose rich-text editor (Quill) ---------------- */

/* Quill's own .ql-formats groups are display:inline-block with no forced
   nowrap, so they already wrap onto additional rows at narrow widths —
   this just rounds the corners to match the rest of the app and gives
   wrapped rows a little breathing room. */
.mail-editor-toolbar.ql-toolbar.ql-snow {
    border-radius: 9px 9px 0 0;
    row-gap: 4px;
}
#editor-container.ql-container.ql-snow {
    border-radius: 0 0 9px 9px;
    background: #FFF;
    min-height: 220px;
    font-size: .95rem;
}
#editor-container .ql-editor {
    min-height: 220px;
}
#editor-container .ql-editor blockquote {
    margin: 0 0 0 .8ex;
    border-left: 2px solid var(--line);
    padding-left: 1ex;
    color: var(--slate);
}

/* Custom HR/Undo/Redo buttons — sized to sit alongside Quill's own 28px
   icon buttons, which a short text label needs a little more room than. */
.mail-editor-btn {
    background: none;
    border: none;
    cursor: pointer;
    display: inline-block;
    float: left;
    height: 24px;
    min-width: 28px;
    padding: 3px 6px;
    font-size: .78rem;
    font-weight: 600;
    color: #444;
    border-radius: 4px;
}
.mail-editor-btn:hover { color: #06c; background: var(--line-soft); }

@media (max-width: 520px) {
    #editor-container.ql-container.ql-snow,
    #editor-container .ql-editor {
        min-height: 160px;
    }
}

.codeblock {
    font-family: var(--font-mono);
    font-size: .82rem;
    background: var(--core);
    color: #E8E2D6;
    padding: 13px 15px;
    border-radius: 7px;
    white-space: pre-wrap;
    overflow-x: auto;
    white-space: pre;
}

.chiplist { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    font-family: var(--font-mono);
    font-size: .78rem;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 3px 8px;
    cursor: pointer;
}
.chip:hover { background: #FFF; border-color: var(--amber); }

/* ---------------- login ---------------- */

.loginwrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 30px;
    background: var(--core);
}
.logincard {
    width: 100%;
    max-width: 380px;
    background: #FFF;
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.loginbrand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.loginbrand span { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; letter-spacing: .04em; }

/* ---------------- responsive ---------------- */

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

@media (max-width: 820px) {
    .topbar { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 12px; }
    .nav-burger { display: block; margin-left: auto; }
    .mainnav {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding-bottom: 8px;
    }
    .mainnav.is-open { display: flex; }
    .navgroup { height: auto; display: block; }
    .navgroup-end { margin-left: 0; }
    .navlink { height: auto; padding: 11px 6px; border-bottom: 1px solid rgba(255,255,255,.07); }
    .navlink.is-active { border-bottom-color: var(--amber); }
    .navmenu {
        position: static;
        display: block;
        background: transparent;
        border: none;
        box-shadow: none;
        padding: 0 0 8px 16px;
    }
    .navmenu a { color: #B7AC99; padding: 7px 6px; }
    .navmenu a:hover { background: rgba(255,255,255,.05); }
    .navmenu hr { border-top-color: rgba(255,255,255,.1); }
    .formgrid { grid-template-columns: 1fr; }
    .deflist > div { grid-template-columns: 1fr; gap: 2px; }
}

/* ---- Shared loading state (assets/loading.js) ---- */
.is-loading { position: relative; cursor: progress; opacity: .85; }
.is-loading::before {
    content: "";
    display: inline-block;
    width: .9em; height: .9em;
    margin-right: .45em;
    vertical-align: -.12em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: qwpa-spin .7s linear infinite;
}
@keyframes qwpa-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .is-loading::before { animation-duration: 2s; } }

/* ---------------- dashboard (item 3) ---------------- */
.tilegrid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}
.tile {
    display: block;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 16px 14px;
    text-decoration: none;
    color: var(--ink);
    transition: border-color .15s;
}
.tile:hover { border-color: var(--amber); }
.tile-count {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}
.tile-label {
    font-size: .82rem;
    color: var(--slate);
    margin-top: 4px;
}
.tile-disabled {
    cursor: default;
    opacity: .55;
}
.tile-disabled:hover { border-color: var(--line); }
.tile-disabled .tile-count { color: var(--slate); }

.dashgrid {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 18px;
    align-items: start;
}
@media (max-width: 820px) {
    .dashgrid { grid-template-columns: 1fr; }
}

.feedlist { display: flex; flex-direction: column; gap: 10px; }
.feeditem {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: .89rem;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line-soft);
}
.feeditem:last-child { border-bottom: none; padding-bottom: 0; }
.feeditem-when { color: var(--slate); font-size: .78rem; white-space: nowrap; }

.attentionlist { display: flex; flex-direction: column; gap: 8px; }
.attentionitem {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    font-size: .89rem;
    padding: 8px 10px;
    background: var(--bad-bg);
    border-radius: 8px;
}
.attentionitem a { color: var(--ink); font-weight: 600; }

/* CRM feedback item 8, Stage 5: document upload progress (assets/portal_upload.js) */
.upload-bar { height: 8px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); overflow: hidden; margin-bottom: 6px; }
.upload-bar-fill { height: 100%; width: 0; background: var(--good); transition: width .15s linear; }
.upload-bar-fill.upload-bar-indeterminate {
    background: linear-gradient(90deg, var(--good) 0%, var(--amber) 50%, var(--good) 100%);
    background-size: 200% 100%;
    animation: upload-indeterminate 1.1s linear infinite;
}
@keyframes upload-indeterminate { from { background-position: 0% 0; } to { background-position: -200% 0; } }
.upload-status-text { margin: 0; font-size: .82rem; color: var(--slate); }
