:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --success: #16a34a;
  --danger: #ef4444;
  --border: #e5e7eb;
  --radius: 18px;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 100%);
  color: var(--text);
}

a {
  color: var(--primary);
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

button {
  border: none;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 2px solid rgba(99, 102, 241, 0.25);
  outline-offset: 2px;
}

.container {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.auth-card,
.card,
.panel,
.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(100%, 430px);
  padding: 2rem;
}

.auth-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.7rem;
  text-align: center;
}

.auth-card p {
  margin: 0 0 1.4rem;
  text-align: center;
  color: var(--muted);
}

.form-group {
  margin-bottom: 1rem;
}

label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.92rem;
  color: var(--muted);
}

input,
select {
  width: 100%;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.82rem 1rem;
  border-radius: 999px;
  font-weight: 600;
  transition: transform 0.18s ease, background 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: #f3f4f6;
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.auth-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.auth-footer {
  margin-top: 1.2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.message {
  display: none;
  padding: 0.8rem 0.9rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  font-size: 0.93rem;
}

.message.error {
  display: block;
  background: #fee2e2;
  color: #991b1b;
}

.message.success {
  display: block;
  background: #dcfce7;
  color: #166534;
}

.page-header {
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid rgba(229, 231, 235, 0.8);
  backdrop-filter: blur(10px);
}

.page-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
}

.page-title {
  margin: 0;
  font-size: 1.2rem;
}

.profile-menu {
  position: relative;
}

.profile-button {
  padding: 0.5rem 0.9rem;
  background: var(--primary);
  color: white;
  border-radius: 999px;
}

.profile-dropdown {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  width: 180px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: none;
  z-index: 20;
}

.profile-dropdown.open {
  display: block;
}

.profile-dropdown button {
  width: 100%;
  padding: 0.75rem 0.9rem;
  text-align: left;
  background: transparent;
  color: var(--text);
}

.profile-dropdown button:hover {
  background: #f9fafb;
}

.profile-dropdown .danger {
  color: var(--danger);
}

main {
  padding: 1.5rem 0 2rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
  margin-bottom: 1.2rem;
}

.stat {
  padding: 1rem 1.1rem;
  background: linear-gradient(135deg, #eef2ff 0%, #ffffff 100%);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat .label {
  color: var(--muted);
  font-size: 0.9rem;
}

.stat strong {
  display: block;
  margin-top: 0.25rem;
  font-size: 1.45rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.dashboard-card {
  padding: 1.3rem;
  border-radius: var(--radius);
  background: white;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.dashboard-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.1);
}

.dashboard-card h3 {
  margin: 0 0 0.4rem;
}

.dashboard-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 1rem;
}

.card,
.panel {
  padding: 1.15rem;
}

.hero-panel {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(255, 255, 255, 0.95));
  border: 1px solid rgba(99, 102, 241, 0.14);
  border-radius: 22px;
  padding: 1.1rem 1.2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.hero-panel h3 {
  margin: 0 0 0.25rem;
}

.hero-panel p {
  margin: 0;
  color: var(--muted);
}

.tenant-view {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.tenant-search {
  min-width: min(300px, 100%);
}

.tenant-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.9rem;
}

.tenant-stat {
  background: white;
  border-radius: 16px;
  padding: 0.95rem 1rem;
  box-shadow: var(--shadow);
}

.tenant-stat span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.tenant-stat strong {
  display: block;
  margin-top: 0.25rem;
  font-size: 1.25rem;
}

.tenant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 1rem;
}

.tenant-card {
  background: white;
  border-radius: 18px;
  padding: 1rem;
  border: 1px solid rgba(229, 231, 235, 0.92);
  box-shadow: var(--shadow);
}

.tenant-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.tenant-card-head h4 {
  margin: 0;
  font-size: 1rem;
}

.tenant-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 600;
}

.tenant-meta {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.94rem;
  margin-bottom: 0.85rem;
}

.tenant-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.9rem;
}

.tenant-amount {
  font-weight: 700;
  color: var(--text);
}

.modern-form {
  background: white;
  border-radius: 24px;
  padding: 1.2rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-hero {
  padding: 1rem 1.1rem;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(255, 255, 255, 0.92));
  border: 1px solid rgba(99, 102, 241, 0.12);
}

.form-hero h3 {
  margin: 0 0 0.25rem;
}

.form-hero p {
  margin: 0;
  color: var(--muted);
}

.form-section {
  border: 1px solid rgba(229, 231, 235, 0.9);
  border-radius: 18px;
  padding: 1rem;
  background: #fcfdff;
}

.form-section-title {
  font-weight: 700;
  margin-bottom: 0.85rem;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.field-label {
  color: var(--muted);
  font-size: 0.92rem;
}

.input-shell {
  position: relative;
}

.input-shell input,
.input-shell select {
  padding-right: 2.5rem;
}

.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: white;
}

.helper-text {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: -0.2rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 0.25rem;
}

.panel + .panel {
  margin-top: 1rem;
}

.panel h3,
.card h3 {
  margin-top: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.device-card {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fcfdff;
}

.toggle {
  width: 44px;
  height: 24px;
  background: #d1d5db;
  border-radius: 999px;
  position: relative;
  margin-top: 0.8rem;
  cursor: pointer;
}

.toggle::after {
  content: '';
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: left 0.2s ease;
}

.toggle.active {
  background: var(--primary);
}

.toggle.active::after {
  left: 23px;
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 0.8rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

th {
  background: #f9fafb;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.row-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.empty-state {
  padding: 1.25rem;
  border: 1px dashed var(--border);
  border-radius: 16px;
  color: var(--muted);
  background: #fcfdff;
}

.form-card {
  max-width: 560px;
  margin: 0 auto;
  padding: 1.3rem;
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-card .form-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.form-card .form-row > * {
  flex: 1;
  min-width: 180px;
}

.form-card .inline-options {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 0.5rem 0 1rem;
}

.form-card .inline-options label {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
}

.nav-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 1rem;
  color: var(--primary);
  cursor: pointer;
  font-weight: 600;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.modal-card {
  width: min(100%, 420px);
  padding: 1.2rem;
}

.modal-card h3 {
  margin-top: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1rem;
}

.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  z-index: 1100;
}

.toast {
  min-width: 260px;
  max-width: 360px;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  color: white;
  box-shadow: var(--shadow);
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--danger);
}

.toast.info {
  background: #4b5563;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1200;
}

.loading-overlay.show {
  display: flex;
}

.loader {
  width: 46px;
  height: 46px;
  border: 4px solid rgba(99, 102, 241, 0.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

footer {
  padding: 1rem 0 2rem;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 640px) {
  .auth-card {
    padding: 1.25rem;
  }

  .page-header .container {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .hero-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .tenant-search {
    width: 100%;
    min-width: 0;
  }

  .stats,
  .dashboard-grid,
  .charts {
    grid-template-columns: 1fr;
  }
}
