* { box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
       margin: 0; color: #222; background: #f5f5f5; line-height: 1.5; }
header.top-nav { display: flex; justify-content: space-between; align-items: center;
                 padding: 0.75rem 1.5rem; background: #fff; border-bottom: 1px solid #ddd; }
header.top-nav .brand { font-weight: bold; text-decoration: none; color: #222; }
header.top-nav nav a { margin: 0 0.5rem; color: #444; text-decoration: none; }
header.top-nav nav a:hover { color: #06c; }
header.top-nav .user { color: #666; font-size: 0.9em; }
header.top-nav form.inline { display: inline; margin-left: 0.5rem; }

main { max-width: 1100px; margin: 1.5rem auto; padding: 0 1.5rem; }

/* Floating toast container — does not push page content down */
.flash-container {
    position: fixed; top: 70px; right: 20px; z-index: 1000;
    display: flex; flex-direction: column; gap: 0.5rem;
    max-width: min(420px, calc(100vw - 40px)); pointer-events: none;
}
.flash {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.65rem 0.9rem; border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    pointer-events: auto; cursor: pointer;
    transition: opacity 0.3s;
}
.flash-msg { flex: 1; }
.flash-close {
    background: transparent; border: none; cursor: pointer;
    font-size: 1.2em; line-height: 1; padding: 0 0.2rem;
    color: inherit; opacity: 0.7;
}
.flash-close:hover { opacity: 1; }
.flash-error { background: #fee; color: #900; border: 1px solid #fcc; }
.flash-info  { background: #eef; color: #036; border: 1px solid #cce; }

.login-form { max-width: 320px; }
.login-form label { display: block; margin-bottom: 0.75rem; }
.login-form input { width: 100%; padding: 0.5rem; border: 1px solid #bbb; border-radius: 3px; }
.login-form button { padding: 0.5rem 1.5rem; }

table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #ddd; }
th, td { padding: 0.5rem 0.75rem; border-bottom: 1px solid #eee; text-align: left; vertical-align: top; }
/* Long hostnames / pubkeys break inside the cell instead of expanding the
   column and squeezing the action column down to where '详情' has to wrap. */
td a, td code { overflow-wrap: anywhere; }
/* Utility: cells whose content is short atoms (IP, role, time, action button)
   that should always render on one line. */
td.nowrap, th.nowrap { white-space: nowrap; }
th { background: #f0f0f0; }
tr:last-child td { border-bottom: none; }

button, .btn { cursor: pointer; padding: 0.4rem 0.9rem; border: 1px solid #aaa;
               background: #fff; border-radius: 3px; font-size: 0.95em; text-decoration: none; color: #222; display: inline-block;
               white-space: nowrap; }
button:hover, .btn:hover { background: #f0f0f0; }
.btn-primary { background: #06c; color: #fff; border-color: #05a; }
.btn-primary:hover { background: #05a; }
.btn-danger { background: #c33; color: #fff; border-color: #a22; }

.form-row { margin-bottom: 1rem; }
.form-row label { display: block; font-weight: 500; margin-bottom: 0.25rem; }
.form-row input, .form-row select, .form-row textarea {
    width: 100%; max-width: 480px; padding: 0.4rem; border: 1px solid #bbb; border-radius: 3px;
    font-family: inherit; font-size: 1em;
}
.form-row textarea { font-family: ui-monospace, SFMono-Regular, monospace; min-height: 5em; }
.form-actions { margin-top: 1rem; }

.muted { color: #888; font-size: 0.9em; }
code { font-family: ui-monospace, SFMono-Regular, monospace; background: #eee; padding: 1px 4px; border-radius: 2px; }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap; }
.page-header h1 { margin: 0; }
.header-actions { display: flex; align-items: center; gap: 0.7rem; }
.auto-refresh-label { font-size: 0.85em; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin: 1rem 0; }
.card { background: #fff; border: 1px solid #ddd; border-radius: 6px; padding: 1.2rem; text-align: center; }
.card-num { font-size: 2.2em; font-weight: 600; color: #333; }
.card-label { color: #666; font-size: 0.9em; text-transform: uppercase; letter-spacing: 0.05em; }

.role-gateway { color: #06c; font-weight: 600; }
.role-service { color: #393; font-weight: 600; }
.role-device  { color: #960; font-weight: 600; }

.status-active         { color: #393; }
.status-enable         { color: #393; }
.status-disabled       { color: #888; }
.status-disable        { color: #888; }
.status-decommissioned { color: #999; text-decoration: line-through; }

/* iOS-style slide switch (used for host enable/disable) */
.toggle-form { display: inline-flex; align-items: center; gap: 0.5rem; }
button.toggle-switch {
    position: relative; display: inline-block;
    width: 42px; height: 22px; padding: 0; border: none;
    border-radius: 11px; cursor: pointer;
    transition: background-color 0.15s;
}
button.toggle-switch.toggle-enable  { background: #393; }
button.toggle-switch.toggle-disable { background: #bbb; }
button.toggle-switch:hover          { filter: brightness(0.92); }
button.toggle-switch:focus-visible  { outline: 2px solid #06c; outline-offset: 2px; }
.toggle-switch .toggle-slider {
    position: absolute; top: 2px; left: 2px;
    width: 18px; height: 18px;
    background: #fff; border-radius: 50%;
    transition: left 0.15s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.toggle-switch.toggle-enable  .toggle-slider { left: 22px; }
.toggle-switch.toggle-disable .toggle-slider { left: 2px; }


dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.4rem 1rem; }
dl.kv dt { color: #666; }
dl.kv dd { margin: 0; }

.push-pending  { color: #888; font-weight: 500; }
.push-running  { color: #06c; font-weight: 600; }
.push-success  { color: #393; font-weight: 600; }
.push-failed   { color: #c33; font-weight: 600; }

.log-pre { font-family: ui-monospace, SFMono-Regular, monospace;
           background: #1e1e1e; color: #ddd;
           padding: 0.8rem 1rem; border-radius: 4px;
           white-space: pre-wrap; word-break: break-all;
           overflow-x: auto; font-size: 0.85em;
           max-height: 600px; overflow-y: auto; }

.inline-form { display: inline; margin-left: 0.4rem; }

.fresh-install-banner {
    display: flex; justify-content: space-between; align-items: center;
    gap: 1rem; flex-wrap: wrap;
    background: #fffbeb; border: 1px solid #f0c000;
    padding: 1rem 1.2rem; border-radius: 6px; margin-bottom: 1.2rem;
}
.fresh-install-banner .btn-primary { font-size: 1.05em; }

.btn.disabled, button.disabled {
    opacity: 0.5; cursor: not-allowed; pointer-events: none;
    color: #888; background: #eee;
}

.inline-form-add { margin: 0.6rem 0 0; display: inline-block; }
.inline-form-add select { padding: 0.35rem; margin-right: 0.4rem; }

/* Audit log filter bar */
.audit-filter { display: flex; flex-wrap: wrap; gap: 0.6rem 1rem;
                align-items: end; margin-bottom: 1rem;
                padding: 0.7rem 0.9rem; background: #fafafa;
                border: 1px solid #e0e0e0; border-radius: 6px; }
.audit-filter label { display: flex; flex-direction: column; gap: 0.2rem;
                      font-size: 0.85em; color: #555; }
.audit-filter select, .audit-filter input { min-width: 160px; padding: 0.3rem; }
/* .nowrap is now a global utility — see above. */
.audit-table td:nth-child(6) { max-width: 500px; }
.audit-diff { white-space: pre-wrap; word-break: break-all;
              background: #f5f5f5; padding: 0.5rem; border-radius: 3px;
              font-size: 0.85em; max-height: 300px; overflow-y: auto;
              margin-top: 0.4rem; }

.pagination { display: flex; align-items: center; gap: 0.6rem;
              margin-top: 1rem; }

/* Live-stats online indicator */
.status-dot { display: inline-block; width: 9px; height: 9px;
              border-radius: 50%; margin-right: 0.35rem;
              vertical-align: 0.05em; }
.status-dot.status-online { background: #393; box-shadow: 0 0 4px #6c6; }
.status-dot.status-idle   { background: #ec0; }
.status-dot.status-stale  { background: #888; }
.status-dot.status-never  { background: #ddd; border: 1px solid #aaa; }
