:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-soft: #f8fafb;
    --text: #17212b;
    --muted: #66737f;
    --line: #dce2e7;
    --primary: #246bfe;
    --primary-dark: #1454d7;
    --success: #147d5b;
    --success-soft: #e8f7f1;
    --danger: #b42318;
    --danger-soft: #fff0ee;
    --warning: #9a6700;
    --warning-soft: #fff6d8;
    --radius: 14px;
    --shadow: 0 8px 30px rgba(31, 45, 61, .07);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .35rem; font-size: clamp(1.75rem, 3vw, 2.35rem); line-height: 1.15; }
h2 { margin-bottom: .75rem; font-size: 1.15rem; }
h3 { margin-top: 1.5rem; margin-bottom: .4rem; font-size: .95rem; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 68px;
    padding: 0 max(24px, calc((100vw - 1240px) / 2));
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
}
.brand { display: inline-flex; align-items: center; gap: .65rem; color: var(--text); font-weight: 750; }
.brand:hover { color: var(--text); }
.brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--primary);
    color: white;
    font-size: 1.15rem;
}
.main-nav { display: flex; align-items: center; gap: .25rem; }
.main-nav > a, .nav-button {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: .55rem .7rem;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: #465461;
}
.main-nav > a:hover, .nav-button:hover { background: var(--surface-soft); color: var(--text); }
.main-nav form { margin: 0; }
.nav-toggle { display: none; border: 0; background: transparent; font-size: 1.5rem; }

.page-shell { width: min(1240px, calc(100% - 40px)); margin: 0 auto; padding: 36px 0 80px; }
.auth-shell { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(circle at top left, #eaf0ff, var(--bg) 45%); }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.heading-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.centered { justify-content: center; }
.eyebrow { margin-bottom: .35rem; color: var(--primary); font-size: .75rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); }
.back-link { display: inline-block; margin-bottom: .8rem; color: var(--muted); }

.panel, .login-card, .client-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.panel { padding: 24px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-heading h2 { margin: 0; }
.login-card { width: min(430px, 100%); padding: 38px; }
.login-brand { margin-bottom: 35px; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: .62rem 1rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-weight: 700;
}
.button:hover { border-color: #b8c1c9; color: var(--text); }
.button-primary { border-color: var(--primary); background: var(--primary); color: white; }
.button-primary:hover { border-color: var(--primary-dark); background: var(--primary-dark); color: white; }
.button-success { border-color: var(--success); background: var(--success); color: white; }
.button-success:hover { color: white; }
.button-danger-ghost { color: var(--danger); }
.button-ghost { border-color: transparent; background: transparent; }
.button-small { min-height: 34px; padding: .35rem .7rem; font-size: .86rem; }
.button-wide { width: 100%; }

.form-stack { display: grid; gap: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.span-2 { grid-column: span 2; }
label, .field-label { display: grid; gap: 7px; color: #34414d; font-size: .9rem; font-weight: 700; }
input, select, textarea {
    width: 100%;
    min-height: 44px;
    padding: .65rem .78rem;
    border: 1px solid #cbd3da;
    border-radius: 9px;
    outline: none;
    background: white;
    color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(36, 107, 254, .12); }
label small { color: var(--muted); font-weight: 400; }
fieldset { padding: 20px; border: 1px solid var(--line); border-radius: 12px; }
legend { padding: 0 8px; font-weight: 750; }
.required { color: var(--danger); }
.file-field { padding: 16px; border: 1px dashed #b8c4cf; border-radius: 10px; background: var(--surface-soft); }
.file-field input { min-height: auto; padding: 0; border: 0; background: transparent; }
.form-actions { display: flex; align-items: center; gap: 10px; }
.push-right { margin-left: auto; }

.flash-stack { display: grid; gap: 8px; margin-bottom: 20px; }
.flash { padding: 12px 15px; border: 1px solid; border-radius: 10px; }
.flash-success { border-color: #aadcc8; background: var(--success-soft); color: #0b6548; }
.flash-error { border-color: #f3b8b2; background: var(--danger-soft); color: var(--danger); }

.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 24px; }
.stat-card { display: grid; gap: 5px; padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.stat-card:hover { color: var(--text); border-color: #b9c7d3; }
.stat-card-alert .stat-value { color: var(--danger); }
.stat-value { overflow-wrap: anywhere; font-size: 1.65rem; font-weight: 800; }
.stat-label { color: var(--muted); font-size: .9rem; }
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.item-list { display: grid; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); color: var(--text); }
.list-item:last-child { border-bottom: 0; }
.list-item span:last-child { display: grid; }
.list-item small { color: var(--muted); }
.item-icon { display: grid; flex: 0 0 38px; height: 38px; place-items: center; border-radius: 50%; background: #edf3ff; color: var(--primary); }
.event-dot { display: inline-block; flex: 0 0 10px; width: 10px; height: 10px; border-radius: 50%; background: #8895a2; }
.event-call { background: #326bff; }
.event-meeting { background: #7e57c2; }
.event-task { background: #f59e0b; }
.event-documents { background: #16a085; }

.filter-bar { display: flex; align-items: end; gap: 10px; margin-bottom: 20px; }
.filter-bar .grow { flex: 1; }
.filter-bar input { min-width: 260px; }
.client-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.client-card { padding: 16px; }
.card-link { display: flex; align-items: center; gap: 14px; color: var(--text); }
.card-link:hover { color: var(--text); }
.client-main { display: grid; flex: 1; min-width: 0; }
.client-main small { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.avatar { display: grid; flex: 0 0 44px; width: 44px; height: 44px; place-items: center; border-radius: 13px; background: #e8efff; color: var(--primary); font-weight: 800; }
.avatar-large { width: 64px; height: 64px; font-size: 1.4rem; }
.tag { display: inline-flex; width: fit-content; padding: .24rem .52rem; border-radius: 999px; background: #edf3ff; color: #2258c9; font-size: .75rem; font-weight: 750; }
.title-with-avatar { display: flex; align-items: center; gap: 16px; }
.title-with-avatar h1 { margin-bottom: .5rem; }
.detail-grid { display: grid; grid-template-columns: minmax(250px, 330px) 1fr; align-items: start; gap: 22px; }
.contact-panel { position: sticky; top: 92px; }
.definition-list { display: grid; grid-template-columns: 88px 1fr; gap: 9px 12px; margin: 0; overflow-wrap: anywhere; }
.definition-list dt { color: var(--muted); font-size: .82rem; }
.definition-list dd { margin: 0; }
.pre-wrap { white-space: pre-wrap; }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin: 30px 0 15px; }
.section-heading h2 { margin: 0; }
.timeline { display: grid; }
.timeline-item { display: grid; grid-template-columns: 76px 1fr; gap: 15px; }
.timeline-date { padding-top: 17px; color: var(--primary); font-family: Consolas, monospace; font-weight: 800; }
.timeline-card { position: relative; padding: 17px 18px 18px; border-left: 2px solid #cfdaee; }
.timeline-card::before { content: ""; position: absolute; top: 22px; left: -6px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.timeline-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 9px; font-size: .78rem; }
.timeline-card p { margin-bottom: 12px; }
.inline-actions { display: flex; gap: 12px; font-size: .82rem; }
.inline-actions form { margin: 0; }
.link-danger { padding: 0; border: 0; background: transparent; color: var(--danger); }
.status { display: inline-flex; padding: .22rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 750; }
.status-warning { background: var(--warning-soft); color: var(--warning); }
.status-success { background: var(--success-soft); color: var(--success); }
.status-neutral { background: #edf0f2; color: #55626d; }
.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.attachment { display: inline-flex; padding: .4rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); font-size: .83rem; }
.attachment-row { display: flex; align-items: center; gap: 8px; }

.result-card { width: min(720px, 100%); margin: 6vh auto; text-align: center; }
.result-icon { display: grid; width: 58px; height: 58px; margin: 0 auto 18px; place-items: center; border-radius: 50%; background: var(--success-soft); color: var(--success); font-size: 1.7rem; font-weight: 800; }
.message-preview { margin: 22px 0; padding: 18px; border-radius: 10px; background: var(--surface-soft); text-align: left; white-space: pre-wrap; }
.notice { display: inline-flex; padding: .7rem; color: var(--warning); }

.calendar-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 16px; }
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.segmented a { padding: .46rem .8rem; border-radius: 7px; color: var(--muted); }
.segmented a.active { background: var(--primary); color: white; }
.calendar-navigation { display: flex; align-items: center; gap: 9px; }
.icon-button { display: grid; width: 36px; height: 36px; place-items: center; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--text); }
.calendar-grid { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.calendar-weekdays, .calendar-row { display: grid; grid-template-columns: repeat(7, minmax(110px, 1fr)); }
.calendar-weekdays { background: var(--surface-soft); color: var(--muted); font-size: .75rem; font-weight: 800; text-transform: uppercase; }
.calendar-weekdays div { padding: 10px; text-align: center; }
.calendar-day { min-height: 130px; padding: 8px; border-top: 1px solid var(--line); border-right: 1px solid var(--line); }
.calendar-week .calendar-day { min-height: 360px; }
.calendar-day:last-child { border-right: 0; }
.calendar-day.outside { background: #fafbfc; opacity: .55; }
.calendar-day.is-today { box-shadow: inset 0 0 0 2px var(--primary); }
.calendar-day-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; font-weight: 750; }
.quick-add { opacity: 0; }
.calendar-day:hover .quick-add { opacity: 1; }
.day-events { display: grid; gap: 4px; }
.calendar-event { display: grid; padding: 5px 6px; border-radius: 6px; color: #25313c; font-size: .73rem; line-height: 1.25; }
.calendar-event:hover { color: #111; }
.calendar-event time { font-weight: 800; }
.event-bg-call { background: #e7efff; }
.event-bg-meeting { background: #eee8fb; }
.event-bg-task { background: #fff1d6; }
.event-bg-documents { background: #def5ef; }
.event-bg-other { background: #edf0f2; }
.agenda-list { display: grid; }
.agenda-item { display: grid; grid-template-columns: 65px 12px 1fr; align-items: center; gap: 12px; padding: 16px 0; border-bottom: 1px solid var(--line); color: var(--text); }
.agenda-item:last-child { border: 0; }
.agenda-item > span:last-child { display: grid; }
.agenda-item small { color: var(--muted); }

.reminder-list { display: grid; gap: 12px; }
.reminder-card { display: grid; grid-template-columns: 48px 1fr auto; gap: 18px; align-items: start; }
.reminder-card.is-overdue { border-left: 4px solid var(--danger); }
.reminder-icon { display: grid; width: 46px; height: 46px; place-items: center; border-radius: 50%; background: #edf3ff; color: var(--primary); }
.reminder-content h2 { margin: 0 0 5px; }
.reminder-content p { margin-bottom: 5px; }
.reminder-actions { display: flex; gap: 8px; }
.reminder-actions form { margin: 0; }
.settings-form { max-width: 680px; }
.meeting-fields[hidden] { display: none; }
.empty-state { padding: 35px 20px; color: var(--muted); text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 900px) {
    .nav-toggle { display: block; }
    .main-nav { display: none; position: absolute; top: 68px; right: 16px; left: 16px; flex-direction: column; align-items: stretch; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
    .main-nav.is-open { display: flex; }
    .main-nav > a, .nav-button { width: 100%; }
    .stat-grid { grid-template-columns: 1fr; }
    .dashboard-grid, .detail-grid { grid-template-columns: 1fr; }
    .contact-panel { position: static; }
    .calendar-grid { overflow-x: auto; }
    .calendar-weekdays, .calendar-row { min-width: 780px; }
}

@media (max-width: 650px) {
    .page-shell { width: min(100% - 24px, 1240px); padding-top: 24px; }
    .page-heading, .calendar-toolbar { flex-direction: column; align-items: stretch; }
    .heading-actions, .calendar-navigation { justify-content: flex-start; }
    .form-grid, .client-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar input { min-width: 0; }
    .timeline-item { grid-template-columns: 58px 1fr; gap: 5px; }
    .reminder-card { grid-template-columns: 40px 1fr; }
    .reminder-actions { grid-column: 2; flex-wrap: wrap; }
    .form-actions { flex-wrap: wrap; }
    .push-right { margin-left: 0; }
}
