:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #e0e4ea;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --primary: #1a56db;
  --primary-dark: #1241b4;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,.08);
  --font: system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

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

/* Nav */
.nav {
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 52px;
}
.nav-brand { font-weight: 700; font-size: 17px; color: var(--text); }
.nav-links { display: flex; gap: 20px; font-size: 14px; }
.nav-links a { color: var(--text-muted); }
.nav-links a:hover { color: var(--text); text-decoration: none; }

/* Container */
.container { max-width: 960px; margin: 0 auto; padding: 28px 16px 60px; }

/* Footer */
.footer { text-align: center; padding: 20px; color: var(--text-muted); font-size: 13px; }

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 22px; font-weight: 700; }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: #fff; color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }

/* Table */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: #fff; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; text-align: left; font-size: 14px; }
.table th { font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border); background: #f9fafb; }
.table td { border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: none; }
.table .actions { white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.listings-row td { background: #f9fafb; padding: 12px 14px; }
.run-inline { vertical-align: middle; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
}
.badge-ok { background: #dcfce7; color: #15803d; }
.badge-error { background: #fee2e2; color: #b91c1c; }
.badge-none { background: #f3f4f6; color: var(--text-muted); }

/* Toggle button */
.toggle-btn {
  padding: 3px 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: #f3f4f6;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all .15s;
}
.toggle-btn.active { background: #dcfce7; color: #15803d; border-color: #86efac; }
.toggle-btn:hover { opacity: .85; }

/* Forms */
.form-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  max-width: 680px;
}
.form-section { padding: 24px; border-bottom: 1px solid var(--border); }
.form-section h2 { font-size: 15px; font-weight: 600; margin-bottom: 16px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.form-actions { padding: 16px 24px; display: flex; gap: 8px; justify-content: flex-end; }
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.field input[type="text"],
.field input[type="number"],
.field input[type="password"],
.field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  background: #fff;
}
.field input:focus, .field select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-weight: 400; color: var(--text-muted); font-size: 12px; }
.radio-group, .checkbox-group { display: flex; flex-wrap: wrap; gap: 12px; }
.checkbox-group-compact { gap: 8px; }
.radio-label, .checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.form-inline .field { max-width: 360px; }

/* Autocomplete */
.autocomplete-wrap { position: relative; }
.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  z-index: 100;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.autocomplete-item {
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
}
.autocomplete-item:hover { background: var(--bg); }

/* Listings grid */
.listings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.listing-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.listing-photo { width: 100%; height: 140px; object-fit: cover; display: block; }
.listing-body { padding: 10px 12px; }
.listing-price { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.listing-title { font-size: 13px; margin-bottom: 6px; }
.listing-title a { color: var(--text); }
.listing-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); }
.energy-label {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 700;
  font-size: 11px;
  background: #d1fae5;
  color: #065f46;
}

/* Settings */
.settings-grid { display: grid; gap: 20px; }
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.card h2 { font-size: 16px; font-weight: 700; margin-bottom: 16px; }
.topic-code { display: block; font-family: monospace; font-size: 14px; background: var(--bg); padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--border); word-break: break-all; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.mt { margin-top: 12px; }

/* Alerts */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-ok { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.alert-error { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; }

/* Login page */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin-bottom: 24px; text-align: center; }
.login-card .field { margin-bottom: 16px; }

/* Empty state */
.empty-state { text-align: center; padding: 48px 16px; color: var(--text-muted); }

/* Misc */
.text-muted { color: var(--text-muted); }
.small { font-size: 12px; }

@media (max-width: 600px) {
  .field-row { grid-template-columns: 1fr; }
  .listings-grid { grid-template-columns: 1fr 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}
