/* ==========================================================
   CornerStone CRM — stylesheet
   Palette: paper #F6F7F4 · panel #FFF · ink #22303A
            accent (deep teal) #146C60 · muted #64707A
   Stage colors carry meaning on the pipeline board.
   ========================================================== */

:root {
    --paper: #DCE0DA;
    --panel: #EFF1EC;
    --ink: #22303A;
    --muted: #5E6A73;
    --line: #CBD1C9;
    --accent: #146C60;
    --accent-ink: #0D4A42;
    --accent-soft: #E4F0ED;
    --danger: #A65B5B;
    --danger-soft: #FBEAEA;

    --stage-lead: #56789B;
    --stage-contacted: #B08536;
    --stage-proposal: #7D5BA6;
    --stage-won: #2E7D5B;
    --stage-lost: #A65B5B;

    --radius: 10px;
    --shadow: 0 4px 18px rgba(34, 48, 58, .07);
    --font-display: 'Bricolage Grotesque', sans-serif;
    --font-body: 'IBM Plex Sans', -apple-system, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: var(--font-body);
    font-size: 15px;
    color: var(--ink);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; font-weight: 700; margin: 0; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 .6rem; }

button { font-family: inherit; }
input, select, textarea {
    font-family: inherit;
    font-size: .95rem;
    color: var(--ink);
    width: 100%;
    padding: .55rem .7rem;
    border: 1px solid #CBD3CE;
    border-radius: 8px;
    background: #fff;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
label { display: block; font-size: .8rem; font-weight: 600; margin: .8rem 0 .3rem; color: var(--ink); }

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: .55rem; }
.brand-mark {
    width: 22px; height: 22px; border-radius: 6px;
    background:
        linear-gradient(135deg, var(--accent) 0 55%, transparent 55%),
        linear-gradient(315deg, var(--accent-ink) 0 40%, transparent 40%);
    background-color: var(--accent-soft);
    flex: none;
}
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.02rem; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card {
    width: 100%; max-width: 380px;
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 14px; padding: 2rem; box-shadow: var(--shadow);
}
.login-sub { color: var(--muted); font-size: .9rem; margin: .4rem 0 1rem; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
.rail {
    background: var(--panel);
    border-right: 1px solid var(--line);
    padding: 1.1rem .8rem;
    display: flex; flex-direction: column; gap: .15rem;
    position: sticky; top: 0; height: 100vh;
}
.rail-brand { padding: 0 .5rem 1rem; }
.rail-link {
    text-align: left; border: 0; background: none; cursor: pointer;
    padding: .55rem .7rem; border-radius: 8px;
    font-size: .92rem; font-weight: 500; color: var(--muted);
}
.rail-link:hover { background: var(--paper); color: var(--ink); }
.rail-link.is-active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.rail-foot { margin-top: auto; padding: .8rem .5rem 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: .5rem; }
.rail-user { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

.main { padding: 1.6rem 2rem 3rem; max-width: 1180px; width: 100%; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.view-head .actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
    border: 1px solid transparent; border-radius: 8px; cursor: pointer;
    padding: .55rem .95rem; font-size: .9rem; font-weight: 600;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-outline { background: #fff; border-color: #CBD3CE; color: var(--ink); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: none; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); background: var(--paper); }
.btn-danger { background: none; border-color: #E3B8B8; color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: .35rem .6rem; font-size: .8rem; }
.btn-block { width: 100%; margin-top: 1.1rem; }

/* ---------- Cards / stats ---------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .8rem; margin-bottom: 1.4rem; }
.stat {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    padding: .9rem 1rem;
}
.stat .num { font-family: var(--font-display); font-size: 1.45rem; font-weight: 700; }
.stat .lbl { font-size: .78rem; color: var(--muted); font-weight: 500; }

.panel {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem;
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: .65rem .9rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #E4E7E1; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: var(--accent-soft); }
.table .no-click { cursor: default; }
.table .no-click:hover { background: none; }

.search-input { max-width: 280px; }

/* ---------- Pipeline (signature element) ---------- */
.board { display: grid; grid-template-columns: repeat(5, minmax(180px, 1fr)); gap: .8rem; align-items: start; overflow-x: auto; }
.col {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 0 0 .6rem; min-height: 220px;
}
.col-head {
    padding: .6rem .8rem .5rem;
    border-top: 4px solid var(--col-color, var(--muted));
    border-radius: var(--radius) var(--radius) 0 0;
    display: flex; justify-content: space-between; align-items: baseline;
    margin-bottom: .4rem;
}
.col-head .col-title { font-family: var(--font-display); font-weight: 600; font-size: .9rem; }
.col-head .col-total { font-size: .75rem; color: var(--muted); }
.col.drag-over { outline: 2px dashed var(--col-color, var(--accent)); outline-offset: -4px; }

.deal-card {
    margin: 0 .6rem .55rem; padding: .6rem .7rem;
    background: #fff; border: 1px solid var(--line); border-left: 3px solid var(--col-color, var(--muted));
    border-radius: 8px; cursor: grab; box-shadow: 0 1px 3px rgba(34,48,58,.05);
}
.deal-card:active { cursor: grabbing; }
.deal-card .deal-title { font-weight: 600; font-size: .88rem; }
.deal-card .deal-meta { font-size: .76rem; color: var(--muted); margin-top: .2rem; }
.deal-card .deal-value { font-size: .82rem; font-weight: 600; color: var(--accent-ink); margin-top: .25rem; }

.stage-pill {
    display: inline-block; padding: .15rem .55rem; border-radius: 99px;
    font-size: .72rem; font-weight: 600; color: #fff; text-transform: capitalize;
}

/* ---------- Notes / timeline ---------- */
.note { border-left: 3px solid var(--accent-soft); padding: .4rem .8rem; margin-bottom: .7rem; }
.note .note-meta { font-size: .75rem; color: var(--muted); margin-bottom: .15rem; }
.note .note-body { font-size: .9rem; white-space: pre-wrap; }

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(34,48,58,.42);
    display: grid; place-items: center; z-index: 50; padding: 1rem;
}
.modal {
    background: var(--panel); border-radius: 14px; box-shadow: var(--shadow);
    width: 100%; max-width: 460px; max-height: 90vh; overflow: auto; padding: 1.4rem 1.5rem;
}
.modal h2 { margin-top: 0; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.3rem; }

/* ---------- Lookup (type-ahead reference fields) ---------- */
.lookup { position: relative; }
.lookup input { padding-right: 2rem; }
.lookup-clear {
    position: absolute; right: .45rem; top: 50%; transform: translateY(-50%);
    border: 0; background: none; color: var(--muted); cursor: pointer;
    font-size: .85rem; padding: .2rem .3rem; line-height: 1;
}
.lookup-clear:hover { color: var(--danger); }
.lookup-menu {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    background: #fff; border: 1px solid var(--line); border-radius: 8px;
    box-shadow: var(--shadow); z-index: 70; max-height: 240px; overflow-y: auto;
}
.lookup-item {
    display: block; width: 100%; text-align: left; border: 0; background: none;
    padding: .5rem .7rem; font-size: .9rem; cursor: pointer;
}
.lookup-item:hover, .lookup-item.is-active { background: var(--accent-soft); }
.lookup-empty { padding: .5rem .7rem; font-size: .85rem; color: var(--muted); }

/* ---------- Alerts & toast ---------- */
.alert { border-radius: 8px; padding: .6rem .8rem; font-size: .85rem; margin: .6rem 0; }
.alert-error { background: var(--danger-soft); border: 1px solid #E3B8B8; color: #7A2E2E; }
.alert-ok { background: #E7F3EC; border: 1px solid #B5D9C3; color: #1F5A3D; }
.alert-warn { background: #FBF3DF; border: 1px solid #E0CD9A; color: #6E5716; font-weight: 500; }

.toast {
    position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
    background: var(--ink); color: #fff; padding: .6rem 1.1rem;
    border-radius: 99px; font-size: .85rem; z-index: 60; box-shadow: var(--shadow);
}

.empty { color: var(--muted); font-size: .9rem; padding: 1rem 0; }
.muted { color: var(--muted); }
.link-btn { background: none; border: 0; color: var(--accent-ink); cursor: pointer; font-weight: 600; padding: 0; font-size: inherit; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .app { grid-template-columns: 1fr; }
    .rail {
        position: static; height: auto; flex-direction: row; flex-wrap: wrap;
        align-items: center; padding: .6rem .8rem; gap: .2rem;
        border-right: 0; border-bottom: 1px solid var(--line);
    }
    .rail-brand { padding: 0 .6rem 0 0; }
    .rail-foot { margin: 0 0 0 auto; padding: 0; border: 0; flex-direction: row; align-items: center; }
    .main { padding: 1rem; }
    .two-col { grid-template-columns: 1fr; }
    .board { grid-template-columns: repeat(5, 220px); }
}

@media (prefers-reduced-motion: no-preference) {
    .rail-link, .btn, .deal-card { transition: background .12s ease, border-color .12s ease, color .12s ease; }
}
