/* ===========================================================
   拾光日历 · 站点样式
   浅色、留白、单一强调色；不用渐变/阴影堆叠，保持安静
   =========================================================== */

:root {
  --bg:        #fafafb;
  --card:      #ffffff;
  --line:      #e8eaed;
  --line-soft: #f0f1f3;
  --text:      #16181d;
  --muted:     #6b7280;
  --faint:     #9aa1ac;
  --accent:    #2f6feb;
  --green:     #12a150;
  --red:       #d93a3a;
  --radius:    14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
a.link, .link { color: var(--accent); }
.link { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p  { margin: 0 0 1em; }

.wrap { width: 100%; max-width: 940px; margin: 0 auto; padding: 0 20px; }

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

.topbar {
  border-bottom: 1px solid var(--line);
  background: rgba(250,250,251,.85);
  backdrop-filter: saturate(1.4) blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  height: 58px; display: flex; align-items: center; justify-content: space-between;
}
.brand { font-weight: 650; font-size: 1rem; letter-spacing: -0.01em; }
.nav { display: flex; align-items: center; gap: 18px; font-size: .9rem; }
.nav a { color: var(--muted); transition: color .12s; }
.nav a:hover, .nav a.on { color: var(--text); }
.who { color: var(--faint); font-size: .85rem; }
.inline { display: inline; margin: 0; }

/* ---------- 页面 ---------- */

.page { flex: 1 0 auto; padding-top: 36px; padding-bottom: 64px; }

.foot {
  flex: none;
  padding-top: 24px; padding-bottom: 32px;
  color: var(--faint); font-size: .8rem;
  border-top: 1px solid var(--line-soft);
  display: flex; gap: 8px;
}

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 24px;
}
.page-head .sub { color: var(--muted); font-size: .88rem; margin-top: 6px; }
.page-head .actions { display: flex; gap: 10px; flex-shrink: 0; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 36px 0 14px;
}
.section-head h2 { font-size: .95rem; color: var(--muted); font-weight: 500; }

/* ---------- 卡片 ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}
.card + .card { margin-top: 14px; }
.card-tight { padding: 16px 18px; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 760px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}

/* 设备卡片 */
.device-card {
  display: block;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px;
  transition: border-color .15s, transform .15s;
}
.device-card:hover { border-color: #d5d8de; transform: translateY(-1px); }
.device-card .top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.device-card .name { font-weight: 600; }
.device-card .id { color: var(--faint); font-size: .78rem; font-family: ui-monospace, "SF Mono", Consolas, monospace; margin-top: 2px; }
.device-card .metrics {
  display: flex; gap: 18px; margin-top: 16px;
  font-size: .82rem; color: var(--muted);
}
.device-card .metrics b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- 状态点 ---------- */

.status { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #c8ccd3; }
.status.on { color: var(--green); }
.status.on::before { background: var(--green); box-shadow: 0 0 0 3px rgba(18,161,80,.13); }

/* ---------- 数字卡 ---------- */

.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .k { color: var(--muted); font-size: .78rem; letter-spacing: .02em; }
.stat .v { font-size: 1.45rem; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat .v small { font-size: .8rem; font-weight: 400; color: var(--muted); margin-left: 3px; }

/* ---------- 按钮 ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font-size: .9rem; font-weight: 500;
  cursor: pointer; transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #f5f6f8; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-dark { background: var(--text); border-color: var(--text); color: #fff; }
.btn-dark:hover:not(:disabled) { background: #2c2f36; border-color: #2c2f36; }
.btn-sm { padding: 7px 14px; font-size: .84rem; border-radius: 8px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: #f2f3f5; }
.btn-danger { color: var(--red); border-color: #f0d4d4; }
.btn-danger:hover:not(:disabled) { background: #fdf4f4; }

/* ---------- 表单 ---------- */

.field { margin-bottom: 16px; }
.field label { display: block; font-size: .84rem; color: var(--muted); margin-bottom: 6px; }
.field .hint { font-size: .78rem; color: var(--faint); margin-top: 6px; }

input[type=text], input[type=password], input[type=number], input[type=date], select {
  width: 100%; padding: 10px 12px; font: inherit; font-size: .92rem;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus {
  outline: none; border-color: #c9d6f5; box-shadow: 0 0 0 3px rgba(47,111,235,.1);
}
input::placeholder { color: #b3b8c0; }

.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row .field { flex: 1 1 160px; margin-bottom: 0; }

/* ---------- 提示 ---------- */

.flashes { margin-bottom: 18px; display: grid; gap: 8px; }
.flash {
  padding: 11px 14px; border-radius: 10px; font-size: .88rem;
  border: 1px solid var(--line); background: #fff;
}
.flash-success { border-color: #cfe8da; background: #f4fbf7; color: #0f7a3d; }
.flash-error   { border-color: #f0d4d4; background: #fdf6f6; color: #b32b2b; }

.empty {
  border: 1px dashed #dcdfe4; border-radius: var(--radius);
  padding: 44px 24px; text-align: center; color: var(--muted);
  background: #fcfcfd;
}
.empty h3 { color: var(--text); margin-bottom: 8px; }
.empty p { margin-bottom: 18px; }

/* ---------- 表格 ---------- */

table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: .78rem;
  padding: 0 12px 10px; border-bottom: 1px solid var(--line);
}
.tbl td { padding: 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { font-variant-numeric: tabular-nums; }
.tbl .mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .82rem; }
/* 注意：不要把 td 改成 display:flex，会破坏表格单元格边框 */
.tbl td.acts { text-align: right; white-space: nowrap; }
.tbl td.acts > * + * { margin-left: 6px; }
.tbl td.acts form { display: inline; }
.tbl-wrap { overflow-x: auto; }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: .75rem; background: #f1f2f4; color: var(--muted);
}
.pill-ok { background: #edf9f1; color: #0f7a3d; }
.pill-warn { background: #fdf6ed; color: #9a6212; }

/* ---------- 详情页 ---------- */

.detail-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.detail-head h1 { font-size: 1.3rem; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; }

.kv { display: grid; grid-template-columns: 96px 1fr; gap: 10px 16px; font-size: .88rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.token-box {
  display: flex; gap: 10px; align-items: center;
  background: #f7f8fa; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-top: 8px;
}
.token-box code {
  flex: 1; font-size: .82rem; word-break: break-all;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
}

.chart { width: 100%; height: 88px; display: block; }

.controls { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- 登录页 ---------- */

.auth-wrap { max-width: 380px; margin: 56px auto 0; }
.auth-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 30px 28px; }
.auth-card h1 { font-size: 1.2rem; margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); font-size: .88rem; margin-bottom: 24px; }
.auth-card .btn { width: 100%; margin-top: 6px; }
.auth-foot { text-align: center; color: var(--muted); font-size: .86rem; margin-top: 18px; }

/* ---------- 落地页 ---------- */

.hero { max-width: 560px; margin: 72px auto; text-align: center; }
.hero h1 { font-size: 2rem; letter-spacing: -0.02em; line-height: 1.3; }
.hero p { color: var(--muted); margin: 18px 0 28px; font-size: 1rem; }
.hero .actions { display: flex; gap: 12px; justify-content: center; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 12px);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: .86rem; opacity: 0; pointer-events: none;
  transition: opacity .18s, transform .18s; max-width: 90vw; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #b32b2b; }

.muted { color: var(--muted); }
.small { font-size: .84rem; }
.mt-0 { margin-top: 0; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }

/* ===========================================================
   手机适配（主要用户是手机，桌面是次要场景）
   目标：单手能点、不横向溢出、输入框不触发 iOS 缩放
   =========================================================== */

html { -webkit-text-size-adjust: 100%; }

@media (max-width: 640px) {

  .wrap { padding: 0 16px; }

  /* 顶栏：品牌一行，导航变成可横滑的一排（像标签页）
     注意：.topbar-inner 和 .wrap 是同一个元素，
     这里只能改纵向 padding，否则会把 .wrap 的左右 16px 一起清零，
     导航就贴到屏幕边上了。 */
  .topbar-inner {
    height: auto; min-height: 52px; flex-wrap: wrap;
    padding-top: 8px; padding-bottom: 0; gap: 0;
  }
  .brand { font-size: .98rem; }
  .nav {
    width: 100%; gap: 16px; font-size: .88rem;
    overflow-x: auto; white-space: nowrap;
    padding: 4px 0 8px; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    align-items: center;
    /* 铺满整行：放得下时两端对齐，不会挤在左边、右边空一大块 */
    justify-content: space-between;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 6px 0; }       /* 加大可点区域 */
  .nav .btn-sm { min-height: 34px; padding: 6px 12px; font-size: .84rem; }
  .who { display: none; }          /* 用户名让位，桌面端仍显示 */

  /* 去掉 iOS 点击时的灰块和 300ms 延迟 */
  .btn, .nav a, .tbl a { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

  .page { padding-top: 20px; padding-bottom: 40px; }

  .page-head {
    flex-direction: column; align-items: flex-start;
    gap: 12px; margin-bottom: 18px;
  }
  .page-head .actions { width: 100%; flex-wrap: wrap; }
  .section-head { margin: 26px 0 12px; }

  h1 { font-size: 1.25rem; }
  .detail-head h1 { font-size: 1.15rem; }
  .card { padding: 16px; border-radius: 12px; }
  .card-tight { padding: 12px 14px; }

  /* 触控目标不小于 44px（Apple 和 Material 都以此为准） */
  .btn { min-height: 44px; padding: 12px 16px; font-size: .92rem; }
  .btn-sm { min-height: 40px; padding: 9px 12px; font-size: .85rem; }

  /* 设备页的「检查更新 / 重启」铺成两列，不再挤成一行 */
  .controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .controls .btn { width: 100%; }

  /* iOS 上输入框字号小于 16px 会在聚焦时自动放大页面 */
  input[type=text], input[type=password], input[type=number],
  input[type=date], select, textarea {
    font-size: 16px; padding: 12px;
  }
  .row { gap: 10px; }
  .row .field { flex: 1 1 100%; }
  .row .btn { width: 100%; }

  .kv { grid-template-columns: 84px 1fr; gap: 8px 12px; font-size: .86rem; }
  .kv dd { word-break: break-word; }

  .device-card { padding: 16px; }
  .device-card .metrics { flex-wrap: wrap; gap: 10px 16px; }
  .stat { padding: 14px; }
  .stat .v { font-size: 1.25rem; }

  .tbl { font-size: .82rem; }
  .tbl th { padding: 0 8px 8px; }
  .tbl td { padding: 10px 8px; }
  .tbl td.acts { text-align: left; }

  /* 手机上表格不要被压扁：保持最小宽度，靠横向滑动看完整列
     （不设 min-width 的话，列头会变成「芯 片 固 件」这样竖排） */
  .tbl-wrap {
    margin: 0 -16px;           /* 贴边，滑动区域更大 */
    padding: 0 16px;
    -webkit-overflow-scrolling: touch;
  }
  .tbl { min-width: 560px; }
  .tbl th { white-space: nowrap; }
  /* 时间/编号/型号这类短字段不要折行，只有说明列允许换行 */
  .tbl td.num, .tbl td.mono { white-space: nowrap; }
  .tbl-wrap::after {
    content: "← 左右滑动查看 →";
    display: block; text-align: center;
    font-size: .72rem; color: var(--faint);
    padding: 8px 0 2px;
  }

  .auth-wrap { margin-top: 20px; }
  .auth-card { padding: 22px 18px; border-radius: 14px; }

  .hero { margin: 40px auto; }
  .hero h1 { font-size: 1.55rem; line-height: 1.35; }
  .hero .actions { flex-direction: column; }
  .hero .actions .btn { width: 100%; }

  .toast {
    left: 16px; right: 16px; width: auto; max-width: none;
    text-align: center; transform: translateY(12px);
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .toast.show { transform: translateY(0); }

  .foot {
    padding-top: 20px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  }

  .token-box { flex-wrap: wrap; }
}

/* 触摸设备上不要保留 hover 的位移/变色，否则点完像没反应 */
@media (hover: none) {
  .device-card:hover { transform: none; border-color: var(--line); }
  .btn:hover:not(:disabled) { background: #fff; }
  .btn-dark:hover:not(:disabled) { background: var(--text); border-color: var(--text); }
  .btn-ghost:hover:not(:disabled) { background: transparent; }
  .btn-danger:hover:not(:disabled) { background: #fff; }
}

/* 窄屏（≤380px，如 iPhone SE / 老安卓）导航再收紧一点，保证最后一项不被截 */
@media (max-width: 380px) {
  .nav { gap: 14px; font-size: .84rem; }
  .nav .btn-sm { padding: 6px 10px; }
  .wrap { padding: 0 14px; }
  .tbl-wrap { margin: 0 -14px; padding: 0 14px; }
}
