/* ---------------------------------------------------------------- */
/*  设备预约看板                                                      */
/* ---------------------------------------------------------------- */

:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f2f4f8;
  --border: #e4e7ee;
  --text: #191d26;
  --text-2: #6b7383;
  --text-3: #9aa1af;
  --accent: #2563eb;
  --accent-soft: #e3ecff;
  --accent-line: #a9c5ff;
  --mine-soft: #d9e7ff;
  --mine-line: #2563eb;
  --taken-soft: #e9ecf3;
  --taken-text: #4a5160;
  --danger: #d92d20;
  --danger-soft: #fdeceb;
  --ok: #0f9d58;
  --sel-soft: #eef4ff;
  --radius: 14px;
  --day-w: 44px;   /* 一天的列宽（最小） */
  --cell-h: 42px;  /* 一小时的格高 */
  --time-w: 54px;  /* 左侧时间列宽 */
  --head-h: 46px;  /* 顶部日期行高 */
  --shadow: 0 12px 34px rgba(15, 23, 42, 0.13);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f26;
    --surface-2: #232730;
    --border: #2e333d;
    --text: #e8ebf1;
    --text-2: #98a1b1;
    --text-3: #6d7787;
    --accent: #5b93ff;
    --accent-soft: #1e2c4a;
    --accent-line: #35518a;
    --mine-soft: #21365c;
    --mine-line: #5b93ff;
    --taken-soft: #262b35;
    --taken-text: #a7b0c0;
    --danger: #ff6b61;
    --danger-soft: #3a1d1c;
    --sel-soft: #1d2a44;
    --shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

/* 重要：下面几个容器显式写了 display: grid/flex，
   会盖掉浏览器对 [hidden] 的默认 display:none，所以必须强制一次。 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
}

input {
  font: inherit;
  color: inherit;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 14px calc(96px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

/* ---------------------------- 顶栏 ---------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 2px 2px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.2px;
  margin-right: auto;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  line-height: 1;
}

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

.name-field {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.name-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.name-label {
  color: var(--text-3);
  font-size: 12px;
  white-space: nowrap;
}

.name-field input {
  width: 92px;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  min-width: 0;
}

.name-field input::placeholder {
  font-weight: 400;
  color: var(--text-3);
}

.ghost-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 7px 13px;
  font-size: 13.5px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.ghost-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.ghost-btn:active { transform: scale(0.97); }

.ghost-btn.tiny {
  padding: 4px 10px;
  font-size: 12.5px;
  border-radius: 8px;
}

.ghost-btn.on {
  border-color: var(--accent-line);
  color: var(--accent);
  background: var(--accent-soft);
}

.primary-btn {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  transition: filter 0.15s;
}

.primary-btn:hover { filter: brightness(1.07); }
.primary-btn:active { transform: scale(0.97); }
.primary-btn:disabled { opacity: 0.5; cursor: default; filter: none; }

.danger-btn {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
}

/* --------------------------- 设备 tab --------------------------- */

.device-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  scrollbar-width: none;
}

.device-tabs::-webkit-scrollbar { display: none; }

.device-tab {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  border-radius: 999px;
  padding: 7px 15px;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}

.device-tab:hover { border-color: var(--accent-line); color: var(--text); }

.device-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.device-tab .tab-count {
  display: inline-block;
  margin-left: 6px;
  font-size: 11.5px;
  opacity: 0.75;
}

/* --------------------------- 工具条 ---------------------------- */

.board-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 2px 8px;
  flex-wrap: wrap;
}

.nav-group,
.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.nav-group {
  flex: 1;
  min-width: 0;
}

.range-label {
  font-size: 12.5px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.select-mini {
  padding-right: 6px;
  cursor: pointer;
  color: var(--text-2);
}

/* ---------------------------- 看板 ----------------------------- */

.board-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.board {
  display: grid;
  /* 行 = 小时，列 = 日期 */
  grid-template-columns: var(--time-w) repeat(var(--cols, 7), minmax(var(--day-w), 1fr));
  gap: 2px;
  padding: 8px;
  width: 100%;
  min-width: max-content;
}

/* 左上角 + 顶部日期行 */
.corner,
.date-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  height: var(--head-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  line-height: 1.15;
}

.corner {
  left: 0;
  z-index: 4;
}

.date-head .dh-dow {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}

.date-head .dh-md {
  font-size: 10.5px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.date-head.is-today .dh-dow { color: var(--accent); }

/* 左侧时间列 */
.time-label {
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--surface);
  height: var(--cell-h);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 6px;
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.slot {
  height: var(--cell-h);
  border-radius: 7px;
  background: var(--surface-2);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0 2px;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
  position: relative;
  min-width: 0;
}

.slot:not(.taken):not(.past):not(.sel):hover {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.slot:not(.past):active { transform: scale(0.95); }

.slot-name {
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--taken-text);
}

.slot.taken {
  background: var(--taken-soft);
}

.slot.taken .slot-name { color: var(--taken-text); }

.slot.mine {
  background: var(--mine-soft);
  border-color: var(--accent-line);
}

.slot.mine .slot-name {
  color: var(--mine-line);
}

.slot.sel {
  background: var(--sel-soft);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* 只有“空格子 + 已经过去”才显示成虚线。
   历史日期里已经有人的格子必须照常显示出来。 */
.slot.past:not(.taken) {
  background: transparent;
  border: 1px dashed var(--border);
  cursor: default;
  opacity: 0.5;
}

.slot.sel .slot-name { color: var(--accent); }

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
}

.empty b { color: var(--text); }

.tips {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  color: var(--text-3);
  padding: 0 4px;
  line-height: 1.6;
}

/* ------------------------- 底部操作条 --------------------------- */

.action-bar {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(680px, calc(100vw - 24px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  z-index: 40;
  animation: rise 0.18s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.action-info { min-width: 0; flex: 1; }

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

.action-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 2px;
}

.action-btns {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ---------------------------- 抽屉 ----------------------------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 22, 0.42);
  z-index: 50;
  animation: fade 0.15s ease-out;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(560px, 100vw);
  max-height: min(80dvh, 720px);
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  z-index: 51;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  padding-bottom: env(safe-area-inset-bottom);
  animation: slide-up 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes slide-up {
  from { transform: translate(-50%, 100%); }
  to { transform: translate(-50%, 0); }
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--border);
}

.sheet-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  flex: 1;
}

.close-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  display: grid;
  place-items: center;
  font-size: 15px;
  line-height: 1;
}

.close-btn:hover { background: var(--border); }

.sheet-body {
  padding: 16px 18px 22px;
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0; /* flex 子项默认 min-height:auto 会把抽屉撑破 */
}

.detail-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.detail-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  background: var(--surface);
  padding: 11px 14px;
  font-size: 14px;
}

.detail-row .k {
  color: var(--text-3);
  font-size: 12.5px;
  width: 62px;
  flex-shrink: 0;
}

.detail-row .v {
  font-weight: 600;
  word-break: break-word;
  flex: 1;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.sheet-actions .ghost-btn,
.sheet-actions .primary-btn,
.sheet-actions .danger-btn {
  flex: 1;
  text-align: center;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 12.5px;
  color: var(--text-2);
}

.field input {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}

.device-manage-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.device-manage-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border-radius: 11px;
  padding: 9px 12px;
}

.device-manage-item .dm-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-manage-item.archived .dm-name {
  color: var(--text-3);
  text-decoration: line-through;
}

.mini-btn {
  font-size: 12.5px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  white-space: nowrap;
}

.mini-btn:hover { background: var(--border); color: var(--text); }

.mini-btn.danger { color: var(--danger); border-color: transparent; background: var(--danger-soft); }

.hint-box {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--text-2);
  line-height: 1.6;
  margin-top: 12px;
}

.exp-sub {
  margin: 22px 2px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

/* ---------------------------- toast ---------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(25, 29, 38, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  z-index: 80;
  max-width: calc(100vw - 40px);
  text-align: center;
  animation: fade 0.15s ease-out;
  pointer-events: none;
}

.toast.err { background: rgba(190, 34, 26, 0.95); }

/* --------------------------- 响应式 ----------------------------- */

@media (max-width: 640px) {
  :root {
    --day-w: 40px;
    --cell-h: 40px;
    --time-w: 48px;
    --head-h: 44px;
  }

  .app { padding: 10px 10px calc(96px + env(safe-area-inset-bottom)); }

  .brand-text { font-size: 16px; }

  /* iOS 上输入框字号小于 16px 会在聚焦时自动放大整个页面 */
  .name-field input,
  .field input {
    font-size: 16px;
  }

  .action-bar { padding: 10px 12px; gap: 10px; }

  .action-title { font-size: 13.5px; }

  .tips { font-size: 11.5px; }
}

@media (max-width: 420px) {
  .brand { font-size: 15px; }
  .name-field input { width: 66px; }
  .ghost-btn { padding: 6px 10px; font-size: 12.5px; }
}
