/* ==========================================================================
   IshiTrackers - Shared Stylesheet
   Enterprise dark-mode design system
   ========================================================================== */

:root {
  --bg-primary: #0b0f17;
  --bg-secondary: #121826;
  --bg-card: #161e2e;
  --bg-card-hover: #1b2538;
  --border-color: #232d42;
  --text-primary: #e8edf6;
  --text-secondary: #94a3b8;
  --text-muted: #5b6779;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

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

img { max-width: 100%; display: block; }

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

.sidebar {
  width: 240px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  border-bottom: 1px solid var(--border-color);
  font-weight: 700;
  font-size: 17px;
}

.sidebar-brand .logo-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.sidebar-nav { flex: 1; padding: 14px 10px; overflow-y: auto; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
}

.sidebar-nav a:hover { background: var(--bg-card); color: var(--text-primary); }
.sidebar-nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-nav .icon { width: 18px; text-align: center; }

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

.main-content {
  margin-left: 240px;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 64px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar h1 { font-size: 18px; font-weight: 600; }

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  cursor: pointer;
}

.page-body { padding: 24px; flex: 1; }

/* ---------------- Cards / Grid ---------------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
}

.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2,1fr);} }
@media (max-width: 640px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat-card { display: flex; flex-direction: column; gap: 6px; }
.stat-card .label { font-size: 13px; color: var(--text-secondary); }
.stat-card .value { font-size: 28px; font-weight: 700; }
.stat-card .sub { font-size: 12px; color: var(--text-muted); }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; border-color: var(--border-color); color: var(--text-primary); }
.btn-outline:hover { background: var(--bg-card-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------------- Forms ---------------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; font-weight: 500; }

input, select, textarea {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------------- Badges ---------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
}
.badge-online { background: rgba(34,197,94,0.12); color: var(--success); }
.badge-offline { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: rgba(234,179,8,0.12); color: var(--warning); }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------------- Tables ---------------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--text-secondary); font-weight: 600; padding: 12px; border-bottom: 1px solid var(--border-color); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
td { padding: 12px; border-bottom: 1px solid var(--border-color); }
tr:hover td { background: var(--bg-card-hover); }
.table-wrap { overflow-x: auto; }

/* ---------------- Auth pages ---------------- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 30% 20%, #15203a 0%, var(--bg-primary) 60%);
  padding: 20px;
}

.auth-box {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 36px;
  box-shadow: var(--shadow);
}

.auth-box .brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 8px; font-size: 20px; font-weight: 700; }
.auth-box h2 { text-align: center; font-size: 15px; color: var(--text-secondary); font-weight: 400; margin-bottom: 26px; }
.auth-footer { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-secondary); }
.error-msg { background: var(--danger-soft); color: var(--danger); padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; display: none; }
.success-msg { background: rgba(34,197,94,0.12); color: var(--success); padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; display: none; }

/* ---------------- Landing page ---------------- */
.nav-public {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 40px; border-bottom: 1px solid var(--border-color);
  position: sticky; top: 0; background: rgba(11,15,23,0.85); backdrop-filter: blur(8px); z-index: 100;
}
.nav-public .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.nav-public nav a { color: var(--text-secondary); margin-left: 26px; font-size: 14px; font-weight: 500; }
.nav-public nav a:hover { color: var(--text-primary); }

.hero { text-align: center; padding: 110px 24px 90px; max-width: 820px; margin: 0 auto; }
.hero .tag { display: inline-block; background: var(--accent-soft); color: var(--accent); padding: 6px 16px; border-radius: 99px; font-size: 13px; font-weight: 600; margin-bottom: 22px; }
.hero h1 { font-size: 46px; line-height: 1.15; margin-bottom: 18px; font-weight: 800; }
.hero p { color: var(--text-secondary); font-size: 17px; line-height: 1.6; margin-bottom: 32px; }
.hero .cta-group { display: flex; gap: 14px; justify-content: center; }

.section { padding: 80px 24px; max-width: 1100px; margin: 0 auto; }
.section h2 { font-size: 30px; text-align: center; margin-bottom: 12px; font-weight: 700; }
.section .lead { text-align: center; color: var(--text-secondary); max-width: 560px; margin: 0 auto 50px; }

.feature-card { padding: 26px; }
.feature-card .f-icon { width: 44px; height: 44px; border-radius: 10px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; font-size: 20px; margin-bottom: 16px; }
.feature-card h3 { font-size: 16px; margin-bottom: 8px; }
.feature-card p { font-size: 14px; color: var(--text-secondary); line-height: 1.6; }

footer.public-footer { border-top: 1px solid var(--border-color); padding: 30px 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ---------------- Map ---------------- */
#map { width: 100%; height: calc(100vh - 64px); }
.map-popup b { font-size: 14px; }
.map-sidebar {
  position: absolute; top: 80px; left: 264px; z-index: 400;
  width: 300px; max-height: calc(100vh - 110px); overflow-y: auto;
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.map-sidebar .device-item { padding: 14px; border-bottom: 1px solid var(--border-color); cursor: pointer; }
.map-sidebar .device-item:hover { background: var(--bg-card-hover); }
.map-sidebar .device-item.active { background: var(--accent-soft); }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .menu-toggle { display: block; }
  .map-sidebar { left: 14px; width: calc(100% - 28px); top: 76px; }
  .hero h1 { font-size: 32px; }
  .nav-public nav { display: none; }
}

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .e-icon { font-size: 40px; margin-bottom: 14px; }

.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 1000;
  background: var(--bg-card); border: 1px solid var(--border-color);
  padding: 14px 20px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 14px; display: flex; align-items: center; gap: 10px;
}

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: none; align-items: center; justify-content: center; z-index: 900; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 28px; width: 100%; max-width: 440px; }
.modal-box h3 { margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--text-muted); }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 16px; } .mb-2 { margin-bottom: 8px; }
