:root {
  color-scheme: light;
  --ink: #17201d;
  --muted: #68736f;
  --line: #dce3df;
  --surface: #ffffff;
  --canvas: #f4f6f4;
  --forest: #183b32;
  --green: #168568;
  --green-soft: #e7f3ee;
  --blue: #3f6f9d;
  --blue-soft: #eaf1f7;
  --coral: #c95b4b;
  --coral-soft: #f9ebe8;
  --gold: #b9842d;
  --gold-soft: #f7f0e3;
  --shadow: 0 18px 50px rgba(24, 54, 45, .1);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; touch-action: manipulation; }
body { min-width: 320px; min-height: 100vh; margin: 0; color: var(--ink); background: var(--canvas); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(22, 133, 104, .22); outline-offset: 2px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

.login-page { background: var(--surface); }
.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 1.05fr) minmax(420px, .95fr); }
.login-brand { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; padding: clamp(50px, 8vw, 120px); color: white; background: var(--forest); }
.brand-symbol { width: 64px; height: 64px; display: grid; place-items: center; border-radius: 8px; color: var(--forest); background: #b8ddcd; }
.brand-symbol svg { width: 30px; height: 30px; }
.login-brand p { margin: 30px 0 4px; color: #b8cec6; font-size: 13px; font-weight: 800; letter-spacing: 0; }
.login-brand h1 { margin: 0; font-size: 64px; line-height: 1; letter-spacing: 0; }
.login-brand > span { margin-top: 14px; color: #cbd8d3; font-size: 16px; }
.login-form-section { width: min(430px, calc(100% - 48px)); margin: auto; }
.login-form { display: grid; }
.form-heading { margin-bottom: 30px; }
.form-heading p, .page-header p, .section-heading p { margin: 0 0 5px; color: var(--green); font-size: 12px; font-weight: 800; }
.form-heading h2 { margin: 0; font-size: 30px; }
.login-form > label { margin: 0 0 8px; color: #39453f; font-size: 14px; font-weight: 700; }
.login-form > label:not(:first-of-type) { margin-top: 20px; }
.input-wrap { height: 48px; display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center; border: 1px solid #cbd4d0; border-radius: 7px; background: white; }
.input-wrap:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(22, 133, 104, .12); }
.input-wrap > svg { margin-left: 14px; color: var(--muted); }
.input-wrap input { min-width: 0; height: 100%; padding: 0 13px 0 4px; border: 0; outline: 0; color: var(--ink); background: transparent; }
.password-wrap { grid-template-columns: 44px minmax(0, 1fr) 44px; }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 6px; color: var(--muted); background: transparent; }
.icon-button:hover { color: var(--ink); background: #edf1ef; }
.form-error { min-height: 22px; margin: 12px 0; color: #b84739; font-size: 13px; }
.primary-button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 18px; border: 1px solid var(--forest); border-radius: 6px; color: white; background: var(--forest); font-weight: 750; text-decoration: none; }
.primary-button:hover { background: #245247; }
.primary-button:disabled { cursor: wait; opacity: .58; }
.full-button { width: 100%; }

.admin-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 20; width: 230px; display: flex; flex-direction: column; padding: 25px 18px; color: #f4f8f6; background: var(--forest); }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 30px; }
.brand-symbol.small { width: 40px; height: 40px; flex: 0 0 auto; color: var(--forest); }
.brand-symbol.small svg { width: 21px; height: 21px; }
.sidebar-brand strong, .sidebar-brand small { display: block; }
.sidebar-brand strong { font-size: 13px; }
.sidebar-brand small { margin-top: 2px; color: #b9ccc5; font-size: 12px; }
.sidebar-nav { display: grid; gap: 6px; }
.sidebar-nav a, .logout-button { height: 44px; display: flex; align-items: center; gap: 11px; padding: 0 13px; border: 0; border-radius: 6px; color: #bdcec8; background: transparent; font-size: 14px; font-weight: 700; text-decoration: none; }
.sidebar-nav a.active, .sidebar-nav a:hover, .logout-button:hover { color: white; background: rgba(255, 255, 255, .1); }
.logout-button { width: 100%; margin-top: auto; }
.admin-main { width: calc(100% - 230px); min-height: 100vh; margin-left: 230px; padding: 36px clamp(28px, 3.2vw, 64px) 70px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.page-header h1 { margin: 0; font-size: 29px; }
.header-account { display: flex; align-items: center; gap: 11px; }
.account-avatar { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--forest); font-weight: 800; }
.header-account strong, .header-account small { display: block; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-account small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.page-section { scroll-margin-top: 24px; }
.page-section + .page-section { margin-top: 50px; padding-top: 36px; border-top: 1px solid var(--line); }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 36px; }
.metric { min-width: 0; display: flex; align-items: center; gap: 14px; padding: 19px 20px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.metric-icon { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 7px; }
.metric-icon.green { color: var(--green); background: var(--green-soft); }
.metric-icon.blue { color: var(--blue); background: var(--blue-soft); }
.metric-icon.coral { color: var(--coral); background: var(--coral-soft); }
.metric-icon.gold { color: var(--gold); background: var(--gold-soft); }
.metric strong, .metric small { display: block; }
.metric strong { font-size: 23px; }
.metric small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.section-heading h2 { margin: 0; font-size: 20px; }
.heading-actions { display: flex; align-items: center; gap: 14px; }
.count-label { color: var(--muted); font-size: 12px; }
.tool-list, .user-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); gap: 14px; }
.tool-card { min-width: 0; display: grid; gap: 18px; padding: 22px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.tool-card-heading { min-width: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.tool-identity { min-width: 0; display: flex; align-items: center; gap: 14px; }
.tool-mark { width: 48px; height: 48px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 8px; color: var(--gold); background: var(--gold-soft); }
.tool-title-row { display: flex; align-items: center; gap: 9px; }
.tool-title-row h3 { margin: 0; font-size: 17px; }
.tool-identity p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.tool-type { display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; padding: 6px 8px; border-radius: 5px; color: #57625e; background: #f0f3f1; font-size: 11px; font-weight: 700; }
.tool-type svg { width: 15px; height: 15px; }
.status-badge { padding: 3px 7px; border-radius: 4px; font-size: 10px; font-weight: 800; }
.status-badge.enabled { color: #126b55; background: var(--green-soft); }
.status-badge.disabled { color: #a5483b; background: var(--coral-soft); }
.status-badge.missing { color: #72541d; background: var(--gold-soft); }
.tool-route { min-width: 0; min-height: 42px; display: flex; align-items: center; gap: 10px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); background: #f7f9f8; font-size: 12px; }
.tool-route svg { width: 17px; height: 17px; flex: 0 0 auto; }
.tool-route span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-route strong { color: var(--ink); }
.tool-card-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.card-actions { display: flex; align-items: center; gap: 8px; }
.toggle-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.toggle-control input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { position: relative; width: 36px; height: 20px; border-radius: 10px; background: #c9d1cd; transition: background 150ms ease; }
.toggle-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgba(0,0,0,.18); transition: transform 150ms ease; }
.toggle-control input:checked + .toggle-track { background: var(--green); }
.toggle-control input:checked + .toggle-track::after { transform: translateX(16px); }
.toggle-control input:focus-visible + .toggle-track { outline: 3px solid rgba(22, 133, 104, .2); outline-offset: 2px; }
.toggle-control input:disabled + .toggle-track { opacity: .55; }
.icon-button.bordered { flex: 0 0 auto; border: 1px solid var(--line); background: white; }
.icon-button:disabled { cursor: not-allowed; opacity: .42; }
.danger-icon-button { color: #b54c3f; }
.danger-icon-button:hover { color: #9d3f34; background: var(--coral-soft); }
.secondary-button, .danger-button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 17px; border-radius: 6px; font-weight: 750; }
.secondary-button { border: 1px solid #cbd4d0; color: #33403b; background: white; }
.secondary-button:hover { border-color: #aebbb5; background: #f5f7f6; }
.danger-button { border: 1px solid #b94d40; color: white; background: #b94d40; }
.danger-button:hover { background: #a54136; }
.loading-state { min-height: 120px; display: flex; align-items: center; justify-content: center; gap: 10px; grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.loading-state span { width: 17px; height: 17px; border: 2px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { min-height: 150px; display: grid; place-content: center; gap: 7px; grid-column: 1 / -1; border: 1px dashed #cbd4d0; border-radius: 8px; color: var(--muted); background: rgba(255,255,255,.5); text-align: center; }
.empty-state strong { color: var(--ink); font-size: 15px; }
.empty-state span { font-size: 12px; }
.user-card { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 18px 22px; padding: 22px; border: 1px solid var(--line); border-radius: 8px; background: white; }
.user-identity { min-width: 0; display: flex; align-items: center; gap: 13px; }
.user-avatar { width: 44px; height: 44px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: white; background: var(--forest); font-weight: 800; }
.user-title { min-width: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.user-title h3 { max-width: 240px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.user-identity p { margin: 6px 0 0; color: var(--muted); font-size: 11px; }
.role-badge, .current-badge { padding: 3px 7px; border-radius: 4px; font-size: 10px; font-weight: 800; }
.role-badge.admin { color: #126b55; background: var(--green-soft); }
.role-badge.user { color: #476a8b; background: var(--blue-soft); }
.current-badge { color: #72541d; background: var(--gold-soft); }
.user-meta { grid-column: 1 / 2; padding-left: 57px; }
.user-meta small, .user-meta strong { display: block; }
.user-meta small { color: var(--muted); font-size: 10px; }
.user-meta strong { margin-top: 4px; font-size: 12px; }
.user-card > .card-actions { grid-area: 1 / 2 / 3 / 3; }
.toast { position: fixed; top: 18px; left: 50%; z-index: 100; max-width: calc(100vw - 32px); padding: 11px 18px; border-radius: 6px; color: white; background: #26332e; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, -14px); transition: 160ms ease; font-size: 13px; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

.modal-open { overflow: hidden; }
.modal-backdrop { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px; background: rgba(12, 28, 23, .48); }
.modal { width: min(540px, 100%); max-height: calc(100vh - 48px); overflow: auto; border-radius: 8px; background: white; box-shadow: 0 24px 70px rgba(16, 38, 31, .23); }
.compact-modal { width: min(460px, 100%); }
.modal-header { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-header p { margin: 0 0 4px; color: var(--green); font-size: 11px; font-weight: 800; }
.modal-header h2, .confirm-modal .modal-body h2 { margin: 0; font-size: 20px; }
.modal-body { display: grid; padding: 22px; }
.modal-body > label { display: flex; justify-content: space-between; gap: 12px; margin: 0 0 7px; color: #39453f; font-size: 12px; font-weight: 750; }
.modal-body > label:not(:first-child) { margin-top: 17px; }
.modal-body > label small { color: var(--muted); font-weight: 500; }
.text-input, .modal-slug-input, .modal-path-input { width: 100%; min-width: 0; height: 44px; border: 1px solid #cbd4d0; border-radius: 6px; color: var(--ink); background: white; }
.text-input { padding: 0 12px; }
select.text-input { cursor: pointer; }
.text-input:disabled { color: #7e8984; background: #f0f3f1; }
.text-input:focus, .modal-slug-input:focus-within, .modal-path-input:focus-within { border-color: var(--green); outline: 0; box-shadow: 0 0 0 3px rgba(22, 133, 104, .11); }
.modal-slug-input, .modal-path-input { display: grid; grid-template-columns: auto minmax(90px, 1fr); overflow: hidden; }
.modal-slug-input span, .modal-path-input span { display: flex; align-items: center; padding: 0 11px; color: var(--muted); background: #f2f5f3; font-size: 11px; white-space: nowrap; }
.modal-slug-input input, .modal-path-input input { min-width: 0; padding: 0 11px; border: 0; outline: 0; color: var(--ink); background: white; }
.password-input { position: relative; }
.password-input .text-input { padding-right: 48px; }
.password-input .icon-button { position: absolute; top: 2px; right: 2px; }
.check-option { align-items: center; justify-content: flex-start !important; gap: 11px !important; padding: 13px; border: 1px solid var(--line); border-radius: 6px; background: #f7f9f8; cursor: pointer; }
.check-option input { width: 17px; height: 17px; flex: 0 0 auto; accent-color: var(--green); }
.check-option span, .check-option b, .check-option small { display: block; }
.check-option small { margin-top: 3px; }
.role-description { margin-top: 10px; padding: 10px 12px; border-left: 3px solid #8fb5a6; color: var(--muted); background: #f3f7f5; font-size: 11px; }
.modal-body .form-error { margin-bottom: 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--line); background: #fafbfa; }
.danger-symbol { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; color: #b94d40; background: var(--coral-soft); }
.confirm-modal .modal-header { border-bottom: 0; padding-bottom: 0; }
.confirm-modal .modal-body { padding-top: 12px; }
.confirm-modal .modal-body p { margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.65; }

.status-page { display: grid; place-items: center; background: white; }
.status-content { width: min(460px, calc(100% - 40px)); text-align: center; }
.status-icon { width: 58px; height: 58px; display: grid; place-items: center; margin: 0 auto 20px; border-radius: 50%; color: var(--coral); background: var(--coral-soft); }
.status-icon.placeholder-icon { color: var(--gold); background: var(--gold-soft); }
.status-icon svg { width: 27px; height: 27px; }
.status-content h1 { margin: 0; font-size: 28px; }
.status-content p { margin: 10px 0 0; color: var(--muted); }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .login-shell { display: block; }
  .login-brand { min-height: 220px; padding: 34px 26px; justify-content: flex-end; }
  .login-brand p { margin-top: 18px; }
  .login-brand h1 { font-size: 42px; }
  .login-brand > span { margin-top: 8px; font-size: 13px; }
  .brand-symbol { width: 48px; height: 48px; }
  .login-form-section { width: min(100% - 40px, 440px); padding: 28px 0 44px; }
  .form-heading h2 { font-size: 24px; }
  .sidebar { position: static; width: 100%; height: 68px; flex-direction: row; align-items: center; padding: 10px 14px; }
  .sidebar-brand { padding: 0; }
  .sidebar-nav { display: none; }
  .logout-button { width: 42px; height: 42px; margin: 0 0 0 auto; padding: 0; justify-content: center; }
  .logout-button span { display: none; }
  .admin-main { width: 100%; margin-left: 0; padding: 24px 16px 46px; }
  .page-header { margin-bottom: 22px; }
  .page-header h1 { font-size: 23px; }
  .header-account div { display: none; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 28px; }
  .metric { display: grid; justify-items: center; gap: 8px; padding: 14px 6px; text-align: center; }
  .metric-icon { width: 36px; height: 36px; }
  .metric strong { font-size: 20px; }
  .section-heading { align-items: flex-start; }
  .heading-actions { align-items: flex-end; flex-direction: column-reverse; gap: 8px; }
  .primary-button, .secondary-button { padding: 0 13px; }
  .tool-card, .user-card { padding: 18px 16px; }
  .tool-card-heading { align-items: flex-start; }
  .tool-type { display: none; }
  .user-card { grid-template-columns: minmax(0, 1fr); }
  .user-meta { grid-column: 1; padding-left: 57px; }
  .user-card > .card-actions { grid-area: auto; justify-content: flex-end; }
  .modal-backdrop { place-items: end center; padding: 0; }
  .modal { width: 100%; max-height: calc(100vh - 28px); border-radius: 8px 8px 0 0; }
}

@media (max-width: 390px) {
  .heading-actions .count-label { display: none; }
  .tool-title-row { align-items: flex-start; flex-direction: column; }
  .tool-route span { font-size: 11px; }
  .toggle-control > span:last-child { display: none; }
  .modal-slug-input { grid-template-columns: minmax(0, 1fr); height: auto; }
  .modal-slug-input span, .modal-slug-input input { height: 42px; }
  .modal-slug-input span { border-bottom: 1px solid var(--line); }
}
