/* ═══════════════════════════════════════════════════════════════
   FibreNet CRM — Design System
   Dark network-operations UI · Space Grotesk display · IBM Plex body
═══════════════════════════════════════════════════════════════ */
:root {
  --bg:          #0A1220;
  --bg-2:        #0E1A2C;
  --card-bg:     #111F35;
  --card-hover:  #16263F;
  --border:      #1E3350;
  --border-2:    #2A4568;
  --text-main:   #E8EEF6;
  --text-muted:  #7B93B0;
  --text-dim:    #566B85;
  --green:       #00D9A3;
  --green-dim:   #00A67E;
  --orange:      #FF7A45;
  --red:         #FF5C6C;
  --yellow:      #FFB627;
  --blue:        #3B9EFF;
  --purple:      #A78BFA;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,.35);
  --font-display:'Space Grotesk', sans-serif;
  --font-body:   'IBM Plex Sans', -apple-system, sans-serif;
  --font-mono:   'IBM Plex Mono', 'SF Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
code, .mono { font-family: var(--font-mono); font-size: 0.9em; }
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── LOGIN ─────────────────────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at top, #12233d 0%, var(--bg) 60%);
  z-index: 100;
}
#fibre-canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.4; }
.login-box {
  position: relative; z-index: 2; width: 400px; max-width: 90vw;
  background: rgba(17,31,53,0.85); backdrop-filter: blur(12px);
  border: 1px solid var(--border-2); border-radius: 16px; padding: 40px; box-shadow: var(--shadow);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .logo-icon { font-size: 40px; color: var(--green); line-height: 1; }
.login-logo h1 { font-size: 24px; margin-top: 10px; }
.login-logo p { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.role-tabs { display: flex; gap: 4px; background: var(--bg); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 20px; }
.role-tab { flex: 1; padding: 8px; border: none; background: transparent; color: var(--text-muted); border-radius: 4px; cursor: pointer; font-family: var(--font-body); font-size: 12px; font-weight: 500; transition: all .15s; }
.role-tab.active { background: var(--green); color: var(--bg); }

/* ── LAYOUT ────────────────────────────────────────────────── */
#app { display: none; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 56px;
  background: var(--bg-2); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.topbar-logo { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 16px; }
.topbar-logo .icon { color: var(--green); font-size: 20px; }
.topbar-spacer { flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.role-badge { padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: uppercase; background: var(--border); color: var(--green); }

.body-wrap { display: flex; flex: 1; overflow: hidden; }
.sidebar {
  width: 210px; background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto;
}
.sidebar-nav { padding: 12px 8px; flex: 1; }
.sidebar-footer { padding: 8px; border-top: 1px solid var(--border); }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px;
  border: none; background: transparent; color: var(--text-muted); border-radius: var(--radius-sm);
  cursor: pointer; font-family: var(--font-body); font-size: 13px; font-weight: 500; text-align: left; transition: all .12s;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--card-bg); color: var(--text-main); }
.nav-item.active { background: var(--card-hover); color: var(--green); }
.nav-item.active svg { color: var(--green); }

.main { flex: 1; overflow-y: auto; padding: 24px; }
.page { display: none; animation: fade .2s; }
.page.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.page-header h2 { font-size: 22px; }
.page-header-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ── BUTTONS ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border: 1px solid transparent;
  border-radius: var(--radius-sm); font-family: var(--font-body); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all .12s; white-space: nowrap;
}
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn-primary { background: var(--green); color: var(--bg); font-weight: 600; }
.btn-primary:hover { background: var(--green-dim); }
.btn-secondary { background: var(--card-hover); color: var(--text-main); border-color: var(--border-2); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border-2); }
.btn-ghost:hover { color: var(--text-main); border-color: var(--text-dim); }
.btn-danger { background: transparent; color: var(--red); border-color: rgba(255,92,108,0.3); }
.btn-danger:hover { background: rgba(255,92,108,0.12); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── CARDS ─────────────────────────────────────────────────── */
.card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.card-title { font-family: var(--font-display); font-weight: 600; font-size: 15px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--card-bg); border: 1px solid var(--border); border-left: 3px solid transparent; border-radius: var(--radius); padding: 18px; transition: border-color .15s; }
.stat-card.accent-green  { border-left-color: var(--green); }
.stat-card.accent-blue   { border-left-color: var(--blue); }
.stat-card.accent-orange { border-left-color: var(--orange); }
.stat-card.accent-red    { border-left-color: var(--red); }
.stat-card .stat-value { font-family: var(--font-display); font-size: 30px; font-weight: 700; line-height: 1; }
.stat-card .stat-label { color: var(--text-muted); font-size: 12px; margin-top: 6px; letter-spacing: .01em; }

@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } .sidebar { width: 60px; } .nav-item span { display: none; } }

/* ── FORMS ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin-bottom: 6px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); color: var(--text-main); font-family: var(--font-body); font-size: 13px; transition: border-color .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); }
button:focus-visible, a:focus-visible, .nav-item:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
textarea { resize: vertical; min-height: 80px; }
input[readonly] { opacity: 0.6; cursor: not-allowed; }

.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters select, .filters input { width: auto; min-width: 130px; }

/* ── TABLES ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 10px 12px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-dim); border-bottom: 1px solid var(--border); }
td { padding: 11px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
tr:hover td { background: rgba(255,255,255,0.02); }

/* ── BADGES ────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge-critical { background: rgba(255,92,108,0.15); color: var(--red); }
.badge-high { background: rgba(255,122,69,0.15); color: var(--orange); }
.badge-medium { background: rgba(255,182,39,0.15); color: var(--yellow); }
.badge-low { background: rgba(59,158,255,0.15); color: var(--blue); }
.badge-open { background: rgba(59,158,255,0.15); color: var(--blue); }
.badge-in_progress { background: rgba(255,182,39,0.15); color: var(--yellow); }
.badge-pending { background: rgba(167,139,250,0.15); color: var(--purple); }
.badge-resolved { background: rgba(0,217,163,0.15); color: var(--green); }
.badge-closed { background: rgba(123,147,176,0.15); color: var(--text-muted); }
.badge-active { background: rgba(0,217,163,0.15); color: var(--green); }
.badge-maintenance { background: rgba(255,182,39,0.15); color: var(--yellow); }
.badge-offline { background: rgba(255,92,108,0.15); color: var(--red); }

.text-sm { font-size: 12px; }
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); }
.text-orange { color: var(--orange); }
.text-red { color: var(--red); }
.mt-16 { margin-top: 16px; }

/* ── MODALS ────────────────────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(5,10,20,0.75); backdrop-filter: blur(4px); z-index: 5000; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal { background: var(--card-bg); border: 1px solid var(--border-2); border-radius: var(--radius); width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 24px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 17px; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text-main); }
.modal-body { padding: 24px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 24px; border-top: 1px solid var(--border); }

/* ── MAP ───────────────────────────────────────────────────── */
#map-container { height: calc(100vh - 220px); min-height: 400px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
#map-standalone-container { height: calc(100vh - 180px); min-height: 500px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.leaflet-popup-content-wrapper { background: var(--card-bg); color: var(--text-main); border-radius: var(--radius-sm); }
.leaflet-popup-tip { background: var(--card-bg); }
.leaflet-popup-content { margin: 12px 14px; font-family: var(--font-body); }
.map-name-label { background: rgba(10,22,40,.75); color: var(--text-main); border: 1px solid var(--border-2);
  border-radius: 3px; padding: 1px 5px; font-size: 10px; font-weight: 600; box-shadow: none; white-space: nowrap; }
.map-name-label::before { display: none; }
.leaflet-container { background: #1a1a1a; }

.layer-panel { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.layer-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.layer-item:last-child { border-bottom: none; }
.layer-swatch { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; }

/* ── UPLOAD ZONE ───────────────────────────────────────────── */
.upload-zone { border: 2px dashed var(--border-2); border-radius: var(--radius); padding: 32px; text-align: center; cursor: pointer; transition: all .15s; }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--green); background: rgba(0,217,163,0.04); }
.upload-zone .upload-icon { margin-bottom: 8px; }
.upload-zone .upload-icon svg { width: 30px; height: 30px; stroke-width: 1.4; opacity: .55; color: var(--green); }

/* ── DEVICE GRID ───────────────────────────────────────────── */
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.device-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; transition: all .15s; }
.device-card:hover { border-color: var(--border-2); box-shadow: var(--shadow); }
.device-card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.device-hostname { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* ── MONITOR ───────────────────────────────────────────────── */
.monitor-status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-dim); }
.monitor-status-dot.live { background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 2s infinite; }
.monitor-status-dot.error { background: var(--red); }
.monitor-status-dot.idle { background: var(--yellow); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.pulse { animation: pulse 1.5s infinite; }

.monitor-tab-bar, .tab-bar { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.monitor-tab, .tab-btn { padding: 10px 16px; border: none; background: transparent; color: var(--text-muted); cursor: pointer; font-family: var(--font-body); font-size: 13px; font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.monitor-tab.active, .tab-btn.active { color: var(--green); border-bottom-color: var(--green); }

.counter-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; align-items: center; }
.counter-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 14px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 20px; font-size: 12px; }
.counter-chip strong { font-size: 18px; font-family: var(--font-display); }

.alert-row { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.alert-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; margin-top: 5px; }
.alert-body { flex: 1; }
.alert-title { font-weight: 600; font-size: 13px; }
.alert-title.severity-critical { color: var(--red); }
.alert-title.severity-high { color: var(--orange); }
.alert-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.alert-actions { flex-shrink: 0; }

.unconfigured-banner { text-align: center; padding: 48px 24px; }
.unconfigured-banner .banner-icon { margin-bottom: 12px; }
.unconfigured-banner .banner-icon svg { width: 40px; height: 40px; stroke-width: 1.4; opacity: .4; color: var(--text-muted); }

.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-state .empty-icon { margin-bottom: 12px; }
.empty-state .empty-icon svg { width: 36px; height: 36px; stroke-width: 1.4; opacity: .4; color: var(--text-muted); }

/* ── COMMENTS ──────────────────────────────────────────────── */
.comment-list { display: flex; flex-direction: column; gap: 12px; }
.comment { padding: 12px 14px; background: var(--bg); border-radius: var(--radius-sm); border-left: 2px solid var(--border-2); }
.comment.internal { border-left-color: var(--yellow); background: rgba(255,182,39,0.04); }
.comment-head { display: flex; justify-content: space-between; margin-bottom: 4px; }
.comment-author { font-weight: 600; font-size: 12px; }
.comment-time { font-size: 11px; color: var(--text-dim); }

/* ── TOAST ─────────────────────────────────────────────────── */
#toast { position: fixed; bottom: 24px; right: 24px; z-index: 6000; display: flex; flex-direction: column; gap: 8px; }
.toast-item { padding: 12px 18px; background: var(--card-bg); border: 1px solid var(--border-2); border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: 13px; animation: slideIn .2s; max-width: 340px; }
.toast-item.success { border-left: 3px solid var(--green); }
.toast-item.error { border-left: 3px solid var(--red); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── PROGRESS BARS ─────────────────────────────────────────── */
.metric-bar-track { height: 4px; background: rgba(255,255,255,0.08); border-radius: 2px; overflow: hidden; }
.metric-bar-fill { height: 100%; border-radius: 2px; transition: width .3s; }

/* ── DASHBOARD RECENT ──────────────────────────────────────── */
.recent-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.recent-row:last-child { border-bottom: none; }
