:root {
  --canvas: #f4f6fa;
  --surface: #ffffff;
  --surface-soft: #f9fafc;
  --text: #172033;
  --muted: #687289;
  --line: #e2e6ef;
  --accent: #e5183d;
  --accent-dark: #b90f2e;
  --accent-soft: #fff0f3;
  --green: #14965f;
  --green-soft: #e9f8f0;
  --amber: #9a6712;
  --amber-soft: #fff6df;
  --danger: #c5263f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { min-height: 100vh; margin: 0; background: var(--canvas); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
form { margin: 0; }
.muted { color: var(--muted) !important; }

.brand { display: flex; align-items: center; gap: .8rem; }
.brand-mark { display: grid; width: 2.65rem; height: 2.65rem; place-items: center; border-radius: .85rem; color: #fff; background: linear-gradient(145deg, #ff3156, #bb0d2d); box-shadow: 0 .7rem 1.5rem rgba(229,24,61,.22); font-size: 1.15rem; font-weight: 900; font-style: italic; }
.brand div { display: grid; gap: .12rem; }
.brand b { font-size: 1rem; letter-spacing: -.02em; }
.brand small { color: #98a0b2; font-size: .55rem; font-weight: 800; letter-spacing: .13em; }
.kicker { margin: 0; color: var(--accent); font-size: .65rem; font-weight: 900; letter-spacing: .14em; }

.auth-page { display: grid; min-height: 100vh; place-items: center; padding: 2rem; background: radial-gradient(circle at 18% 12%, rgba(229,24,61,.1), transparent 27%), radial-gradient(circle at 85% 85%, rgba(45,91,255,.08), transparent 30%), #f7f8fb; }
.login-card { width: min(30rem, 94vw); padding: 2.7rem; border: 1px solid rgba(221,225,235,.9); border-radius: 1.4rem; background: rgba(255,255,255,.96); box-shadow: 0 2rem 6rem rgba(39,50,79,.14); }
.login-card .brand { margin-bottom: 2.5rem; }
.login-card h1 { margin: .45rem 0 .45rem; font-size: 2rem; letter-spacing: -.045em; }
.login-card > p:not(.kicker) { margin: 0 0 1.6rem; color: var(--muted); line-height: 1.55; }
.login-card form { display: grid; gap: 1rem; }

label { display: grid; gap: .46rem; color: #4e586e; font-size: .75rem; font-weight: 750; }
label small { color: #8b93a5; font-size: .66rem; font-weight: 500; line-height: 1.4; }
input { width: 100%; height: 3rem; padding: 0 .9rem; border: 1px solid #d8dde7; border-radius: .7rem; outline: none; color: var(--text); background: #fff; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(229,24,61,.12); }
input[type="color"] { min-width: 7rem; padding: .28rem; }
.primary, .ghost, .danger, .test-button, .soft-button { display: inline-flex; min-height: 2.65rem; align-items: center; justify-content: center; padding: 0 1rem; border-radius: .68rem; font-size: .74rem; font-weight: 800; }
.primary { border: 0; color: #fff; background: linear-gradient(135deg, #f22549, #c20f30); box-shadow: 0 .65rem 1.3rem rgba(229,24,61,.18); }
.primary:hover { filter: brightness(1.04); transform: translateY(-1px); }
.ghost, .soft-button { border: 1px solid var(--line); color: #455069; background: #fff; }
.ghost:hover, .soft-button:hover { border-color: #cfd5e2; background: #f7f8fb; }
.danger { border: 1px solid #f4cad2; color: var(--danger); background: #fff5f7; }
.test-button { border: 1px solid #bddfce; color: #15744e; background: #effaf4; }
.alert { margin: 0 0 1.2rem; padding: .95rem 1rem; border: 1px solid #bfe4d0; border-radius: .8rem; color: #176b4a; background: var(--green-soft); font-size: .8rem; line-height: 1.45; }
.alert.error { border-color: #f2c1ca; color: #9f1d34; background: #fff1f4; }
.alert.warning { border-color: #f0d79d; color: var(--amber); background: var(--amber-soft); }

.sidebar { position: fixed; z-index: 5; top: 0; bottom: 0; left: 0; display: grid; width: 16rem; grid-template-rows: auto 1fr auto; padding: 1.75rem 1.2rem; border-right: 1px solid var(--line); background: rgba(255,255,255,.95); backdrop-filter: blur(18px); }
.sidebar nav { display: grid; align-content: start; gap: .42rem; margin-top: 2.6rem; }
.sidebar nav a { display: flex; min-height: 2.8rem; align-items: center; gap: .75rem; padding: 0 .75rem; border-radius: .75rem; color: #70798d; font-size: .8rem; font-weight: 730; }
.sidebar nav a span { display: grid; width: 1.8rem; height: 1.8rem; place-items: center; border-radius: .55rem; color: #8a92a4; background: #f2f4f8; font-size: .85rem; }
.sidebar nav a:hover { color: var(--text); background: #f7f8fb; }
.sidebar nav a.active { color: var(--accent); background: var(--accent-soft); }
.sidebar nav a.active span { color: #fff; background: var(--accent); }
.sidebar-foot { display: grid; gap: .2rem; padding: 1rem; border: 1px solid var(--line); border-radius: .85rem; background: var(--surface-soft); }
.sidebar-foot span { color: var(--muted); font-size: .62rem; }
.sidebar-foot strong { font-size: .8rem; }
.sidebar-foot a { margin-top: .5rem; color: var(--accent); font-size: .68rem; font-weight: 750; }

.panel-main { min-height: 100vh; margin-left: 16rem; padding: 2.15rem clamp(1.5rem, 4vw, 4rem) 2rem; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 2rem; margin-bottom: 1.8rem; }
.topbar h1 { margin: .35rem 0 .22rem; font-size: clamp(1.9rem, 3vw, 2.55rem); letter-spacing: -.055em; }
.topbar > div > p:last-child { margin: 0; color: var(--muted); font-size: .82rem; }
.health { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .16rem .65rem; min-width: 12rem; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: .85rem; background: var(--surface); box-shadow: 0 .5rem 1.5rem rgba(39,50,79,.05); }
.health i { grid-row: 1/3; width: .52rem; height: .52rem; border-radius: 50%; background: #25bb77; box-shadow: 0 0 0 .3rem rgba(37,187,119,.11); }
.health span { color: var(--green); font-size: .58rem; font-weight: 900; letter-spacing: .1em; }
.health strong { font-size: .7rem; }

.metric-grid { display: grid; grid-template-columns: 1.2fr repeat(3, 1fr); gap: 1rem; }
.metric { position: relative; display: grid; min-height: 9rem; align-content: center; gap: .38rem; overflow: hidden; padding: 1.35rem; border: 1px solid var(--line); border-radius: 1.05rem; background: var(--surface); box-shadow: 0 .7rem 2rem rgba(39,50,79,.055); }
.metric::after { content: ""; position: absolute; right: -2rem; bottom: -3.2rem; width: 8rem; height: 8rem; border-radius: 50%; background: rgba(38,59,104,.035); }
.metric.hero { border-color: transparent; color: #fff; background: linear-gradient(135deg, #ef274a, #a90d29); box-shadow: 0 1rem 2.5rem rgba(192,19,50,.2); }
.metric span { color: #8b93a5; font-size: .61rem; font-weight: 900; letter-spacing: .12em; }
.metric.hero span, .metric.hero small { color: rgba(255,255,255,.74); }
.metric strong { font-size: 2.35rem; letter-spacing: -.05em; }
.metric small { color: var(--muted); font-size: .68rem; }
.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
.theme-card { position: relative; min-height: 12rem; overflow: hidden; padding: 1.6rem; border-radius: 1.1rem; color: #fff; box-shadow: 0 1rem 2.5rem rgba(30,39,64,.13); }
.theme-card::after { content: ""; position: absolute; width: 16rem; height: 16rem; right: -5rem; top: -7rem; border-radius: 50%; background: rgba(255,255,255,.09); }
.theme-one { background: linear-gradient(135deg, #192033, #343e58); }
.theme-two { background: linear-gradient(135deg, #ec2045, #9f0a25); }
.theme-card span { font-size: .63rem; font-weight: 900; letter-spacing: .14em; opacity: .72; }
.theme-card h2 { margin: 1.15rem 0 .3rem; font-size: 1.5rem; }
.theme-card p { max-width: 80%; margin: 0; overflow: hidden; color: rgba(255,255,255,.72); font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
.theme-card b { position: absolute; bottom: 1.5rem; font-size: .7rem; }
.quick-actions { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: .75rem; margin-top: 1rem; padding: 1.15rem 1.25rem; border: 1px solid var(--line); border-radius: 1rem; background: var(--surface); }
.quick-actions h2 { margin: .28rem 0 0; font-size: 1rem; }

.panel-section { margin: 0 0 1rem; padding: 1.35rem; border: 1px solid var(--line); border-radius: 1.05rem; background: var(--surface); box-shadow: 0 .7rem 2rem rgba(39,50,79,.045); }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.15rem; }
.section-title h2 { margin: .25rem 0 0; font-size: 1.25rem; letter-spacing: -.02em; }
.section-title > span { color: var(--muted); font-size: .72rem; }
.provider-form { display: grid; grid-template-columns: minmax(12rem, .8fr) minmax(18rem, 1.5fr) auto; align-items: end; gap: .8rem; }
.provider-form .primary { height: 3rem; }
.settings-form { display: grid; grid-template-columns: 1fr 1fr; align-content: start; gap: 1rem; margin: 0; }
.settings-form .wide { grid-column: 1/-1; }
.settings-form .primary { align-self: end; height: 3rem; }
.upload-field { position: relative; min-height: 6rem; place-items: center; align-content: center; padding: 1rem; border: 1px dashed #c9d0dd; border-radius: .85rem; color: #59647a; background: #f8f9fb; text-align: center; }
.upload-field input { position: absolute; inset: 0; height: 100%; opacity: 0; cursor: pointer; }
.upload-field span { font-size: .74rem; font-weight: 700; }
.remove-check { display: flex; align-items: center; gap: .6rem; }
.remove-check input { width: 1rem; height: 1rem; }
.appearance-layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(17rem, .6fr); align-items: stretch; gap: 1rem; }
.appearance-preview { position: relative; display: grid; min-height: 30rem; align-content: space-between; overflow: hidden; padding: 1.4rem; border-radius: 1.05rem; color: #fff; background: linear-gradient(155deg, rgba(15,20,34,.66), rgba(15,20,34,.96)), var(--preview-image, linear-gradient(135deg, #4c1021, #17243d)); background-position: center; background-size: cover; box-shadow: 0 1rem 3rem rgba(30,39,64,.14); }
.appearance-preview > span { font-size: .62rem; font-weight: 900; letter-spacing: .14em; opacity: .7; }
.appearance-preview b { color: var(--preview-accent); font-size: .75rem; letter-spacing: .12em; }
.appearance-preview h2 { margin: .7rem 0 1.3rem; font-size: 2rem; line-height: 1.02; }
.appearance-preview i { display: inline-block; width: 5.5rem; height: 2.3rem; margin-right: .35rem; border-radius: .55rem; background: var(--preview-accent); }
.appearance-preview i + i { background: rgba(255,255,255,.2); }
.appearance-preview p { margin: 0; font-size: .7rem; opacity: .75; }

.table-search { width: min(20rem, 100%); height: 2.6rem; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: .85rem; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: .86rem .95rem; border-bottom: 1px solid #edf0f5; text-align: left; }
th { color: #8991a3; background: #f8f9fb; font-size: .58rem; font-weight: 900; letter-spacing: .1em; }
td { color: #4c566c; font-size: .74rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfbfd; }
td strong, td small { display: block; }
td strong { color: #263047; }
td small { margin-top: .2rem; color: #8a92a3; font-size: .62rem; }
td code { color: #4e5870; font-size: .69rem; }
.row-actions { display: flex; align-items: center; gap: .45rem; }
.status, .theme-pill { display: inline-flex !important; width: max-content; align-items: center; gap: .35rem; padding: .34rem .52rem; border-radius: 2rem; font-size: .54rem; font-weight: 900; letter-spacing: .07em; }
.status::before { content: ""; width: .36rem; height: .36rem; border-radius: 50%; background: currentColor; }
.status.online { color: var(--green); background: var(--green-soft); }
.status.idle { color: var(--amber); background: var(--amber-soft); }
.status.off { color: #727b8f; background: #eff1f5; }
.theme-pill { color: var(--accent); background: var(--accent-soft); }
.device-code { color: #263047 !important; font-weight: 850; letter-spacing: .06em; }
.empty { padding: 2.7rem !important; color: var(--muted); text-align: center; }
.panel-footer { padding: 1.5rem 0 0; color: #8a92a3; font-size: .65rem; text-align: center; }

@media (max-width: 1120px) {
  .sidebar { position: static; width: auto; grid-template-columns: auto 1fr; grid-template-rows: auto auto; align-items: center; gap: 1rem; }
  .sidebar nav { display: flex; grid-column: 1/-1; margin: 0; overflow: auto; }
  .sidebar-foot { display: none; }
  .panel-main { margin: 0; padding: 1.5rem; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .sidebar { grid-template-columns: 1fr; padding: 1rem; }
  .sidebar nav { padding-bottom: .2rem; }
  .sidebar nav a { flex: 0 0 auto; }
  .topbar { align-items: flex-start; }
  .health { display: none; }
  .panel-main { padding: 1rem; }
  .metric-grid, .theme-grid, .appearance-layout, .settings-form { grid-template-columns: 1fr; }
  .settings-form .wide { grid-column: auto; }
  .metric { min-height: 7.5rem; }
  .quick-actions { grid-template-columns: 1fr; }
  .provider-form { grid-template-columns: 1fr; }
  .section-title { align-items: flex-start; flex-direction: column; }
  .table-search { width: 100%; }
  .appearance-preview { min-height: 22rem; }
}
