/* =========================================================
   Agri Smart 4.0 — Admin Panel Styles
   Extends app.css design system
   ========================================================= */

@import url('app.css');

/* ---------- Layout ---------- */
.admin-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 0;
  background: var(--bg);
}

.admin-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(7, 17, 12, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.admin-header .brand-mini {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-header .brand-mini img {
  width: 32px;
  height: 32px;
}

.admin-header .brand-mini span {
  font-family: 'Orbitron', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 255, 136, 0.05);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
}

.icon-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(0, 200, 83, 0.1);
}

.icon-btn.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(255, 82, 82, 0.1);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px 4px 6px;
  background: rgba(0, 200, 83, 0.08);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.8rem;
  cursor: pointer;
}

.user-badge .avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #003d16;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.75rem;
}

/* ---------- Main Content ---------- */
.admin-main {
  flex: 1;
  padding: 16px 16px 90px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.page {
  display: none;
  animation: fadeIn 0.25s ease;
}

.page.active {
  display: block;
}

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

.page-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin: 20px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ---------- Cards ---------- */
.a-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  backdrop-filter: blur(12px);
}

.a-card .card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

.a-card .card-head .title {
  font-weight: 600;
  font-size: 0.95rem;
}

.a-card .card-head .sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ---------- Status ---------- */
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot.online { background: var(--primary); box-shadow: 0 0 8px var(--primary); }
.dot.offline { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  font-size: 0.85rem;
}

.badge {
  font-size: 0.65rem;
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: 600;
}

.badge.ok { background: rgba(0,200,83,0.15); color: var(--primary); }
.badge.warn { background: rgba(255,171,0,0.15); color: var(--warning); }
.badge.err { background: rgba(255,82,82,0.15); color: var(--danger); }
.badge.run { background: rgba(0,229,255,0.12); color: var(--accent); }

/* ---------- Forms ---------- */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.form-row.full { grid-template-columns: 1fr; }

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 5px;
  font-weight: 500;
}

.form-control {
  width: 100%;
  padding: 11px 14px;
  background: rgba(0,20,10,0.5);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,200,83,0.12);
}

select.form-control[multiple] {
  min-height: 100px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 9px 14px;
  border: none;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 36px;
}

.btn-sm { padding: 5px 10px; font-size: 0.75rem; min-height: 30px; }
.btn-xs { padding: 3px 8px; font-size: 0.7rem; min-height: 26px; }
.btn-block { width: 100%; }

.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: #003d16; }
.btn-success { background: var(--primary); color: #003d16; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #1a1200; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); }
.btn-ota { background: #7c4dff; color: #fff; }
.btn-power { background: var(--warning); color: #1a1200; }

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

/* ---------- ESP / Device Card ---------- */
.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.device-card .name-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  width: 100%;
  padding: 4px 0;
  outline: none;
}

.device-card .name-input:focus {
  border-bottom-color: var(--primary);
}

.device-card .meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 8px 0;
}

.device-card .meta .label { opacity: 0.7; }

.monitor-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 10px 0;
  padding: 10px;
  background: rgba(0,0,0,0.25);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.monitor-grid .item { text-align: center; }
.monitor-grid .item .lbl { font-size: 0.55rem; color: var(--text-muted); text-transform: uppercase; }
.monitor-grid .item .val { font-size: 0.95rem; font-weight: 700; margin-top: 2px; }
.monitor-grid .item .val.green { color: var(--primary); }
.monitor-grid .item .val.cyan { color: var(--accent); }
.monitor-grid .item .val.yellow { color: var(--warning); }
.monitor-grid .item .val.orange { color: #ff9100; }

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 6px 0;
}

.tag {
  font-size: 0.65rem;
  padding: 2px 10px;
  border-radius: 12px;
  background: rgba(0,200,83,0.12);
  color: var(--primary);
  border: 1px solid rgba(0,200,83,0.25);
}

.tag.empty {
  background: rgba(255,82,82,0.1);
  color: var(--danger);
  border-color: rgba(255,82,82,0.2);
}

/* ---------- Logs ---------- */
.log-stats {
  display: flex;
  gap: 14px;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 8px 12px;
  background: rgba(0,0,0,0.2);
  border-radius: 10px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.log-box {
  background: #000;
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 380px;
  overflow-y: auto;
  padding: 8px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.7rem;
}

.log-entry {
  padding: 5px 8px;
  margin-bottom: 3px;
  border-left: 2px solid var(--primary);
  background: rgba(0,20,10,0.5);
  border-radius: 3px;
  line-height: 1.45;
}

/* ---------- Bottom Nav ---------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: rgba(7, 17, 12, 0.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px));
  height: calc(62px + env(safe-area-inset-bottom, 0px));
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.58rem;
  padding: 4px 10px;
  cursor: pointer;
  transition: color 0.2s;
  min-width: 52px;
}

.nav-item .icon { font-size: 1.3rem; line-height: 1.2; }
.nav-item .label { margin-top: 2px; font-weight: 500; }
.nav-item.active { color: var(--primary); }
.nav-item.active .icon { transform: scale(1.08); }

/* ---------- Modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,0.7);
  justify-content: center;
  align-items: center;
  padding: 16px;
  backdrop-filter: blur(4px);
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn 0.22s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.94) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-head h3 {
  font-size: 1.05rem;
  color: var(--primary);
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
}

/* ---------- Empty / Toast ---------- */
.empty {
  text-align: center;
  padding: 32px 12px;
  color: var(--text-muted);
}

.empty .icon { font-size: 2.2rem; margin-bottom: 8px; }

.toast-box {
  position: fixed;
  bottom: 80px;
  left: 16px;
  right: 16px;
  z-index: 500;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.toast {
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--primary);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 0.85rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toastIn 0.3s ease;
  max-width: 400px;
  text-align: center;
}

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

/* ---------- Progress ---------- */
.progress-bar {
  height: 6px;
  background: rgba(0,0,0,0.3);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 6px;
}

.progress-bar .fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.4s linear;
}

/* ---------- Responsive ---------- */
@media (max-width: 400px) {
  .monitor-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
}
