@import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap");

:root {
  color-scheme: light;
  --bg: #f0f2ff;
  --surface: #ffffff;
  --surface-muted: #e5e9ff;
  --surface-strong: #cdd5ff;
  --text: #182040;
  --muted: #566084;
  --line: #bdc7f5;
  --accent: #3d5afe;
  --accent-strong: #243fda;
  --accent-soft: #dce2ff;
  --danger: #f52f54;
  --danger-soft: #ffe0e6;
  --danger-badge: #ffe0e6;
  --danger-badge-text: #f52f54;
  --success: #008a43;
  --success-soft: #cefae2;
  --warning: #e58a00;
  --warning-soft: #fff0c2;
  --shadow: 0 12px 28px rgba(61, 90, 254, 0.16);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11152d;
  --surface: #1a2042;
  --surface-muted: #252e61;
  --surface-strong: #384796;
  --text: #f5f6ff;
  --muted: #c1c8f4;
  --line: #5362ad;
  --accent: #3d5afe;
  --accent-strong: #a2afff;
  --accent-soft: #303f91;
  --danger: #ff7088;
  --danger-soft: #572838;
  --danger-badge: #572838;
  --danger-badge-text: #ff7088;
  --success: #77eba1;
  --success-soft: #1b5936;
  --warning: #ffd166;
  --warning-soft: #5a4215;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.32);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Manrope", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent-strong); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.shell { width: min(100% - 40px, 1080px); margin: 0 auto; padding: 26px 0 48px; }
.topbar { align-items: center; display: flex; gap: 16px; justify-content: space-between; margin-bottom: 24px; }
.brand { align-items: center; color: var(--text); display: inline-flex; font-size: 21px; font-weight: 800; gap: 10px; letter-spacing: 0; text-decoration: none; }
.brand-icon { align-items: center; background: var(--accent); border-radius: 8px; color: white; display: inline-flex; font-size: 17px; height: 34px; justify-content: center; width: 34px; }
.icon { display: inline-block; line-height: 1; }
.top-actions { align-items: center; display: flex; gap: 8px; min-width: 0; }
.account-login { align-items: center; display: flex; font-size: 13px; font-weight: 700; gap: 4px; max-width: 180px; min-width: 0; white-space: nowrap; }
.account-login-label { flex: 0 0 auto; }
.account-login-name { overflow: hidden; text-overflow: ellipsis; }

.icon-button, .button {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 40px;
  text-decoration: none;
  transition: background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease, color 150ms ease, transform 150ms ease;
}
.icon-button { background: var(--surface); border-color: var(--line); color: var(--muted); padding: 0; width: 40px; }
.icon-button:hover { background: var(--surface-muted); color: var(--text); transform: translateY(-1px); }
.button { background: var(--accent); box-shadow: 0 2px 5px rgba(61, 90, 254, 0.34); color: white; padding: 0 16px; }
.button:hover { background: var(--accent-strong); box-shadow: 0 5px 13px rgba(61, 90, 254, 0.4); transform: translateY(-1px); }
.button.secondary { background: var(--surface); border-color: var(--line); box-shadow: none; color: var(--text); }
.button.secondary:hover { background: var(--surface-muted); }
.button.danger { background: var(--danger); box-shadow: none; }
.button.small { font-size: 13px; min-height: 34px; padding: 0 11px; }
.button.with-icon { gap: 8px; }
.button:disabled, .icon-button:disabled { cursor: progress; opacity: 0.65; transform: none; }

.nav { display: flex; gap: 4px; margin-bottom: 28px; overflow-x: auto; padding: 3px; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  align-items: center;
  border-radius: 7px;
  color: var(--muted);
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 14px;
  font-weight: 800;
  gap: 8px;
  padding: 9px 13px;
  text-decoration: none;
  transition: background-color 150ms ease, color 150ms ease;
}
.nav a:hover { background: var(--surface-muted); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-strong); }
.nav-icon, .button-icon { display: inline-block; font-size: 16px; line-height: 1; }
.button-icon { color: currentColor; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  padding: 24px;
}
.auth-panel { margin: 11vh auto 0; max-width: 440px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 24px; letter-spacing: 0; line-height: 1.25; margin-bottom: 8px; }
h2 { font-size: 19px; letter-spacing: 0; line-height: 1.35; margin-bottom: 12px; }
.page-title { align-items: center; display: flex; gap: 10px; }
.page-title-icon { color: var(--accent); font-size: 23px; }
.section-title { align-items: center; display: flex; gap: 8px; }
.section-title-icon { color: var(--accent); font-size: 18px; }
.muted { color: var(--muted); }

.notice { background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 0 7px 7px 0; margin-bottom: 18px; padding: 12px 14px; }
.notice.error { background: var(--danger-soft); border-color: var(--danger); }
.notice.warning { background: var(--warning-soft); border-color: var(--warning); }
.form-grid { display: grid; gap: 16px; }
label { display: grid; font-size: 14px; font-weight: 800; gap: 7px; }
input, select { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; color: var(--text); min-height: 42px; padding: 8px 11px; transition: border-color 150ms ease, box-shadow 150ms ease; width: 100%; }
input:hover, select:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }

.open-button { -webkit-appearance: none; -webkit-tap-highlight-color: transparent; align-items: center; appearance: none; background: var(--accent); border: 0; border-radius: 8px; box-shadow: 0 10px 20px rgba(61, 90, 254, 0.32); color: white; display: flex; flex-direction: column; font-size: 28px; font-weight: 800; gap: 10px; justify-content: center; letter-spacing: 0; min-height: 132px; transition: background-color 150ms ease, box-shadow 150ms ease, transform 150ms ease; width: 100%; }
.open-icon { color: white; font-size: 34px; line-height: 1; }
.open-button:disabled { cursor: progress; opacity: 0.7; transform: none; }

@media (hover: hover) {
  .open-button:hover { background: var(--accent-strong); box-shadow: 0 14px 25px rgba(61, 90, 254, 0.44); transform: translateY(-2px); }
}

.status-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.metric { background: var(--surface-muted); border-radius: 7px; padding: 14px; }
.metric strong { display: block; font-size: 18px; margin-top: 3px; }
.filters { align-items: end; display: flex; flex-wrap: wrap; gap: 12px; }
.filters label { flex: 1 1 170px; min-width: 150px; }
.pagination { align-items: center; display: grid; font-size: 14px; grid-template-columns: 40px 1fr 40px; margin-top: 16px; width: 100%; }
.pagination a { font-weight: 800; text-decoration: none; }
.pagination-previous { grid-column: 1; justify-self: start; }
.pagination-next { grid-column: 3; justify-self: end; }
.page-jump { align-items: center; display: flex; font-weight: 700; gap: 8px; grid-column: 2; justify-self: center; }
.page-jump input { min-height: 34px; padding: 4px 8px; width: 72px; }
.check { align-items: center; display: flex; font-weight: 700; gap: 8px; min-height: 42px; }
.check input { min-height: 0; width: auto; }
.table-wrap { border: 1px solid var(--line); border-radius: 7px; overflow: auto; }
.users-table { margin-top: 18px; }
table { border-collapse: collapse; min-width: 620px; width: 100%; }
th, td { border-bottom: 1px solid var(--line); padding: 12px 13px; text-align: left; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-muted) 60%, transparent); }
th { background: var(--surface-muted); color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.tag { background: var(--surface-muted); border-radius: 999px; color: var(--text); display: inline-block; font-size: 11px; font-weight: 800; padding: 3px 8px; }
.tag.ok { background: var(--success-soft); color: var(--success); }
.tag.fail { background: var(--danger-badge); color: var(--danger-badge-text); }
.tag.warn { background: var(--warning-soft); color: var(--warning); }
.open-heading { align-items: center; display: flex; flex-wrap: wrap; gap: 10px 16px; justify-content: space-between; margin-bottom: 12px; }
.open-heading h1, .controller-status { margin-bottom: 0; }
.section-heading { align-items: center; display: flex; flex-wrap: wrap; gap: 10px 16px; justify-content: space-between; margin-bottom: 12px; }
.section-heading h2 { margin-bottom: 0; }
.controller-status-badge { align-items: center; display: inline-flex; gap: 7px; }
.controller-status-badge.online { background: var(--success-soft); color: var(--success); }
.controller-status-badge.offline { background: var(--danger-soft); color: var(--danger); }
.controller-status-dot { background: currentColor; border-radius: 50%; height: 7px; width: 7px; }
.controller-status-badge.online .controller-status-dot { animation: controller-status-pulse 1.2s ease-in-out infinite; }
@keyframes controller-status-pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.user-edit-dialog { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); color: var(--text); padding: 24px; width: min(calc(100% - 32px), 460px); }
.user-edit-dialog::backdrop { background: rgba(10, 14, 32, 0.62); }
.user-edit-dialog-header { align-items: center; display: grid; gap: 16px; grid-template-columns: 40px 1fr 40px; }
.user-edit-dialog-header h2 { grid-column: 2; margin-bottom: 0; text-align: center; }
.user-edit-dialog-header > :first-child { grid-column: 1; }
.user-edit-dialog-header > :last-child { grid-column: 3; }
.user-edit-login { font-size: 18px; font-weight: 800; margin: 16px 0; text-align: center; }
.user-edit-details { margin: 16px 0; }
.user-password-form { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 16px; }
.link-output { background: var(--surface-muted); border: 1px dashed var(--line); border-radius: 7px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; padding: 12px; word-break: break-all; }
.settings-content > .link-output { margin-bottom: 18px; }
.toast { align-items: center; background: var(--text); border-radius: 8px; bottom: 24px; box-shadow: var(--shadow); color: var(--surface); display: flex; gap: 10px; left: 50%; opacity: 0; padding: 14px 16px; pointer-events: none; position: fixed; transform: translate(-50%, 8px); transition: opacity 180ms ease, transform 180ms ease, visibility 0s linear 180ms; visibility: hidden; width: min(calc(100% - 32px), 440px); z-index: 20; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); transition: opacity 180ms ease, transform 180ms ease; visibility: visible; }
.toast-icon { flex: 0 0 auto; font-size: 18px; }
.toast.success { background: #00b955; color: #ffffff; }
.toast.error { background: var(--danger); color: white; }
.app-footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; margin-top: 34px; padding-top: 16px; text-align: center; }

.page-content.page-enter { animation: page-enter 190ms ease-out both; }
.page-content.page-leaving { animation: page-leave 140ms ease-in both; pointer-events: none; }
@keyframes page-enter { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes page-leave { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-4px); } }

@media (max-width: 640px) {
  .shell { padding-top: 16px; width: min(100% - 24px, 1080px); }
  .topbar { gap: 8px; margin-bottom: 18px; }
  .brand { min-width: 0; }
  .top-actions { gap: 6px; }
  .account-login { max-width: calc(100vw - 195px); }
  .nav { margin: 0 -3px 22px; }
  .panel { margin-bottom: 14px; padding: 18px; }
  .auth-panel { margin-top: 7vh; }
  h1 { font-size: 22px; }
  .open-button { font-size: 24px; min-height: 116px; }
  th, td { padding: 10px; }
  .regular-history-table { min-width: 0; table-layout: fixed; }
  .regular-history-table th:first-child, .regular-history-table td:first-child { width: 58%; }
  .regular-history-table th:last-child, .regular-history-table td:last-child { overflow-wrap: anywhere; width: 42%; }
  .regular-history-table .tag { overflow-wrap: normal; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; scroll-behavior: auto !important; transition-duration: 1ms !important; }
}
