:root {
    --bg: #f6f7fb;
    --surface: #ffffff;
    --surface-muted: #eef1f7;
    --border: #dfe3ec;
    --text: #1d2433;
    --muted: #697386;
    --accent: #4f46e5;
    --accent-soft: #eef0ff;
    --danger: #dc2626;
    --success: #0f9d58;
    --hour-height: 64px;
    --radius: 12px;
    --shadow: 0 12px 32px rgba(29, 36, 51, .12);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    font-size: 14px;
}

button, input, select { font: inherit; }

.hidden { display: none !important; }

.muted { color: var(--muted); margin: 4px 0 0; }

.topbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 14px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
    flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
}

.brand-sub { display: block; color: var(--muted); font-size: 12px; }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.toolbar select,
.toolbar input[type="date"] {
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 8px 10px;
    background: var(--surface);
    color: var(--text);
}

.date-nav { display: flex; align-items: center; gap: 6px; }

.icon-button {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    border: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
    background: var(--surface);
    font-size: 18px;
}

.view-toggle {
    display: flex;
    border: 1px solid var(--border);
    border-radius: 9px;
    overflow: hidden;
}

.view-toggle button {
    border: 0;
    background: var(--surface);
    padding: 8px 14px;
    cursor: pointer;
    color: var(--muted);
}

.view-toggle button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.topbar-user { margin-left: auto; display: flex; align-items: center; gap: 12px; color: var(--muted); }

.link-button {
    border: 0;
    background: none;
    color: var(--accent);
    cursor: pointer;
    padding: 0;
}

.workspace { padding: 24px; max-width: 1500px; margin: 0 auto; }

.workspace-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.workspace-head h1 { margin: 0; font-size: 22px; }

.legend { display: flex; gap: 16px; align-items: center; color: var(--muted); font-size: 12px; flex-wrap: wrap; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.dot-free { background: #c7f0da; }
.dot-busy { background: var(--accent); }

.hint { color: #9aa3b5; }

.schedule-app {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.loading { padding: 32px; text-align: center; color: var(--muted); }

.board { min-width: 760px; }

.board-head,
.board-body {
    display: grid;
    grid-template-columns: 68px repeat(var(--staff-count, 1), minmax(180px, 1fr));
}

.board-head {
    position: sticky;
    top: 69px;
    z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.staff-head {
    padding: 12px 10px;
    border-left: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.staff-avatar {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex: none;
}

.board-body { position: relative; }

.time-gutter {
    position: relative;
    border-right: 1px solid var(--border);
    background: #fbfcfe;
}

.time-label {
    position: absolute;
    right: 8px;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 11px;
}

.staff-column {
    position: relative;
    border-left: 1px solid var(--border);
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0,
        transparent calc(var(--hour-height) - 1px),
        #eef1f7 calc(var(--hour-height) - 1px),
        #eef1f7 var(--hour-height)
    );
    cursor: crosshair;
}

.staff-column.drag-over { background-color: var(--accent-soft); }

.appointment {
    position: absolute;
    left: 4px;
    right: 4px;
    border-radius: 8px;
    padding: 6px 8px;
    background: var(--accent-soft);
    border-left: 4px solid var(--accent);
    color: var(--text);
    overflow: hidden;
    cursor: grab;
    box-shadow: 0 1px 2px rgba(29, 36, 51, .08);
    transition: box-shadow .15s ease, transform .15s ease;
}

.appointment:hover { box-shadow: 0 6px 18px rgba(29, 36, 51, .16); z-index: 3; }

.appointment.dragging { opacity: .45; }

.appointment .appointment-time { font-size: 11px; color: var(--muted); }

.appointment .appointment-title { font-weight: 600; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.appointment.status-hold { background: #fff7e6; border-left-color: #d97706; }
.appointment.status-pending { background: #eef7ff; border-left-color: #0284c7; }
.appointment.status-cancelled,
.appointment.status-completed,
.appointment.status-no_show { opacity: .55; border-left-color: #9aa3b5; }

.week-view { display: grid; grid-template-columns: repeat(7, minmax(150px, 1fr)); }

.week-day { border-left: 1px solid var(--border); min-height: 420px; padding: 10px; }
.week-day:first-child { border-left: 0; }
.week-day.today { background: #fbfcff; }

.week-day h3 { margin: 0 0 8px; font-size: 13px; }
.week-day .week-date { color: var(--muted); font-weight: 400; }

.week-card {
    border-left: 3px solid var(--accent);
    background: var(--accent-soft);
    border-radius: 7px;
    padding: 6px 8px;
    margin-bottom: 6px;
    font-size: 12px;
    cursor: pointer;
}

.week-card .week-time { color: var(--muted); font-size: 11px; }

.week-empty { color: #b3bac7; font-size: 12px; }

.modal {
    position: fixed;
    inset: 0;
    background: rgba(20, 26, 38, .45);
    display: grid;
    place-items: center;
    z-index: 50;
    padding: 20px;
}

.modal-card {
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow);
    width: min(520px, 100%);
    max-height: 86vh;
    overflow: auto;
    padding: 22px;
}

.modal-card h2 { margin: 0 0 4px; font-size: 18px; }
.modal-card .modal-sub { color: var(--muted); margin: 0 0 16px; }

.modal-close {
    float: right;
    border: 0;
    background: var(--surface-muted);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
}

.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }

.field select,
.field input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 9px 10px;
}

.slot-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 12px 0; }

.slot-button {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    padding: 8px 4px;
    cursor: pointer;
}

.slot-button:hover { border-color: var(--accent); color: var(--accent); }

.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

.primary-button,
.secondary-button,
.danger-button {
    border-radius: 9px;
    padding: 9px 14px;
    cursor: pointer;
    border: 1px solid transparent;
}

.primary-button { background: var(--accent); color: #fff; }
.secondary-button { background: var(--surface); border-color: var(--border); }
.danger-button { background: #fef2f2; color: var(--danger); border-color: #fecaca; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    background: #1f2937;
    color: #fff;
    padding: 10px 16px;
    border-radius: 9px;
    z-index: 60;
    box-shadow: var(--shadow);
}

.audit-list { max-height: 380px; overflow: auto; }

.audit-row {
    border-left: 3px solid var(--accent-soft);
    padding: 8px 10px;
    margin-bottom: 8px;
    background: #fbfcff;
    border-radius: 7px;
}

.audit-title { font-weight: 600; }
.audit-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.audit-change { font-size: 12px; color: #444c5c; margin-top: 4px; }

.toast.error { background: var(--danger); }

/* Auth */

.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }

.auth-card {
    width: min(400px, 100%);
    background: var(--surface);
    padding: 28px;
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.auth-card h1 { margin: 0; }
.auth-subtitle { color: var(--muted); margin: 4px 0 20px; }

.auth-form label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }

.auth-form input {
    display: block;
    width: 100%;
    margin-top: 5px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--text);
}

.form-errors { background: #fef2f2; color: var(--danger); border-radius: 9px; padding: 10px 12px; margin-bottom: 14px; }
.form-errors p { margin: 0 0 4px; }

.primary-button { width: 100%; }

@media (max-width: 900px) {
    .topbar { gap: 12px; }
    .topbar-user { margin-left: 0; }
    .workspace { padding: 14px; }
    .week-view { display: block; }
    .week-day { border-left: 0; border-top: 1px solid var(--border); min-height: auto; }
}
