:root {
    --ink: #172033;
    --muted: #67728a;
    --line: #dfe5ef;
    --surface: #ffffff;
    --canvas: #f5f7fb;
    --brand: #5a4fcf;
    --brand-dark: #4439b6;
    --accent: #e9e7ff;
    --success: #176b45;
    --success-bg: #e8f7ef;
    --danger: #9b2c2c;
    --danger-bg: #fff0f0;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(20, 30, 55, .08);
}
* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--canvas); }
body { margin: 0; min-height: 100vh; }
a { color: var(--brand); }
.topbar {
    min-height: 68px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10;
}
.brand { display: inline-flex; gap: 10px; align-items: center; text-decoration: none; color: var(--ink); font-size: 20px; font-weight: 800; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: var(--brand); color: white; font-size: 14px; }
.main-nav { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.main-nav a { text-decoration: none; color: var(--ink); padding: 10px 12px; border-radius: 10px; font-weight: 650; }
.main-nav a:hover { background: var(--accent); color: var(--brand-dark); }
.menu-button { display: none; border: 0; background: transparent; font-size: 26px; }
.page-shell { width: min(1180px, calc(100% - 32px)); margin: 32px auto; }
.page-heading { margin-bottom: 24px; }
.page-heading h1 { margin: 0; font-size: clamp(28px, 5vw, 44px); letter-spacing: -.04em; }
.page-heading p { color: var(--muted); margin: 8px 0 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.card h2, .card h3 { margin-top: 0; }
.narrow { max-width: 680px; margin-inline: auto; }
.card-grid, .settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.metric-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.metric-card span { display: block; color: var(--muted); font-weight: 650; }
.metric-card strong { display: block; font-size: 36px; margin-top: 8px; }
label { display: block; font-weight: 700; font-size: 14px; }
input, select, textarea {
    width: 100%; margin-top: 7px; padding: 12px 13px; border: 1px solid #cfd7e6; border-radius: 10px;
    background: white; color: var(--ink); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(90,79,207,.16); border-color: var(--brand); }
form > label { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.button {
    display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 10px;
    padding: 12px 16px; background: var(--brand); color: white; text-decoration: none; font-weight: 750; cursor: pointer;
}
.button:hover { background: var(--brand-dark); }
.button.secondary { background: var(--accent); color: var(--brand-dark); }
.button.small { padding: 9px 12px; font-size: 14px; }
.full-button { width: 100%; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.alert { padding: 14px 16px; border-radius: 11px; margin-bottom: 18px; font-weight: 650; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.section-title { margin: 32px 0 14px; }
.setting-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.setting-card p { color: var(--muted); }
.setting-card code { color: var(--muted); font-size: 12px; }
.inline-setting { min-width: 210px; display: flex; gap: 8px; align-items: end; }
.inline-setting input, .inline-setting select { margin: 0; }
.split-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
.stacked-links { display: grid; gap: 5px; }
.stacked-links a { display: flex; justify-content: space-between; text-decoration: none; color: var(--ink); padding: 10px 12px; border-radius: 9px; }
.stacked-links a.active, .stacked-links a:hover { background: var(--accent); color: var(--brand-dark); }
.compact-form { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 20px; }
.compact-form input { margin-bottom: 10px; }
.inline-add { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-top: 18px; }
.inline-add input { margin: 0; }
.responsive-table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.link-button { border: 0; background: none; color: var(--brand); cursor: pointer; font-weight: 750; padding: 0; }
.permission-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 18px; }
.check-card { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-weight: 500; }
.check-card input { width: auto; margin: 3px 0 0; }
.check-card small { display: block; color: var(--muted); margin-top: 3px; }
.footer { text-align: center; color: var(--muted); padding: 28px; font-size: 13px; }

@media (max-width: 850px) {
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .card-grid, .settings-grid { grid-template-columns: 1fr; }
    .split-layout { grid-template-columns: 1fr; }
    .menu-button { display: block; }
    .main-nav {
        display: none; position: absolute; left: 0; right: 0; top: 68px; background: white;
        padding: 14px; border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
    }
    .nav-open .main-nav { display: grid; }
}
@media (max-width: 600px) {
    .page-shell { width: min(100% - 20px, 1180px); margin-top: 20px; }
    .topbar { padding: 0 14px; }
    .card { padding: 18px; }
    .metric-grid, .form-grid, .permission-grid { grid-template-columns: 1fr; }
    .metric-card strong { font-size: 30px; }
    .setting-card { display: block; }
    .inline-setting { min-width: 0; margin-top: 16px; }
    .inline-add { grid-template-columns: 1fr; }
    .responsive-table thead { display: none; }
    .responsive-table tr { display: block; border-bottom: 1px solid var(--line); padding: 10px 0; }
    .responsive-table td { display: flex; justify-content: space-between; gap: 18px; border: 0; padding: 7px 0; }
    .responsive-table td::before { content: attr(data-label); color: var(--muted); font-weight: 700; }
}


/* ===== Phase 1 Client Management ===== */

.toolbar{
display:flex;
justify-content:space-between;
align-items:center;
gap:16px;
margin-bottom:20px;
flex-wrap:wrap;
}

.search-form{
display:flex;
gap:10px;
flex-wrap:wrap;
align-items:center;
}

.search-form input[type=search]{
min-width:280px;
}

.record-link{
display:flex;
flex-direction:column;
text-decoration:none;
color:inherit;
}

.record-link small{
color:var(--muted);
margin-top:4px;
}

.status-pill{
display:inline-block;
padding:4px 10px;
border-radius:999px;
font-size:12px;
font-weight:700;
}

.status-active{background:#e8f7ef;color:#176b45;}
.status-prospect{background:#fff7d6;color:#8a6a00;}
.status-inactive{background:#f1f3f5;color:#555;}
.status-archived{background:#fff0f0;color:#9b2c2c;}

.record-header{
display:flex;
justify-content:space-between;
align-items:flex-start;
gap:20px;
margin-bottom:18px;
flex-wrap:wrap;
}

.record-kicker{
font-size:12px;
text-transform:uppercase;
letter-spacing:.08em;
color:var(--muted);
font-weight:700;
margin-bottom:6px;
}

.tabs{
display:flex;
gap:8px;
margin:18px 0;
flex-wrap:wrap;
}

.tabs a{
padding:10px 14px;
border-radius:10px;
text-decoration:none;
color:var(--ink);
background:#fff;
border:1px solid var(--line);
}

.tabs a.active{
background:var(--brand);
color:#fff;
}

.detail-grid{
display:grid;
grid-template-columns:repeat(2,minmax(0,1fr));
gap:18px;
}

.full-span{grid-column:1/-1;}

.detail-list div{margin-bottom:14px;}
.detail-list dt{font-weight:700;color:var(--muted);}
.detail-list dd{margin:4px 0 0;}

.preline{white-space:pre-wrap;}

.note-stack{display:grid;gap:14px;}
.note-item{border:1px solid var(--line);border-radius:10px;padding:16px;}
.note-item.pinned{border-left:5px solid var(--brand);}

.timeline article{
padding:12px 0;
border-bottom:1px solid var(--line);
}

.empty-state{
text-align:center;
padding:40px;
}

@media(max-width:700px){
.detail-grid{grid-template-columns:1fr;}
.record-header{display:block;}
.search-form input[type=search]{min-width:0;width:100%;}
}