/* 工作预约 · 移动网页版 —— 移动端优先，尽量一屏显示全部时段 */

:root {
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --ink: #1f2329;
    --muted: #8a94a6;
    --line: #e6ebf3;
    --bg: #f4f6fa;
    --free-bg: #e8f7ee;
    --free-line: #c8ebd7;
    --free-ink: #2f7d55;
    --booked-bg: #fff1ee;
    --booked-line: #f5c2ae;
    --booked-ink: #b3410f;
    --selected-bg: #e3edff;
    --past-bg: #5c6472;
    --past-line: #4e5563;
    --past-ink: #f0f2f5;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --shell-width: 680px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body { touch-action: manipulation; }

button, input, textarea { font-family: inherit; }

button {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 0;
    margin: 0;
    padding: 0 14px;
    height: 40px;
    line-height: 1.2;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    background: transparent;
    color: inherit;
    -webkit-appearance: none;
    appearance: none;
}

button:disabled, button.is-disabled { opacity: .55; pointer-events: none; }

input, textarea {
    font-size: 16px; /* iOS 聚焦时不放大页面 */
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    padding: 10px 12px;
    width: 100%;
    outline: none;
}

input:focus, textarea:focus { border-color: var(--blue); }
textarea { resize: vertical; line-height: 1.5; }

.app-shell {
    max-width: var(--shell-width);
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg);
    padding-bottom: calc(96px + var(--safe-bottom));
}

/* ---------- 顶栏 ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 50px;
    padding: 0 14px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand { display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 600; }

.brand-mark {
    width: 26px; height: 26px; border-radius: 8px;
    background: var(--blue); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700;
}

.top-actions { display: flex; align-items: center; gap: 4px; }
.link-btn { height: 34px; padding: 0 9px; color: var(--blue); font-size: 13px; }
.link-btn.is-admin { color: var(--free-ink); font-weight: 600; }

/* ---------- Tab ---------- */
.tabbar { display: flex; background: #fff; border-bottom: 1px solid var(--line); }
.tab {
    flex: 1; height: 42px; font-size: 14px; color: var(--muted);
    border-bottom: 2px solid transparent; border-radius: 0;
}
.tab.active { color: var(--blue); font-weight: 600; border-bottom-color: var(--blue); }
.tab-count {
    margin-left: 6px; font-size: 12px; color: var(--muted);
    background: #eef3fb; border-radius: 10px; padding: 1px 7px;
}

/* ---------- 横幅 ---------- */
.banner {
    position: fixed; left: 50%; transform: translateX(-50%);
    top: 100px; z-index: 90;
    max-width: calc(var(--shell-width) - 32px); width: calc(100% - 32px);
    background: rgba(31,35,41,.92); color: #fff;
    padding: 11px 16px; border-radius: 12px; font-size: 14px;
    text-align: center; pointer-events: none; box-shadow: 0 8px 24px rgba(0,0,0,.16);
}
.banner[hidden] { display: none; }

/* ---------- 卡片通用 ---------- */
.card { background: #fff; border-radius: 14px; margin: 10px 12px; padding: 12px; box-shadow: 0 1px 3px rgba(31,35,41,.04); }
.state-card { background: #fff; border-radius: 14px; margin: 14px 12px; padding: 26px 18px; text-align: center; }
.state-title { font-size: 15px; font-weight: 600; }
.state-desc { font-size: 13px; color: var(--muted); margin-top: 8px; line-height: 1.6; }
.state-card .btn { margin: 16px auto 0; }

/* ---------- 周导航与日期条 ---------- */
.control-card { background: #fff; border-radius: 14px; margin: 10px 12px; padding: 10px 10px 8px; box-shadow: 0 1px 3px rgba(31,35,41,.04); }
.date-head { display: flex; align-items: center; gap: 4px; height: 32px; }
.week-nav {
    display: flex; align-items: center; gap: 2px; height: 30px; padding: 0 8px;
    color: var(--blue); font-size: 13px; border-radius: 8px; background: #f1f5fb;
}
.week-nav.disabled { color: #c0c8d6; background: #f6f7f9; pointer-events: none; }
.nav-icon { font-size: 18px; line-height: 1; }
.date-current { flex: 1; text-align: center; font-size: 15px; font-weight: 600; }
.date-today { height: 30px; padding: 0 9px; font-size: 13px; color: var(--blue); background: #f1f5fb; border-radius: 8px; }

.date-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 8px; }
.date-cell {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 52px; border-radius: 9px; background: #f6f8fc; color: #3c4557;
    font-size: 12px; cursor: pointer; user-select: none; border: 1px solid transparent;
}
.date-cell .day { font-size: 17px; font-weight: 600; line-height: 1.25; }
.date-cell.weekend { color: #98a2b3; }
.date-cell.is-today { border-color: #b6c2d6; }
/* 过去的日期：明确置灰，不用透明度；选中时也只用中性灰，避免看起来像可预约 */
.date-cell.is-past { background: #f2f4f7; color: #8a94a6; }
.date-cell.is-past.weekend { color: #8a94a6; }
.date-cell.is-selected { background: var(--blue); color: #fff; border-color: var(--blue); }
.date-cell.is-selected.weekend { color: #fff; }
.date-cell.is-past.is-selected { background: #dfe3ea; color: #5b6478; border-color: #dfe3ea; }
.date-cell.is-past.is-selected.weekend { color: #5b6478; }

.control-divider { height: 1px; background: var(--line); margin: 10px 0 8px; }
.tech-head { display: flex; align-items: center; gap: 8px; }
.tech-scroll { flex: 1; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tech-scroll::-webkit-scrollbar { display: none; }
.tech-list { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.tech-chip {
    height: 30px; padding: 0 11px; border-radius: 16px; font-size: 13px;
    background: #f1f5fb; color: #5b6478; flex: none; user-select: none;
}
.tech-chip.active { background: var(--blue); color: #fff; font-weight: 600; }
.tech-chip.add { background: #fff; border: 1px dashed #b6c2d6; color: var(--blue); }
.tech-refresh { font-size: 12px; color: var(--blue); flex: none; height: 30px; padding: 0 4px; }


/* ---------- 时段网格 ---------- */
.slots-card { background: #fff; border-radius: 14px; margin: 10px 12px; padding: 10px; box-shadow: 0 1px 3px rgba(31,35,41,.04); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; padding: 2px 2px 8px; }
.section-title { font-size: 14px; font-weight: 600; }
.section-range { font-size: 12px; color: var(--muted); }

.slot-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.slot-cell {
    position: relative; min-height: 60px; border-radius: 9px; padding: 7px 4px 6px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    border: 1px solid var(--free-line); background: var(--free-bg);
    cursor: pointer; user-select: none; overflow: hidden;
}
.cell-time { font-size: 13px; font-weight: 600; color: var(--free-ink); line-height: 1.2; }
/* 状态文字默认中性灰，只有「空闲」才是绿色；已过期不能显示成绿色 */
.cell-state { font-size: 11px; color: #b0b8c8; margin-top: 3px; white-space: nowrap; }

.slot-cell.free { background: var(--free-bg); border-color: var(--free-line); }
.slot-cell.free .cell-state { color: var(--free-ink); }
.slot-cell.booked { background: var(--booked-bg); border-color: var(--booked-line); }
.slot-cell.booked .cell-time, .slot-cell.booked .cell-state { color: var(--booked-ink); }
/* 已约格显示预约人全名：常规中文名完整显示，极长名字才省略，避免撑破格子 */
.slot-cell.booked .cell-state {
    display: block; width: 100%; text-align: center;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    letter-spacing: -.2px;
}
.slot-cell.selected { background: var(--selected-bg); border-color: var(--blue); }
.slot-cell.selected .cell-time, .slot-cell.selected .cell-state { color: var(--blue); }
.slot-cell.past { background: var(--past-bg); border-color: var(--past-line); }
.slot-cell.past .cell-time, .slot-cell.past .cell-state { color: var(--past-ink); }
/* 过去时段若已有人预约，保留「已约」橙色，不让深灰盖掉预约信息 */
.slot-cell.booked.past { background: var(--booked-bg); border-color: var(--booked-line); }
.slot-cell.booked.past .cell-time,
.slot-cell.booked.past .cell-state { color: var(--booked-ink); }

.slot-cell.multi { background: #fff; border-color: var(--line); }
.slot-cell.multi .cell-time { color: #3c4557; }
.slot-cell.multi .cell-state { color: #8a94a6; }
/* 已过期：与图例、单人视图统一为明显深灰底，文字改浅色保证可读 */
.slot-cell.multi.is-past { background: var(--past-bg); border-color: var(--past-line); }
.slot-cell.multi.is-past .cell-time,
.slot-cell.multi.is-past .cell-state { color: var(--past-ink); }
.slot-cell.multi.is-past .person-extra { color: #d9dee7; }
.slot-cell.multi.is-past .person-extra.has-booked { color: #ffbda6; }

.person-row { display: flex; gap: 3px; margin-top: 4px; align-items: center; justify-content: center; }
.person-badge {
    min-width: 20px; height: 20px; padding: 0 3px; border-radius: 5px;
    font-size: 11px; line-height: 20px; text-align: center;
    background: var(--free-bg); color: var(--free-ink); border: 1px solid var(--free-line);
}
.person-badge.booked { background: var(--booked-bg); color: var(--booked-ink); border-color: var(--booked-line); }
.person-badge.past { background: rgba(255,255,255,.16); color: #eef1f5; border-color: rgba(255,255,255,.26); }
.person-extra { font-size: 10px; color: var(--muted); }
.person-extra.has-booked { color: var(--booked-ink); font-weight: 600; }

.cell-remove {
    position: absolute; right: 3px; top: 3px; width: 18px; height: 18px;
    border-radius: 9px; background: rgba(37,99,235,.14); color: var(--blue);
    font-size: 13px; line-height: 18px; text-align: center;
}
.lunch-break { text-align: center; font-size: 11px; color: var(--muted); padding: 8px 0; }
.lunch-break span { background: #f6f8fc; border-radius: 8px; padding: 3px 10px; }

.legend { display: flex; justify-content: center; gap: 14px; font-size: 11px; color: var(--muted); padding: 2px 0 4px; }
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend-dot.free { background: var(--free-bg); border: 1px solid var(--free-line); }
.legend-dot.booked { background: var(--booked-bg); border: 1px solid var(--booked-line); }
.legend-dot.selected { background: var(--selected-bg); border: 1px solid var(--blue); }
.legend-dot.past { background: var(--past-bg); }

/* ---------- 记录页 ---------- */
.record-window { display: flex; align-items: center; justify-content: space-between; margin: 12px 12px 0; gap: 6px; }
.record-window-nav { font-size: 13px; color: var(--blue); background: #fff; border-radius: 8px; height: 32px; padding: 0 10px; }
.record-window-main { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.record-window-label { font-size: 12px; color: #5b6478; }
.record-window-today { font-size: 11px; color: var(--blue); height: 20px; padding: 0 6px; }
.record-tip { font-size: 12px; color: var(--muted); margin: 8px 14px; }
.record-filter, .record-truncate { margin: 0 12px 8px; font-size: 12px; padding: 8px 10px; border-radius: 8px; background: #eaf1ff; color: var(--blue-dark); }
.record-truncate { background: var(--booked-bg); color: var(--booked-ink); }
.record-filter-clear { color: var(--blue); text-decoration: underline; margin-left: 6px; cursor: pointer; }

.record-card { background: #fff; border-radius: 12px; margin: 8px 12px; padding: 12px; cursor: pointer; border: 1px solid var(--line); }
.record-card.is-past { opacity: .68; }
.record-summary { display: flex; align-items: stretch; justify-content: space-between; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.record-summary-main { display: flex; flex-direction: column; gap: 4px; }
.record-date-row { display: flex; align-items: center; gap: 6px; }
.record-summary-date { font-size: 14px; font-weight: 600; }
.record-past-tag { font-size: 10px; color: #5b6478; background: #e9ebef; border-radius: 4px; padding: 2px 5px; }
.record-summary-range { font-size: 12px; color: #5b6478; }
.record-summary-person { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-align: right; flex: none; }
.record-summary-label { font-size: 11px; color: var(--muted); }
.record-summary-name { font-size: 14px; font-weight: 600; color: var(--blue); }
.record-field { display: flex; gap: 10px; padding-top: 9px; font-size: 13px; line-height: 1.5; }
.record-field-label { flex: none; width: 58px; color: var(--muted); }
.record-field-value { flex: 1; word-break: break-word; white-space: pre-wrap; }
.empty-card { background: #fff; border-radius: 14px; margin: 14px 12px; padding: 30px 18px; text-align: center; }
.empty-title { font-size: 15px; font-weight: 600; }
.empty-desc { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* ---------- 底部操作条 ---------- */
.bottom-bar {
    position: fixed; left: 50%; transform: translateX(-50%); bottom: 0;
    width: 100%; max-width: var(--shell-width); z-index: 30;
    background: #fff; border-top: 1px solid var(--line);
    padding: 8px 12px calc(8px + var(--safe-bottom));
    box-shadow: 0 -3px 14px rgba(31,35,41,.06);
    display: flex; align-items: center; gap: 8px;
}
.selection-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.selection-label { font-size: 14px; font-weight: 600; }
.selection-duration { font-size: 11px; color: var(--muted); margin-top: 2px; }
.clear-button { height: 38px; padding: 0 10px; color: var(--muted); font-size: 13px; border: 1px solid var(--line); border-radius: 9px; }

/* ---------- 按钮 ---------- */
.btn { height: 40px; padding: 0 16px; font-size: 14px; border-radius: 10px; font-weight: 500; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.secondary { background: #f1f5fb; color: #5b6478; }
.btn.danger { background: #fdece8; color: var(--booked-ink); }
.btn.block { width: 100%; height: 44px; }
.btn.flex { flex: 1; }

/* ---------- 弹层 ---------- */
.mask { position: fixed; inset: 0; background: rgba(20,26,38,.45); z-index: 40; }
.sheet {
    position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 50;
    width: 100%; max-width: var(--shell-width); background: #fff;
    border-radius: 18px 18px 0 0; max-height: 88vh; display: flex; flex-direction: column;
    box-shadow: 0 -8px 30px rgba(0,0,0,.12);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.sheet-title { font-size: 16px; font-weight: 600; }
.sheet-close { width: 32px; height: 32px; font-size: 18px; color: var(--muted); }
.sheet-body { padding: 12px 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.sheet-actions { display: flex; gap: 10px; padding: 10px 16px calc(12px + var(--safe-bottom)); border-top: 1px solid var(--line); }
.sheet-actions .btn { flex: 1; }

.dialog {
    position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 50;
    width: calc(100% - 40px); max-width: 420px; background: #fff;
    border-radius: 16px; padding: 18px; max-height: 84vh; overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0,0,0,.18);
}
.dialog-title { font-size: 16px; font-weight: 600; display: block; margin-bottom: 8px; }
.dialog-desc { font-size: 13px; color: #5b6478; line-height: 1.6; display: block; margin-bottom: 12px; }
.dialog-actions { display: flex; gap: 10px; margin-top: 14px; }
.dialog-actions .btn { flex: 1; }
.dialog .field-label { display: block; font-size: 13px; margin: 12px 0 6px; color: #3c4557; }
.dialog-error { display: block; font-size: 12px; color: var(--booked-ink); margin-top: 8px; line-height: 1.5; }

.summary-card { display: flex; align-items: stretch; justify-content: space-between; gap: 10px; background: #f6f8fc; border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.summary-main { display: flex; flex-direction: column; gap: 4px; }
.summary-date { font-size: 14px; font-weight: 600; }
.summary-range { font-size: 12px; color: #5b6478; }
.summary-person { display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: 2px; flex: none; }
.summary-person-label { font-size: 11px; color: var(--muted); }
.summary-person-name { font-size: 15px; font-weight: 600; color: var(--blue); }

.form-item { margin-top: 12px; }
.form-label { display: block; font-size: 13px; margin-bottom: 6px; color: #3c4557; }
.required { color: var(--booked-ink); }
.form-locked { display: flex; align-items: center; justify-content: space-between; background: #f6f8fc; border-radius: 10px; padding: 11px 12px; font-size: 14px; }
.form-locked .lock-tag { font-size: 11px; color: var(--muted); }
.form-error { background: var(--booked-bg); color: var(--booked-ink); font-size: 12px; border-radius: 8px; padding: 9px 10px; margin-bottom: 10px; line-height: 1.5; }
.form-textarea { min-height: 132px; }

.detail-row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; line-height: 1.6; }
.detail-label { flex: none; width: 66px; color: var(--muted); }
.detail-value { flex: 1; white-space: pre-wrap; word-break: break-word; }
.detail-actions { margin-top: 16px; }
.detail-actions .btn { width: 100%; }
.detail-note { font-size: 12px; color: var(--muted); text-align: center; margin-top: 12px; line-height: 1.6; }
.cancel-confirm { background: #fff7f5; border-radius: 12px; padding: 12px; margin-top: 14px; }
.cancel-confirm-title { font-size: 13px; line-height: 1.6; display: block; }
.cancel-actions { display: flex; gap: 10px; margin-top: 12px; }
.cancel-actions .btn { flex: 1; }

.person-options { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.person-option { border: 1px solid var(--free-line); background: var(--free-bg); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.person-option.booked { border-color: var(--booked-line); background: var(--booked-bg); }
.person-option.past { border-color: #dfe3ea; background: #f2f4f7; }
.person-option-name { font-size: 14px; font-weight: 600; display: block; }
.person-option-state { font-size: 12px; color: #5b6478; display: block; margin-top: 3px; }
.person-cancel { width: 100%; margin-top: 14px; }

/* ---------- 进入门禁 ---------- */
.gate { position: fixed; inset: 0; z-index: 100; background: linear-gradient(160deg, #eef3fb 0%, #f8fafc 55%, #eaf6ef 100%); display: flex; align-items: center; justify-content: center; padding: 20px; }
.gate[hidden] { display: none; }
.gate-card { width: 100%; max-width: 380px; background: #fff; border-radius: 20px; padding: 28px 22px calc(24px + var(--safe-bottom)); box-shadow: 0 16px 46px rgba(31,35,41,.1); text-align: center; }
.gate-logo { width: 52px; height: 52px; border-radius: 15px; background: var(--blue); color: #fff; font-size: 24px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; }
.gate-title { font-size: 20px; margin: 0 0 4px; }
.gate-sub { font-size: 12px; color: var(--muted); margin: 0 0 22px; }
.gate-section[hidden] { display: none; }
.gate-label { display: block; text-align: left; font-size: 13px; color: #3c4557; margin-bottom: 8px; }
.gate-input { height: 46px; text-align: center; letter-spacing: 1px; }
#gate-name-input { letter-spacing: 0; text-align: left; }
.gate-error { font-size: 12px; color: var(--booked-ink); text-align: left; margin: 8px 0 0; }
.gate-error[hidden] { display: none; }
.gate-section .btn { margin-top: 14px; }
.gate-note { font-size: 11px; color: var(--muted); line-height: 1.6; margin: 14px 0 0; text-align: left; }

.noscript { padding: 30px; text-align: center; font-size: 15px; }

/* ---------- 同步状态 ---------- */
.sync-bar { margin: 8px 12px 0; font-size: 11px; line-height: 1.6; padding: 7px 10px; border-radius: 8px; }
.sync-bar.ok {
    color: #9aa3b2; background: transparent; text-align: center; font-size: 10px;
    margin: 14px 12px calc(10px + var(--safe-bottom)); padding: 4px 10px;
}
.sync-bar.error {
    color: var(--booked-ink); background: var(--booked-bg); cursor: pointer;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.sync-bar.error .sync-retry { flex: none; color: var(--blue); text-decoration: underline; }
.record-loading { margin: 8px 12px; font-size: 12px; color: var(--blue); background: #eaf1ff; border-radius: 8px; padding: 8px 10px; }
.record-list-stale { opacity: .5; }
.record-filter-clear {
    display: inline; height: auto; padding: 0 2px; margin-left: 6px;
    background: transparent; border: 0; border-radius: 0;
    color: var(--blue); text-decoration: underline; font-size: 12px;
    line-height: inherit; cursor: pointer;
}

@media (min-width: 700px) {
    .app-shell { box-shadow: 0 0 0 1px var(--line); }
    .slot-cell { min-height: 66px; }
}
