:root {
  --bg: #f6f8ff;
  --sidebar: #f8fbff;
  --surface: #ffffff;
  --surface-soft: #eef4ff;
  --field: #edf3ff;
  --line: #d9e0ef;
  --line-strong: #b9c2d8;
  --text: #071426;
  --muted: #66758d;
  --primary: #312eff;
  --primary-2: #5c58f0;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow: 0 18px 40px rgba(29, 38, 77, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

a {
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

/* Loader */
.page-loader {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 22% 22%, rgba(49, 46, 255, .13), transparent 28%),
    radial-gradient(circle at 78% 66%, rgba(22, 163, 74, .12), transparent 24%),
    #f8fbff;
  transition: opacity .45s ease, visibility .45s ease;
}

.page-loader.hide {
  opacity: 0;
  visibility: hidden;
}

.loader-card {
  width: min(360px, calc(100vw - 40px));
  padding: 36px;
  text-align: center;
  background: rgba(255, 255, 255, .84);
  border: 1px solid rgba(185, 194, 216, .7);
  border-radius: 26px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.loader-card h1 {
  margin: 18px 0 4px;
  font-size: 30px;
  font-weight: 800;
}

.loader-card p {
  margin: 0 0 24px;
  color: var(--muted);
}

.brand-orbit {
  position: relative;
  width: 82px;
  height: 82px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-radius: 24px;
  box-shadow: 0 24px 44px rgba(49, 46, 255, .24);
}

.brand-orbit span {
  position: absolute;
  inset: -12px;
  border: 2px solid rgba(49, 46, 255, .18);
  border-top-color: var(--primary);
  border-radius: 28px;
  animation: spin 1.3s linear infinite;
}

.brand-orbit i {
  font-size: 34px;
}

.loader-line {
  height: 7px;
  overflow: hidden;
  background: #e6ecfb;
  border-radius: 999px;
}

.loader-line span {
  display: block;
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #20c997);
  border-radius: inherit;
  animation: loadLine 1.15s ease-in-out infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes loadLine {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(220%); }
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(420px, 1fr) minmax(420px, 520px);
  background: #f6f8ff;
}

.login-visual {
  position: relative;
  display: grid;
  align-content: space-between;
  min-height: 100vh;
  padding: 42px;
  overflow: hidden;
  color: #fff;
  background:
    linear-gradient(145deg, rgba(19, 26, 52, .94), rgba(49, 46, 255, .82)),
    radial-gradient(circle at 24% 30%, rgba(255, 255, 255, .18), transparent 25%);
}

.login-visual::after {
  content: "";
  position: absolute;
  inset: 14%;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 34px;
  transform: rotate(-8deg);
}

.login-brand {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  flex: 0 0 50px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-radius: 16px;
  box-shadow: 0 18px 34px rgba(49, 46, 255, .28);
}

.login-brand h1,
.brand-copy h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
}

.login-brand p,
.brand-copy p {
  margin: 2px 0 0;
  color: rgba(255, 255, 255, .68);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.device-preview {
  position: relative;
  z-index: 1;
  width: min(370px, 70vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin: auto;
}

.pulse-ring,
.pulse-ring::before,
.pulse-ring::after {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 50%;
  animation: pulse 2.8s ease-in-out infinite;
}

.pulse-ring::before,
.pulse-ring::after {
  content: "";
  inset: 54px;
  animation-delay: .4s;
}

.pulse-ring::after {
  inset: 108px;
  animation-delay: .8s;
}

.watch-face {
  width: 150px;
  height: 150px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .13);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 40px;
  backdrop-filter: blur(16px);
}

.watch-face i {
  font-size: 52px;
}

.watch-face span {
  display: block;
  font-size: 22px;
  font-weight: 800;
}

.login-stat {
  position: absolute;
  z-index: 2;
  min-width: 170px;
  padding: 18px;
  background: rgba(255, 255, 255, .13);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 18px;
  backdrop-filter: blur(18px);
}

.login-stat strong,
.login-stat span {
  display: block;
}

.login-stat strong {
  font-size: 28px;
}

.login-stat span {
  color: rgba(255, 255, 255, .72);
}

.stat-one {
  left: 9%;
  bottom: 18%;
}

.stat-two {
  right: 10%;
  top: 24%;
}

.login-panel {
  display: grid;
  place-items: center;
  padding: 38px;
}

.login-card {
  width: min(100%, 430px);
  padding: 38px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
}

.login-card h2 {
  margin: 0 0 8px;
  font-size: 30px;
  font-weight: 800;
}

.login-card p {
  margin: 0;
  color: var(--muted);
}

@keyframes pulse {
  50% { transform: scale(1.04); opacity: .65; }
}

/* Shared controls */
.btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 12px;
  font-weight: 700;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border-color: var(--primary);
  box-shadow: 0 16px 28px rgba(49, 46, 255, .2);
}

.btn-light {
  color: #34435c;
  background: #fff;
  border-color: var(--line);
}

.btn-link {
  color: var(--primary);
  font-weight: 800;
  text-decoration: none;
}

.icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  color: #53647d;
  background: transparent;
  border: 0;
  border-radius: 12px;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}

.icon-btn:hover {
  color: var(--primary);
  background: var(--surface-soft);
}

.icon-btn:active,
.btn:active {
  transform: scale(.96);
}

.form-control,
.form-select,
.input-group-text {
  min-height: 48px;
  color: var(--text);
  background-color: var(--field);
  border-color: var(--line-strong);
  border-radius: 14px;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 .2rem rgba(49, 46, 255, .14);
}

.form-label {
  margin-bottom: 8px;
  color: #151c2e;
  font-size: 13px;
  font-weight: 500;
}

.input-icon {
  position: relative;
}

.input-icon > i {
  position: absolute;
  top: 50%;
  left: 16px;
  color: #7a8aa4;
  transform: translateY(-50%);
}

.input-icon .form-control {
  padding-left: 44px;
}

.input-icon .reveal-password,
.password-wrap .reveal-password {
  position: absolute;
  top: 4px;
  right: 6px;
}

.password-wrap {
  position: relative;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 600;
}

.text-link {
  color: var(--primary);
  font-weight: 700;
}

/* Shell */
.app-shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 1040;
  width: 320px;
  display: flex;
  flex-direction: column;
  padding: 30px 20px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  transition: width .24s ease, transform .24s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 36px;
}

.brand-copy h2 {
  color: var(--text);
}

.brand-copy p {
  color: #526581;
}

.sidebar-nav {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  padding-right: 2px;
}

.side-link {
  position: relative;
  min-height: 50px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  color: #526581;
  background: transparent;
  border: 0;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 500;
  text-align: left;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}

.side-link i {
  width: 25px;
  font-size: 22px;
}

.side-link:hover,
.side-link.active {
  color: var(--primary);
  background: #fff;
}

.side-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 4px;
  border-radius: 999px;
  background: var(--primary);
}

.nav-section {
  margin: 22px 20px 8px;
  color: #8da0bb;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.sidebar-footer {
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.collapse-btn {
  width: 100%;
  height: 44px;
  margin-top: 18px;
  color: #8da0bb;
  background: transparent;
  border: 0;
}

.main {
  min-height: 100vh;
  margin-left: 320px;
  padding-top: 80px;
  transition: margin-left .24s ease;
}

.topbar {
  position: fixed;
  top: 0;
  right: 0;
  left: 320px;
  z-index: 1030;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 40px;
  background: rgba(255, 255, 255, .88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
  transition: left .24s ease;
}

.topbar-left,
.topbar-actions,
.breadcrumb-nav,
.user-chip {
  display: flex;
  align-items: center;
}

.topbar-left,
.topbar-actions {
  gap: 18px;
}

.breadcrumb-nav {
  gap: 12px;
  color: #8796ad;
  font-size: 16px;
  font-weight: 500;
}

.breadcrumb-nav span:last-child {
  color: var(--primary);
  font-weight: 700;
}

.top-search {
  position: relative;
  width: min(310px, 24vw);
}

.top-search i {
  position: absolute;
  top: 50%;
  left: 14px;
  color: #91a1b7;
  transform: translateY(-50%);
}

.top-search input {
  width: 100%;
  height: 40px;
  padding: 0 14px 0 40px;
  background: #f8fbff;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: 0;
}

.notification-btn span {
  position: absolute;
  top: 8px;
  right: 9px;
  width: 7px;
  height: 7px;
  background: var(--danger);
  border-radius: 50%;
}

.notification-menu {
  width: 310px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.dropdown-title {
  padding: 12px 14px;
  font-weight: 800;
}

.notification-item {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  padding: 12px;
  color: #334155;
  background: transparent;
  border: 0;
  border-radius: 12px;
  text-align: left;
}

.notification-item:hover {
  background: var(--surface-soft);
}

.notification-item small {
  grid-column: 2;
  color: var(--muted);
}

.status-dot {
  width: 9px;
  height: 9px;
  margin-top: 5px;
  border-radius: 50%;
}

.status-dot.success { background: var(--success); }
.status-dot.warning { background: var(--warning); }
.status-dot.danger { background: var(--danger); }

.user-chip {
  gap: 12px;
  padding-left: 18px;
  border-left: 1px solid var(--line);
}

.user-chip strong,
.user-chip span {
  display: block;
}

.user-chip span {
  color: #53647d;
}

.avatar {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-2), #7270ff);
  border: 3px solid #e5e8ff;
  border-radius: 50%;
}

.content-wrap {
  max-width: 1500px;
  margin: 0 auto;
  padding: 44px 40px 64px;
}

.view-section {
  display: none;
  animation: fadeUp .36s ease both;
}

.view-section.active {
  display: block;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 30px;
}

.page-heading h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1.08;
  font-weight: 700;
}

.page-heading p {
  max-width: 760px;
  margin: 14px 0 0;
  color: #242536;
  font-size: 20px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

/* Cards, tables, forms */
.metric-card,
.panel-card,
.insight-box,
.settings-menu {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(29, 38, 77, .04);
}

.metric-card {
  height: 100%;
  padding: 18px;
}

.metric-card i {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  margin-bottom: 12px;
  color: var(--primary);
  background: var(--surface-soft);
  border-radius: 12px;
}

.metric-card span,
.metric-card small,
.metric-card strong {
  display: block;
}

.metric-card span {
  color: #66758d;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-card strong {
  margin: 8px 0;
  font-size: 25px;
  font-weight: 800;
}

.metric-card small {
  color: var(--muted);
  font-weight: 700;
}

.metric-card .up { color: var(--success); }
.metric-card .down { color: var(--danger); }

.panel-card {
  padding: 28px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.panel-card h2,
.panel-header h2,
.section-title h2 {
  margin: 0 0 6px;
  font-size: 25px;
  font-weight: 800;
}

.panel-header p,
.section-title p {
  margin: 0;
  color: #34394f;
}

.alert-list {
  display: grid;
  gap: 14px;
}

.alert-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 18px;
  background: #f8fbff;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.alert-item i {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
}

.alert-item p {
  margin: 4px 0 0;
  color: var(--muted);
}

.alert-item.success i { color: var(--success); background: #ecfdf5; }
.alert-item.warning i { color: var(--warning); background: #fffbeb; }
.alert-item.danger i { color: var(--danger); background: #fff1f2; }

.bar-stack {
  display: grid;
  gap: 22px;
}

.bar-stack div {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding-bottom: 16px;
}

.bar-stack div::after,
.bar-stack em {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 8px;
  border-radius: 999px;
}

.bar-stack div::after {
  right: 0;
  background: #edf2ff;
}

.bar-stack em {
  z-index: 1;
  background: linear-gradient(90deg, var(--primary), #20c997);
}

.w-42 { width: 42%; }
.w-28 { width: 28%; }
.w-18 { width: 18%; }
.w-12 { width: 12%; }

.table-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(2, minmax(140px, 220px)) auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.table {
  margin: 0;
  white-space: nowrap;
}

.table thead th {
  padding: 16px 18px;
  color: #6a7890;
  background: #f8fbff;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.table tbody td {
  padding: 16px 18px;
  border-bottom-color: #edf2fa;
  color: #34435c;
}

.table tbody tr {
  transition: background .18s ease, box-shadow .18s ease;
}

.table tbody tr:hover {
  background: #f8fbff;
  box-shadow: inset 3px 0 0 rgba(49, 46, 255, .34);
}

.table small {
  display: block;
  color: var(--muted);
}

.badge-soft,
.battery {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.badge-soft::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.badge-soft.success,
.battery.high { color: #047857; background: #ecfdf5; }
.badge-soft.warning,
.battery.medium { color: #b45309; background: #fffbeb; }
.badge-soft.danger,
.battery.low { color: #be123c; background: #fff1f2; }
.badge-soft.primary { color: var(--primary); background: #eef2ff; }

.insight-box {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 22px;
  padding: 18px 20px;
  color: #32405a;
  background: linear-gradient(135deg, #eef2ff, #ffffff);
}

.insight-box > i {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  flex: 0 0 40px;
  color: var(--primary);
  background: #fff;
  border-radius: 12px;
}

.insight-box span {
  flex: 1;
}

.form-tabs {
  gap: 22px;
  margin-bottom: 40px;
  border-bottom: 1px solid var(--line-strong);
}

.form-tabs .nav-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 0 20px;
  color: #666b7b;
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  font-weight: 700;
}

.form-tabs .nav-link.active {
  color: var(--primary);
  background: transparent;
  border-color: var(--primary);
}

.form-panel {
  padding: 48px 40px;
  border-color: var(--line-strong);
}

.section-title {
  margin-bottom: 38px;
}

.small-title {
  margin-bottom: 8px;
}

.static-form hr {
  margin: 22px 0;
  color: var(--line-strong);
  opacity: 1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
}

.settings-menu {
  padding: 10px;
}

.settings-menu button {
  width: 100%;
  padding: 13px 14px;
  color: #53647d;
  background: transparent;
  border: 0;
  border-radius: 10px;
  text-align: left;
  font-weight: 700;
}

.settings-menu button.active,
.settings-menu button:hover {
  color: #fff;
  background: var(--primary);
}

.upload-zone {
  min-height: 250px;
  display: grid;
  place-items: center;
  padding: 28px;
  color: #54647d;
  background: #f8fbff;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  text-align: center;
  cursor: pointer;
}

.upload-zone input {
  display: none;
}

.upload-zone i {
  display: block;
  margin-bottom: 14px;
  color: var(--primary);
  font-size: 40px;
}

.upload-zone strong,
.upload-zone span {
  display: block;
}

.export-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.export-row:last-child {
  border-bottom: 0;
}

/* Collapsed and mobile */
body.sidebar-collapsed .sidebar {
  width: 92px;
}

body.sidebar-collapsed .brand-copy,
body.sidebar-collapsed .side-link span,
body.sidebar-collapsed .nav-section,
body.sidebar-collapsed .sidebar-footer .btn {
  display: none;
}

body.sidebar-collapsed .main {
  margin-left: 92px;
}

body.sidebar-collapsed .topbar {
  left: 92px;
}

.mobile-menu {
  display: none;
}

.mobile-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1035;
  display: none;
  background: rgba(7, 20, 38, .46);
}

.mobile-backdrop.show {
  display: block;
}

@media (max-width: 1199px) {
  .login-page {
    grid-template-columns: 1fr;
  }

  .login-visual {
    display: none;
  }

  .top-search {
    display: none;
  }

  .table-toolbar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 991px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
  }

  .topbar {
    left: 0;
    padding: 0 18px;
  }

  .mobile-menu {
    display: inline-grid;
  }

  .content-wrap {
    padding: 28px 18px 42px;
  }

  .page-heading {
    flex-direction: column;
  }

  .page-heading p {
    font-size: 16px;
  }
}

@media (max-width: 767px) {
  .login-panel {
    padding: 18px;
  }

  .login-card {
    padding: 28px 20px;
  }

  .sidebar {
    width: min(320px, 88vw);
  }

  .topbar-actions {
    gap: 8px;
  }

  .breadcrumb-nav {
    display: none;
  }

  .user-chip .text-end {
    display: none;
  }

  .panel-card,
  .form-panel {
    padding: 22px 18px;
  }

  .table-toolbar {
    grid-template-columns: 1fr;
  }

  .actions,
  .form-actions,
  .insight-box {
    align-items: stretch;
    flex-direction: column;
  }

  .actions .btn,
  .form-actions .btn,
  .insight-box .btn {
    width: 100%;
  }
}
