:root {
  --ink: #20332d;
  --muted: #687a74;
  --line: #dfe8e4;
  --surface: #ffffff;
  --canvas: #f4f7f6;
  --forest: #173e34;
  --forest-2: #225749;
  --mint: #43b77d;
  --mint-soft: #e8f6ef;
  --amber: #c78319;
  --amber-soft: #fff3dd;
  --red: #c34545;
  --red-soft: #fdecec;
  --navy: #263d4d;
  --radius: 14px;
  --shadow: 0 12px 34px rgba(25, 57, 47, .08);
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--ink); background: var(--canvas); }
body { margin: 0; min-width: 320px; font-size: 16px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(1.75rem, 4vw, 2.35rem); letter-spacing: -.035em; }
h2 { margin-bottom: 6px; font-size: 1.25rem; }
.muted { color: var(--muted); }
.eyebrow { margin-bottom: 8px; color: var(--mint); font-size: .75rem; font-weight: 800; letter-spacing: .14em; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.brand-lockup { display: flex; align-items: center; gap: 12px; font-size: 1.05rem; }
.brand-lockup small { display: block; margin-top: 2px; color: #a8c0b8; font-size: .75rem; font-weight: 500; }
.brand-mark { display: inline-flex; align-items: end; gap: 3px; width: 30px; height: 30px; padding: 6px; border-radius: 8px; background: var(--mint); }
.brand-mark i { display: block; width: 4px; border-radius: 4px; background: var(--forest); }
.brand-mark i:nth-child(1) { height: 8px; }
.brand-mark i:nth-child(2) { height: 16px; }
.brand-mark i:nth-child(3) { height: 12px; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; min-height: 72px; padding: 12px clamp(20px, 4vw, 56px); color: white; background: var(--forest); box-shadow: 0 4px 18px rgba(10, 35, 28, .16); }
.topbar-actions { display: flex; align-items: center; gap: 18px; }
.engine-state { display: inline-flex; align-items: center; gap: 8px; color: #d4e5df; font-size: .875rem; }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: #65dc9c; box-shadow: 0 0 0 5px rgba(101, 220, 156, .13); }

.page-shell { width: min(1480px, calc(100% - 40px)); margin: 0 auto; padding: 38px 0 44px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.page-heading p:last-child { margin-bottom: 0; }
.btn { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; gap: 7px; padding: 0 17px; border: 1px solid transparent; border-radius: 9px; font-weight: 700; transition: transform .15s, background .15s, border-color .15s; }
.btn:hover { transform: translateY(-1px); }
.btn:disabled { cursor: wait; opacity: .62; transform: none; }
.btn-primary { color: #fff; background: var(--forest-2); box-shadow: 0 8px 16px rgba(34, 87, 73, .18); }
.btn-primary:hover { background: var(--forest); }
.btn-secondary { color: var(--forest); background: var(--mint-soft); border-color: #c9e8d9; }
.btn-ghost { color: inherit; background: transparent; border-color: var(--line); }
.topbar .btn-ghost { color: #e8f3ef; border-color: rgba(255,255,255,.24); }
.btn-danger { color: white; background: var(--red); }
.btn-full { width: 100%; margin-top: 8px; }

.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; margin-bottom: 22px; }
.metric-card { display: flex; align-items: center; gap: 15px; min-height: 126px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 8px 24px rgba(28, 58, 49, .045); }
.metric-card small, .metric-card span { display: block; color: var(--muted); font-size: .78rem; }
.metric-card strong { display: block; margin: 3px 0 2px; font-size: 2rem; line-height: 1; }
.metric-icon { display: grid !important; flex: 0 0 46px; height: 46px; place-items: center; border-radius: 12px; font-size: 1.35rem !important; font-weight: 800; }
.metric-total .metric-icon { color: var(--navy); background: #eaf0f4; }
.metric-up .metric-icon { color: #147146; background: var(--mint-soft); }
.metric-warning .metric-icon { color: #a4680a; background: var(--amber-soft); }
.metric-down .metric-icon { color: #ac3232; background: var(--red-soft); }

.monitor-card { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.monitor-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.monitor-toolbar p { margin-bottom: 0; font-size: .88rem; }
.filters { display: flex; gap: 10px; }
.search-box { display: flex; align-items: center; gap: 8px; min-width: 240px; height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: #fafcfb; }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
select, input { min-height: 42px; padding: 0 12px; border: 1px solid #cedbd6; border-radius: 8px; color: var(--ink); background: #fff; }
input:focus, select:focus { outline: 3px solid rgba(67,183,125,.18); border-color: var(--mint); }
.table-wrapper { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 13px 16px; color: #687a74; background: #f7f9f8; font-size: .75rem; font-weight: 800; letter-spacing: .04em; text-align: left; text-transform: uppercase; white-space: nowrap; }
td { padding: 16px; border-top: 1px solid #edf1ef; vertical-align: middle; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: #fafcfb; }
.sensor-name { display: block; max-width: 260px; overflow: hidden; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.sensor-location { display: block; max-width: 260px; margin-top: 3px; overflow: hidden; color: var(--muted); font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .9rem; }
.status-pill { display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; border-radius: 999px; font-size: .75rem; font-weight: 800; white-space: nowrap; }
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-UP { color: #17764b; background: var(--mint-soft); }
.status-DOWN { color: #b23737; background: var(--red-soft); }
.status-WARNING { color: #a36608; background: var(--amber-soft); }
.status-PENDING, .status-PAUSED { color: #60716b; background: #edf1ef; }
.latency { font-weight: 750; }
.availability { min-width: 120px; }
.availability-progress { display: block; width: 94px; height: 5px; margin-top: 6px; overflow: hidden; border: 0; border-radius: 6px; background: #e7ecea; accent-color: var(--mint); }
.availability-progress::-webkit-progress-bar { border-radius: 6px; background: #e7ecea; }
.availability-progress::-webkit-progress-value { border-radius: 6px; background: var(--mint); }
.availability-progress::-moz-progress-bar { border-radius: 6px; background: var(--mint); }
.availability-warn { accent-color: var(--amber); }
.availability-warn::-webkit-progress-value, .availability-warn::-moz-progress-bar { background: var(--amber); }
.availability-bad { accent-color: var(--red); }
.availability-bad::-webkit-progress-value, .availability-bad::-moz-progress-bar { background: var(--red); }
.date-cell { min-width: 152px; color: var(--muted); font-size: .82rem; }
.action-group { display: flex; justify-content: flex-end; gap: 4px; }
.icon-button { display: inline-grid; width: 36px; height: 36px; place-items: center; border: 1px solid transparent; border-radius: 8px; color: #52645e; background: transparent; font-size: 1.08rem; }
.icon-button:hover { border-color: var(--line); background: #f2f6f4; }
.icon-button.danger:hover { color: var(--red); background: var(--red-soft); }
.table-state, .empty-state { padding: 56px 24px; color: var(--muted); text-align: center; }
.empty-state > span { display: grid; width: 52px; height: 52px; margin: 0 auto 14px; place-items: center; border-radius: 15px; color: var(--forest-2); background: var(--mint-soft); font-size: 1.6rem; }
.empty-state h3 { margin-bottom: 6px; color: var(--ink); }
.empty-state .btn { margin-top: 8px; }
.operational-note { margin: 16px 4px 0; color: var(--muted); font-size: .82rem; line-height: 1.5; }

.modal { width: min(720px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 0; border-radius: 16px; color: var(--ink); background: transparent; box-shadow: 0 24px 70px rgba(10, 34, 27, .25); }
.modal::backdrop { background: rgba(15, 35, 29, .56); backdrop-filter: blur(3px); }
.modal-wide { width: min(920px, calc(100% - 28px)); }
.modal-small { width: min(440px, calc(100% - 28px)); text-align: center; }
.modal-card { padding: 26px; border-radius: 16px; background: white; }
.modal-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.modal-heading p:last-child { margin-bottom: 0; }
.modal-heading .icon-button { font-size: 1.5rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; }
.form-grid label { display: grid; gap: 7px; font-size: .86rem; font-weight: 700; }
.toggle-row { display: flex; align-items: center; gap: 11px; margin-top: 20px; padding: 13px; border-radius: 10px; background: #f6f9f8; }
.toggle-row input { min-height: auto; accent-color: var(--forest-2); }
.toggle-row span { display: grid; }
.toggle-row small { margin-top: 2px; color: var(--muted); font-weight: 400; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 24px; }
.form-alert { margin: 16px 0; padding: 11px 13px; border: 1px solid #f2c9c9; border-radius: 8px; color: #9f3030; background: var(--red-soft); font-size: .85rem; }
.danger-symbol { display: grid; width: 48px; height: 48px; margin: 0 auto 14px; place-items: center; border-radius: 50%; color: var(--red); background: var(--red-soft); font-size: 1.35rem; font-weight: 800; }
.modal-small .modal-actions { justify-content: center; }
.history-chart { min-height: 160px; margin-bottom: 20px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #f9fbfa; }
.history-chart svg { display: block; width: 100%; height: 136px; }
.history-list-wrap { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.history-list-wrap td { padding: 12px 14px; font-size: .84rem; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 60; max-width: min(390px, calc(100% - 44px)); padding: 13px 17px; border-radius: 10px; color: white; background: var(--forest); box-shadow: 0 15px 40px rgba(13, 39, 31, .25); font-weight: 650; }
.toast.error { background: #9e3535; }

.login-page { min-height: 100vh; background: #eef3f1; }
.login-shell { display: grid; min-height: 100vh; grid-template-columns: minmax(360px, .9fr) 1.1fr; }
.login-brand { display: flex; flex-direction: column; justify-content: space-between; padding: clamp(34px, 6vw, 72px); color: white; background: linear-gradient(145deg, #12372e 0%, #1d5243 70%, #286855 100%); }
.login-brand h1 { margin-bottom: 18px; font-size: clamp(2.4rem, 5vw, 4.4rem); line-height: 1.03; }
.login-copy { max-width: 530px; color: #c9ded7; font-size: 1.05rem; line-height: 1.65; }
.login-footnote { margin: 0; color: #adc8bf; font-size: .8rem; }
.login-panel { display: grid; place-items: center; padding: 30px; }
.login-form { width: min(430px, 100%); padding: clamp(28px, 5vw, 46px); border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: var(--shadow); }
.login-form h2 { margin-bottom: 8px; font-size: 1.8rem; }
.login-form > label { display: block; margin: 19px 0 7px; font-size: .86rem; font-weight: 750; }
.login-form > input:not([type="hidden"]) { width: 100%; }
.mobile-brand { display: none; margin-bottom: 34px; color: var(--forest); font-weight: 800; }

@media (max-width: 1050px) {
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .monitor-toolbar { align-items: stretch; flex-direction: column; }
  .filters { width: 100%; }
  .search-box { flex: 1; }
}

@media (max-width: 760px) {
  .topbar { position: static; }
  .engine-state, .brand-lockup small { display: none; }
  .page-shell { width: min(100% - 24px, 1480px); padding-top: 25px; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .page-heading .btn { align-self: start; }
  .metrics-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card { min-height: 112px; padding: 14px; }
  .metric-icon { flex-basis: 38px; height: 38px; }
  .filters { flex-direction: column; }
  .search-box, .filters select { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .mobile-brand { display: flex; }
}

@media (max-width: 470px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .topbar { padding-inline: 14px; }
  .topbar .btn { padding-inline: 11px; font-size: .82rem; }
  .modal-card { padding: 20px; }
}

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