:root {
    --purple: #4b1e5a;
    --purple-2: #6d2c78;
    --purple-soft: #f2eaf4;
    --gold: #e4a245;
    --gold-soft: #fff4df;
    --neutral: #f9f1ed;
    --ink: #262028;
    --muted: #726c74;
    --border: #e7e0e8;
    --surface: #ffffff;
    --success: #287a54;
    --danger: #b8404d;
    --shadow: 0 14px 38px rgba(55, 27, 61, .08);
    --minute-height: 1.4px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: #fbfafb;
}
* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-height: 100vh; font-size: 16px; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid rgba(228, 162, 69, .45); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
code { background: var(--purple-soft); color: var(--purple); border-radius: 6px; padding: .15rem .4rem; }

.auth-page { display: grid; place-items: center; padding: 28px; background: radial-gradient(circle at 10% 0, #f4e7f5, transparent 36%), linear-gradient(135deg, #fff 0%, #fbf6f1 100%); }
.auth-card, .install-card { width: min(100%, 470px); background: rgba(255,255,255,.96); border: 1px solid var(--border); border-radius: 24px; padding: clamp(28px, 6vw, 48px); box-shadow: var(--shadow); }
.install-card { width: min(100%, 560px); }
.auth-logo { display: block; width: min(100%, 320px); height: auto; margin: 0 auto 32px; }
.auth-card h1, .install-card h1 { margin: 0 0 8px; color: var(--purple); font-size: 2rem; }
.form-stack { display: grid; gap: 18px; margin-top: 24px; }
label { display: grid; gap: 7px; color: #4d4650; font-size: .9rem; font-weight: 650; }
input, select, textarea { width: 100%; border: 1px solid #d9d1dc; border-radius: 10px; background: #fff; color: var(--ink); padding: 11px 12px; min-height: 44px; }
textarea { resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #c3b2c8; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 550; }
.check input { width: 18px; min-height: 18px; accent-color: var(--purple); }
.notice { margin: 20px 0; border-radius: 10px; background: #f4f1f5; padding: 13px 15px; line-height: 1.45; }
.notice.success { color: #165d3f; background: #e9f7f0; }
.notice.error { color: #8c2632; background: #fff0f1; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; border: 1px solid transparent; border-radius: 10px; padding: 9px 15px; text-decoration: none; font-weight: 700; font-size: .9rem; transition: transform .14s ease, box-shadow .14s ease, background .14s ease; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: white; background: linear-gradient(135deg, var(--purple), var(--purple-2)); box-shadow: 0 8px 20px rgba(75,30,90,.18); }
.button.primary:hover { box-shadow: 0 10px 24px rgba(75,30,90,.26); }
.button.subtle { background: white; border-color: var(--border); color: var(--purple); }
.button.danger { background: #fff1f2; border-color: #f0c8cd; color: var(--danger); }
.button.wide { width: 100%; }
.icon-button { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); color: var(--purple); background: white; font-size: 1.25rem; }

.app-shell { display: grid; grid-template-columns: 265px minmax(0, 1fr); background: #fbfafb; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; display: flex; flex-direction: column; width: 265px; background: #fff; border-right: 1px solid var(--border); }
.brand-panel { height: 108px; display: grid; place-items: center; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.sidebar-logo { display: block; max-width: 205px; max-height: 58px; }
.nav { padding: 18px 14px; overflow-y: auto; flex: 1; }
.nav-heading { margin: 18px 11px 7px; color: #9a909d; text-transform: uppercase; letter-spacing: .13em; font-size: .68rem; font-weight: 800; }
.nav-heading:first-child { margin-top: 2px; }
.nav-item { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; border-radius: 11px; padding: 11px 12px; background: transparent; color: #5d5560; font-weight: 650; text-align: left; }
.nav-item span { width: 20px; text-align: center; color: #8a758f; }
.nav-item em { margin-left: auto; color: #8d7e91; background: #f3eef4; border-radius: 999px; padding: 2px 7px; font-size: .66rem; font-style: normal; }
.nav-item:hover { background: #faf7fb; color: var(--purple); }
.nav-item.active { color: var(--purple); background: var(--purple-soft); }
.nav-item.active span { color: var(--purple); }
.sidebar-user { display: grid; grid-template-columns: 38px minmax(0,1fr) 28px; gap: 10px; align-items: center; padding: 16px; border-top: 1px solid var(--border); }
.sidebar-user strong, .sidebar-user small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user strong { font-size: .88rem; }
.sidebar-user small { margin-top: 2px; color: var(--muted); font-size: .72rem; }
.sidebar-user a { text-decoration: none; color: var(--muted); font-size: 1.2rem; }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--purple); color: white; font-weight: 800; }
.main { min-width: 0; grid-column: 2; padding: clamp(22px, 4vw, 48px); }
.mobile-header { display: none; }
.view { max-width: 1500px; margin: 0 auto; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-heading > div:first-child > span { color: var(--purple); text-transform: uppercase; letter-spacing: .15em; font-size: .72rem; font-weight: 850; }
.page-heading h1 { margin: 7px 0 6px; color: #301936; font-size: clamp(2rem, 4vw, 2.8rem); letter-spacing: -.045em; line-height: 1; }
.page-heading p { margin: 0; color: var(--muted); line-height: 1.5; }
.heading-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.heading-actions select { min-width: 190px; }
.panel { background: white; border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 5px 18px rgba(55,27,61,.035); }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 13px; margin-bottom: 20px; }
.stat { display: grid; gap: 5px; min-height: 112px; padding: 18px; background: white; border: 1px solid var(--border); border-radius: 14px; }
.stat small { color: var(--muted); font-weight: 700; }
.stat strong { color: var(--purple); font-size: 1.75rem; letter-spacing: -.04em; }
.stat span { color: #8a828c; font-size: .75rem; }
.welcome-panel { display: flex; align-items: center; gap: 38px; padding: clamp(24px, 5vw, 48px); overflow: hidden; background: linear-gradient(130deg, #fff 0%, #fcf6ee 100%); }
.welcome-panel img { width: 160px; height: 160px; object-fit: contain; }
.welcome-panel h2 { margin: 0 0 10px; color: var(--purple); font-size: 1.6rem; }
.welcome-panel p { max-width: 700px; color: var(--muted); line-height: 1.65; }
.calendar-toolbar { display: grid; grid-template-columns: 1fr auto auto 1fr; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px 16px 0 0; }
.calendar-toolbar > div:first-child { display: flex; gap: 7px; }
.calendar-toolbar h2 { margin: 0; font-size: 1.12rem; text-align: center; }
.legend { display: flex; justify-content: flex-end; gap: 13px; color: var(--muted); font-size: .76rem; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; }
.view-toggle { display: flex; gap: 4px; padding: 3px; border-radius: 11px; background: #f4eff5; }
.view-toggle .button { min-height: 34px; padding: 5px 11px; border: 0; background: transparent; }
.view-toggle .button.active { background: white; box-shadow: 0 2px 8px rgba(55,27,61,.1); }
.requested-dot { background: var(--gold); }
.override-dot { background: var(--danger); }
.calendar-wrap { min-height: 580px; overflow: hidden; border-radius: 0 0 16px 16px; }
.calendar-scroll { width: 100%; overflow: auto; max-height: calc(100vh - 280px); }
.calendar-grid { display: grid; grid-template-columns: 76px repeat(var(--provider-count), minmax(220px, 1fr)); min-width: calc(76px + var(--provider-count) * 220px); }
.calendar-corner, .provider-header { position: sticky; top: 0; z-index: 12; height: 66px; background: rgba(255,255,255,.96); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.calendar-corner { left: 0; z-index: 15; border-right: 1px solid var(--border); }
.provider-header { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-right: 1px solid var(--border); }
.provider-header i { flex: 0 0 auto; width: 10px; height: 38px; border-radius: 99px; }
.provider-header strong, .provider-header small { display: block; }
.provider-header strong { color: #3a273f; font-size: .9rem; }
.provider-header small { margin-top: 3px; color: var(--muted); font-size: .68rem; }
.time-axis, .provider-column { position: relative; height: calc(720 * var(--minute-height)); }
.time-axis { position: sticky; left: 0; z-index: 8; background: white; border-right: 1px solid var(--border); }
.time-label { position: absolute; right: 10px; transform: translateY(-50%); color: #948b96; font-size: .67rem; }
.provider-column { border-right: 1px solid var(--border); background: repeating-linear-gradient(to bottom, #fff 0, #fff calc(42px - 1px), #eee9ef calc(42px - 1px), #eee9ef 42px); }
.provider-column.drag-over { background-color: #faf3fc; box-shadow: inset 0 0 0 2px rgba(75,30,90,.18); }
.current-time { position: absolute; left: 0; right: 0; z-index: 5; height: 2px; background: #dc4e5c; pointer-events: none; }
.current-time::before { content: ''; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; background: #dc4e5c; border-radius: 50%; }
.appointment-card { position: absolute; left: 6px; right: 6px; z-index: 4; overflow: hidden; border: 1px solid color-mix(in srgb, var(--event-color) 34%, white); border-left: 5px solid var(--event-color); border-radius: 9px; padding: 7px 9px; background: color-mix(in srgb, var(--event-color) 11%, white); box-shadow: 0 4px 12px rgba(53,30,59,.08); color: #332637; cursor: grab; user-select: none; }
.appointment-card:active { cursor: grabbing; }
.appointment-card.dragging { opacity: .45; }
.appointment-card strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .78rem; }
.appointment-card small { display: block; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #695c6d; font-size: .67rem; }
.appointment-card.status-arrived { box-shadow: inset 0 0 0 2px rgba(40,122,84,.24), 0 4px 12px rgba(53,30,59,.08); }
.appointment-card.status-in_service { box-shadow: inset 0 0 0 2px rgba(79,115,150,.32), 0 4px 12px rgba(53,30,59,.08); }
.appointment-card.status-completed { opacity: .68; }
.appointment-card.status-no_show { filter: grayscale(.7); opacity: .72; }
.resize-handle { position: absolute; left: 10px; right: 10px; bottom: 1px; height: 7px; cursor: ns-resize; border-bottom: 2px solid rgba(75,30,90,.35); }
.appointment-flags { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; }
.appointment-flags i { width: 7px; height: 7px; border-radius: 50%; }
.loading { display: grid; place-items: center; min-height: 180px; color: var(--muted); }
.table-panel { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: #756d77; background: #fcfbfc; font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; }
td { font-size: .9rem; }
tr:last-child td { border-bottom: 0; }
.person { display: flex; align-items: center; gap: 10px; }
.person > i { width: 8px; height: 34px; border-radius: 99px; }
.person strong, .person small { display: block; }
.person small { color: var(--muted); font-size: .74rem; margin-top: 2px; }
.badge { display: inline-flex; border-radius: 999px; padding: 4px 8px; background: #f1edf2; color: #695e6d; font-size: .7rem; font-weight: 750; }
.badge.success { background: #e8f6ee; color: var(--success); }
.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.location-card { display: flex; align-items: center; gap: 14px; padding: 20px; }
.location-card > span:first-child { font-size: 1.6rem; color: var(--gold); }
.location-card div { flex: 1; }
.location-card h2, .role-card h2, .csv-help h2 { margin: 0 0 5px; color: var(--purple); font-size: 1.05rem; }
.location-card p, .role-card p, .csv-help p { margin: 0; color: var(--muted); line-height: 1.5; font-size: .88rem; }
.role-card { padding: 22px; }
.empty-state { padding: 60px 24px; text-align: center; }
.empty-state img { width: 100px; height: 100px; object-fit: contain; }
.empty-state h2 { color: var(--purple); }
.empty-state p { max-width: 620px; margin: 0 auto; color: var(--muted); }
.csv-help { margin-top: 16px; padding: 20px; }
.csv-help code { display: inline-block; margin: 7px 0; }
.report-filters { display: flex; align-items: end; gap: 12px; margin-bottom: 16px; padding: 16px; }
.search-bar { display: flex; gap: 10px; margin-bottom: 16px; padding: 14px; }
.search-bar input { flex: 1; }
.management-grid { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 14px; align-items: start; }
.management-panel { padding: 20px; }
.management-panel h2 { margin: 0 0 16px; color: var(--purple); font-size: 1.12rem; }
.form-stack.compact { gap: 10px; margin-top: 12px; }
.availability-week { display: grid; gap: 8px; margin: 16px 0; }
.availability-row { display: grid; grid-template-columns: 28px 70px 1fr 1fr; gap: 8px; align-items: center; }
.availability-row input[type=checkbox] { width: 18px; min-height: 18px; accent-color: var(--purple); }
.availability-row strong { font-size: .78rem; }
.resource-list, .exception-list { display: grid; gap: 8px; margin: 14px 0; }
.resource-item, .exception-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 11px; }
.resource-item strong, .resource-item small, .exception-item strong, .exception-item small { display: block; }
.resource-item small, .exception-item small { margin-top: 2px; color: var(--muted); font-size: .7rem; }
.week-board { padding: 10px; }
.week-day { border-bottom: 1px solid var(--border); padding: 12px; }
.week-day:last-child { border-bottom: 0; }
.week-day h3 { margin: 0 0 9px; color: var(--purple); font-size: .95rem; }
.week-entry { display: grid; grid-template-columns: 78px 1fr auto; gap: 10px; align-items: center; border-left: 4px solid var(--event-color); padding: 8px 10px; margin: 5px 0; border-radius: 7px; background: #fbf8fc; cursor: pointer; }
.week-entry small { color: var(--muted); }
.provider-checks { border: 1px solid var(--border); border-radius: 10px; padding: 13px; }
.provider-checks legend { color: var(--purple); font-weight: 750; font-size: .85rem; }
.provider-checks > div { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.client-alert { max-width: 280px; color: var(--danger); font-size: .75rem; }
.status-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; }
.status-actions .button { min-height: 34px; padding: 5px 9px; font-size: .75rem; }
.history-list { margin-top: 14px; border-top: 1px solid var(--border); }
.history-item { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: .8rem; }
.audit-list { overflow: hidden; }
.audit-item { display: grid; grid-template-columns: 12px minmax(0,1fr) auto auto; gap: 13px; align-items: start; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.audit-item:last-child { border-bottom: 0; }
.audit-item > i { width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: var(--gold); }
.audit-item strong, .audit-item small { display: block; }
.audit-item small { margin-top: 3px; color: var(--muted); }
.audit-item time { color: var(--muted); font-size: .75rem; white-space: nowrap; }

.dialog { width: min(94vw, 700px); max-height: 92vh; border: 0; border-radius: 18px; padding: 0; box-shadow: 0 30px 90px rgba(39,20,44,.28); }
.dialog::backdrop { background: rgba(28,14,32,.53); backdrop-filter: blur(3px); }
.dialog header { display: flex; justify-content: space-between; align-items: start; padding: 22px 24px; border-bottom: 1px solid var(--border); }
.dialog header span { color: var(--purple); text-transform: uppercase; letter-spacing: .13em; font-size: .68rem; font-weight: 800; }
.dialog header h2 { margin: 4px 0 0; color: #351c3b; font-size: 1.45rem; }
.dialog-close { border: 0; background: transparent; color: var(--muted); font-size: 1.8rem; }
.dialog-body { padding: 22px 24px; overflow-y: auto; max-height: 65vh; }
.dialog footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.span-2 { grid-column: span 2; }
.details-dialog { width: min(94vw, 560px); }
.entry-details { padding: 24px; }
.entry-details h2 { margin: 0; color: var(--purple); }
.entry-details .entry-time { color: var(--muted); margin: 7px 0 20px; }
.detail-grid { display: grid; grid-template-columns: 130px 1fr; gap: 11px; margin-bottom: 22px; font-size: .88rem; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; font-weight: 650; }
.detail-actions { display: flex; justify-content: flex-end; gap: 10px; }
.quick-move { margin: 18px 0; border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: #fcfafc; }
.quick-move h3 { margin: 0 0 12px; color: var(--purple); font-size: .95rem; }
.quick-move > div { display: grid; grid-template-columns: 1fr 1fr 1.35fr; gap: 9px; margin-bottom: 10px; }
.quick-move label { font-size: .75rem; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 24px; transform: translate(-50%, 30px); min-width: 260px; max-width: min(90vw, 520px); padding: 13px 17px; border-radius: 11px; background: #302634; color: white; box-shadow: 0 16px 40px rgba(0,0,0,.22); opacity: 0; pointer-events: none; transition: .22s ease; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.error { background: #9a3240; }

@media (max-width: 1050px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .card-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .management-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar { transform: translateX(-102%); transition: transform .2s ease; box-shadow: 20px 0 50px rgba(33,18,37,.18); }
    .sidebar.open { transform: translateX(0); }
    .main { padding: 18px 14px 34px; }
    .mobile-header { display: flex; align-items: center; gap: 14px; margin: -4px 0 24px; }
    .mobile-header img { width: 165px; max-height: 46px; object-fit: contain; }
    .page-heading { display: block; }
    .heading-actions { margin-top: 18px; }
    .heading-actions > * { flex: 1; }
    .page-heading h1 { font-size: 2rem; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .stat { min-height: 100px; padding: 14px; }
    .calendar-toolbar { grid-template-columns: auto 1fr auto; }
    .calendar-toolbar h2 { text-align: right; font-size: .95rem; }
    .legend { grid-column: 1 / -1; justify-content: flex-start; }
    .calendar-scroll { max-height: calc(100vh - 300px); }
    .calendar-grid { grid-template-columns: 64px repeat(var(--provider-count), minmax(200px, 1fr)); min-width: calc(64px + var(--provider-count) * 200px); }
    .calendar-corner { width: 64px; }
    .welcome-panel { align-items: flex-start; gap: 16px; }
    .welcome-panel img { width: 82px; height: 82px; }
    .card-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: 1; }
    .report-filters { display: grid; grid-template-columns: 1fr 1fr; }
    .quick-move > div { grid-template-columns: 1fr; }
    .report-filters .button { grid-column: 1 / -1; }
    th, td { padding: 12px; }
    .management-grid { grid-template-columns: 1fr; }
}
@media (max-width: 430px) {
    .stat-grid { grid-template-columns: 1fr; }
    .schedule-stats { grid-template-columns: 1fr 1fr; }
    .schedule-stats .stat { min-height: 88px; }
    .welcome-panel { display: block; }
    .welcome-panel img { float: right; margin-left: 10px; }
}
