:root {
    --bg: #f5f2ea;
    --bg-2: #ede9dd;
    --surface: #ffffff;
    --surface-2: #faf8f2;
    --border: rgba(15, 15, 15, 0.08);
    --border-strong: rgba(15, 15, 15, 0.18);
    --text: #0f0f0f;
    --muted: #6b6b6b;
    --muted-2: #9a9a9a;
    --accent: #0f0f0f;
    --accent-soft: rgba(15,15,15,0.06);
    --warn: #c2410c;
    --warn-bg: rgba(194, 65, 12, 0.08);
    --ok: #0f7d3a;
    --ok-bg: rgba(15, 125, 58, 0.08);
    --danger: #b91c1c;
    --danger-bg: rgba(185, 28, 28, 0.08);
    --easing: cubic-bezier(.8, 0, 0, .8);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    font-feature-settings: "ss01", "cv11";
}

code, .mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
button { font-family: inherit; }
a { color: inherit; }

.app {
    max-width: 1320px;
    margin: 0 auto;
    padding: 32px 28px 80px;
}

.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.025em;
}
.brand-mark {
    width: 32px; height: 32px;
    background: var(--accent);
    color: white;
    border-radius: 9px;
    display: grid; place-items: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 15px;
    font-weight: 500;
}
.brand .role-tag {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 3px 8px;
    border-radius: 6px;
    margin-left: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.user-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 13px;
}
.user-pill .dot { width: 10px; height: 10px; border-radius: 50%; }
.user-pill .name { font-weight: 500; }

.forfait-pill {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    padding: 7px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 13px;
}
.forfait-pill .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.forfait-pill .val { font-family: 'JetBrains Mono', monospace; font-weight: 500; }
.forfait-pill .val .sep { color: var(--muted-2); margin: 0 2px; }
.forfait-pill.is-met { border-color: var(--ok); background: var(--ok-bg); }
.forfait-pill.is-met .val { color: var(--ok); }
.forfait-pill.is-tight { border-color: var(--warn); background: var(--warn-bg); }
.forfait-pill.is-tight .val { color: var(--warn); }
.forfait-pill.is-blocked { border-color: var(--danger); background: var(--danger-bg); }
.forfait-pill.is-blocked .val { color: var(--danger); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 9px 14px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.35s var(--easing);
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: #2a2a2a; border-color: #2a2a2a; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--accent-soft); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: rgba(185, 28, 28, 0.3); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }

.btn-row { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.btn-row.between { justify-content: space-between; }

.flash {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 13px;
    border: 1px solid transparent;
    animation: slide-in 0.5s var(--easing);
}
.flash.error   { background: var(--danger-bg); color: var(--danger); border-color: rgba(185, 28, 28, 0.2); }
.flash.ok      { background: var(--ok-bg);     color: var(--ok);     border-color: rgba(15, 125, 58, 0.2); }
.flash.warn    { background: var(--warn-bg);   color: var(--warn);   border-color: rgba(194, 65, 12, 0.2); }
@keyframes slide-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.week-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding: 14px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    gap: 12px;
    flex-wrap: wrap;
}
.week-title {
    font-size: 20px;
    font-weight: 500;
    letter-spacing: -0.02em;
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}
.week-title .week-num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.week-nav-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.week-jump-form { display: inline-flex; margin: 0; }
.date-picker {
    appearance: none;
    -webkit-appearance: none;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    line-height: 1.3;
    cursor: pointer;
    transition: all 0.35s var(--easing);
    min-width: 140px;
    min-height: 30px;
}
.date-picker:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.date-picker:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15,15,15,0.06); }
.date-picker::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.45;
    transition: opacity 0.3s var(--easing);
}
.date-picker:hover::-webkit-calendar-picker-indicator { opacity: 0.85; }

.legend {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 16px;
    font-size: 12px;
    color: var(--muted);
    padding: 0 4px;
    align-items: center;
}
.legend .li { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; }
.sw.avail   { background: var(--surface); border: 1px solid var(--border-strong); }
.sw.book    { background: #7c5cff; }
.sw.block   { background: repeating-linear-gradient(45deg, rgba(15,15,15,0.08), rgba(15,15,15,0.08) 4px, rgba(15,15,15,0.16) 4px, rgba(15,15,15,0.16) 8px); }
.sw.pend    { background: var(--warn); }

.grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 10px;
}
@media (max-width: 1100px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 720px) {
    .grid {
        display: flex;
        gap: 10px;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        padding: 0 16px 14px;
        margin: 0 -16px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: var(--border-strong) transparent;
    }
    .grid::-webkit-scrollbar { height: 6px; }
    .grid::-webkit-scrollbar-track { background: transparent; }
    .grid::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
    .day {
        flex: 0 0 calc(86% - 5px);
        max-width: 320px;
        scroll-snap-align: start;
    }
    .day.today { scroll-snap-align: center; }
}

.day {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: all 0.4s var(--easing);
}
.day.today {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15,15,15,0.05);
}
.day.past { opacity: 0.78; }
.day.past .cell.available { opacity: 0.55; }
.day.weekend { background: var(--surface-2); }

.day-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 4px 6px 8px;
    border-bottom: 1px dashed var(--border);
}
.day-name {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.day-date {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--muted);
}
.day.today .day-name { color: var(--accent); }
.day.today .day-date { color: var(--accent); font-weight: 500; }

.cell {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    min-height: 84px;
    cursor: pointer;
    transition: all 0.4s var(--easing);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 6px;
    background: var(--surface);
    position: relative;
    overflow: hidden;
    text-align: left;
    width: 100%;
    color: inherit;
    font: inherit;
}
.cell:hover { transform: translateY(-1px); border-color: var(--border-strong); }
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.cell-half {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--muted);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 500;
}
.cell-content {
    font-size: 13px;
    font-weight: 500;
    line-height: 1.3;
    word-break: break-word;
}
.cell-meta {
    font-size: 11px;
    color: var(--muted);
    line-height: 1.3;
}

.cell.available { background: var(--surface); }
.cell.available .cell-content { color: var(--muted-2); }

.cell.booked {
    background: var(--client-color, #7c5cff);
    color: #fff;
    border-color: transparent;
}
.cell.booked .cell-half { color: rgba(255,255,255,0.7); }
.cell.booked .cell-meta { color: rgba(255,255,255,0.78); }

.cell.others {
    background: var(--bg-2);
    color: var(--muted);
}
.cell.others .cell-half { color: var(--muted-2); }

.cell.blocked {
    background:
        repeating-linear-gradient(45deg,
            rgba(15,15,15,0.04),
            rgba(15,15,15,0.04) 6px,
            rgba(15,15,15,0.10) 6px,
            rgba(15,15,15,0.10) 12px);
    color: var(--muted);
    border-color: var(--border);
}

.cell.has-pending::after {
    content: '';
    position: absolute;
    top: 9px; right: 9px;
    width: 7px; height: 7px;
    background: var(--warn);
    border-radius: 50%;
    box-shadow: 0 0 0 4px rgba(194, 65, 12, 0.18);
}

.cell.my-pending {
    border: 1px dashed var(--warn);
    background: var(--warn-bg);
}
.cell.my-pending .cell-content { color: var(--warn); font-weight: 500; }

.cell-tag {
    align-self: flex-start;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(15,15,15,0.06);
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    line-height: 1.6;
}
.cell.booked .cell-tag {
    background: rgba(255,255,255,0.18);
    color: rgba(255,255,255,0.92);
}
.cell.others.done {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}
.cell.others.done .cell-content { color: var(--text); }

.panel {
    margin-top: 28px;
    padding: 18px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
}
.panel h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}
.panel-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 10px;
    flex-wrap: wrap;
}
.req-list { display: flex; flex-direction: column; }
.req-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-top: 1px dashed var(--border);
    gap: 12px;
    flex-wrap: wrap;
}
.req-item:first-child { border-top: none; }
.req-info { display: flex; gap: 12px; align-items: center; flex: 1; min-width: 0; }
.req-info .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.req-info .body { min-width: 0; }
.req-info .when { font-weight: 500; font-size: 14px; }
.req-info .small { font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-word; }
.req-actions { display: flex; gap: 6px; flex-shrink: 0; }

.empty-state {
    text-align: center;
    color: var(--muted-2);
    font-size: 13px;
    padding: 16px 0;
}

.stats-list { display: flex; flex-direction: column; }
.stat-row {
    display: grid;
    grid-template-columns: minmax(140px, 200px) 1fr auto auto;
    align-items: center;
    gap: 14px;
    padding: 12px 0;
    border-top: 1px dashed var(--border);
}
.stat-row:first-child { border-top: none; }
@media (max-width: 800px) {
    .stat-row { grid-template-columns: 1fr; gap: 8px; }
}
.stat-name {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    font-size: 14px;
}
.stat-name .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.stat-segs {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
}
.stat-seg { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-weight: 500; }
.stat-seg.done     { background: var(--ok-bg);     color: var(--ok); }
.stat-seg.upcoming { background: var(--accent-soft); color: var(--text); }
.stat-seg.min      { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.stat-seg.min.is-met     { background: var(--ok-bg);    color: var(--ok);     border-color: rgba(15,125,58,0.2); }
.stat-seg.min.is-tight   { background: var(--warn-bg);  color: var(--warn);   border-color: rgba(194,65,12,0.2); }
.stat-seg.min.is-blocked { background: var(--danger-bg); color: var(--danger); border-color: rgba(185,28,28,0.2); }
.stat-sep { color: var(--muted-2); }
.stat-year { font-size: 12px; color: var(--muted); }
.stat-year .mono { font-size: 11px; }

.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15,15,15,0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s var(--easing);
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }

.modal {
    background: var(--surface);
    border-radius: 20px;
    padding: 24px 26px 22px;
    max-width: 460px;
    width: 100%;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    transform: translateY(12px) scale(0.97);
    opacity: 0;
    transition: transform 0.45s var(--easing), opacity 0.45s var(--easing);
    box-shadow: 0 30px 80px -20px rgba(15,15,15,0.25);
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); opacity: 1; }

.modal-large { max-width: 560px; }

.modal h3 {
    font-size: 18px;
    font-weight: 500;
    letter-spacing: -0.01em;
    margin-bottom: 4px;
}
.modal h4 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 10px;
    margin-top: 4px;
}
.modal .modal-subtitle {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 20px;
    font-family: 'JetBrains Mono', monospace;
}
.modal-section {
    padding: 16px 0;
    border-top: 1px dashed var(--border);
}
.modal-section:first-of-type { border-top: none; padding-top: 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
}
.field input,
.field select,
.field textarea {
    border: 1px solid var(--border);
    background: var(--surface);
    padding: 10px 12px;
    border-radius: 10px;
    font: inherit;
    font-size: 14px;
    color: var(--text);
    transition: border-color 0.3s var(--easing), box-shadow 0.3s var(--easing);
    width: 100%;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15,15,15,0.06);
}
.field textarea { resize: vertical; min-height: 70px; font-family: inherit; }
.field input[type=color] { padding: 4px; height: 40px; cursor: pointer; }
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; }
.field-help { font-size: 12px; color: var(--muted); margin-top: -4px; }

.options {
    display: grid;
    gap: 6px;
    margin-bottom: 14px;
}
.option {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 11px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s var(--easing);
    font-size: 14px;
    background: var(--surface);
}
.option:hover { background: var(--surface-2); }
.option input { display: none; }
.option .opt-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.option.is-selected { border-color: var(--accent); background: var(--surface-2); box-shadow: 0 0 0 3px rgba(15,15,15,0.04); }
.option .opt-desc { color: var(--muted); font-size: 12px; margin-top: 2px; }
.option .opt-body { flex: 1; }

.client-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    background: var(--surface-2);
}
.client-row .dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.client-row .info { flex: 1; min-width: 0; }
.client-row .info .name { font-weight: 500; font-size: 14px; }
.client-row .info .uname { font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted); }
.client-row .info .meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.client-row .actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }

.divider { height: 1px; background: var(--border); margin: 18px 0; }

.modal-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border);
    margin-left: -2px;
    margin-right: -2px;
    padding: 0 2px;
}
.modal-tab {
    background: transparent;
    border: none;
    padding: 8px 14px;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.3s var(--easing);
    margin-bottom: -1px;
}
.modal-tab:hover { color: var(--text); }
.modal-tab.active { color: var(--text); border-bottom-color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.error-msg {
    background: var(--danger-bg);
    color: var(--danger);
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    margin-bottom: 14px;
}

.notice {
    background: var(--warn-bg);
    color: var(--warn);
    border-left: 3px solid var(--warn);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
}
.notice.info {
    background: var(--accent-soft);
    color: var(--text);
    border-left-color: var(--accent);
}

/* login */
.login-page { background: var(--bg); }
.login-wrap {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 36px 32px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 20px 60px -30px rgba(15,15,15,0.2);
}
.login-card .login-mark { width: 36px; height: 36px; border-radius: 10px; margin-bottom: 18px; }
.login-card h1 { font-size: 24px; font-weight: 500; letter-spacing: -0.02em; margin-bottom: 4px; }
.login-card p.sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
