/* ── Bridge v2.0 ── Modular Shell Styles ────────────────────────── */
:root {
  --bg: #0c0c14;
  --surface: #12121e;
  --surface2: #1a1a2a;
  --surface3: #222236;
  --border: #2a2a40;
  --border2: #3a3a55;
  --text: #e0e0ec;
  --text2: #8888a0;
  --text3: #5a5a70;
  --orange: #F05A28;
  --orange2: #e8652e;
  --orange-dim: rgba(240, 90, 40, 0.15);
  --green: #2da87a;
  --green-dim: rgba(45, 168, 122, 0.15);
  --red: #c4584a;
  --red-dim: rgba(196, 88, 74, 0.15);
  --blue: #3B82F6;
  --blue-dim: rgba(59, 130, 246, 0.15);
  --purple: #8B5CF6;
  --sidebar-width: 220px;
  --header-height: 0px;
  --radius: 8px;
  --radius-sm: 4px;
  --transition: 0.15s ease;
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
}
input, button, textarea, select { font-family: inherit; font-size: inherit; }
a { color: var(--orange); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Utility ───────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text2); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }

/* ── Login Screen ──────────────────────────────────────────────── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--bg);
}
.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0; left: 0;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.login-logo { margin-bottom: 24px; }
.login-card h1, .login-card h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
}
.login-card p { margin-bottom: 24px; }
.login-card form { text-align: left; }
.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text3);
  font-size: 12px;
}
.login-divider::before, .login-divider::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--border);
}
.login-error {
  color: var(--red);
  font-size: 13px;
  margin: 8px 0;
  min-height: 20px;
}
.login-spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Shell Layout ──────────────────────────────────────────────── */
.shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.3px;
}
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: var(--text2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
  border-left: 3px solid transparent;
}
.sidebar-item:hover {
  color: var(--text);
  background: var(--surface2);
  text-decoration: none;
}
.sidebar-item.active {
  color: var(--orange);
  background: var(--orange-dim);
  border-left-color: var(--orange);
}
.sidebar-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.sidebar-icon svg { width: 18px; height: 18px; }
.sidebar-label { flex: 1; }
.sidebar-badge {
  background: var(--orange);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 16px;
}
.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text3);
  padding: 4px 16px 4px 19px;
}
.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--orange);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.user-meta { flex: 1; min-width: 0; }
.user-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 11px;
  color: var(--text2);
  text-transform: capitalize;
}

/* ── Content Area ──────────────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  background: var(--bg);
}
.content::-webkit-scrollbar { width: 6px; }
.content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Module Layout ─────────────────────────────────────────────── */
.module-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.module-header h1 {
  font-size: 20px;
  font-weight: 700;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.module-body {
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.module-error {
  padding: 40px;
  text-align: center;
  color: var(--red);
  font-size: 15px;
}

/* ── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.card-tag {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--orange);
}
.card-meta {
  font-size: 12px;
  color: var(--text2);
}
.card-body {
  padding: 16px;
}
.card-body p { margin-bottom: 8px; }
.card-body p:last-child { margin-bottom: 0; }

/* ── Stat Grid ─────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.stat-grid-2 { grid-template-columns: repeat(2, 1fr); }
.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stat-grid-5 { grid-template-columns: repeat(5, 1fr); }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--orange);
  line-height: 1;
  margin-bottom: 4px;
}
.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
}

/* ── List View ─────────────────────────────────────────────────── */
.list-view {
  display: flex;
  flex-direction: column;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
  cursor: default;
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--surface2); }
.list-item-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface3);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.list-item-content { flex: 1; min-width: 0; }
.list-item-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-subtitle {
  font-size: 13px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-meta {
  font-size: 12px;
  color: var(--text3);
  flex-shrink: 0;
}

/* ── Table View ────────────────────────────────────────────────── */
.table-view { width: 100%; }
.table-header {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 2px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text3);
}
.table-row {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  transition: background var(--transition);
}
.table-row:hover { background: var(--surface2); }
.table-col { width: 100px; flex-shrink: 0; }
.table-col-grow { flex: 1; min-width: 0; }

/* ── Card Grid (Sites) ────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.site-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.site-card-preview {
  height: 140px;
  background: var(--surface2);
  overflow: hidden;
}
.site-card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.site-card-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--surface2) 0%, var(--surface3) 100%);
}
.site-card-info { padding: 12px 16px; }
.site-card-name { font-weight: 600; }
.site-card-domain { font-size: 12px; color: var(--text2); }
.site-card-actions {
  display: flex;
  gap: 8px;
  padding: 8px 16px 12px;
}

/* ── Integration Grid ──────────────────────────────────────────── */
.integration-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.integration-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition);
}
.integration-card:hover { border-color: var(--border2); }
.integration-coming { opacity: 0.5; }
.integration-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--surface3);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.integration-info { flex: 1; min-width: 0; }
.integration-info strong { font-size: 14px; display: block; }
.integration-info p { font-size: 12px; margin: 0; }

/* ── Tags ──────────────────────────────────────────────────────── */
.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.tag-role { background: var(--orange-dim); color: var(--orange); }
.tag-success { background: var(--green-dim); color: var(--green); }
.tag-muted { background: var(--surface3); color: var(--text3); }
.tag-event { background: var(--blue-dim); color: var(--blue); margin: 2px; }
.tag-default { background: var(--surface3); color: var(--text2); }
.tag-CORE { background: var(--orange-dim); color: var(--orange); }
.tag-SENSOR { background: var(--green-dim); color: var(--green); }
.tag-INFRA { background: var(--purple); color: #fff; }
.tag-LC { background: var(--blue-dim); color: var(--blue); }
.tag-grid { display: flex; flex-wrap: wrap; gap: 4px; }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: var(--orange);
  color: #fff;
  border-color: var(--orange);
}
.btn-primary:hover { background: var(--orange2); }
.btn-ghost {
  background: transparent;
  color: var(--text2);
  border-color: var(--border);
}
.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border2);
  background: var(--surface2);
}
.btn-sm { padding: 4px 12px; font-size: 12px; }
.btn-block { width: 100%; }

/* ── Form Elements ─────────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
  margin-bottom: 6px;
}
.input, input[type="text"], input[type="email"], input[type="password"],
input[type="url"], input[type="number"], textarea, select {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  transition: border-color var(--transition);
}
.input:focus, input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--orange);
}
.input-sm {
  padding: 4px 10px;
  font-size: 13px;
  width: auto;
  min-width: 180px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.input-code {
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 8px;
  padding: 12px;
}
.input-color {
  height: 36px;
  padding: 2px;
  cursor: pointer;
}
.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  text-transform: none !important;
  font-weight: 500 !important;
  cursor: pointer;
  margin-bottom: 4px;
}
.checkbox-label input[type="checkbox"] { width: auto; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%238888a0' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── Modal ─────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-body label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
  margin-bottom: 16px;
}
.modal-body label input,
.modal-body label textarea,
.modal-body label select {
  margin-top: 6px;
}
.modal-footer {
  padding: 16px 0 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Chat Layout ───────────────────────────────────────────────── */
.chat-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
  padding: 0 !important;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 28px;
}
.chat-msg { margin-bottom: 16px; }
.chat-msg-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text3);
  margin-bottom: 4px;
}
.chat-msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  max-width: 80%;
  line-height: 1.5;
  font-size: 14px;
}
.chat-msg-user .chat-msg-bubble {
  background: var(--orange);
  color: #fff;
  margin-left: auto;
}
.chat-msg-user .chat-msg-label { text-align: right; }
.chat-msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.chat-msg-assistant .chat-msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
}
.chat-msg-system .chat-msg-bubble {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  font-size: 13px;
  max-width: 100%;
}
.chat-msg-system .chat-msg-label { color: var(--orange); }
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 12px 28px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.chat-input-bar input {
  flex: 1;
}

/* ── Security ──────────────────────────────────────────────────── */
.security-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.security-item:last-child { border-bottom: none; }
.security-item-info strong { display: block; font-size: 14px; }
.security-item-info p { margin: 0; }

/* ── Settings ──────────────────────────────────────────────────── */
.settings-sections { display: flex; flex-direction: column; gap: 20px; }
.settings-footer {
  padding: 20px 0 0;
  border-top: 1px solid var(--border);
}

/* ── Profile ───────────────────────────────────────────────────── */
.profile-info {
  display: flex;
  align-items: center;
  gap: 16px;
}
.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--orange);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 28px;
  flex-shrink: 0;
}
.profile-details h2 { font-size: 18px; }

/* ── Code Block ────────────────────────────────────────────────── */
.code-block {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  overflow-x: auto;
}
.code-block code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 13px;
  color: var(--text);
}

/* ── Tabs ──────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 2px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.tab-btn {
  padding: 5px 14px;
  border: none;
  background: transparent;
  color: var(--text2);
  font-size: 12px;
  font-weight: 600;
  border-radius: 3px;
  cursor: pointer;
  transition: all var(--transition);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  background: var(--orange);
  color: #fff;
}

/* ── Bar Charts ────────────────────────────────────────────────── */
.bar-row {
  position: relative;
  display: flex;
  align-items: center;
  padding: 7px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  min-height: 32px;
}
.bar-row:hover { background: var(--surface2); }
.bar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--orange-dim);
  border-radius: var(--radius-sm);
  z-index: 0;
  transition: width 0.3s ease;
}
.bar-label {
  position: relative;
  z-index: 1;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70%;
}
.bar-value {
  position: relative;
  z-index: 1;
  margin-left: auto;
  font-size: 13px;
  font-weight: 700;
  color: var(--text2);
  flex-shrink: 0;
  padding-left: 8px;
}

/* ── Leaflet Map ───────────────────────────────────────────────── */
.leaflet-container { background: var(--bg) !important; font-family: inherit !important; }
.dark-popup .leaflet-popup-content-wrapper { background: var(--surface); color: var(--text); border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,0.5); border: 1px solid var(--border); }
.dark-popup .leaflet-popup-tip { background: var(--surface); }
.leaflet-control-zoom a { background: var(--surface) !important; color: var(--text2) !important; border-color: var(--border) !important; }
.leaflet-control-zoom a:hover { background: var(--surface2) !important; color: var(--text) !important; }
@keyframes map-ping { 0% { transform: scale(1); opacity: 0.6; } 100% { transform: scale(2.5); opacity: 0; } }
.map-ping { animation: map-ping 2s cubic-bezier(0,0,0.2,1) infinite; }

/* ── Spark Chart ───────────────────────────────────────────────── */
.spark-chart { padding: 4px 0; }
.spark-bar:hover { opacity: 1 !important; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -var(--sidebar-width);
    z-index: 50;
    transition: left var(--transition);
  }
  .sidebar.open { left: 0; }
  .content { width: 100%; }
  .stat-grid-5 { grid-template-columns: repeat(2, 1fr); }
  .card-grid { grid-template-columns: 1fr; }
}
