:root {
  --green-950: #073f32;
  --green-900: #0a4a3a;
  --green-700: #126b52;
  --green-100: #eaf3ef;
  --brass: #d8b56f;
  --ink: #202522;
  --muted: #6d756f;
  --line: #e2e7e4;
  --soft: #f7f9f8;
  --white: #fff;
  --danger: #a33c31;
  --shadow: 0 18px 50px rgba(20, 45, 36, .12);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  color: var(--ink);
  background: var(--white);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { min-width: 320px; background: var(--white); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(18, 107, 82, .2); outline-offset: 2px; }
[hidden] { display: none !important; }
.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }

.login-view { min-height: 100vh; display: grid; grid-template-columns: minmax(420px, 44%) 1fr; }
.login-brand { position: relative; overflow: hidden; display: grid; place-content: center; justify-items: center; gap: 24px; padding: 56px; color: var(--brass); background: var(--green-950); }
.brand-lattice, .sidebar-pattern { position: absolute; inset: 0; opacity: .12; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='96' height='96' viewBox='0 0 96 96'%3E%3Cpath d='M0 24h24V0M72 0v24h24M96 72H72v24M24 96V72H0M24 24h48v48H24zM36 36h24v24H36z' fill='none' stroke='%23d8b56f' stroke-width='2'/%3E%3C/svg%3E"); background-size: 96px 96px; }
.temple-mark { position: relative; width: 250px; max-width: 70%; }
.temple-mark svg { display: block; width: 100%; stroke-width: 2; }
.login-brand h1 { position: relative; margin: 0; font-size: clamp(28px, 3vw, 48px); letter-spacing: .12em; color: #ebcc8e; }
.login-panel { display: grid; place-items: center; padding: 56px; background: var(--white); }
.login-form { width: min(520px, 100%); }
.login-form h2 { margin: 0 0 46px; font-size: clamp(30px, 3.2vw, 46px); letter-spacing: .04em; }
.login-form label, .device-form label { display: block; margin: 23px 0 10px; color: #2c332f; font-size: 15px; font-weight: 700; }
.input-with-icon { position: relative; }
.input-with-icon > svg { position: absolute; z-index: 1; top: 50%; left: 17px; width: 21px; height: 21px; color: var(--green-700); transform: translateY(-50%); }
.input-with-icon input { width: 100%; height: 58px; padding: 0 52px; border: 1px solid #cbd2ce; border-radius: 5px; color: var(--ink); background: var(--white); }
.icon-button { display: inline-grid; place-items: center; padding: 8px; border: 0; color: var(--muted); background: transparent; }
.icon-button svg { width: 22px; height: 22px; }
.input-with-icon .icon-button { position: absolute; top: 50%; right: 9px; transform: translateY(-50%); }
.primary-button, .secondary-button, .outline-button { min-height: 44px; border-radius: 5px; font-size: 15px; font-weight: 700; transition: transform .15s ease, background .15s ease, border-color .15s ease; }
.primary-button:hover, .outline-button:hover, .secondary-button:hover { transform: translateY(-1px); }
.primary-button { border: 1px solid var(--green-950); color: var(--white); background: var(--green-950); }
.primary-button:hover { background: var(--green-900); }
.secondary-button { border: 1px solid #b9c2bd; color: var(--green-950); background: var(--white); }
.login-button { width: 100%; height: 58px; margin-top: 30px; font-size: 18px; }
.login-help { margin: 18px 0 0; color: var(--muted); text-align: center; }
.form-error { min-height: 20px; margin: 9px 0 0; color: var(--danger); font-size: 13px; }

.app-view { min-height: 100vh; display: grid; grid-template-columns: 220px minmax(0, 1fr); }
.sidebar { position: fixed; z-index: 20; inset: 0 auto 0 0; width: 220px; display: flex; flex-direction: column; overflow: hidden; color: var(--white); background: var(--green-950); }
.sidebar-pattern { opacity: .08; }
.sidebar-brand, .sidebar-nav, .sidebar-logout { position: relative; }
.sidebar-brand { display: grid; justify-items: center; gap: 7px; padding: 28px 20px 34px; color: #f1d08e; }
.sidebar-brand svg { width: 84px; height: 62px; }
.sidebar-brand strong { color: var(--white); font-size: 18px; letter-spacing: .04em; }
.sidebar-nav { display: grid; gap: 8px; padding: 0 10px; }
.nav-item, .sidebar-logout { display: flex; align-items: center; gap: 13px; width: 100%; min-height: 52px; padding: 0 18px; border: 0; border-radius: 5px; color: rgba(255,255,255,.78); background: transparent; font-size: 15px; text-align: left; }
.nav-item svg, .sidebar-logout svg { width: 21px; height: 21px; }
.nav-item.active, .nav-item:hover, .sidebar-logout:hover { color: var(--white); background: rgba(255,255,255,.12); }
.sidebar-logout { margin: auto 10px 20px; width: calc(100% - 20px); }
.main-shell { grid-column: 2; min-width: 0; transition: margin-right .24s ease; }
.topbar { min-height: 82px; display: flex; align-items: center; justify-content: space-between; padding: 16px 32px; border-bottom: 1px solid var(--line); }
.topbar p { margin: 0 0 4px; color: var(--muted); font-size: 13px; }
.topbar h1 { margin: 0; font-size: 24px; }
.topbar-user { display: flex; align-items: center; gap: 11px; color: var(--muted); font-size: 14px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #2c936f; box-shadow: 0 0 0 4px #e1f2eb; }
.status-dot.offline { background: #a33c31; box-shadow: 0 0 0 4px #f7e8e5; }
.content { padding: 30px 32px 48px; }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.summary-card { min-height: 112px; display: flex; align-items: center; gap: 18px; padding: 20px; border: 1px solid var(--line); border-radius: 6px; background: var(--white); }
.summary-card > svg { width: 38px; height: 38px; color: var(--green-700); }
.summary-card span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 14px; }
.summary-card strong { color: var(--green-900); font-size: 31px; font-weight: 650; }
.summary-card .status-copy { color: var(--ink); font-size: 19px; }
.summary-card .status-copy.online { color: var(--green-700); }
.summary-card .status-copy.offline { color: var(--danger); }
.summary-card small { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.device-section { margin-top: 38px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 15px; }
.section-heading h2 { margin: 0; font-size: 20px; }
.section-heading p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.outline-button { display: inline-flex; align-items: center; gap: 8px; padding: 0 16px; border: 1px solid var(--green-700); color: var(--green-900); background: var(--white); }
.outline-button svg { width: 19px; height: 19px; }
.outline-button:hover { background: var(--green-100); }
.table-frame { position: relative; min-height: 480px; overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 16px 18px; border-bottom: 1px solid var(--line); font-size: 14px; text-align: left; white-space: nowrap; }
th { color: #3a423d; background: #fbfcfb; font-size: 13px; font-weight: 700; }
td { color: #3c4540; }
td { white-space: pre-line; }
.status-label { color: var(--muted); }
.enabled { color: var(--green-700); font-weight: 700; }
.disabled { color: var(--muted); }
.event-failed { color: var(--danger); font-weight: 700; }
.row-actions { min-width: 120px; vertical-align: middle; text-align: center; white-space: nowrap; }
.row-action { min-width: 44px; padding: 6px 9px; border: 1px solid #c8d8d1; border-radius: 4px; color: var(--green-700); background: var(--white); font-size: 13px; line-height: 1.2; }
.row-action + .row-action { margin-left: 8px; }
.row-action:hover { background: var(--green-100); }
.row-action.control { border-color: var(--green-700); color: var(--white); background: var(--green-700); }
.row-action.control:hover { background: var(--green-900); }
.row-action.danger { border-color: #e3c8c4; color: var(--danger); }
.row-action.danger:hover { background: #fbefed; }
.position-table th:last-child, .position-table td:last-child { width: 190px; min-width: 190px; text-align: center; }
.empty-state { min-height: 390px; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.empty-state svg { width: 76px; height: 76px; color: #b5bdb8; stroke-width: 1.5; }
.empty-state h3 { margin: 12px 0 8px; color: #464e49; font-size: 18px; }
.empty-state button { padding: 4px; border: 0; color: var(--green-700); background: transparent; font-weight: 700; }
.empty-state.compact { min-height: 220px; padding: 20px; text-align: center; }
.empty-state p { margin: 5px 0 0; font-size: 13px; }
.hall-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 520px; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.hall-list-panel { padding: 14px; border-right: 1px solid var(--line); background: var(--soft); }
.hall-cards { display: grid; gap: 10px; }
.hall-card { overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: var(--white); }
.hall-card.active { border-color: var(--green-700); box-shadow: 0 0 0 2px rgba(18, 107, 82, .1); }
.hall-select { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; padding: 15px; border: 0; color: var(--ink); background: transparent; text-align: left; }
.hall-select strong { font-size: 15px; }
.hall-select span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.hall-actions { display: flex; gap: 12px; padding: 0 15px 12px; }
.position-panel { min-width: 0; padding: 18px; }
.position-heading { min-height: 54px; display: flex; align-items: start; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.position-heading h3 { margin: 0; font-size: 19px; }
.position-heading p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.position-heading .outline-button:disabled { cursor: not-allowed; opacity: .45; transform: none; }
.position-table { min-height: 420px; }
.device-drawer { position: fixed; z-index: 50; inset: 0 0 0 auto; width: min(400px, 100vw); display: flex; flex-direction: column; padding: 0 28px 28px; border-left: 1px solid var(--line); background: var(--white); box-shadow: var(--shadow); transform: translateX(102%); transition: transform .24s ease; }
.device-drawer.open { transform: translateX(0); }
.drawer-backdrop { position: fixed; z-index: 40; inset: 0; background: rgba(12, 26, 21, .08); }
.drawer-header { min-height: 82px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.drawer-header h2 { margin: 0; font-size: 21px; }
.device-form { flex: 1; display: flex; flex-direction: column; }
.form-fields { padding-bottom: 12px; }
.device-form input, .device-form select, .device-form textarea { width: 100%; border: 1px solid #cbd2ce; border-radius: 5px; color: var(--ink); background: var(--white); }
.device-form input, .device-form select { height: 48px; padding: 0 13px; }
.device-form textarea { padding: 13px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.check-label { display: flex !important; align-items: center; gap: 10px; margin-top: 26px !important; cursor: pointer; }
.device-form .check-label input { width: 18px; height: 18px; margin: 0; accent-color: var(--green-700); }
.drawer-actions { display: grid; grid-template-columns: 1fr 1.35fr; gap: 12px; margin-top: auto; padding-top: 28px; }
.toast { position: fixed; z-index: 80; right: 24px; bottom: 24px; max-width: min(360px, calc(100vw - 48px)); padding: 13px 18px; border-radius: 5px; color: var(--white); background: var(--green-950); box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 980px) {
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .login-view { grid-template-columns: 36% 1fr; }
  .login-brand { padding: 32px; }
  .hall-layout { grid-template-columns: 1fr; }
  .hall-list-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .hall-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1101px) {
  .app-view.drawer-open .main-shell { margin-right: 400px; }
}

@media (min-width: 1101px) and (max-width: 1350px) {
  .app-view.drawer-open .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .login-view { grid-template-columns: 1fr; }
  .login-brand { min-height: 220px; padding: 28px; }
  .brand-lattice { background-size: 72px; }
  .temple-mark { width: 130px; }
  .login-brand h1 { font-size: 25px; }
  .login-panel { padding: 38px 22px; place-items: start center; }
  .login-form h2 { margin-bottom: 32px; font-size: 29px; }
  .app-view { display: block; }
  .sidebar { position: relative; width: 100%; height: auto; min-height: 64px; display: flex; flex-direction: row; align-items: center; padding: 8px 14px; }
  .sidebar-brand { display: flex; gap: 10px; padding: 0; }
  .sidebar-brand svg { width: 42px; height: 38px; }
  .sidebar-brand strong { font-size: 15px; }
  .sidebar-nav { display: none; }
  .sidebar-logout { width: auto; min-height: 42px; margin: 0 0 0 auto; padding: 0 10px; }
  .sidebar-logout span { display: none; }
  .main-shell { grid-column: auto; }
  .topbar { min-height: 72px; padding: 13px 18px; }
  .topbar p { display: none; }
  .topbar h1 { font-size: 21px; }
  .content { padding: 22px 18px 38px; }
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .summary-card { min-height: 92px; gap: 11px; padding: 14px; }
  .summary-card > svg { width: 28px; height: 28px; }
  .summary-card strong { font-size: 24px; }
  .summary-card .status-copy { font-size: 17px; }
  .section-heading { align-items: center; }
  .table-frame { min-height: 420px; }
  th, td { padding: 14px; }
  .form-grid, .form-grid.two { grid-template-columns: 1fr; gap: 0; }
  .hall-cards { grid-template-columns: 1fr; }
  .position-panel { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
.section-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.enrollment-dialog { width: min(580px, calc(100vw - 32px)); max-height: calc(100dvh - 40px); overflow: auto; padding: 28px; border: 1px solid #dde5df; border-radius: 16px; color: #17392d; background: #fff; box-shadow: 0 24px 80px #10251d30; }
.enrollment-dialog::backdrop { background: #132a235e; }
.enrollment-heading, .enrollment-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.enrollment-heading h2 { margin: 0; }
.enrollment-dialog label { display: block; margin: 16px 0 8px; }
.enrollment-dialog select { width: 100%; min-height: 44px; border: 1px solid #d9e1dc; border-radius: 8px; padding: 8px; background: white; color: #17392d; }
.enrollment-help, #enrollmentStatus { font-size: 14px; line-height: 1.7; color: #53665c; }
.enrollment-card { margin-top: 20px; padding: 20px; background: #f0f6f2; border-radius: 12px; }
.enrollment-card span { display: block; font-size: 13px; }
.enrollment-card strong { display: block; margin-top: 8px; font-size: 30px; letter-spacing: 1px; overflow-wrap: anywhere; }
.enrollment-card p { margin-bottom: 0; font-size: 12px; overflow-wrap: anywhere; }
.enrollment-dialog [hidden] { display: none !important; }
.enrollment-dialog button:disabled { opacity: .5; cursor: not-allowed; }
.enrollment-actions { margin-top: 20px; }
