/* common.css — shared base: variables, reset, layout, components */
  :root {
    --bg: #f5f6f8;
    --panel: #ffffff;
    --line: #e5e7eb;
    --line-soft: #f0f2f5;
    --text: #1f2937;
    --muted: #6b7280;
    --muted2: #9ca3af;
    --primary: #3b82f6;
    --primary-soft: #eff6ff;
    --ok: #047857;
    --ok-bg: #ecfdf5;
    --warn: #c2410c;
    --warn-bg: #fff7ed;
    --err: #b91c1c;
    --err-bg: #fef2f2;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(15,23,42,.04);
    --sidebar-w: 200px;
    --bottom-h: 56px;
    --header-h: 52px;
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
  }
  button, input, select, textarea { font: inherit; }
  .btn {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 5px 10px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
  }
  .btn:hover { border-color: var(--primary); box-shadow: 0 1px 2px rgba(59,130,246,.15); }
  .btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
  .btn-primary:hover { filter: brightness(.96); }
  .btn-ghost { background: transparent; }
  .btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
  .tag {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 12px; padding: 1px 6px; border-radius: 4px;
    background: var(--primary-soft); color: #1d4ed8;
  }
  .tag.ok { background: var(--ok-bg); color: var(--ok); }
  .tag.warn { background: var(--warn-bg); color: var(--warn); }
  .tag.err { background: var(--err-bg); color: var(--err); }
  .tag.muted { background: #f3f4f6; color: var(--muted); }
  .muted { color: var(--muted); }
  .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    white-space: nowrap;
  }
  .hidden { display: none !important; }
  .err-banner {
    background: var(--err-bg);
    border: 1px solid #fecaca;
    color: var(--err);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
    font-size: 13px;
    white-space: pre-wrap;
  }

  .app {
    min-height: 100%;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: 100%;
  }
  .sidebar {
    background: #ffffff;
    color: var(--text);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    padding: 14px 10px;
    gap: 8px;
  }
  .brand {
    padding: 6px 10px 14px;
    border-bottom: 1px solid var(--line-soft);
    margin-bottom: 6px;
  }
  .brand h1 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text); }
  .nav-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; text-align: left; border: 0;
    background: transparent; color: #4b5563;
    border-radius: 6px; padding: 9px 10px;
    cursor: pointer; font-size: 13px;
  }
  .nav-item:hover { background: #f3f4f6; color: var(--text); }
  .nav-item.active { background: var(--primary-soft); color: #1d4ed8; font-weight: 500; }
  .nav-item .ico {
    width: 18px; height: 18px; display: inline-grid; place-items: center;
    font-size: 14px; opacity: .9;
  }

  .main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
  }
  .topbar {
    height: var(--header-h);
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
  }
  .topbar h2 { margin: 0; font-size: 16px; font-weight: 600; }
  .content {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }
  .card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow);
  }
  .card .label { color: var(--muted); font-size: 12px; }
  .card .value { font-size: 24px; font-weight: 600; margin-top: 4px; }
  .card .hint { color: var(--muted2); font-size: 12px; margin-top: 4px; word-break: break-all; }

  .panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - var(--header-h) - 24px);
  }
  .toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line-soft);
  }
  .toolbar-left, .toolbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
  input, select, textarea {
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 5px 8px;
    background: #fff;
    color: var(--text);
    font-size: 13px;
  }
  textarea { width: 100%; min-height: 72px; resize: vertical; }

  .table-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
    min-width: 720px;
  }
  th, td {
    text-align: left;
    padding: 9px 12px;
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
    white-space: nowrap;
  }
  th {
    position: sticky; top: 0; z-index: 1;
    background: #fafbfc;
    color: var(--muted);
    font-weight: 500;
    border-bottom: 1px solid var(--line);
  }
  th.col-ops, td.col-ops {
    position: sticky;
    right: 0;
    z-index: 2;
    background: #fff;
    box-shadow: -6px 0 8px rgba(15, 23, 42, .04);
    border-left: 1px solid var(--line-soft);
  }
  th.col-ops {
    z-index: 3;
    background: #fafbfc;
  }
  td.col-ops { background: #fff; }
  .truncate {
    white-space: nowrap;
  }
  .row-actions { display: flex; gap: 6px; flex-wrap: nowrap; }
  .pager {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 8px 12px;
    border-top: 1px solid var(--line-soft);
    background: #fff;
  }
  .pager-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

  .modal-mask {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.35);
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    z-index: 100;
  }
  .modal {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 10px;
    width: min(760px, 100%);
    max-height: min(86vh, 860px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(15,23,42,.18);
  }
  .modal.wide { width: min(960px, 100%); }
  .modal-hd {
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px; padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    flex: 0 0 auto;
  }
  .modal-hd h3 { margin: 0; font-size: 15px; font-weight: 600; }
  .modal-bd {
    padding: 14px;
    overflow: auto;
    overscroll-behavior: contain;
    flex: 1;
    min-height: 0;
  }
  .modal-ft {
    display: flex; justify-content: flex-end; gap: 8px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: #fafbfc;
    flex: 0 0 auto;
  }
  .form-grid {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 10px 12px;
    align-items: start;
  }
  .form-grid label { color: var(--muted); font-size: 13px; padding-top: 7px; }
  .form-grid .field-hint { grid-column: 2; margin-top: -6px; font-size: 12px; color: var(--muted2); }
  .form-grid label + input,
  .form-grid label + select,
  .form-grid label + textarea { min-width: 0; }
  .form-grid input[type=number] { width: 200px; }
  .form-grid select { min-width: 200px; max-width: 100%; }
  .form-grid textarea { min-height: 96px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
  .form-grid .ui-check {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 7px 2px; cursor: pointer; user-select: none;
  }
  .form-grid .ui-check input { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; cursor: pointer; }
  .form-grid .ui-check span { color: var(--muted); font-size: 13px; }
  .seg {
    display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
  }
  .seg button {
    border: 0; background: #fff; padding: 5px 10px; cursor: pointer; font-size: 12px; color: var(--muted);
  }
  .seg button.active { background: var(--primary-soft); color: #1d4ed8; font-weight: 500; }
  .seg button + button { border-left: 1px solid var(--line); }
  pre {
    margin: 0; background: #f9fafb; border: 1px solid var(--line-soft);
    border-radius: 6px; padding: 10px; font-size: 12px;
    overflow: auto; white-space: pre-wrap; word-break: break-word;
  }

  .bottom-nav {
    display: none;
    position: fixed; left: 0; right: 0; bottom: 0;
    height: calc(var(--bottom-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: #fff;
    border-top: 1px solid var(--line);
    z-index: 40;
  }
  .bottom-nav .nav-item {
    flex: 1;
    flex-direction: column;
    gap: 2px;
    color: var(--muted);
    border-radius: 0;
    padding: 8px 4px;
    font-size: 11px;
  }
  .bottom-nav .nav-item.active { color: var(--primary); background: transparent; }
  .bottom-nav .ico { font-size: 16px; }

  @media (max-width: 768px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .bottom-nav { display: flex; }
    .main { height: 100dvh; }
    .content {
      padding-bottom: calc(var(--bottom-h) + 12px + env(safe-area-inset-bottom));
    }
    .grid { grid-template-columns: 1fr; }
    .panel { min-height: calc(100dvh - var(--header-h) - var(--bottom-h) - 24px - env(safe-area-inset-bottom)); }
    .modal-mask { padding: 0; align-items: stretch; }
    .modal, .modal.wide {
      width: 100%;
      height: 100dvh;
      max-height: 100dvh;
      border-radius: 0;
      border: 0;
    }
    .form-grid { grid-template-columns: 1fr; gap: 6px; }
    .form-grid label { padding-top: 0; }
    .form-grid .field-hint { grid-column: 1; }
    table { min-width: 640px; }
  }
