:root {
  --bg-root: #121417;
  --bg-surface: #181b20;
  --bg-elevated: #20242b;
  --bg-input: #171a1f;
  --border-subtle: #2a2f38;
  --border-focus: #2e86de;
  --text-main: #d8dde6;
  --text-muted: #7f8896;
  --accent-blue: #2b79c2;
  --accent-blue-hover: #358ce0;
  --badge-green-bg: #2e8540;
  --badge-amber-bg: #b4690e;
  --badge-red-bg: #b83232;
  --gold: #e5b84b;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background-color: var(--bg-root);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.45;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Login */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #1b222e 0%, #121417 65%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.login-brand {
  text-align: center;
  margin-bottom: 22px;
}

.login-logo {
  width: 78px;
  height: 78px;
  border-radius: 18px;
  object-fit: cover;
  margin-bottom: 10px;
  border: 1px solid rgba(229, 184, 75, 0.35);
}

.login-brand h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.6px;
}

.login-brand p {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}

.login-hint {
  margin-top: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  border-top: 1px solid var(--border-subtle);
  padding-top: 12px;
}

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

.sidebar {
  width: 92px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 6px;
  flex-shrink: 0;
}

.sidebar-brand img {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: cover;
  margin-bottom: 18px;
  border: 1px solid rgba(229, 184, 75, 0.3);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.nav-item {
  background: transparent;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 4px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  width: 100%;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
}

.nav-item.active {
  color: #3d9df6;
  background: rgba(43, 121, 194, 0.12);
}

.nav-icon svg {
  width: 24px;
  height: 24px;
}

.nav-label {
  font-size: 11px;
  text-align: center;
  font-weight: 500;
}

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: 54px;
  background: #101215;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.topbar-brand-text {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand-gold {
  font-weight: 700;
  font-size: 16px;
  color: var(--gold);
  letter-spacing: 0.5px;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.credits-pill {
  background: rgba(43, 121, 194, 0.16);
  border: 1px solid rgba(43, 121, 194, 0.45);
  color: #e6eef9;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
  font-size: 13px;
}

.avatar-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #d97706;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
}

.btn-icon-logout {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

.btn-icon-logout:hover {
  color: #fff;
  border-color: #ef4444;
}

.btn-icon-logout svg {
  width: 16px;
  height: 16px;
}

.content-area {
  padding: 22px 28px;
  flex: 1;
}

.page-header {
  display: flex;
  align-items: baseline;
  gap: 14px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 14px;
  margin-bottom: 18px;
}

.page-header > div {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}

.page-header h2 {
  font-size: 24px;
  font-weight: 500;
  color: #e2e8f0;
}

.breadcrumb {
  color: var(--text-muted);
  font-size: 13px;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--accent-blue);
  color: #fff;
}

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

.btn-secondary {
  background: #28303d;
  color: #dce4f0;
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
  background: #323b4a;
}

.filter-bar {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 14px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-bar input,
.filter-bar select {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 13px;
}

.filter-bar input {
  flex: 1;
  min-width: 220px;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 16px 18px;
}

.narrow-card {
  max-width: 560px;
}

.card-title-row {
  margin-bottom: 12px;
}

.card-title-row h3 {
  font-size: 16px;
  font-weight: 500;
}

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

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

th,
td {
  text-align: left;
  padding: 13px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 13px;
}

th {
  color: #cfd6e2;
  font-weight: 600;
  font-size: 12.5px;
}

td {
  color: #9ba5b4;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.badge {
  display: inline-block;
  padding: 2px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
}

.badge-paid {
  background: var(--badge-green-bg);
}

.badge-trial {
  background: var(--badge-amber-bg);
}

.badge-expired {
  background: var(--badge-red-bg);
}

.badge-muted {
  background: #3a414d;
  color: #cfd6e2;
}

.actions-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.icon-btn svg {
  width: 17px;
  height: 17px;
}

.icon-blue { color: #38bdf8; }
.icon-amber { color: #f59e0b; }
.icon-green { color: #22c55e; }
.icon-red { color: #ef4444; }

/* Device Status Detail */
.device-status-panel {
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 18px;
  margin-bottom: 18px;
}

.device-status-panel h3 {
  font-size: 17px;
  font-weight: 500;
  margin-bottom: 14px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 16px 28px;
}

.status-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-label {
  font-size: 12.5px;
  color: #c7d0dc;
  font-weight: 600;
}

.status-val {
  color: var(--text-muted);
  font-size: 13.5px;
}

.detail-actions-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.detail-right-btns {
  display: flex;
  gap: 10px;
}

/* Pagination */
.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 14px;
  color: var(--text-muted);
  font-size: 12.5px;
  flex-wrap: wrap;
  gap: 10px;
}

.pagination-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.page-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
}

.page-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

.pagination-limit select {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 4px 8px;
  border-radius: 999px;
  margin-left: 6px;
}

/* Dashboard stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 16px;
}

.stat-card .stat-title {
  color: var(--text-muted);
  font-size: 12px;
}

.stat-card .stat-value {
  font-size: 26px;
  font-weight: 700;
  color: #f1f5f9;
  margin-top: 4px;
}

.stat-card .stat-sub {
  font-size: 11.5px;
  color: var(--gold);
  margin-top: 2px;
}

/* Forms & Modals */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  color: #aeb8c6;
}

.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 5px;
  padding: 9px 11px;
  color: var(--text-main);
  font-size: 13.5px;
  outline: none;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--border-focus);
}

.plan-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.plan-option {
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  background: var(--bg-input);
  transition: border-color 0.15s, background 0.15s;
}

.plan-option input {
  display: none;
}

.plan-option.selected {
  border-color: #3b82f6;
  background: rgba(43, 121, 194, 0.16);
}

.plan-option .plan-title {
  font-weight: 600;
  color: #f1f5f9;
  display: block;
}

.plan-option .plan-meta {
  font-size: 12px;
  color: var(--gold);
  margin-top: 3px;
  display: block;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #363c46;
  border-radius: 24px;
  transition: 0.2s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #121417;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .slider {
  background-color: var(--accent-blue);
}

.switch input:checked + .slider:before {
  transform: translateX(22px);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 1000;
}

.modal-box {
  width: 100%;
  max-width: 490px;
}

.modal-brand-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.modal-brand-top img {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

.modal-brand-top span {
  font-weight: 700;
  color: var(--gold);
  font-size: 15px;
  letter-spacing: 0.4px;
}

.modal-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 500;
  color: #e2e8f0;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.alert-error {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fca5a5;
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 12.5px;
}

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #1f2937;
  color: #f8fafc;
  border: 1px solid #3b82f6;
  padding: 11px 16px;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 2000;
  font-size: 13px;
}

.toast.error {
  border-color: #ef4444;
}

.url-cell {
  max-width: 340px;
  word-break: break-all;
}

@media (max-width: 760px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    padding: 8px 12px;
  }
  .sidebar-brand img {
    margin-bottom: 0;
    margin-right: 10px;
  }
  .sidebar-nav {
    flex-direction: row;
  }
  .status-grid {
    grid-template-columns: 1fr;
  }
}
